| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/toolbar/app_menu.h" | 5 #include "chrome/browser/ui/views/toolbar/app_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 void Init(InMenuButtonBackground::ButtonType type) { | 266 void Init(InMenuButtonBackground::ButtonType type) { |
| 267 SetFocusable(true); | 267 SetFocusable(true); |
| 268 set_request_focus_on_press(false); | 268 set_request_focus_on_press(false); |
| 269 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 269 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 270 | 270 |
| 271 in_menu_background_ = new InMenuButtonBackground(type); | 271 in_menu_background_ = new InMenuButtonBackground(type); |
| 272 set_background(in_menu_background_); | 272 set_background(in_menu_background_); |
| 273 SetBorder(views::Border::CreateEmptyBorder(0, kHorizontalPadding, 0, | 273 SetBorder(views::Border::CreateEmptyBorder(0, kHorizontalPadding, 0, |
| 274 kHorizontalPadding)); | 274 kHorizontalPadding)); |
| 275 SetFontList(MenuConfig::instance().font_list); | |
| 276 } | 275 } |
| 277 | 276 |
| 278 void SetOtherButtons(const InMenuButton* left, const InMenuButton* right) { | 277 void SetOtherButtons(const InMenuButton* left, const InMenuButton* right) { |
| 279 in_menu_background_->SetOtherButtons(left, right); | 278 in_menu_background_->SetOtherButtons(left, right); |
| 280 } | 279 } |
| 281 | 280 |
| 282 // views::LabelButton | 281 // views::LabelButton |
| 283 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { | 282 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { |
| 283 const MenuConfig& menu_config = MenuConfig::instance(theme); |
| 284 SetFontList(menu_config.font_list); |
| 285 |
| 284 if (theme) { | 286 if (theme) { |
| 285 SetTextColor( | 287 SetTextColor( |
| 286 views::Button::STATE_DISABLED, | 288 views::Button::STATE_DISABLED, |
| 287 theme->GetSystemColor( | 289 theme->GetSystemColor( |
| 288 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); | 290 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); |
| 289 SetTextColor( | 291 SetTextColor( |
| 290 views::Button::STATE_HOVERED, | 292 views::Button::STATE_HOVERED, |
| 291 theme->GetSystemColor( | 293 theme->GetSystemColor( |
| 292 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); | 294 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
| 293 SetTextColor( | 295 SetTextColor( |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 x += bounds.width(); | 589 x += bounds.width(); |
| 588 bounds.set_x(x); | 590 bounds.set_x(x); |
| 589 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + | 591 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + |
| 590 kFullscreenPadding); | 592 kFullscreenPadding); |
| 591 fullscreen_button_->SetBoundsRect(bounds); | 593 fullscreen_button_->SetBoundsRect(bounds); |
| 592 } | 594 } |
| 593 | 595 |
| 594 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { | 596 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { |
| 595 AppMenuView::OnNativeThemeChanged(theme); | 597 AppMenuView::OnNativeThemeChanged(theme); |
| 596 | 598 |
| 599 const MenuConfig& menu_config = MenuConfig::instance(theme); |
| 597 zoom_label_->SetBorder(views::Border::CreateEmptyBorder( | 600 zoom_label_->SetBorder(views::Border::CreateEmptyBorder( |
| 598 0, kZoomLabelHorizontalPadding, 0, kZoomLabelHorizontalPadding)); | 601 0, kZoomLabelHorizontalPadding, 0, kZoomLabelHorizontalPadding)); |
| 599 zoom_label_->SetFontList(MenuConfig::instance().font_list); | 602 zoom_label_->SetFontList(menu_config.font_list); |
| 600 zoom_label_max_width_valid_ = false; | 603 zoom_label_max_width_valid_ = false; |
| 601 | 604 |
| 602 if (theme) { | 605 if (theme) { |
| 603 zoom_label_->SetEnabledColor(theme->GetSystemColor( | 606 zoom_label_->SetEnabledColor(theme->GetSystemColor( |
| 604 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); | 607 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); |
| 605 gfx::ImageSkia* full_screen_image = | 608 gfx::ImageSkia* full_screen_image = |
| 606 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 609 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 607 IDR_FULLSCREEN_MENU_BUTTON); | 610 IDR_FULLSCREEN_MENU_BUTTON); |
| 608 SkColor fg_color = theme->GetSystemColor( | 611 SkColor fg_color = theme->GetSystemColor( |
| 609 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); | 612 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 void AppMenu::PopulateMenu(MenuItemView* parent, MenuModel* model) { | 1108 void AppMenu::PopulateMenu(MenuItemView* parent, MenuModel* model) { |
| 1106 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { | 1109 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { |
| 1107 // Add the menu item at the end. | 1110 // Add the menu item at the end. |
| 1108 int menu_index = parent->HasSubmenu() ? | 1111 int menu_index = parent->HasSubmenu() ? |
| 1109 parent->GetSubmenu()->child_count() : 0; | 1112 parent->GetSubmenu()->child_count() : 0; |
| 1110 MenuItemView* item = | 1113 MenuItemView* item = |
| 1111 AddMenuItem(parent, menu_index, model, i, model->GetTypeAt(i)); | 1114 AddMenuItem(parent, menu_index, model, i, model->GetTypeAt(i)); |
| 1112 | 1115 |
| 1113 if (model->GetCommandIdAt(i) == IDC_EDIT_MENU || | 1116 if (model->GetCommandIdAt(i) == IDC_EDIT_MENU || |
| 1114 model->GetCommandIdAt(i) == IDC_ZOOM_MENU) { | 1117 model->GetCommandIdAt(i) == IDC_ZOOM_MENU) { |
| 1115 const MenuConfig& config = views::MenuConfig::instance(); | 1118 const MenuConfig& config = item->GetMenuConfig(); |
| 1116 int top_margin = config.item_top_margin + config.separator_height / 2; | 1119 int top_margin = config.item_top_margin + config.separator_height / 2; |
| 1117 int bottom_margin = | 1120 int bottom_margin = |
| 1118 config.item_bottom_margin + config.separator_height / 2; | 1121 config.item_bottom_margin + config.separator_height / 2; |
| 1119 | 1122 |
| 1120 // Chromeos adds extra vertical space for the menu buttons. | 1123 // Chromeos adds extra vertical space for the menu buttons. |
| 1121 #if defined(OS_CHROMEOS) | 1124 #if defined(OS_CHROMEOS) |
| 1122 top_margin += 4; | 1125 top_margin += 4; |
| 1123 bottom_margin += 5; | 1126 bottom_margin += 5; |
| 1124 #endif | 1127 #endif |
| 1125 | 1128 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 0, | 1265 0, |
| 1263 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1266 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1264 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1267 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
| 1265 } | 1268 } |
| 1266 | 1269 |
| 1267 int AppMenu::ModelIndexFromCommandId(int command_id) const { | 1270 int AppMenu::ModelIndexFromCommandId(int command_id) const { |
| 1268 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1271 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1269 DCHECK(ix != command_id_to_entry_.end()); | 1272 DCHECK(ix != command_id_to_entry_.end()); |
| 1270 return ix->second.second; | 1273 return ix->second.second; |
| 1271 } | 1274 } |
| OLD | NEW |