| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/wrench_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 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 TextButton* decrement_button_; | 706 TextButton* decrement_button_; |
| 707 | 707 |
| 708 ImageButton* fullscreen_button_; | 708 ImageButton* fullscreen_button_; |
| 709 | 709 |
| 710 // Width given to |zoom_label_|. This is the width at 100%. | 710 // Width given to |zoom_label_|. This is the width at 100%. |
| 711 int zoom_label_width_; | 711 int zoom_label_width_; |
| 712 | 712 |
| 713 DISALLOW_COPY_AND_ASSIGN(ZoomView); | 713 DISALLOW_COPY_AND_ASSIGN(ZoomView); |
| 714 }; | 714 }; |
| 715 | 715 |
| 716 // RecentTabsMenuModelDelegate ------------------------------------------------- |
| 717 |
| 718 // Provides the ui::MenuModelDelegate implementation for RecentTabsSubMenuModel |
| 719 // items. |
| 720 class WrenchMenu::RecentTabsMenuModelDelegate : public ui::MenuModelDelegate { |
| 721 public: |
| 722 RecentTabsMenuModelDelegate(ui::MenuModel* model, |
| 723 views::MenuItemView* menu_item) |
| 724 : model_(model), |
| 725 menu_item_(menu_item) { |
| 726 model_->SetMenuModelDelegate(this); |
| 727 } |
| 728 |
| 729 virtual ~RecentTabsMenuModelDelegate() { |
| 730 model_->SetMenuModelDelegate(NULL); |
| 731 } |
| 732 |
| 733 // ui::MenuModelDelegate implementation: |
| 734 virtual void OnIconChanged(int index) OVERRIDE { |
| 735 // |index| specifies position in children items of |menu_item_| starting at |
| 736 // 0, its corresponding command id as used in the children menu item views |
| 737 // follows that of the parent menu item view |menu_item_|. |
| 738 int command_id = menu_item_->GetCommand() + 1 + index; |
| 739 views::MenuItemView* item = menu_item_->GetMenuItemByID(command_id); |
| 740 DCHECK(item); |
| 741 gfx::Image icon; |
| 742 if (model_->GetIconAt(index, &icon)) |
| 743 item->SetIcon(*icon.ToImageSkia()); |
| 744 } |
| 745 |
| 746 private: |
| 747 ui::MenuModel* model_; |
| 748 views::MenuItemView* menu_item_; |
| 749 |
| 750 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate); |
| 751 }; |
| 752 |
| 716 // WrenchMenu ------------------------------------------------------------------ | 753 // WrenchMenu ------------------------------------------------------------------ |
| 717 | 754 |
| 718 WrenchMenu::WrenchMenu(Browser* browser, | 755 WrenchMenu::WrenchMenu(Browser* browser, |
| 719 bool use_new_menu, | 756 bool use_new_menu, |
| 720 bool supports_new_separators) | 757 bool supports_new_separators) |
| 721 : root_(NULL), | 758 : root_(NULL), |
| 722 browser_(browser), | 759 browser_(browser), |
| 723 selected_menu_model_(NULL), | 760 selected_menu_model_(NULL), |
| 724 selected_index_(0), | 761 selected_index_(0), |
| 725 bookmark_menu_(NULL), | 762 bookmark_menu_(NULL), |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 const Entry& entry = id_to_entry_.find(id)->second; | 937 const Entry& entry = id_to_entry_.find(id)->second; |
| 901 int command_id = entry.first->GetCommandIdAt(entry.second); | 938 int command_id = entry.first->GetCommandIdAt(entry.second); |
| 902 | 939 |
| 903 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { | 940 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { |
| 904 // These items are represented by child views. If ExecuteCommand is invoked | 941 // These items are represented by child views. If ExecuteCommand is invoked |
| 905 // it means the user clicked on the area around the buttons and we should | 942 // it means the user clicked on the area around the buttons and we should |
| 906 // not do anyting. | 943 // not do anyting. |
| 907 return; | 944 return; |
| 908 } | 945 } |
| 909 | 946 |
| 910 return entry.first->ActivatedAt(entry.second); | 947 return entry.first->ActivatedAt(entry.second, mouse_event_flags); |
| 911 } | 948 } |
| 912 | 949 |
| 913 bool WrenchMenu::GetAccelerator(int id, ui::Accelerator* accelerator) { | 950 bool WrenchMenu::GetAccelerator(int id, ui::Accelerator* accelerator) { |
| 914 if (is_bookmark_command(id)) | 951 if (is_bookmark_command(id)) |
| 915 return false; | 952 return false; |
| 916 IDToEntry::iterator ix = id_to_entry_.find(id); | 953 IDToEntry::iterator ix = id_to_entry_.find(id); |
| 917 if (ix == id_to_entry_.end()) { | 954 if (ix == id_to_entry_.end()) { |
| 918 // There is no entry for this id. | 955 // There is no entry for this id. |
| 919 return false; | 956 return false; |
| 920 } | 957 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 SetVisibilityChangedAnimationsEnabled(false); | 990 SetVisibilityChangedAnimationsEnabled(false); |
| 954 } | 991 } |
| 955 } | 992 } |
| 956 | 993 |
| 957 void WrenchMenu::BookmarkModelChanged() { | 994 void WrenchMenu::BookmarkModelChanged() { |
| 958 DCHECK(bookmark_menu_delegate_.get()); | 995 DCHECK(bookmark_menu_delegate_.get()); |
| 959 if (!bookmark_menu_delegate_->is_mutating_model()) | 996 if (!bookmark_menu_delegate_->is_mutating_model()) |
| 960 root_->Cancel(); | 997 root_->Cancel(); |
| 961 } | 998 } |
| 962 | 999 |
| 963 | |
| 964 void WrenchMenu::Observe(int type, | 1000 void WrenchMenu::Observe(int type, |
| 965 const content::NotificationSource& source, | 1001 const content::NotificationSource& source, |
| 966 const content::NotificationDetails& details) { | 1002 const content::NotificationDetails& details) { |
| 967 switch (type) { | 1003 switch (type) { |
| 968 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: | 1004 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: |
| 969 // A change in the global errors list can add or remove items from the | 1005 // A change in the global errors list can add or remove items from the |
| 970 // menu. Close the menu to avoid have a stale menu on-screen. | 1006 // menu. Close the menu to avoid have a stale menu on-screen. |
| 971 root_->Cancel(); | 1007 root_->Cancel(); |
| 972 break; | 1008 break; |
| 973 default: | 1009 default: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 case IDC_BOOKMARKS_MENU: | 1058 case IDC_BOOKMARKS_MENU: |
| 1023 DCHECK(!bookmark_menu_); | 1059 DCHECK(!bookmark_menu_); |
| 1024 bookmark_menu_ = item; | 1060 bookmark_menu_ = item; |
| 1025 break; | 1061 break; |
| 1026 | 1062 |
| 1027 case IDC_FEEDBACK: | 1063 case IDC_FEEDBACK: |
| 1028 DCHECK(!feedback_menu_item_); | 1064 DCHECK(!feedback_menu_item_); |
| 1029 feedback_menu_item_ = item; | 1065 feedback_menu_item_ = item; |
| 1030 break; | 1066 break; |
| 1031 | 1067 |
| 1068 case IDC_RECENT_TABS_MENU: |
| 1069 DCHECK(chrome::search::IsInstantExtendedAPIEnabled( |
| 1070 browser_->profile())); |
| 1071 DCHECK(!recent_tabs_menu_model_delegate_.get()); |
| 1072 recent_tabs_menu_model_delegate_.reset( |
| 1073 new RecentTabsMenuModelDelegate(model->GetSubmenuModelAt(index), |
| 1074 item)); |
| 1075 break; |
| 1076 |
| 1032 default: | 1077 default: |
| 1033 break; | 1078 break; |
| 1034 } | 1079 } |
| 1035 } | 1080 } |
| 1036 } | 1081 } |
| 1037 | 1082 |
| 1038 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent, | 1083 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent, |
| 1039 MenuModel* model, | 1084 MenuModel* model, |
| 1040 int index, | 1085 int index, |
| 1041 MenuModel::ItemType menu_type, | 1086 MenuModel::ItemType menu_type, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 bookmark_menu_delegate_.reset( | 1140 bookmark_menu_delegate_.reset( |
| 1096 new BookmarkMenuDelegate(browser_, | 1141 new BookmarkMenuDelegate(browser_, |
| 1097 browser_, | 1142 browser_, |
| 1098 parent, | 1143 parent, |
| 1099 first_bookmark_command_id_)); | 1144 first_bookmark_command_id_)); |
| 1100 bookmark_menu_delegate_->Init( | 1145 bookmark_menu_delegate_->Init( |
| 1101 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1146 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
| 1102 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1147 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1103 bookmark_utils::LAUNCH_WRENCH_MENU); | 1148 bookmark_utils::LAUNCH_WRENCH_MENU); |
| 1104 } | 1149 } |
| OLD | NEW |