summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 14:57:25 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 14:57:25 +0000
commit5145ec78b86247f3fe84431dda61d9aa3d4541e6 (patch)
treed30c8ebb62e220b41211b04d3cf7400bfc2aafc6 /chrome/browser
parent57e953106d2de9186e68232b38c05cc20aca4596 (diff)
downloadchromium_src-5145ec78b86247f3fe84431dda61d9aa3d4541e6.zip
chromium_src-5145ec78b86247f3fe84431dda61d9aa3d4541e6.tar.gz
chromium_src-5145ec78b86247f3fe84431dda61d9aa3d4541e6.tar.bz2
Linux omnibox suggestions, only force LTR on URLs.
I had previously forced LTR on all match contents. These are usually URLs, but in the case of history they are the search query. Use the classification to only for LTR on match contents that are actually URLs. Review URL: http://codereview.chromium.org/155636 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20867 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 5b5d6ca..ad197aa 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -128,8 +128,12 @@ void SetupLayoutForMatch(PangoLayout* layout,
AutocompleteMatch::ACMatchClassifications classifications,
const GdkColor* base_color,
const std::string& prefix_text) {
+
+ // 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);
- pango_layout_set_text(layout, text_utf8.data(), text_utf8.size());
PangoAttrList* attrs = pango_attr_list_new();
@@ -148,7 +152,7 @@ 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) + prefix_text.size();
+ size_t offset = GetUTF8Offset(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
@@ -158,8 +162,13 @@ void SetupLayoutForMatch(PangoLayout* layout,
// special case that is not very common, but we should figure out and
// support it.
const GdkColor* color = base_color;
- if (i->style & ACMatchClassification::URL)
- color = &kURLTextColor;
+ if (i->style & ACMatchClassification::URL) {
+ color = &kURLTextColor;
+ // 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();
+ }
PangoAttribute* fg_attr = pango_attr_foreground_new(
color->red, color->green, color->blue);
@@ -174,6 +183,7 @@ void SetupLayoutForMatch(PangoLayout* layout,
pango_attr_list_insert(attrs, weight_attr); // Ownership taken.
}
+ pango_layout_set_text(layout, text_utf8.data(), text_utf8.size());
pango_layout_set_attributes(layout, attrs); // Ref taken.
pango_attr_list_unref(attrs);
}
@@ -460,7 +470,7 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
// Note: We force to URL to LTR for all text directions.
SetupLayoutForMatch(layout_, match.contents, match.contents_class,
- &kContentTextColor, std::string(kLRE));
+ &kContentTextColor, std::string());
int actual_content_width, actual_content_height;
pango_layout_get_size(layout_,