Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4265)

Unified Diff: chrome/browser/ui/views/toolbar/wrench_menu.cc

Issue 245863002: Fix text color of WrenchMenu buttons on Linux Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 68a877c03f22a395f7a7d3f4c43d78bb3ddc7c08..76f6037cb262312e3572665ab79c779e680f1b5e 100644
--- a/chrome/browser/ui/views/toolbar/wrench_menu.cc
+++ b/chrome/browser/ui/views/toolbar/wrench_menu.cc
@@ -366,17 +366,25 @@ class WrenchMenuView : public views::View,
View::SchedulePaintInRect(gfx::Rect(size()));
}
- LabelButton* CreateAndConfigureButton(const ui::NativeTheme* native_theme,
- int string_id,
+ virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE {
+ views::View::OnNativeThemeChanged(theme);
+ for (int i = 0; i < child_count(); ++i) {
+ if (child_at(i)->GetClassName() == views::LabelButton::kViewClassName) {
+ UpdateButtonWithNativeTheme(
+ static_cast<views::LabelButton*>(child_at(i)), theme);
+ }
+ }
+ }
+
+ LabelButton* CreateAndConfigureButton(int string_id,
MenuButtonBackground::ButtonType type,
int index,
MenuButtonBackground** background) {
- return CreateButtonWithAccName(
- native_theme, string_id, type, index, background, string_id);
+ return
+ CreateButtonWithAccName(string_id, type, index, background, string_id);
}
- LabelButton* CreateButtonWithAccName(const ui::NativeTheme* native_theme,
- int string_id,
+ LabelButton* CreateButtonWithAccName(int string_id,
MenuButtonBackground::ButtonType type,
int index,
MenuButtonBackground** background,
@@ -394,33 +402,14 @@ class WrenchMenuView : public views::View,
MenuButtonBackground* bg =
new MenuButtonBackground(type, menu_->use_new_menu());
button->set_background(bg);
- const MenuConfig& menu_config = menu_->GetMenuConfig();
if (background)
*background = bg;
- button->SetBorder(scoped_ptr<views::Border>(
- new MenuButtonBorder(menu_config, menu_->use_new_menu())));
button->SetHorizontalAlignment(gfx::ALIGN_CENTER);
- button->SetFontList(menu_config.font_list);
- 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);
// all buttons on menu should must be a custom button in order for
// the keyboard nativigation work.
DCHECK(CustomButton::AsCustomButton(button));
+ UpdateButtonWithNativeTheme(button, NULL);
return button;
}
@@ -436,6 +425,33 @@ class WrenchMenuView : public views::View,
MenuModel* menu_model() { return menu_model_; }
private:
+ void UpdateButtonWithNativeTheme(views::LabelButton* button,
+ const ui::NativeTheme* native_theme) {
+ if (native_theme) {
+ 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));
+ }
+
+ MenuConfig menu_config(native_theme);
+ button->SetBorder(scoped_ptr<views::Border>(
+ new MenuButtonBorder(menu_config, menu_->use_new_menu())));
+ button->SetFontList(menu_config.font_list);
+ }
+
// Hosting WrenchMenu.
// WARNING: this may be NULL during shutdown.
WrenchMenu* menu_;
@@ -520,20 +536,17 @@ class WrenchMenu::CutCopyPasteView : public WrenchMenuView {
public:
CutCopyPasteView(WrenchMenu* menu,
MenuModel* menu_model,
- const ui::NativeTheme* native_theme,
int cut_index,
int copy_index,
int paste_index)
: WrenchMenuView(menu, menu_model) {
LabelButton* cut = CreateAndConfigureButton(
- native_theme, IDS_CUT, MenuButtonBackground::LEFT_BUTTON,
- cut_index, NULL);
+ IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL);
MenuButtonBackground* copy_background = NULL;
CreateAndConfigureButton(
- native_theme, IDS_COPY, MenuButtonBackground::CENTER_BUTTON,
+ IDS_COPY, MenuButtonBackground::CENTER_BUTTON,
copy_index, &copy_background);
LabelButton* paste = CreateAndConfigureButton(
- native_theme,
IDS_PASTE,
menu->use_new_menu() && menu->supports_new_separators_ ?
MenuButtonBackground::CENTER_BUTTON :
@@ -588,7 +601,6 @@ class WrenchMenu::ZoomView : public WrenchMenuView {
public:
ZoomView(WrenchMenu* menu,
MenuModel* menu_model,
- const ui::NativeTheme* native_theme,
int decrement_index,
int increment_index,
int fullscreen_index)
@@ -605,7 +617,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView {
base::Unretained(this)));
decrement_button_ = CreateButtonWithAccName(
- native_theme, IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON,
+ IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON,
decrement_index, NULL, IDS_ACCNAME_ZOOM_MINUS2);
zoom_label_ = new Label(
@@ -619,16 +631,11 @@ class WrenchMenu::ZoomView : public WrenchMenuView {
MenuButtonBackground::CENTER_BUTTON,
menu->use_new_menu());
zoom_label_->set_background(center_bg);
- const MenuConfig& menu_config(menu->GetMenuConfig());
- zoom_label_->SetBorder(scoped_ptr<views::Border>(
- new MenuButtonBorder(menu_config, menu->use_new_menu())));
- zoom_label_->SetFontList(menu_config.font_list);
AddChildView(zoom_label_);
- zoom_label_width_ = MaxWidthForZoomLabel();
increment_button_ = CreateButtonWithAccName(
- native_theme, IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON,
+ IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON,
increment_index, NULL, IDS_ACCNAME_ZOOM_PLUS2);
center_bg->SetOtherButtons(decrement_button_, increment_button_);
@@ -641,29 +648,6 @@ class WrenchMenu::ZoomView : public WrenchMenuView {
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_FULLSCREEN_MENU_BUTTON);
fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image);
- SkColor fg_color = native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor);
- gfx::ImageSkia hovered_fullscreen_image(
- new HoveredImageSource(*full_screen_image, fg_color),
- full_screen_image->size());
- fullscreen_button_->SetImage(
- ImageButton::STATE_HOVERED, &hovered_fullscreen_image);
- fullscreen_button_->SetImage(
- ImageButton::STATE_PRESSED, &hovered_fullscreen_image);
-
- 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_->SetFocusable(true);
fullscreen_button_->set_request_focus_on_press(false);
fullscreen_button_->set_tag(fullscreen_index);
@@ -681,6 +665,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView {
menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
AddChildView(fullscreen_button_);
+ OnNativeThemeChanged(NULL);
UpdateZoomControls();
}
@@ -727,6 +712,33 @@ class WrenchMenu::ZoomView : public WrenchMenuView {
fullscreen_button_->SetBoundsRect(bounds);
}
+ virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE {
+ WrenchMenuView::OnNativeThemeChanged(theme);
+
+ MenuConfig menu_config(theme);
+ zoom_label_->SetBorder(scoped_ptr<views::Border>(
+ new MenuButtonBorder(menu_config, menu()->use_new_menu())));
+ zoom_label_->SetFontList(menu_config.font_list);
+ zoom_label_width_ = MaxWidthForZoomLabel();
+
+ if (theme) {
+ zoom_label_->SetEnabledColor(theme->GetSystemColor(
+ ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor));
+ gfx::ImageSkia* full_screen_image =
+ ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_FULLSCREEN_MENU_BUTTON);
+ SkColor fg_color = theme->GetSystemColor(
+ ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor);
+ gfx::ImageSkia hovered_fullscreen_image(
+ new HoveredImageSource(*full_screen_image, fg_color),
+ full_screen_image->size());
+ fullscreen_button_->SetImage(
+ ImageButton::STATE_HOVERED, &hovered_fullscreen_image);
+ fullscreen_button_->SetImage(
+ ImageButton::STATE_PRESSED, &hovered_fullscreen_image);
+ }
+ }
+
// Overridden from ButtonListener.
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE {
@@ -971,17 +983,6 @@ bool WrenchMenu::IsShowing() {
return menu_runner_.get() && menu_runner_->IsRunning();
}
-const ui::NativeTheme* WrenchMenu::GetNativeTheme() const {
- views::Widget* browser_widget = views::Widget::GetWidgetForNativeView(
- browser_->window()->GetNativeWindow());
- DCHECK(browser_widget);
- return browser_widget->GetNativeTheme();
-}
-
-const views::MenuConfig& WrenchMenu::GetMenuConfig() const {
- return MenuConfig::instance(GetNativeTheme());
-}
-
void WrenchMenu::AddObserver(WrenchMenuObserver* observer) {
observer_list_.AddObserver(observer);
}
@@ -1225,8 +1226,6 @@ void WrenchMenu::PopulateMenu(MenuItemView* parent,
if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU)
PopulateMenu(item, model->GetSubmenuModelAt(i));
- const ui::NativeTheme* native_theme = GetNativeTheme();
-
switch (model->GetCommandIdAt(i)) {
case IDC_CUT:
DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i));
@@ -1234,7 +1233,7 @@ void WrenchMenu::PopulateMenu(MenuItemView* parent,
DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1));
DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2));
item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2));
- item->AddChildView(new CutCopyPasteView(this, model, native_theme,
+ item->AddChildView(new CutCopyPasteView(this, model,
i, i + 1, i + 2));
i += 2;
break;
@@ -1244,8 +1243,7 @@ void WrenchMenu::PopulateMenu(MenuItemView* parent,
DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1));
DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2));
item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2));
- item->AddChildView(new ZoomView(this, model, native_theme,
- i, i + 1, i + 2));
+ item->AddChildView(new ZoomView(this, model, i, i + 1, i + 2));
i += 2;
break;

Powered by Google App Engine
This is Rietveld 408576698