diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 23:15:21 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 23:15:21 +0000 |
commit | c2f4bdb7deec2fe9aaa3583ff2066e634001be8f (patch) | |
tree | e1ba425190c39667910ff1c864bdee6afc4bd191 /views | |
parent | 6e76d8d105739f3b40274dd0247a75ea44e46a89 (diff) | |
download | chromium_src-c2f4bdb7deec2fe9aaa3583ff2066e634001be8f.zip chromium_src-c2f4bdb7deec2fe9aaa3583ff2066e634001be8f.tar.gz chromium_src-c2f4bdb7deec2fe9aaa3583ff2066e634001be8f.tar.bz2 |
Eliminate View::UILayoutIsRightToLeft() to standardize on base::i18n::IsRTL(). Was only needed for EnableUIMirroringForRTLLanguages(), which was only used by Views::Label, which already had this capability via set_rtl_alignment_mode().
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1991002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/button/button_dropdown.cc | 2 | ||||
-rw-r--r-- | views/controls/button/menu_button.cc | 4 | ||||
-rw-r--r-- | views/controls/image_view.cc | 2 | ||||
-rw-r--r-- | views/controls/label.cc | 2 | ||||
-rw-r--r-- | views/controls/label_unittest.cc | 6 | ||||
-rw-r--r-- | views/controls/menu/menu_controller.cc | 2 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.cc | 2 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_win.cc | 4 | ||||
-rw-r--r-- | views/controls/native_control.cc | 4 | ||||
-rw-r--r-- | views/controls/native_control_win.cc | 4 | ||||
-rw-r--r-- | views/controls/resize_gripper.cc | 2 | ||||
-rw-r--r-- | views/controls/single_split_view.cc | 4 | ||||
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_win.cc | 6 | ||||
-rw-r--r-- | views/controls/table/native_table_win.cc | 2 | ||||
-rw-r--r-- | views/controls/table/table_view.cc | 4 | ||||
-rw-r--r-- | views/controls/tree/tree_view.cc | 6 | ||||
-rw-r--r-- | views/view.cc | 8 | ||||
-rw-r--r-- | views/view.h | 32 |
18 files changed, 33 insertions, 63 deletions
diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc index 2d3f30e..7b2b3d0 100644 --- a/views/controls/button/button_dropdown.cc +++ b/views/controls/button/button_dropdown.cc @@ -134,7 +134,7 @@ void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) { // is right-to-left. gfx::Point menu_position(lb.origin()); menu_position.Offset(0, lb.height() - 1); - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) menu_position.Offset(lb.width() - 1, 0); View::ConvertPointToScreen(this, &menu_position); diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc index b45c2ac..b515e17 100644 --- a/views/controls/button/menu_button.cc +++ b/views/controls/button/menu_button.cc @@ -125,11 +125,11 @@ bool MenuButton::Activate() { // The position of the menu depends on whether or not the locale is // right-to-left. gfx::Point menu_position(lb.right(), lb.bottom()); - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) menu_position.set_x(lb.x()); View::ConvertPointToScreen(this, &menu_position); - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) menu_position.Offset(2, -4); else menu_position.Offset(-2, -4); diff --git a/views/controls/image_view.cc b/views/controls/image_view.cc index 9728332..fe6ad38 100644 --- a/views/controls/image_view.cc +++ b/views/controls/image_view.cc @@ -80,7 +80,7 @@ gfx::Point ImageView::ComputeImageOrigin(const gfx::Size& image_size) const { // horizontal alignment is set to trailing, then we'll use left alignment for // the image instead of right alignment if the UI layout is RTL. Alignment actual_horiz_alignment = horiz_alignment_; - if (UILayoutIsRightToLeft() && (horiz_alignment_ != CENTER)) + if (base::i18n::IsRTL() && (horiz_alignment_ != CENTER)) actual_horiz_alignment = (horiz_alignment_ == LEADING) ? TRAILING : LEADING; switch (actual_horiz_alignment) { case LEADING: x = insets.left(); break; diff --git a/views/controls/label.cc b/views/controls/label.cc index 2aff154..9ab4e36 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -135,7 +135,7 @@ void Label::SetHorizontalAlignment(Alignment a) { // If the View's UI layout is right-to-left and rtl_alignment_mode_ is // USE_UI_ALIGNMENT, we need to flip the alignment so that the alignment // settings take into account the text directionality. - if (UILayoutIsRightToLeft() && (rtl_alignment_mode_ == USE_UI_ALIGNMENT) && + if (base::i18n::IsRTL() && (rtl_alignment_mode_ == USE_UI_ALIGNMENT) && (a != ALIGN_CENTER)) a = (a == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; if (horiz_alignment_ != a) { diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc index 19751ca..d238cb3 100644 --- a/views/controls/label_unittest.cc +++ b/views/controls/label_unittest.cc @@ -287,7 +287,7 @@ TEST(LabelTest, DrawSingleLineString) { // Turn off mirroring so that we don't need to figure out if // align right really means align left. - label.EnableUIMirroringForRTLLanguages(false); + label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); std::wstring test_text(L"Here's a string with no returns."); label.SetText(test_text); @@ -405,7 +405,7 @@ TEST(LabelTest, DrawMultiLineString) { // Turn off mirroring so that we don't need to figure out if // align right really means align left. - label.EnableUIMirroringForRTLLanguages(false); + label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); std::wstring test_text(L"Another string\nwith returns\n\n!"); label.SetText(test_text); @@ -550,7 +550,6 @@ TEST(LabelTest, DrawSingleLineStringInRTL) { Label label; label.SetFocusable(false); - label.EnableUIMirroringForRTLLanguages(true); std::string locale = l10n_util::GetApplicationLocale(std::wstring()); base::i18n::SetICUDefaultLocale("he"); @@ -673,7 +672,6 @@ TEST(LabelTest, DrawMultiLineStringInRTL) { label.SetFocusable(false); // Test for RTL. - label.EnableUIMirroringForRTLLanguages(true); std::string locale = l10n_util::GetApplicationLocale(std::wstring()); base::i18n::SetICUDefaultLocale("he"); diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index a89aa8c..9005fd6 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -1264,7 +1264,7 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, // We must make sure we take into account the UI layout. If the layout is // RTL, then a 'leading' menu is positioned to the left of the parent menu // item and not to the right. - bool layout_is_rtl = item->UILayoutIsRightToLeft(); + bool layout_is_rtl = base::i18n::IsRTL(); bool create_on_the_right = (prefer_leading && !layout_is_rtl) || (!prefer_leading && layout_is_rtl); diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 64b8270..29864b2 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -386,7 +386,7 @@ void MenuItemView::PrepareForRun(bool has_mnemonics) { int MenuItemView::GetDrawStringFlags() { int flags = 0; - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; else flags |= gfx::Canvas::TEXT_ALIGN_LEFT; diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc index 489fe90..cb956cb 100644 --- a/views/controls/menu/menu_item_view_win.cc +++ b/views/controls/menu/menu_item_view_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -134,7 +134,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { // locale is RTL) then we should make sure the menu arrow points to the // right direction. NativeTheme::MenuArrowDirection arrow_direction; - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) arrow_direction = NativeTheme::LEFT_POINTING_ARROW; else arrow_direction = NativeTheme::RIGHT_POINTING_ARROW; diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc index 347406f..f714382 100644 --- a/views/controls/native_control.cc +++ b/views/controls/native_control.cc @@ -330,7 +330,7 @@ DWORD NativeControl::GetAdditionalExStyle() const { // extended window style for a right-to-left layout so the subclass creates // a mirrored HWND for the underlying control. DWORD ex_style = 0; - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) ex_style |= l10n_util::GetExtendedStyles(); return ex_style; @@ -341,7 +341,7 @@ DWORD NativeControl::GetAdditionalRTLStyle() const { // extended window style for a right-to-left layout so the subclass creates // a mirrored HWND for the underlying control. DWORD ex_style = 0; - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) ex_style |= l10n_util::GetExtendedTooltipStyles(); return ex_style; diff --git a/views/controls/native_control_win.cc b/views/controls/native_control_win.cc index baa5a19..c73d17c 100644 --- a/views/controls/native_control_win.cc +++ b/views/controls/native_control_win.cc @@ -134,7 +134,7 @@ DWORD NativeControlWin::GetAdditionalExStyle() const { // extended window style for a right-to-left layout so the subclass creates // a mirrored HWND for the underlying control. DWORD ex_style = 0; - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) ex_style |= l10n_util::GetExtendedStyles(); return ex_style; @@ -145,7 +145,7 @@ DWORD NativeControlWin::GetAdditionalRTLStyle() const { // extended window style for a right-to-left layout so the subclass creates // a mirrored HWND for the underlying control. DWORD ex_style = 0; - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) ex_style |= l10n_util::GetExtendedTooltipStyles(); return ex_style; diff --git a/views/controls/resize_gripper.cc b/views/controls/resize_gripper.cc index 1a49957..4d6d93b 100644 --- a/views/controls/resize_gripper.cc +++ b/views/controls/resize_gripper.cc @@ -87,7 +87,7 @@ void ResizeGripper::ReportResizeAmount(int resize_amount, bool last_update) { View::ConvertPointToScreen(this, &point); resize_amount = point.x() - initial_position_; - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) resize_amount = -1 * resize_amount; delegate_->OnResize(resize_amount, last_update); } diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc index f76acb3..298a540 100644 --- a/views/controls/single_split_view.cc +++ b/views/controls/single_split_view.cc @@ -151,7 +151,7 @@ bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - drag_info_.initial_mouse_offset; - if (is_horizontal_ && UILayoutIsRightToLeft()) + if (is_horizontal_ && base::i18n::IsRTL()) delta_offset *= -1; // Honor the minimum size when resizing. gfx::Size min = GetChildViewAt(0)->GetMinimumSize(); @@ -188,7 +188,7 @@ bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { int divider_relative_offset; if (is_horizontal_) { divider_relative_offset = - p.x() - GetChildViewAt(UILayoutIsRightToLeft() ? 1 : 0)->width(); + p.x() - GetChildViewAt(base::i18n::IsRTL() ? 1 : 0)->width(); } else { divider_relative_offset = p.y() - GetChildViewAt(0)->height(); } diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 26579f9..87f2ebb 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -107,7 +107,7 @@ void NativeTabbedPaneWin::AddNativeTab(int index, // If the locale is RTL, we set the TCIF_RTLREADING so that BiDi text is // rendered properly on the tabs. - if (UILayoutIsRightToLeft()) { + if (base::i18n::IsRTL()) { tcitem.mask |= TCIF_RTLREADING; } @@ -222,7 +222,7 @@ void NativeTabbedPaneWin::CreateNativeControl() { // Explicitly setting the WS_EX_LAYOUTRTL property for the HWND (see above // for a thorough explanation regarding why we waited until |content_window_| // if created before we set this property for the tabbed pane's HWND). - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) l10n_util::HWNDSetRTLLayout(tab_control); RootView* root_view = content_window_->GetRootView(); diff --git a/views/controls/table/native_table_win.cc b/views/controls/table/native_table_win.cc index 22ca250..d34856f 100644 --- a/views/controls/table/native_table_win.cc +++ b/views/controls/table/native_table_win.cc @@ -670,7 +670,7 @@ LRESULT CALLBACK NativeTableWin::TableWndProc(HWND window, // // As a work around this uses the position of the cursor and ignores // the position supplied in the l_param. - if (table->UILayoutIsRightToLeft() && + if (base::i18n::IsRTL() && (GET_X_LPARAM(l_param) != -1 || GET_Y_LPARAM(l_param) != -1)) { POINT screen_point; GetCursorPos(&screen_point); diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index c1d07d9..b165ba4 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -493,7 +493,7 @@ gfx::Point TableView::GetKeyboardContextMenuLocation() { } } gfx::Point screen_loc(0, y); - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) screen_loc.set_x(width()); ConvertPointToScreen(this, &screen_loc); return screen_loc; @@ -538,7 +538,7 @@ LRESULT CALLBACK TableView::TableWndProc(HWND window, // // As a work around this uses the position of the cursor and ignores // the position supplied in the l_param. - if (table_view->UILayoutIsRightToLeft() && + if (base::i18n::IsRTL() && (GET_X_LPARAM(l_param) != -1 || GET_Y_LPARAM(l_param) != -1)) { POINT screen_point; GetCursorPos(&screen_point); diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc index e5587b9..b544abc 100644 --- a/views/controls/tree/tree_view.cc +++ b/views/controls/tree/tree_view.cc @@ -64,7 +64,7 @@ bool TreeView::GetAccessibleRole(AccessibilityTypes::Role* role) { bool TreeView::GetAccessibleState(AccessibilityTypes::State* state) { DCHECK(state); - + *state = AccessibilityTypes::STATE_READONLY; return true; } @@ -357,7 +357,7 @@ gfx::Point TreeView::GetKeyboardContextMenuLocation() { } } gfx::Point screen_loc(0, y); - if (UILayoutIsRightToLeft()) + if (base::i18n::IsRTL()) screen_loc.set_x(width()); ConvertPointToScreen(this, &screen_loc); return screen_loc; @@ -656,7 +656,7 @@ HIMAGELIST TreeView::CreateImageList() { std::vector<SkBitmap> model_images; model_->GetIcons(&model_images); - bool rtl = UILayoutIsRightToLeft(); + bool rtl = base::i18n::IsRTL(); // Creates the default image list used for trees. SkBitmap* closed_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( diff --git a/views/view.cc b/views/view.cc index d04ccec..4978003 100644 --- a/views/view.cc +++ b/views/view.cc @@ -10,7 +10,6 @@ #endif #include "app/drag_drop_types.h" -#include "base/i18n/rtl.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/scoped_handle.h" @@ -71,7 +70,6 @@ View::View() accessibility_(NULL), #endif drag_controller_(NULL), - ui_mirroring_is_enabled_for_rtl_languages_(true), flip_canvas_on_paint_for_rtl_ui_(false) { } @@ -234,10 +232,6 @@ void View::SetLayoutManager(LayoutManager* layout_manager) { layout_manager_->Installed(this); } -bool View::UILayoutIsRightToLeft() const { - return (ui_mirroring_is_enabled_for_rtl_languages_ && base::i18n::IsRTL()); -} - //////////////////////////////////////////////////////////////////////////////// // // View - Right-to-left UI layout @@ -250,7 +244,7 @@ int View::MirroredX() const { } int View::MirroredLeftPointForRect(const gfx::Rect& bounds) const { - return UILayoutIsRightToLeft() ? + return base::i18n::IsRTL() ? (width() - bounds.x() - bounds.width()) : bounds.x(); } diff --git a/views/view.h b/views/view.h index bdf1b23..68d583d 100644 --- a/views/view.h +++ b/views/view.h @@ -14,6 +14,7 @@ #include <vector> #include "app/os_exchange_data.h" +#include "base/i18n/rtl.h" #include "base/scoped_ptr.h" #include "gfx/native_widget_types.h" #include "gfx/rect.h" @@ -288,24 +289,6 @@ class View : public AcceleratorTarget { // Right-to-left UI layout functions - // Indicates whether the UI layout for this view is right-to-left. The view - // has an RTL UI layout if RTL hasn't been disabled for the view and if the - // locale's language is an RTL language. - bool UILayoutIsRightToLeft() const; - - // Enables or disables the right-to-left layout for the view. If |enable| is - // true, the layout will become right-to-left only if the locale's language - // is right-to-left. - // - // By default, right-to-left UI layout is enabled for the view and therefore - // this function must be called (with false as the |enable| parameter) in - // order to disable the right-to-left layout property for a specific instance - // of the view. Disabling the right-to-left UI layout is necessary in case a - // UI element will not appear correctly when mirrored. - void EnableUIMirroringForRTLLanguages(bool enable) { - ui_mirroring_is_enabled_for_rtl_languages_ = enable; - } - // This method determines whether the gfx::Canvas object passed to // View::Paint() needs to be transformed such that anything drawn on the // canvas object during View::Paint() is flipped horizontally. @@ -315,13 +298,13 @@ class View : public AcceleratorTarget { // a flipped gfx::Canvas when the UI layout is right-to-left need to call // EnableCanvasFlippingForRTLUI(). bool FlipCanvasOnPaintForRTLUI() const { - return flip_canvas_on_paint_for_rtl_ui_ ? UILayoutIsRightToLeft() : false; + return flip_canvas_on_paint_for_rtl_ui_ ? base::i18n::IsRTL() : false; } // Enables or disables flipping of the gfx::Canvas during View::Paint(). // Note that if canvas flipping is enabled, the canvas will be flipped only // if the UI layout is right-to-left; that is, the canvas will be flipped - // only if UILayoutIsRightToLeft() returns true. + // only if base::i18n::IsRTL() returns true. // // Enabling canvas flipping is useful for leaf views that draw a bitmap that // needs to be flipped horizontally when the UI layout is right-to-left @@ -361,7 +344,7 @@ class View : public AcceleratorTarget { // MirroredXCoordinateInsideView(20) -> 80 // MirroredXCoordinateInsideView(99) -> 1 int MirroredXCoordinateInsideView(int x) const { - return UILayoutIsRightToLeft() ? width() - x : x; + return base::i18n::IsRTL() ? width() - x : x; } // Given a X coordinate and a width inside the View, this function returns @@ -374,7 +357,7 @@ class View : public AcceleratorTarget { // MirroredXCoordinateInsideView(0, 10) -> 90 // MirroredXCoordinateInsideView(20, 20) -> 60 int MirroredXWithWidthInsideView(int x, int w) const { - return UILayoutIsRightToLeft() ? width() - x - w : x; + return base::i18n::IsRTL() ? width() - x - w : x; } // Painting functions @@ -1287,11 +1270,6 @@ class View : public AcceleratorTarget { DragController* drag_controller_; - // Indicates whether or not the view is going to be mirrored (that is, use a - // right-to-left UI layout) if the locale's language is a right-to-left - // language like Arabic or Hebrew. - bool ui_mirroring_is_enabled_for_rtl_languages_; - // Indicates whether or not the gfx::Canvas object passed to View::Paint() // is going to be flipped horizontally (using the appropriate transform) on // right-to-left locales for this View. |