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

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

Issue 1005873012: Makes bookmark menu lazily create menus and removes limits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback Created 5 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 unified diff | Download patch
OLDNEW
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/wrench_menu.h" 5 #include "chrome/browser/ui/views/toolbar/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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const int kFullscreenPadding = 74; 84 const int kFullscreenPadding = 74;
85 // Padding to left and right of the XX% label. 85 // Padding to left and right of the XX% label.
86 const int kZoomLabelHorizontalPadding = kHorizontalPadding; 86 const int kZoomLabelHorizontalPadding = kHorizontalPadding;
87 #else 87 #else
88 const int kFullscreenPadding = 38; 88 const int kFullscreenPadding = 38;
89 const int kZoomLabelHorizontalPadding = 2; 89 const int kZoomLabelHorizontalPadding = 2;
90 #endif 90 #endif
91 91
92 // Returns true if |command_id| identifies a bookmark menu item. 92 // Returns true if |command_id| identifies a bookmark menu item.
93 bool IsBookmarkCommand(int command_id) { 93 bool IsBookmarkCommand(int command_id) {
94 return command_id >= WrenchMenuModel::kMinBookmarkCommandId && 94 return command_id >= IDC_FIRST_BOOKMARK_MENU;
95 command_id <= WrenchMenuModel::kMaxBookmarkCommandId;
96 } 95 }
97 96
98 // Returns true if |command_id| identifies a recent tabs menu item. 97 // Returns true if |command_id| identifies a recent tabs menu item.
99 bool IsRecentTabsCommand(int command_id) { 98 bool IsRecentTabsCommand(int command_id) {
100 return command_id >= WrenchMenuModel::kMinRecentTabsCommandId && 99 return command_id >= WrenchMenuModel::kMinRecentTabsCommandId &&
101 command_id <= WrenchMenuModel::kMaxRecentTabsCommandId; 100 command_id <= WrenchMenuModel::kMaxRecentTabsCommandId;
102 } 101 }
103 102
104 // Subclass of ImageButton whose preferred size includes the size of the border. 103 // Subclass of ImageButton whose preferred size includes the size of the border.
105 class FullscreenButton : public ImageButton { 104 class FullscreenButton : public ImageButton {
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 FOR_EACH_OBSERVER(WrenchMenuObserver, observer_list_, WrenchMenuDestroyed()); 809 FOR_EACH_OBSERVER(WrenchMenuObserver, observer_list_, WrenchMenuDestroyed());
811 } 810 }
812 811
813 void WrenchMenu::Init(ui::MenuModel* model) { 812 void WrenchMenu::Init(ui::MenuModel* model) {
814 DCHECK(!root_); 813 DCHECK(!root_);
815 root_ = new MenuItemView(this); 814 root_ = new MenuItemView(this);
816 root_->set_has_icons(true); // We have checks, radios and icons, set this 815 root_->set_has_icons(true); // We have checks, radios and icons, set this
817 // so we get the taller menu style. 816 // so we get the taller menu style.
818 PopulateMenu(root_, model); 817 PopulateMenu(root_, model);
819 818
820 #if !defined(NDEBUG)
821 // Verify that the reserved command ID's for bookmarks menu are not used.
822 for (int i = WrenchMenuModel::kMinBookmarkCommandId;
823 i <= WrenchMenuModel::kMaxBookmarkCommandId; ++i)
824 DCHECK(command_id_to_entry_.find(i) == command_id_to_entry_.end());
825 #endif // !defined(NDEBUG)
826
827 int32 types = views::MenuRunner::HAS_MNEMONICS; 819 int32 types = views::MenuRunner::HAS_MNEMONICS;
828 if (for_drop()) { 820 if (for_drop()) {
829 // We add NESTED_DRAG since currently the only operation to open the wrench 821 // We add NESTED_DRAG since currently the only operation to open the wrench
830 // menu for is an extension action drag, which is controlled by the child 822 // menu for is an extension action drag, which is controlled by the child
831 // BrowserActionsContainer view. 823 // BrowserActionsContainer view.
832 types |= views::MenuRunner::FOR_DROP | views::MenuRunner::NESTED_DRAG; 824 types |= views::MenuRunner::FOR_DROP | views::MenuRunner::NESTED_DRAG;
833 } 825 }
834 menu_runner_.reset(new views::MenuRunner(root_, types)); 826 menu_runner_.reset(new views::MenuRunner(root_, types));
835 } 827 }
836 828
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 return false; 1040 return false;
1049 1041
1050 *accelerator = ui::Accelerator(menu_accelerator.key_code(), 1042 *accelerator = ui::Accelerator(menu_accelerator.key_code(),
1051 menu_accelerator.modifiers()); 1043 menu_accelerator.modifiers());
1052 return true; 1044 return true;
1053 } 1045 }
1054 1046
1055 void WrenchMenu::WillShowMenu(MenuItemView* menu) { 1047 void WrenchMenu::WillShowMenu(MenuItemView* menu) {
1056 if (menu == bookmark_menu_) 1048 if (menu == bookmark_menu_)
1057 CreateBookmarkMenu(); 1049 CreateBookmarkMenu();
1050 else if (bookmark_menu_delegate_)
1051 bookmark_menu_delegate_->WillShowMenu(menu);
1058 } 1052 }
1059 1053
1060 void WrenchMenu::WillHideMenu(MenuItemView* menu) { 1054 void WrenchMenu::WillHideMenu(MenuItemView* menu) {
1061 // Turns off the fade out animation of the wrench menus if 1055 // Turns off the fade out animation of the wrench menus if
1062 // |feedback_menu_item_| or |screenshot_menu_item_| is selected. This 1056 // |feedback_menu_item_| or |screenshot_menu_item_| is selected. This
1063 // excludes the wrench menu itself from the screenshot. 1057 // excludes the wrench menu itself from the screenshot.
1064 if (menu->HasSubmenu() && 1058 if (menu->HasSubmenu() &&
1065 ((feedback_menu_item_ && feedback_menu_item_->IsSelected()) || 1059 ((feedback_menu_item_ && feedback_menu_item_->IsSelected()) ||
1066 (screenshot_menu_item_ && screenshot_menu_item_->IsSelected()))) { 1060 (screenshot_menu_item_ && screenshot_menu_item_->IsSelected()))) {
1067 // It's okay to just turn off the animation and no to take care the 1061 // It's okay to just turn off the animation and not turn it back on because
1068 // animation back because the menu widget will be recreated next time 1062 // the menu widget will be recreated next time it's opened. See
1069 // it's opened. See ToolbarView::RunMenu() and Init() of this class. 1063 // ToolbarView::RunMenu() and Init() of this class.
1070 menu->GetSubmenu()->GetWidget()-> 1064 menu->GetSubmenu()->GetWidget()->
1071 SetVisibilityChangedAnimationsEnabled(false); 1065 SetVisibilityChangedAnimationsEnabled(false);
1072 } 1066 }
1073 } 1067 }
1074 1068
1075 bool WrenchMenu::ShouldCloseOnDragComplete() { 1069 bool WrenchMenu::ShouldCloseOnDragComplete() {
1076 return false; 1070 return false;
1077 } 1071 }
1078 1072
1079 void WrenchMenu::BookmarkModelChanged() { 1073 void WrenchMenu::BookmarkModelChanged() {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 1184
1191 MenuItemView* WrenchMenu::AddMenuItem(MenuItemView* parent, 1185 MenuItemView* WrenchMenu::AddMenuItem(MenuItemView* parent,
1192 int menu_index, 1186 int menu_index,
1193 MenuModel* model, 1187 MenuModel* model,
1194 int model_index, 1188 int model_index,
1195 MenuModel::ItemType menu_type) { 1189 MenuModel::ItemType menu_type) {
1196 int command_id = model->GetCommandIdAt(model_index); 1190 int command_id = model->GetCommandIdAt(model_index);
1197 DCHECK(command_id > -1 || 1191 DCHECK(command_id > -1 ||
1198 (command_id == -1 && 1192 (command_id == -1 &&
1199 model->GetTypeAt(model_index) == MenuModel::TYPE_SEPARATOR)); 1193 model->GetTypeAt(model_index) == MenuModel::TYPE_SEPARATOR));
1194 DCHECK_LT(command_id, IDC_FIRST_BOOKMARK_MENU);
1200 1195
1201 if (command_id > -1) { // Don't add separators to |command_id_to_entry_|. 1196 if (command_id > -1) { // Don't add separators to |command_id_to_entry_|.
1202 // All command ID's should be unique except for IDC_SHOW_HISTORY which is 1197 // All command ID's should be unique except for IDC_SHOW_HISTORY which is
1203 // in both wrench menu and RecentTabs submenu, 1198 // in both wrench menu and RecentTabs submenu,
1204 if (command_id != IDC_SHOW_HISTORY) { 1199 if (command_id != IDC_SHOW_HISTORY) {
1205 DCHECK(command_id_to_entry_.find(command_id) == 1200 DCHECK(command_id_to_entry_.find(command_id) ==
1206 command_id_to_entry_.end()) 1201 command_id_to_entry_.end())
1207 << "command ID " << command_id << " already exists!"; 1202 << "command ID " << command_id << " already exists!";
1208 } 1203 }
1209 command_id_to_entry_[command_id].first = model; 1204 command_id_to_entry_[command_id].first = model;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 BookmarkModelFactory::GetForProfile(browser_->profile()); 1237 BookmarkModelFactory::GetForProfile(browser_->profile());
1243 if (!model->loaded()) 1238 if (!model->loaded())
1244 return; 1239 return;
1245 1240
1246 model->AddObserver(this); 1241 model->AddObserver(this);
1247 1242
1248 // TODO(oshima): Replace with views only API. 1243 // TODO(oshima): Replace with views only API.
1249 views::Widget* parent = views::Widget::GetWidgetForNativeWindow( 1244 views::Widget* parent = views::Widget::GetWidgetForNativeWindow(
1250 browser_->window()->GetNativeWindow()); 1245 browser_->window()->GetNativeWindow());
1251 bookmark_menu_delegate_.reset( 1246 bookmark_menu_delegate_.reset(
1252 new BookmarkMenuDelegate(browser_, 1247 new BookmarkMenuDelegate(browser_, browser_, parent));
1253 browser_,
1254 parent,
1255 WrenchMenuModel::kMinBookmarkCommandId,
1256 WrenchMenuModel::kMaxBookmarkCommandId));
1257 bookmark_menu_delegate_->Init(this, 1248 bookmark_menu_delegate_->Init(this,
1258 bookmark_menu_, 1249 bookmark_menu_,
1259 model->bookmark_bar_node(), 1250 model->bookmark_bar_node(),
1260 0, 1251 0,
1261 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1252 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1262 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); 1253 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU);
1263 } 1254 }
1264 1255
1265 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { 1256 int WrenchMenu::ModelIndexFromCommandId(int command_id) const {
1266 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1257 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1267 DCHECK(ix != command_id_to_entry_.end()); 1258 DCHECK(ix != command_id_to_entry_.end());
1268 return ix->second.second; 1259 return ix->second.second;
1269 } 1260 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_menu_delegate_unittest.cc ('k') | ui/views/controls/menu/menu_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698