summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-07 18:35:15 +0000
committerxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-07 18:35:15 +0000
commit34dc5d9713620a3859d4b12cf400d0314d68a043 (patch)
tree426a1336ef4b6db7f47c223ccc27eba830678ee3 /chrome/browser
parent3fae54b2355ba858551f875245d135bf17f0d5c5 (diff)
downloadchromium_src-34dc5d9713620a3859d4b12cf400d0314d68a043.zip
chromium_src-34dc5d9713620a3859d4b12cf400d0314d68a043.tar.gz
chromium_src-34dc5d9713620a3859d4b12cf400d0314d68a043.tar.bz2
This CL fixes issue 2780 - RTL: Omnibar - message "Press Tab to search Google" doesn't show correctly in a "New Tab" for RTL locales.
(http://crbug.com/2780) The error happens in LocationBarView::TextDisplayWidth() which does not correctly calculate the location entry's text display width. The fix itself contains comments so hope it is self-explained. Test steps: 1. Start Chrome with a new user data directory (or clean up all browsing data) and make sure the UI language is Hebrew. 2 Type www.google.com in the omnibox and press Enter. 3 Close and re-open the browser. 4 Type character "h" in Ominibox Without the fix, only "tab" button is showing as keyword hint. With the fix, Hebrew translation of "press tab to search google" is displayed. Please be noted: you need to have enough space in omnibox in order for the whole keyword hint to be displayed, otherwise, only "tab" button will be displayed. Review URL: http://codereview.chromium.org/100360 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/views/location_bar_view.cc49
1 files changed, 45 insertions, 4 deletions
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index d7267ea..7a89fba 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -433,12 +433,53 @@ int LocationBarView::TopMargin() const {
}
int LocationBarView::TextDisplayWidth() {
- POINT last_char_position =
- location_entry_->PosFromChar(location_entry_->GetTextLength());
+ // location_entry_->PosFromChar(location_entry_->GetTextLength()) returns
+ // 1. The rightmost position for LTR UI, in which the layout and the
+ // alignment are both left-to-right. Or
+ // 2. The leftmost position for a text if the layout and the alignment of the
+ // text are both right-to-left.
+ //
+ // But the are two problems:
+ // 1. In our current RTL UI, text in Omnibox is right aligned, but the layout
+ // is left-to-right. Please see http://crbug.com/6573 for detail information.
+ // 2. In both LTR and RTL UI , there is the following problem in
+ // PosFromChar(), which I do not know the reason.
+ // location_entry_->PosFromChar(location_entry_->GetTextLength()) might
+ // return 0. For example, type 'h' in omnibox which should display the first
+ // matched list, say "http://www.google.com/", with "ttp://www.google.com/"
+ // highlighted, in omnibox. location_entry_->GetTextLength() returns 22,
+ // which is the length of "http://www.google.com/". But
+ // location_entry_->PosFromChar(i) returns 0 when i is greater than 1.
+ // location_entry_->PosFromChar(i) should return the right position after the
+ // last character when i is greater than 22.
+ //
+ // Due to the above 2 problems, we do not use
+ // location_entry_->PosFromChar(location_entry_->GetTextLength()) to compute
+ // text display width. Instead, we compute and compare each character's
+ // position to find out the leftmost position for RTL UI, or the rightmost
+ // position for LTR UI.
POINT scroll_position;
location_entry_->GetScrollPos(&scroll_position);
- const int position_x = last_char_position.x + scroll_position.x;
- return UILayoutIsRightToLeft() ? width() - position_x : position_x;
+
+ int max_text_length = location_entry_->GetTextLength();
+ if (UILayoutIsRightToLeft()) {
+ int leftmost_position = location_entry_->PosFromChar(0).x;
+ for (int i = 1; i <= max_text_length; ++i) {
+ int x = location_entry_->PosFromChar(i).x;
+ if (x && x < leftmost_position)
+ leftmost_position = x;
+ }
+ return location_entry_view_->width() - leftmost_position -
+ scroll_position.x;
+ } else {
+ int rightmost_position = location_entry_->PosFromChar(max_text_length).x;
+ for (int i = 0; i < max_text_length; ++i) {
+ int x = location_entry_->PosFromChar(i).x;
+ if (x > rightmost_position)
+ rightmost_position = x;
+ }
+ return rightmost_position + scroll_position.x;
+ }
}
bool LocationBarView::UsePref(int pref_width, int text_width, int max_width) {