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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #include "ui/views/controls/button/image_button.h" | 58 #include "ui/views/controls/button/image_button.h" |
59 #include "ui/views/controls/button/label_button.h" | 59 #include "ui/views/controls/button/label_button.h" |
60 #include "ui/views/controls/button/menu_button.h" | 60 #include "ui/views/controls/button/menu_button.h" |
61 #include "ui/views/controls/label.h" | 61 #include "ui/views/controls/label.h" |
62 #include "ui/views/controls/menu/menu_config.h" | 62 #include "ui/views/controls/menu/menu_config.h" |
63 #include "ui/views/controls/menu/menu_item_view.h" | 63 #include "ui/views/controls/menu/menu_item_view.h" |
64 #include "ui/views/controls/menu/menu_model_adapter.h" | 64 #include "ui/views/controls/menu/menu_model_adapter.h" |
65 #include "ui/views/controls/menu/menu_runner.h" | 65 #include "ui/views/controls/menu/menu_runner.h" |
66 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 66 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
67 #include "ui/views/controls/menu/submenu_view.h" | 67 #include "ui/views/controls/menu/submenu_view.h" |
| 68 #include "ui/views/style/platform_style.h" |
68 #include "ui/views/widget/widget.h" | 69 #include "ui/views/widget/widget.h" |
69 | 70 |
70 using base::UserMetricsAction; | 71 using base::UserMetricsAction; |
71 using bookmarks::BookmarkModel; | 72 using bookmarks::BookmarkModel; |
72 using content::WebContents; | 73 using content::WebContents; |
73 using ui::ButtonMenuItemModel; | 74 using ui::ButtonMenuItemModel; |
74 using ui::MenuModel; | 75 using ui::MenuModel; |
75 using views::CustomButton; | 76 using views::CustomButton; |
76 using views::ImageButton; | 77 using views::ImageButton; |
77 using views::Label; | 78 using views::Label; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 278 } |
278 | 279 |
279 // A button that lives inside a menu item. | 280 // A button that lives inside a menu item. |
280 class InMenuButton : public LabelButton { | 281 class InMenuButton : public LabelButton { |
281 public: | 282 public: |
282 InMenuButton(views::ButtonListener* listener, const base::string16& text) | 283 InMenuButton(views::ButtonListener* listener, const base::string16& text) |
283 : LabelButton(listener, text), in_menu_background_(NULL) {} | 284 : LabelButton(listener, text), in_menu_background_(NULL) {} |
284 ~InMenuButton() override {} | 285 ~InMenuButton() override {} |
285 | 286 |
286 void Init(InMenuButtonBackground::ButtonType type) { | 287 void Init(InMenuButtonBackground::ButtonType type) { |
287 SetFocusable(true); | 288 views::PlatformStyle::ConfigureFocus( |
| 289 views::PlatformStyle::CONTROL::IN_MENU_BUTTON, this); |
288 set_request_focus_on_press(false); | 290 set_request_focus_on_press(false); |
289 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 291 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
290 | 292 |
291 in_menu_background_ = new InMenuButtonBackground(type); | 293 in_menu_background_ = new InMenuButtonBackground(type); |
292 set_background(in_menu_background_); | 294 set_background(in_menu_background_); |
293 SetBorder(views::Border::CreateEmptyBorder(0, kHorizontalPadding, 0, | 295 SetBorder(views::Border::CreateEmptyBorder(0, kHorizontalPadding, 0, |
294 kHorizontalPadding)); | 296 kHorizontalPadding)); |
295 SetFontList(MenuConfig::instance().font_list); | 297 SetFontList(MenuConfig::instance().font_list); |
296 } | 298 } |
297 | 299 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 548 |
547 fullscreen_button_ = new FullscreenButton(this); | 549 fullscreen_button_ = new FullscreenButton(this); |
548 // all buttons on menu should must be a custom button in order for | 550 // all buttons on menu should must be a custom button in order for |
549 // the keyboard nativigation work. | 551 // the keyboard nativigation work. |
550 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); | 552 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); |
551 gfx::ImageSkia* full_screen_image = | 553 gfx::ImageSkia* full_screen_image = |
552 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 554 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
553 IDR_FULLSCREEN_MENU_BUTTON); | 555 IDR_FULLSCREEN_MENU_BUTTON); |
554 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); | 556 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); |
555 | 557 |
556 fullscreen_button_->SetFocusable(true); | 558 views::PlatformStyle::ConfigureFocus( |
| 559 views::PlatformStyle::CONTROL::IN_MENU_BUTTON, fullscreen_button_); |
| 560 |
557 fullscreen_button_->set_request_focus_on_press(false); | 561 fullscreen_button_->set_request_focus_on_press(false); |
558 fullscreen_button_->set_tag(fullscreen_index); | 562 fullscreen_button_->set_tag(fullscreen_index); |
559 fullscreen_button_->SetImageAlignment( | 563 fullscreen_button_->SetImageAlignment( |
560 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | 564 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
561 fullscreen_button_->set_background( | 565 fullscreen_button_->set_background( |
562 new InMenuButtonBackground(InMenuButtonBackground::SINGLE_BUTTON)); | 566 new InMenuButtonBackground(InMenuButtonBackground::SINGLE_BUTTON)); |
563 fullscreen_button_->SetAccessibleName(GetAccessibleNameForAppMenuItem( | 567 fullscreen_button_->SetAccessibleName(GetAccessibleNameForAppMenuItem( |
564 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); | 568 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); |
565 AddChildView(fullscreen_button_); | 569 AddChildView(fullscreen_button_); |
566 | 570 |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 0, | 1293 0, |
1290 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1294 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1291 BOOKMARK_LAUNCH_LOCATION_APP_MENU); | 1295 BOOKMARK_LAUNCH_LOCATION_APP_MENU); |
1292 } | 1296 } |
1293 | 1297 |
1294 int AppMenu::ModelIndexFromCommandId(int command_id) const { | 1298 int AppMenu::ModelIndexFromCommandId(int command_id) const { |
1295 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1299 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1296 DCHECK(ix != command_id_to_entry_.end()); | 1300 DCHECK(ix != command_id_to_entry_.end()); |
1297 return ix->second.second; | 1301 return ix->second.second; |
1298 } | 1302 } |
OLD | NEW |