diff options
author | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 21:32:14 +0000 |
---|---|---|
committer | xji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-24 21:32:14 +0000 |
commit | 6c73dd61bc320f9f2df7ade207d3aed1d99c8d81 (patch) | |
tree | cc4c1033fed45f056b276cc933392f76d70ebb54 /chrome/browser/autocomplete | |
parent | d09660fada816968f0a89fd6b1fcc7674e680a16 (diff) | |
download | chromium_src-6c73dd61bc320f9f2df7ade207d3aed1d99c8d81.zip chromium_src-6c73dd61bc320f9f2df7ade207d3aed1d99c8d81.tar.gz chromium_src-6c73dd61bc320f9f2df7ade207d3aed1d99c8d81.tar.bz2 |
This CL fixes issue 43800 - RTL/LTR eliding in Linux omnibox dropdown.
Unlike Windows, in Linux, we do not draw the strings in autocomplete popup by ourselves. Instead, we rely on Pango to draw the strings. We only need to pass the text, the attribute, and the width to Pango, and Pango will draw the text correctly (taking care of visual runs for bidi text).
The only small problems are that:
when the UI is RTL, for pure English text, we need to insert LRE mark so that the ending punctuation is drawn correctly as is (not flipped), for example "....(choose location)" will not be drawn as "(....(choose location" in RTL UI.
Also, for some (not all) pure English text, when eliding, the ellipsis appears at the very left of the string in RTL UI. I do not know the reason of such inconsistency, but looks like adding LRE mark to pure English also forces the ellipsis appears at the right of the string.
BUG=43800
TEST=Omnibox should elide long URLs, mixed LTR/RTL text, etc. correctly in both LTR and RTL locales
Review URL: http://codereview.chromium.org/2824027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50773 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index 3d9d96f..a6605ba 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -120,12 +120,25 @@ void SetupLayoutForMatch(PangoLayout* layout, const GdkColor* base_color, const GdkColor* url_color, const std::string& prefix_text) { + // In RTL, mark text with left-to-right embedding mark if there is no strong + // RTL characters inside it, so the ending punctuation displays correctly + // and the eliding ellipsis displays correctly. We only mark the text with + // LRE. Wrapping it with LRE and PDF by calling AdjustStringForLocaleDirection + // will render the elllipsis at the left of the elided pure LTR text. + bool marked_with_lre = false; + std::wstring localized_text = text; + bool is_rtl = base::i18n::IsRTL(); + if (is_rtl && !base::i18n::StringContainsStrongRTLChars(localized_text)) { + localized_text.insert(0, 1, + static_cast<wchar_t>(base::i18n::kLeftToRightEmbeddingMark)); + marked_with_lre = true; + } // We can have a prefix, or insert additional characters while processing the // classifications. We need to take this in to account when we translate the // wide offsets in the classification into text_utf8 byte offsets. size_t additional_offset = prefix_text.size(); // Length in utf-8 bytes. - std::string text_utf8 = prefix_text + WideToUTF8(text); + std::string text_utf8 = prefix_text + WideToUTF8(localized_text); PangoAttrList* attrs = pango_attr_list_new(); @@ -144,7 +157,8 @@ void SetupLayoutForMatch(PangoLayout* layout, // portion correctly, we just don't need to compute the end offset. for (ACMatchClassifications::const_iterator i = classifications.begin(); i != classifications.end(); ++i) { - size_t offset = GetUTF8Offset(text, i->offset) + additional_offset; + size_t offset = GetUTF8Offset(localized_text, i->offset) + + additional_offset; // TODO(deanm): All the colors should probably blend based on whether this // result is selected or not. This would include the green URLs. Right @@ -157,9 +171,11 @@ void SetupLayoutForMatch(PangoLayout* layout, if (i->style & ACMatchClassification::URL) { color = url_color; // Insert a left to right embedding to make sure that URLs are shown LTR. - std::string lre(kLRE); - text_utf8.insert(offset, lre); - additional_offset += lre.size(); + if (is_rtl && !marked_with_lre) { + std::string lre(kLRE); + text_utf8.insert(offset, lre); + additional_offset += lre.size(); + } } PangoAttribute* fg_attr = pango_attr_foreground_new( @@ -446,9 +462,9 @@ void AutocompletePopupViewGtk::Show(size_t num_results) { gtk_widget_set_size_request(window_, allocation.width + (kBorderThickness * 2) - (horizontal_offset * 2), (num_results * kHeightPerResult) + (kBorderThickness * 2)); - gtk_widget_show(window_); - StackWindow(); - opened_ = true; + gtk_widget_show(window_); + StackWindow(); + opened_ = true; } void AutocompletePopupViewGtk::Hide() { |