summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 20:07:47 +0000
committerxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 20:07:47 +0000
commit2248d729d57ca026d78e88355f760bb4048f8430 (patch)
treea40bdff57f59eac86f9adadd5baaee88172b9978
parent9debcda5ca7a1b952cebb342a845cb0be1bb94c4 (diff)
downloadchromium_src-2248d729d57ca026d78e88355f760bb4048f8430.zip
chromium_src-2248d729d57ca026d78e88355f760bb4048f8430.tar.gz
chromium_src-2248d729d57ca026d78e88355f760bb4048f8430.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
Because of the bug in PosFromChar() (see bug report for detailed information), we actually calculate the width of the string ourselves using font.GetStringWidth(). BUG=http://crbug.com/2780 TEST= 1 Start Chrome with a *new user data directory* 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 5 Message "Press Tab to search Google" should show correctly, not only "Tab" is displayed Review URL: http://codereview.chromium.org/155789 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21312 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/views/location_bar_view.cc49
-rw-r--r--chrome/browser/views/location_bar_view.h24
2 files changed, 38 insertions, 35 deletions
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 1e12760..43d588e 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -420,9 +420,9 @@ void LocationBarView::DoLayout(const bool force_layout) {
if (max_edit_width < 0)
return;
- const int text_width = TextDisplayWidth();
+ const int available_width = AvailableWidth(max_edit_width);
bool needs_layout = force_layout;
- needs_layout |= AdjustHints(text_width, max_edit_width);
+ needs_layout |= AdjustHints(available_width);
if (!needs_layout)
return;
@@ -461,13 +461,13 @@ void LocationBarView::DoLayout(const bool force_layout) {
gfx::Rect location_bounds(kEntryPadding, location_y, entry_width,
location_height);
if (selected_keyword_view_.IsVisible()) {
- LayoutView(true, &selected_keyword_view_, text_width, max_edit_width,
+ LayoutView(true, &selected_keyword_view_, available_width,
&location_bounds);
} else if (keyword_hint_view_.IsVisible()) {
- LayoutView(false, &keyword_hint_view_, text_width, max_edit_width,
+ LayoutView(false, &keyword_hint_view_, available_width,
&location_bounds);
} else if (type_to_search_view_.IsVisible()) {
- LayoutView(false, &type_to_search_view_, text_width, max_edit_width,
+ LayoutView(false, &type_to_search_view_, available_width,
&location_bounds);
}
@@ -483,32 +483,32 @@ int LocationBarView::TopMargin() const {
return std::min(kVertMargin, height());
}
-int LocationBarView::TextDisplayWidth() {
+int LocationBarView::AvailableWidth(int location_bar_width) {
#if defined(OS_WIN)
- POINT last_char_position =
- location_entry_->PosFromChar(location_entry_->GetTextLength());
- 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;
+ // Use font_.GetStringWidth() instead of
+ // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
+ // apparently buggy. In both LTR UI and RTL UI with left-to-right layout,
+ // PosFromChar(i) might return 0 when i is greater than 1.
+ return std::max(
+ location_bar_width - font_.GetStringWidth(location_entry_->GetText()), 0);
#else
NOTIMPLEMENTED();
- return 0;
+ return location_bar_width;
#endif
}
-bool LocationBarView::UsePref(int pref_width, int text_width, int max_width) {
- return (pref_width + kInnerPadding + text_width <= max_width);
+bool LocationBarView::UsePref(int pref_width, int available_width) {
+ return (pref_width + kInnerPadding <= available_width);
}
-bool LocationBarView::NeedsResize(View* view, int text_width, int max_width) {
+bool LocationBarView::NeedsResize(View* view, int available_width) {
gfx::Size size = view->GetPreferredSize();
- if (!UsePref(size.width(), text_width, max_width))
+ if (!UsePref(size.width(), available_width))
size = view->GetMinimumSize();
return (view->width() != size.width());
}
-bool LocationBarView::AdjustHints(int text_width, int max_width) {
+bool LocationBarView::AdjustHints(int available_width) {
const std::wstring keyword(location_entry_->model()->keyword());
const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
@@ -519,7 +519,7 @@ bool LocationBarView::AdjustHints(int text_width, int max_width) {
if (show_search_hint) {
// Only show type to search if all the text fits.
gfx::Size view_pref = type_to_search_view_.GetPreferredSize();
- show_search_hint = UsePref(view_pref.width(), text_width, max_width);
+ show_search_hint = UsePref(view_pref.width(), available_width);
}
// NOTE: This isn't just one big || statement as ToggleVisibility MUST be
@@ -534,24 +534,25 @@ bool LocationBarView::AdjustHints(int text_width, int max_width) {
needs_layout = true;
selected_keyword_view_.SetKeyword(keyword);
}
- needs_layout |= NeedsResize(&selected_keyword_view_, text_width, max_width);
+ needs_layout |= NeedsResize(&selected_keyword_view_, available_width);
} else if (show_keyword_hint) {
if (keyword_hint_view_.keyword() != keyword) {
needs_layout = true;
keyword_hint_view_.SetKeyword(keyword);
}
- needs_layout |= NeedsResize(&keyword_hint_view_, text_width, max_width);
+ needs_layout |= NeedsResize(&keyword_hint_view_, available_width);
}
return needs_layout;
}
-void LocationBarView::LayoutView(bool leading, views::View* view,
- int text_width, int max_width,
+void LocationBarView::LayoutView(bool leading,
+ views::View* view,
+ int available_width,
gfx::Rect* bounds) {
DCHECK(view && bounds);
gfx::Size view_size = view->GetPreferredSize();
- if (!UsePref(view_size.width(), text_width, max_width))
+ if (!UsePref(view_size.width(), available_width))
view_size = view->GetMinimumSize();
if (view_size.width() + kInnerPadding < bounds->width()) {
view->SetVisible(true);
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index d5d82e4..1ab1811 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -383,30 +383,32 @@ class LocationBarView : public LocationBar,
// Returns the height in pixels of the margin at the top of the bar.
int TopMargin() const;
- // Returns the width in pixels of the contents of the edit.
- int TextDisplayWidth();
-
- // Returns true if the preferred size should be used for a view whose width
- // is pref_width, the width of the text in the edit is text_width, and
- // max_width is the maximum width of the edit. If this returns false, the
+ // Returns the amount of horizontal space (in pixels) out of
+ // |location_bar_width| that is not taken up by the actual text in
+ // location_entry_.
+ int AvailableWidth(int location_bar_width);
+
+ // Returns whether the |available_width| is large enough to contain a view
+ // with preferred width |pref_width| at its preferred size. If this returns
+ // true, the preferred size should be used. If this returns false, the
// minimum size of the view should be used.
- bool UsePref(int pref_width, int text_width, int max_width);
+ bool UsePref(int pref_width, int available_width);
// Returns true if the view needs to be resized. This determines whether the
// min or pref should be used, and returns true if the view is not at that
// size.
- bool NeedsResize(View* view, int text_width, int max_width);
+ bool NeedsResize(View* view, int available_width);
// Adjusts the keyword hint, selected keyword and type to search views
// based on the contents of the edit. Returns true if something changed that
// necessitates a layout.
- bool AdjustHints(int text_width, int max_width);
+ bool AdjustHints(int available_width);
// If View fits in the specified region, it is made visible and the
// bounds are adjusted appropriately. If the View does not fit, it is
// made invisible.
- void LayoutView(bool leading, views::View* view, int text_width,
- int max_width, gfx::Rect* bounds);
+ void LayoutView(bool leading, views::View* view, int available_width,
+ gfx::Rect* bounds);
// Sets the security icon to display. Note that no repaint is done.
void SetSecurityIcon(ToolbarModel::Icon icon);