Bug 214180 - [GTK] MiniBrowser: title of back-forward menu items needs to be truncated when it's too large
Summary: [GTK] MiniBrowser: title of back-forward menu items needs to be truncated whe...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2020-07-10 04:03 PDT by Carlos Garcia Campos
Modified: 2020-07-10 23:32 PDT (History)
2 users (show)

See Also:


Attachments
Patch (2.77 KB, patch)
2020-07-10 04:06 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2020-07-10 04:03:56 PDT
The popover menu doesn't set ellipsize on the inner label, so we need to do it manually. In the case of GTK4 we also need to markup escape it.
Comment 1 Carlos Garcia Campos 2020-07-10 04:06:36 PDT
Created attachment 403956 [details]
Patch
Comment 2 Adrian Perez 2020-07-10 05:38:26 PDT
Comment on attachment 403956 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=403956&action=review

> Tools/MiniBrowser/gtk/BrowserWindow.c:235
> +            displayTitle[MAX_TITLE - 1] = '.';

I would use an actual ellipsis character (“…”, U+2026) which in
UTF-8 is the sequence of bytes 0xE2, 0x80, 0xA6:

  displayTitle[MAX_TITLE - 3] = 0xE2;
  displayTitle[MAX_TITLE - 2] = 0x80;
  displayTitle[MAX_TITLE - 1] = 0xA6;

😉️
Comment 3 Carlos Garcia Campos 2020-07-10 06:20:27 PDT
Committed r264217: <https://trac.webkit.org/changeset/264217>
Comment 4 Adrian Perez 2020-07-10 12:41:01 PDT
Comment on attachment 403956 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=403956&action=review

>> Tools/MiniBrowser/gtk/BrowserWindow.c:235
>> +            displayTitle[MAX_TITLE - 1] = '.';
> 
> I would use an actual ellipsis character (“…”, U+2026) which in
> UTF-8 is the sequence of bytes 0xE2, 0x80, 0xA6:
> 
>   displayTitle[MAX_TITLE - 3] = 0xE2;
>   displayTitle[MAX_TITLE - 2] = 0x80;
>   displayTitle[MAX_TITLE - 1] = 0xA6;
> 
> 😉️

I just had a sudden realization: If the “MAX_TITLE - 3” index falls
in the middle of an UTF-8 multi byte sequence, the string resulting
from ellipsizing this way results in an invalid UTF-8 string.

Dunno if there is a better option, but one idea would be to use
g_utf8_offset_to_pointer(displayTitle, MAX_TITLE - 3) to find out
the corresponding byte offset for the amount of *Unicode* characters
(not bytes) we want to show before the ellipsis, and then append the
ellipsis there.

Sorry for not noticing this earlier.
Comment 5 Carlos Garcia Campos 2020-07-10 23:32:48 PDT
(In reply to Adrian Perez from comment #4)
> Comment on attachment 403956 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=403956&action=review
> 
> >> Tools/MiniBrowser/gtk/BrowserWindow.c:235
> >> +            displayTitle[MAX_TITLE - 1] = '.';
> > 
> > I would use an actual ellipsis character (“…”, U+2026) which in
> > UTF-8 is the sequence of bytes 0xE2, 0x80, 0xA6:
> > 
> >   displayTitle[MAX_TITLE - 3] = 0xE2;
> >   displayTitle[MAX_TITLE - 2] = 0x80;
> >   displayTitle[MAX_TITLE - 1] = 0xA6;
> > 
> > 😉️
> 
> I just had a sudden realization: If the “MAX_TITLE - 3” index falls
> in the middle of an UTF-8 multi byte sequence, the string resulting
> from ellipsizing this way results in an invalid UTF-8 string.
> 
> Dunno if there is a better option, but one idea would be to use
> g_utf8_offset_to_pointer(displayTitle, MAX_TITLE - 3) to find out
> the corresponding byte offset for the amount of *Unicode* characters
> (not bytes) we want to show before the ellipsis, and then append the
> ellipsis there.
> 
> Sorry for not noticing this earlier.

You are right, I'll try to fix it in a follow up.