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

Side by Side Diff: chrome/browser/ui/views/wrench_menu.cc

Issue 11298004: alternate ntp: add "Recent Tabs" submenu to wrench menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased to resolve conflicts Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/wrench_menu.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 TextButton* decrement_button_; 699 TextButton* decrement_button_;
700 700
701 ImageButton* fullscreen_button_; 701 ImageButton* fullscreen_button_;
702 702
703 // Width given to |zoom_label_|. This is the width at 100%. 703 // Width given to |zoom_label_|. This is the width at 100%.
704 int zoom_label_width_; 704 int zoom_label_width_;
705 705
706 DISALLOW_COPY_AND_ASSIGN(ZoomView); 706 DISALLOW_COPY_AND_ASSIGN(ZoomView);
707 }; 707 };
708 708
709 // RecentTabsMenuModelDelegate -------------------------------------------------
710
711 // Provides the ui::MenuModelDelegate implementation for RecentTabsSubMenuModel
712 // items.
713 class WrenchMenu::RecentTabsMenuModelDelegate : public ui::MenuModelDelegate {
714 public:
715 RecentTabsMenuModelDelegate(ui::MenuModel* model,
716 views::MenuItemView* menu_item)
717 : model_(model),
718 menu_item_(menu_item) {
719 model_->SetMenuModelDelegate(this);
720 }
721
722 virtual ~RecentTabsMenuModelDelegate() {
723 model_->SetMenuModelDelegate(NULL);
724 }
725
726 // ui::MenuModelDelegate implementation:
727 virtual void OnIconChanged(int index) OVERRIDE {
728 // |index| specifies position in children items of |menu_item_| starting at
729 // 0, its corresponding command id as used in the children menu item views
730 // follows that of the parent menu item view |menu_item_|.
731 int command_id = menu_item_->GetCommand() + 1 + index;
732 views::MenuItemView* item = menu_item_->GetMenuItemByID(command_id);
733 DCHECK(item);
734 gfx::Image icon;
735 if (model_->GetIconAt(index, &icon))
736 item->SetIcon(*icon.ToImageSkia());
737 }
738
739 private:
740 ui::MenuModel* model_;
741 views::MenuItemView* menu_item_;
742
743 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate);
744 };
745
709 // WrenchMenu ------------------------------------------------------------------ 746 // WrenchMenu ------------------------------------------------------------------
710 747
711 WrenchMenu::WrenchMenu(Browser* browser, 748 WrenchMenu::WrenchMenu(Browser* browser,
712 bool use_new_menu, 749 bool use_new_menu,
713 bool supports_new_separators) 750 bool supports_new_separators)
714 : root_(NULL), 751 : root_(NULL),
715 browser_(browser), 752 browser_(browser),
716 selected_menu_model_(NULL), 753 selected_menu_model_(NULL),
717 selected_index_(0), 754 selected_index_(0),
718 bookmark_menu_(NULL), 755 bookmark_menu_(NULL),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 const Entry& entry = id_to_entry_.find(id)->second; 930 const Entry& entry = id_to_entry_.find(id)->second;
894 int command_id = entry.first->GetCommandIdAt(entry.second); 931 int command_id = entry.first->GetCommandIdAt(entry.second);
895 932
896 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { 933 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) {
897 // These items are represented by child views. If ExecuteCommand is invoked 934 // These items are represented by child views. If ExecuteCommand is invoked
898 // it means the user clicked on the area around the buttons and we should 935 // it means the user clicked on the area around the buttons and we should
899 // not do anyting. 936 // not do anyting.
900 return; 937 return;
901 } 938 }
902 939
903 return entry.first->ActivatedAt(entry.second); 940 return entry.first->ActivatedAt(entry.second, mouse_event_flags);
904 } 941 }
905 942
906 bool WrenchMenu::GetAccelerator(int id, ui::Accelerator* accelerator) { 943 bool WrenchMenu::GetAccelerator(int id, ui::Accelerator* accelerator) {
907 if (is_bookmark_command(id)) 944 if (is_bookmark_command(id))
908 return false; 945 return false;
909 IDToEntry::iterator ix = id_to_entry_.find(id); 946 IDToEntry::iterator ix = id_to_entry_.find(id);
910 if (ix == id_to_entry_.end()) { 947 if (ix == id_to_entry_.end()) {
911 // There is no entry for this id. 948 // There is no entry for this id.
912 return false; 949 return false;
913 } 950 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 SetVisibilityChangedAnimationsEnabled(false); 983 SetVisibilityChangedAnimationsEnabled(false);
947 } 984 }
948 } 985 }
949 986
950 void WrenchMenu::BookmarkModelChanged() { 987 void WrenchMenu::BookmarkModelChanged() {
951 DCHECK(bookmark_menu_delegate_.get()); 988 DCHECK(bookmark_menu_delegate_.get());
952 if (!bookmark_menu_delegate_->is_mutating_model()) 989 if (!bookmark_menu_delegate_->is_mutating_model())
953 root_->Cancel(); 990 root_->Cancel();
954 } 991 }
955 992
956
957 void WrenchMenu::Observe(int type, 993 void WrenchMenu::Observe(int type,
958 const content::NotificationSource& source, 994 const content::NotificationSource& source,
959 const content::NotificationDetails& details) { 995 const content::NotificationDetails& details) {
960 switch (type) { 996 switch (type) {
961 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: 997 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
962 // A change in the global errors list can add or remove items from the 998 // A change in the global errors list can add or remove items from the
963 // menu. Close the menu to avoid have a stale menu on-screen. 999 // menu. Close the menu to avoid have a stale menu on-screen.
964 root_->Cancel(); 1000 root_->Cancel();
965 break; 1001 break;
966 default: 1002 default:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 case IDC_BOOKMARKS_MENU: 1051 case IDC_BOOKMARKS_MENU:
1016 DCHECK(!bookmark_menu_); 1052 DCHECK(!bookmark_menu_);
1017 bookmark_menu_ = item; 1053 bookmark_menu_ = item;
1018 break; 1054 break;
1019 1055
1020 case IDC_FEEDBACK: 1056 case IDC_FEEDBACK:
1021 DCHECK(!feedback_menu_item_); 1057 DCHECK(!feedback_menu_item_);
1022 feedback_menu_item_ = item; 1058 feedback_menu_item_ = item;
1023 break; 1059 break;
1024 1060
1061 case IDC_RECENT_TABS_MENU:
1062 DCHECK(chrome::search::IsInstantExtendedAPIEnabled(
1063 browser_->profile()));
1064 DCHECK(!recent_tabs_menu_model_delegate_.get());
1065 recent_tabs_menu_model_delegate_.reset(
1066 new RecentTabsMenuModelDelegate(model->GetSubmenuModelAt(index),
1067 item));
1068 break;
1069
1025 default: 1070 default:
1026 break; 1071 break;
1027 } 1072 }
1028 } 1073 }
1029 } 1074 }
1030 1075
1031 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent, 1076 MenuItemView* WrenchMenu::AppendMenuItem(MenuItemView* parent,
1032 MenuModel* model, 1077 MenuModel* model,
1033 int index, 1078 int index,
1034 MenuModel::ItemType menu_type, 1079 MenuModel::ItemType menu_type,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 bookmark_menu_delegate_.reset( 1133 bookmark_menu_delegate_.reset(
1089 new BookmarkMenuDelegate(browser_, 1134 new BookmarkMenuDelegate(browser_,
1090 browser_, 1135 browser_,
1091 parent, 1136 parent,
1092 first_bookmark_command_id_)); 1137 first_bookmark_command_id_));
1093 bookmark_menu_delegate_->Init( 1138 bookmark_menu_delegate_->Init(
1094 this, bookmark_menu_, model->bookmark_bar_node(), 0, 1139 this, bookmark_menu_, model->bookmark_bar_node(), 0,
1095 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1140 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1096 bookmark_utils::LAUNCH_WRENCH_MENU); 1141 bookmark_utils::LAUNCH_WRENCH_MENU);
1097 } 1142 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/wrench_menu.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698