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

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

Issue 413323002: Resubmit: Open the WrenchMenu on mouseover when dragging a browser action (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Created 6 years, 5 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 int paste_index) 565 int paste_index)
566 : WrenchMenuView(menu, menu_model) { 566 : WrenchMenuView(menu, menu_model) {
567 InMenuButton* cut = CreateAndConfigureButton( 567 InMenuButton* cut = CreateAndConfigureButton(
568 IDS_CUT, InMenuButtonBackground::LEFT_BUTTON, 568 IDS_CUT, InMenuButtonBackground::LEFT_BUTTON,
569 cut_index); 569 cut_index);
570 InMenuButton* copy = CreateAndConfigureButton( 570 InMenuButton* copy = CreateAndConfigureButton(
571 IDS_COPY, InMenuButtonBackground::CENTER_BUTTON, 571 IDS_COPY, InMenuButtonBackground::CENTER_BUTTON,
572 copy_index); 572 copy_index);
573 InMenuButton* paste = CreateAndConfigureButton( 573 InMenuButton* paste = CreateAndConfigureButton(
574 IDS_PASTE, 574 IDS_PASTE,
575 menu->use_new_menu() && menu->supports_new_separators_ ? 575 menu->use_new_menu() && menu->supports_new_separators() ?
576 InMenuButtonBackground::CENTER_BUTTON : 576 InMenuButtonBackground::CENTER_BUTTON :
577 InMenuButtonBackground::RIGHT_BUTTON, 577 InMenuButtonBackground::RIGHT_BUTTON,
578 paste_index); 578 paste_index);
579 copy->SetOtherButtons(cut, paste); 579 copy->SetOtherButtons(cut, paste);
580 } 580 }
581 581
582 // Overridden from View. 582 // Overridden from View.
583 virtual gfx::Size GetPreferredSize() const OVERRIDE { 583 virtual gfx::Size GetPreferredSize() const OVERRIDE {
584 // Returned height doesn't matter as MenuItemView forces everything to the 584 // Returned height doesn't matter as MenuItemView forces everything to the
585 // height of the menuitemview. 585 // height of the menuitemview.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 decrement_button_ = CreateButtonWithAccName( 647 decrement_button_ = CreateButtonWithAccName(
648 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, 648 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON,
649 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); 649 decrement_index, IDS_ACCNAME_ZOOM_MINUS2);
650 650
651 zoom_label_ = new Label( 651 zoom_label_ = new Label(
652 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 652 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
653 zoom_label_->SetAutoColorReadabilityEnabled(false); 653 zoom_label_->SetAutoColorReadabilityEnabled(false);
654 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 654 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
655 655
656 InMenuButtonBackground* center_bg = new InMenuButtonBackground( 656 InMenuButtonBackground* center_bg = new InMenuButtonBackground(
657 menu->use_new_menu() && menu->supports_new_separators_ ? 657 menu->use_new_menu() && menu->supports_new_separators() ?
658 InMenuButtonBackground::RIGHT_BUTTON : 658 InMenuButtonBackground::RIGHT_BUTTON :
659 InMenuButtonBackground::CENTER_BUTTON, 659 InMenuButtonBackground::CENTER_BUTTON,
660 menu->use_new_menu()); 660 menu->use_new_menu());
661 zoom_label_->set_background(center_bg); 661 zoom_label_->set_background(center_bg);
662 662
663 AddChildView(zoom_label_); 663 AddChildView(zoom_label_);
664 zoom_label_width_ = MaxWidthForZoomLabel(); 664 zoom_label_width_ = MaxWidthForZoomLabel();
665 665
666 increment_button_ = CreateButtonWithAccName( 666 increment_button_ = CreateButtonWithAccName(
667 IDS_ZOOM_PLUS2, InMenuButtonBackground::RIGHT_BUTTON, 667 IDS_ZOOM_PLUS2, InMenuButtonBackground::RIGHT_BUTTON,
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 private: 939 private:
940 WrenchMenu* wrench_menu_; 940 WrenchMenu* wrench_menu_;
941 ui::MenuModel* model_; 941 ui::MenuModel* model_;
942 views::MenuItemView* menu_item_; 942 views::MenuItemView* menu_item_;
943 943
944 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate); 944 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate);
945 }; 945 };
946 946
947 // WrenchMenu ------------------------------------------------------------------ 947 // WrenchMenu ------------------------------------------------------------------
948 948
949 WrenchMenu::WrenchMenu(Browser* browser, 949 WrenchMenu::WrenchMenu(Browser* browser, int run_flags)
950 bool use_new_menu,
951 bool supports_new_separators)
952 : root_(NULL), 950 : root_(NULL),
953 browser_(browser), 951 browser_(browser),
954 selected_menu_model_(NULL), 952 selected_menu_model_(NULL),
955 selected_index_(0), 953 selected_index_(0),
956 bookmark_menu_(NULL), 954 bookmark_menu_(NULL),
957 feedback_menu_item_(NULL), 955 feedback_menu_item_(NULL),
958 use_new_menu_(use_new_menu), 956 run_flags_(run_flags) {
959 supports_new_separators_(supports_new_separators) {
960 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, 957 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
961 content::Source<Profile>(browser_->profile())); 958 content::Source<Profile>(browser_->profile()));
962 } 959 }
963 960
964 WrenchMenu::~WrenchMenu() { 961 WrenchMenu::~WrenchMenu() {
965 if (bookmark_menu_delegate_.get()) { 962 if (bookmark_menu_delegate_.get()) {
966 BookmarkModel* model = BookmarkModelFactory::GetForProfile( 963 BookmarkModel* model = BookmarkModelFactory::GetForProfile(
967 browser_->profile()); 964 browser_->profile());
968 if (model) 965 if (model)
969 model->RemoveObserver(this); 966 model->RemoveObserver(this);
970 } 967 }
971 FOR_EACH_OBSERVER(WrenchMenuObserver, observer_list_, WrenchMenuDestroyed()); 968 FOR_EACH_OBSERVER(WrenchMenuObserver, observer_list_, WrenchMenuDestroyed());
972 } 969 }
973 970
974 void WrenchMenu::Init(ui::MenuModel* model) { 971 void WrenchMenu::Init(ui::MenuModel* model) {
975 DCHECK(!root_); 972 DCHECK(!root_);
976 root_ = new MenuItemView(this); 973 root_ = new MenuItemView(this);
977 root_->set_has_icons(true); // We have checks, radios and icons, set this 974 root_->set_has_icons(true); // We have checks, radios and icons, set this
978 // so we get the taller menu style. 975 // so we get the taller menu style.
979 PopulateMenu(root_, model); 976 PopulateMenu(root_, model);
980 977
981 #if defined(DEBUG) 978 #if defined(DEBUG)
982 // Verify that the reserved command ID's for bookmarks menu are not used. 979 // Verify that the reserved command ID's for bookmarks menu are not used.
983 for (int i = WrenchMenuModel:kMinBookmarkCommandId; 980 for (int i = WrenchMenuModel:kMinBookmarkCommandId;
984 i <= WrenchMenuModel::kMaxBookmarkCommandId; ++i) 981 i <= WrenchMenuModel::kMaxBookmarkCommandId; ++i)
985 DCHECK(command_id_to_entry_.find(i) == command_id_to_entry_.end()); 982 DCHECK(command_id_to_entry_.find(i) == command_id_to_entry_.end());
986 #endif // defined(DEBUG) 983 #endif // defined(DEBUG)
987 984
988 menu_runner_.reset( 985 int32 types = views::MenuRunner::HAS_MNEMONICS;
989 new views::MenuRunner(root_, views::MenuRunner::HAS_MNEMONICS)); 986 if (for_drop()) {
987 // We add NESTED_DRAG since currently the only operation to open the wrench
988 // menu for is an extension action drag, which is controlled by the child
989 // BrowserActionsContainer view.
990 types |= views::MenuRunner::FOR_DROP | views::MenuRunner::NESTED_DRAG;
991 }
992 menu_runner_.reset(new views::MenuRunner(root_, types));
990 } 993 }
991 994
992 void WrenchMenu::RunMenu(views::MenuButton* host) { 995 void WrenchMenu::RunMenu(views::MenuButton* host) {
993 gfx::Point screen_loc; 996 gfx::Point screen_loc;
994 views::View::ConvertPointToScreen(host, &screen_loc); 997 views::View::ConvertPointToScreen(host, &screen_loc);
995 gfx::Rect bounds(screen_loc, host->size()); 998 gfx::Rect bounds(screen_loc, host->size());
996 content::RecordAction(UserMetricsAction("ShowAppMenu")); 999 content::RecordAction(UserMetricsAction("ShowAppMenu"));
997 if (menu_runner_->RunMenuAt(host->GetWidget(), 1000 if (menu_runner_->RunMenuAt(host->GetWidget(),
998 host, 1001 host,
999 bounds, 1002 bounds,
1000 views::MENU_ANCHOR_TOPRIGHT, 1003 views::MENU_ANCHOR_TOPRIGHT,
1001 ui::MENU_SOURCE_NONE) == 1004 ui::MENU_SOURCE_NONE) ==
1002 views::MenuRunner::MENU_DELETED) 1005 views::MenuRunner::MENU_DELETED)
1003 return; 1006 return;
1004 if (bookmark_menu_delegate_.get()) { 1007 if (bookmark_menu_delegate_.get()) {
1005 BookmarkModel* model = BookmarkModelFactory::GetForProfile( 1008 BookmarkModel* model = BookmarkModelFactory::GetForProfile(
1006 browser_->profile()); 1009 browser_->profile());
1007 if (model) 1010 if (model)
1008 model->RemoveObserver(this); 1011 model->RemoveObserver(this);
1009 } 1012 }
1010 if (selected_menu_model_) 1013 if (selected_menu_model_)
1011 selected_menu_model_->ActivatedAt(selected_index_); 1014 selected_menu_model_->ActivatedAt(selected_index_);
1012 } 1015 }
1013 1016
1017 void WrenchMenu::CloseMenu() {
1018 if (menu_runner_.get())
1019 menu_runner_->Cancel();
1020 }
1021
1014 bool WrenchMenu::IsShowing() { 1022 bool WrenchMenu::IsShowing() {
1015 return menu_runner_.get() && menu_runner_->IsRunning(); 1023 return menu_runner_.get() && menu_runner_->IsRunning();
1016 } 1024 }
1017 1025
1018 void WrenchMenu::AddObserver(WrenchMenuObserver* observer) { 1026 void WrenchMenu::AddObserver(WrenchMenuObserver* observer) {
1019 observer_list_.AddObserver(observer); 1027 observer_list_.AddObserver(observer);
1020 } 1028 }
1021 1029
1022 void WrenchMenu::RemoveObserver(WrenchMenuObserver* observer) { 1030 void WrenchMenu::RemoveObserver(WrenchMenuObserver* observer) {
1023 observer_list_.RemoveObserver(observer); 1031 observer_list_.RemoveObserver(observer);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 NOTREACHED(); 1253 NOTREACHED();
1246 } 1254 }
1247 } 1255 }
1248 1256
1249 void WrenchMenu::PopulateMenu(MenuItemView* parent, 1257 void WrenchMenu::PopulateMenu(MenuItemView* parent,
1250 MenuModel* model) { 1258 MenuModel* model) {
1251 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { 1259 for (int i = 0, max = model->GetItemCount(); i < max; ++i) {
1252 // The button container menu items have a special height which we have to 1260 // The button container menu items have a special height which we have to
1253 // use instead of the normal height. 1261 // use instead of the normal height.
1254 int height = 0; 1262 int height = 0;
1255 if (use_new_menu_ && 1263 if (use_new_menu() &&
1256 (model->GetCommandIdAt(i) == IDC_CUT || 1264 (model->GetCommandIdAt(i) == IDC_CUT ||
1257 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS)) 1265 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS))
1258 height = kMenuItemContainingButtonsHeight; 1266 height = kMenuItemContainingButtonsHeight;
1259 1267
1260 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar_menu_view; 1268 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar_menu_view;
1261 if (model->GetCommandIdAt(i) == IDC_EXTENSIONS_OVERFLOW_MENU) { 1269 if (model->GetCommandIdAt(i) == IDC_EXTENSIONS_OVERFLOW_MENU) {
1262 extension_toolbar_menu_view.reset(new ExtensionToolbarMenuView(browser_)); 1270 extension_toolbar_menu_view.reset(
1271 new ExtensionToolbarMenuView(browser_, this));
1263 height = extension_toolbar_menu_view->GetPreferredSize().height(); 1272 height = extension_toolbar_menu_view->GetPreferredSize().height();
1264 } 1273 }
1265 1274
1266 // Add the menu item at the end. 1275 // Add the menu item at the end.
1267 int menu_index = parent->HasSubmenu() ? 1276 int menu_index = parent->HasSubmenu() ?
1268 parent->GetSubmenu()->child_count() : 0; 1277 parent->GetSubmenu()->child_count() : 0;
1269 MenuItemView* item = AddMenuItem( 1278 MenuItemView* item = AddMenuItem(
1270 parent, menu_index, model, i, model->GetTypeAt(i), height); 1279 parent, menu_index, model, i, model->GetTypeAt(i), height);
1271 1280
1272 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) 1281 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 parent->CreateSubmenu(); 1365 parent->CreateSubmenu();
1357 parent->GetSubmenu()->AddChildViewAt(menu_item, menu_index); 1366 parent->GetSubmenu()->AddChildViewAt(menu_item, menu_index);
1358 } else { 1367 } else {
1359 // For all other cases we use the more generic way to add menu items. 1368 // For all other cases we use the more generic way to add menu items.
1360 menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt( 1369 menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt(
1361 model, model_index, parent, menu_index, command_id); 1370 model, model_index, parent, menu_index, command_id);
1362 } 1371 }
1363 1372
1364 if (menu_item) { 1373 if (menu_item) {
1365 // Flush all buttons to the right side of the menu for the new menu type. 1374 // Flush all buttons to the right side of the menu for the new menu type.
1366 menu_item->set_use_right_margin(!use_new_menu_); 1375 menu_item->set_use_right_margin(!use_new_menu());
1367 menu_item->SetVisible(model->IsVisibleAt(model_index)); 1376 menu_item->SetVisible(model->IsVisibleAt(model_index));
1368 1377
1369 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) { 1378 if (menu_type == MenuModel::TYPE_COMMAND && model->HasIcons()) {
1370 gfx::Image icon; 1379 gfx::Image icon;
1371 if (model->GetIconAt(model_index, &icon)) 1380 if (model->GetIconAt(model_index, &icon))
1372 menu_item->SetIcon(*icon.ToImageSkia()); 1381 menu_item->SetIcon(*icon.ToImageSkia());
1373 } 1382 }
1374 } 1383 }
1375 1384
1376 return menu_item; 1385 return menu_item;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 0, 1417 0,
1409 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1418 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1410 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); 1419 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU);
1411 } 1420 }
1412 1421
1413 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { 1422 int WrenchMenu::ModelIndexFromCommandId(int command_id) const {
1414 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1423 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1415 DCHECK(ix != command_id_to_entry_.end()); 1424 DCHECK(ix != command_id_to_entry_.end());
1416 return ix->second.second; 1425 return ix->second.second;
1417 } 1426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698