Index: chrome/browser/ui/views/toolbar/wrench_menu.cc |
diff --git a/chrome/browser/ui/views/toolbar/wrench_menu.cc b/chrome/browser/ui/views/toolbar/wrench_menu.cc |
index e3db7ce41575d32ae5fa0e8d621272fb32c16600..4f88b49fc7b8a525d567cece41563e059ecf63c4 100644 |
--- a/chrome/browser/ui/views/toolbar/wrench_menu.cc |
+++ b/chrome/browser/ui/views/toolbar/wrench_menu.cc |
@@ -74,13 +74,6 @@ using views::View; |
namespace { |
-// Colors used for buttons. |
-const SkColor kEnabledTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255); |
-const SkColor kHoverTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242); |
-const SkColor kFocusedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235); |
- |
-const SkColor kTouchButtonText = 0xff5a5a5a; |
- |
// Horizontal padding on the edges of the buttons. |
const int kHorizontalPadding = 6; |
// Horizontal padding for a touch enabled menu. |
@@ -188,75 +181,76 @@ class MenuButtonBackground : public views::Background { |
// Overridden from views::Background. |
virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { |
- CustomButton::ButtonState state = |
- (!strcmp(view->GetClassName(), views::Label::kViewClassName)) ? |
- CustomButton::STATE_NORMAL : static_cast<CustomButton*>(view)->state(); |
+ CustomButton* button = CustomButton::AsCustomButton(view); |
+ views::Button::ButtonState state = |
+ button ? button->state() : views::Button::STATE_NORMAL; |
int w = view->width(); |
int h = view->height(); |
#if defined(USE_AURA) |
- if (use_new_menu_ && |
- view->GetNativeTheme() == ui::NativeThemeAura::instance()) { |
- // Normal buttons get a border drawn on the right side and the rest gets |
- // filled in. The left button however does not get a line to combine |
- // buttons. |
- int border = 0; |
- if (type_ != RIGHT_BUTTON) { |
- border = 1; |
- canvas->FillRect(gfx::Rect(0, 0, border, h), |
- BorderColor(view, CustomButton::STATE_NORMAL)); |
- } |
- canvas->FillRect(gfx::Rect(border, 0, w - border, h), |
- touch_background_color(state)); |
+ // Normal buttons get a border drawn on the right side and the rest gets |
+ // filled in. The left button however does not get a line to combine |
+ // buttons. |
+ int border = 0; |
+ if (type_ != RIGHT_BUTTON) { |
+ border = 1; |
+ canvas->FillRect(gfx::Rect(0, 0, border, h), |
+ BorderColor(view, views::Button::STATE_NORMAL)); |
+ } |
+ if (use_new_menu_) { |
+ gfx::Rect bounds(view->GetLocalBounds()); |
+ bounds.set_x(view->GetMirroredXForRect(bounds)); |
+ DrawBackground(canvas, view, bounds, state); |
return; |
} |
+ if (use_new_menu_) |
+ return; |
#endif |
- const SkColor background = BackgroundColor(view, state); |
- const SkColor border = BorderColor(view, state); |
+ const SkColor border_color = BorderColor(view, state); |
switch (TypeAdjustedForRTL()) { |
// TODO(pkasting): Why don't all the following use SkPaths with rounded |
// corners? |
case LEFT_BUTTON: |
- canvas->FillRect(gfx::Rect(1, 1, w, h - 2), background); |
- canvas->FillRect(gfx::Rect(2, 0, w, 1), border); |
- canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); |
- canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); |
- canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); |
- canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border); |
+ DrawBackground(canvas, view, gfx::Rect(1, 1, w, h - 2), state); |
+ canvas->FillRect(gfx::Rect(2, 0, w, 1), border_color); |
+ canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); |
+ canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); |
+ canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); |
+ canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border_color); |
break; |
case CENTER_BUTTON: { |
- canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); |
- SkColor left_color = state != CustomButton::STATE_NORMAL ? |
- border : BorderColor(view, left_button_->state()); |
+ DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); |
+ SkColor left_color = state != views::Button::STATE_NORMAL ? |
+ border_color : BorderColor(view, left_button_->state()); |
canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); |
- canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border); |
+ canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border_color); |
canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), |
- border); |
- SkColor right_color = state != CustomButton::STATE_NORMAL ? |
- border : BorderColor(view, right_button_->state()); |
+ border_color); |
+ SkColor right_color = state != views::Button::STATE_NORMAL ? |
+ border_color : BorderColor(view, right_button_->state()); |
canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); |
break; |
} |
case RIGHT_BUTTON: |
- canvas->FillRect(gfx::Rect(0, 1, w - 1, h - 2), background); |
- canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border); |
- canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); |
- canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); |
- canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); |
- canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border); |
+ DrawBackground(canvas, view, gfx::Rect(0, 1, w - 1, h - 2), state); |
+ canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border_color); |
+ canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); |
+ canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); |
+ canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); |
+ canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border_color); |
break; |
case SINGLE_BUTTON: |
- canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); |
- canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border); |
- canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); |
- canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); |
- canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); |
- canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border); |
- canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); |
- canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); |
- canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); |
+ DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); |
+ canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border_color); |
+ canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); |
+ canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); |
+ canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); |
+ canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border_color); |
+ canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); |
+ canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); |
+ canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); |
break; |
default: |
@@ -266,13 +260,13 @@ class MenuButtonBackground : public views::Background { |
} |
private: |
- static SkColor BorderColor(View* view, CustomButton::ButtonState state) { |
+ static SkColor BorderColor(View* view, views::Button::ButtonState state) { |
ui::NativeTheme* theme = view->GetNativeTheme(); |
switch (state) { |
- case CustomButton::STATE_HOVERED: |
+ case views::Button::STATE_HOVERED: |
return theme->GetSystemColor( |
ui::NativeTheme::kColorId_HoverMenuButtonBorderColor); |
- case CustomButton::STATE_PRESSED: |
+ case views::Button::STATE_PRESSED: |
return theme->GetSystemColor( |
ui::NativeTheme::kColorId_FocusedMenuButtonBorderColor); |
default: |
@@ -281,13 +275,14 @@ class MenuButtonBackground : public views::Background { |
} |
} |
- static SkColor BackgroundColor(View* view, CustomButton::ButtonState state) { |
- ui::NativeTheme* theme = view->GetNativeTheme(); |
+ static SkColor BackgroundColor(const View* view, views::Button::ButtonState state) { |
+ const ui::NativeTheme* theme = view->GetNativeTheme(); |
switch (state) { |
- case CustomButton::STATE_HOVERED: |
+ case views::Button::STATE_HOVERED: |
+ NOTREACHED(); |
return theme->GetSystemColor( |
ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); |
- case CustomButton::STATE_PRESSED: |
+ case views::Button::STATE_PRESSED: |
return theme->GetSystemColor( |
ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); |
default: |
@@ -296,12 +291,21 @@ class MenuButtonBackground : public views::Background { |
} |
} |
- static SkColor touch_background_color(CustomButton::ButtonState state) { |
- switch (state) { |
- case CustomButton::STATE_HOVERED: return kHoverTouchBackgroundColor; |
- case CustomButton::STATE_PRESSED: return kFocusedTouchBackgroundColor; |
- default: return kEnabledTouchBackgroundColor; |
+ void DrawBackground(gfx::Canvas* canvas, |
+ const views::View* view, |
+ const gfx::Rect& bounds, |
+ views::Button::ButtonState state) const { |
+ if (state == views::Button::STATE_HOVERED) { |
+ view->GetNativeTheme()->Paint(canvas->sk_canvas(), |
+ ui::NativeTheme::kMenuItemBackground, |
+ ui::NativeTheme::kHovered, |
+ bounds, |
+ ui::NativeTheme::ExtraParams()); |
+ return; |
} |
+ if (use_new_menu_) |
+ return; |
+ canvas->FillRect(bounds, BackgroundColor(view, state)); |
oshima
2013/11/25 21:59:01
I wonder if this is correct/intentional. MenuItemv
|
} |
ButtonType TypeAdjustedForRTL() const { |
@@ -368,9 +372,9 @@ class WrenchMenuView : public views::View, |
} |
LabelButton* CreateAndConfigureButton(int string_id, |
- MenuButtonBackground::ButtonType type, |
- int index, |
- MenuButtonBackground** background) { |
+ MenuButtonBackground::ButtonType type, |
+ int index, |
+ MenuButtonBackground** background) { |
return CreateButtonWithAccName( |
string_id, type, index, background, string_id); |
} |
@@ -401,6 +405,24 @@ class WrenchMenuView : public views::View, |
new MenuButtonBorder(menu_config, menu_->use_new_menu())); |
button->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
button->SetFont(menu_config.font); |
+ ui::NativeTheme* native_theme = button->GetNativeTheme(); |
+ |
+ button->SetTextColor( |
+ views::Button::STATE_DISABLED, |
+ native_theme->GetSystemColor( |
+ ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); |
+ button->SetTextColor( |
+ views::Button::STATE_HOVERED, |
+ native_theme->GetSystemColor( |
+ ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
+ button->SetTextColor( |
+ views::Button::STATE_PRESSED, |
+ native_theme->GetSystemColor( |
+ ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
+ button->SetTextColor( |
+ views::Button::STATE_NORMAL, |
+ native_theme->GetSystemColor( |
+ ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); |
AddChildView(button); |
return button; |
} |
@@ -484,17 +506,11 @@ class WrenchMenu::CutCopyPasteView : public WrenchMenuView { |
MenuButtonBackground::RIGHT_BUTTON, |
paste_index, |
NULL); |
- if (menu->use_new_menu()) { |
- cut->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); |
- copy->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); |
- paste->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); |
- } else { |
- SkColor text_color = native_theme->GetSystemColor( |
- ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
- cut->SetTextColor(views::Button::STATE_NORMAL, text_color); |
- copy->SetTextColor(views::Button::STATE_NORMAL, text_color); |
- paste->SetTextColor(views::Button::STATE_NORMAL, text_color); |
- } |
+ SkColor text_color = native_theme->GetSystemColor( |
+ ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
+ cut->SetTextColor(views::Button::STATE_NORMAL, text_color); |
+ copy->SetTextColor(views::Button::STATE_NORMAL, text_color); |
+ paste->SetTextColor(views::Button::STATE_NORMAL, text_color); |
copy_background->SetOtherButtons(cut, paste); |
} |
@@ -593,28 +609,19 @@ class WrenchMenu::ZoomView : public WrenchMenuView { |
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
IDR_FULLSCREEN_MENU_BUTTON); |
fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); |
- if (menu->use_new_menu()) { |
- zoom_label_->SetEnabledColor(kTouchButtonText); |
- decrement_button_->SetTextColor(views::Button::STATE_NORMAL, |
- kTouchButtonText); |
- increment_button_->SetTextColor(views::Button::STATE_NORMAL, |
- kTouchButtonText); |
- } else { |
- SkColor enabled_text_color = native_theme->GetSystemColor( |
- ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
- zoom_label_->SetEnabledColor(enabled_text_color); |
- decrement_button_->SetTextColor(views::Button::STATE_NORMAL, |
- enabled_text_color); |
- increment_button_->SetTextColor(views::Button::STATE_NORMAL, |
- enabled_text_color); |
- SkColor disabled_text_color = native_theme->GetSystemColor( |
- ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
- decrement_button_->SetTextColor(views::Button::STATE_DISABLED, |
- disabled_text_color); |
- increment_button_->SetTextColor(views::Button::STATE_DISABLED, |
- disabled_text_color); |
- } |
- |
+ SkColor enabled_text_color = native_theme->GetSystemColor( |
+ ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
+ zoom_label_->SetEnabledColor(enabled_text_color); |
+ decrement_button_->SetTextColor(views::Button::STATE_NORMAL, |
+ enabled_text_color); |
+ increment_button_->SetTextColor(views::Button::STATE_NORMAL, |
+ enabled_text_color); |
+ SkColor disabled_text_color = native_theme->GetSystemColor( |
+ ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
+ decrement_button_->SetTextColor(views::Button::STATE_DISABLED, |
+ disabled_text_color); |
+ increment_button_->SetTextColor(views::Button::STATE_DISABLED, |
+ disabled_text_color); |
fullscreen_button_->set_focusable(true); |
fullscreen_button_->set_request_focus_on_press(false); |
fullscreen_button_->set_tag(fullscreen_index); |