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

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

Issue 324393002: Extension Toolbar redesign, part 1 (overflow) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missing gypi change 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_view.cc ('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 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
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
15 #include "chrome/browser/bookmarks/bookmark_stats.h" 15 #include "chrome/browser/bookmarks/bookmark_stats.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search/search.h" 18 #include "chrome/browser/search/search.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" 22 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
23 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" 23 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h"
24 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h"
24 #include "chrome/browser/ui/views/toolbar/wrench_menu_observer.h" 25 #include "chrome/browser/ui/views/toolbar/wrench_menu_observer.h"
25 #include "components/bookmarks/browser/bookmark_model.h" 26 #include "components/bookmarks/browser/bookmark_model.h"
26 #include "content/public/browser/host_zoom_map.h" 27 #include "content/public/browser/host_zoom_map.h"
27 #include "content/public/browser/notification_observer.h" 28 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h" 29 #include "content/public/browser/notification_registrar.h"
29 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
30 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
31 #include "content/public/browser/user_metrics.h" 32 #include "content/public/browser/user_metrics.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "extensions/common/feature_switch.h"
33 #include "grit/chromium_strings.h" 35 #include "grit/chromium_strings.h"
34 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
35 #include "grit/theme_resources.h" 37 #include "grit/theme_resources.h"
36 #include "third_party/skia/include/core/SkCanvas.h" 38 #include "third_party/skia/include/core/SkCanvas.h"
37 #include "third_party/skia/include/core/SkPaint.h" 39 #include "third_party/skia/include/core/SkPaint.h"
38 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/layout.h" 41 #include "ui/base/layout.h"
40 #include "ui/base/resource/resource_bundle.h" 42 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/gfx/canvas.h" 43 #include "ui/gfx/canvas.h"
42 #include "ui/gfx/font_list.h" 44 #include "ui/gfx/font_list.h"
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 673
672 fullscreen_button_->SetFocusable(true); 674 fullscreen_button_->SetFocusable(true);
673 fullscreen_button_->set_request_focus_on_press(false); 675 fullscreen_button_->set_request_focus_on_press(false);
674 fullscreen_button_->set_tag(fullscreen_index); 676 fullscreen_button_->set_tag(fullscreen_index);
675 fullscreen_button_->SetImageAlignment( 677 fullscreen_button_->SetImageAlignment(
676 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); 678 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
677 int horizontal_padding = 679 int horizontal_padding =
678 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; 680 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding;
679 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder( 681 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder(
680 0, horizontal_padding, 0, horizontal_padding)); 682 0, horizontal_padding, 0, horizontal_padding));
681 fullscreen_button_->set_background( 683 fullscreen_button_->set_background(new InMenuButtonBackground(
682 new InMenuButtonBackground(InMenuButtonBackground::SINGLE_BUTTON, 684 InMenuButtonBackground::SINGLE_BUTTON, menu->use_new_menu()));
683 menu->use_new_menu()));
684 fullscreen_button_->SetAccessibleName( 685 fullscreen_button_->SetAccessibleName(
685 GetAccessibleNameForWrenchMenuItem( 686 GetAccessibleNameForWrenchMenuItem(
686 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); 687 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
687 AddChildView(fullscreen_button_); 688 AddChildView(fullscreen_button_);
688 689
689 // Need to set a font list for the zoom label width calculations. 690 // Need to set a font list for the zoom label width calculations.
690 OnNativeThemeChanged(NULL); 691 OnNativeThemeChanged(NULL);
691 UpdateZoomControls(); 692 UpdateZoomControls();
692 } 693 }
693 694
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 return entry.first->IsItemCheckedAt(entry.second); 1138 return entry.first->IsItemCheckedAt(entry.second);
1138 } 1139 }
1139 1140
1140 bool WrenchMenu::IsCommandEnabled(int command_id) const { 1141 bool WrenchMenu::IsCommandEnabled(int command_id) const {
1141 if (IsBookmarkCommand(command_id)) 1142 if (IsBookmarkCommand(command_id))
1142 return true; 1143 return true;
1143 1144
1144 if (command_id == 0) 1145 if (command_id == 0)
1145 return false; // The root item. 1146 return false; // The root item.
1146 1147
1147 // The items representing the cut menu (cut/copy/paste) and zoom menu 1148 // The items representing the cut menu (cut/copy/paste), zoom menu
1148 // (increment/decrement/reset) are always enabled. The child views of these 1149 // (increment/decrement/reset) and extension toolbar view are always enabled.
1149 // items enabled state updates appropriately. 1150 // The child views of these items enabled state updates appropriately.
1150 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) 1151 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS ||
1152 command_id == IDC_EXTENSIONS_OVERFLOW_MENU)
1151 return true; 1153 return true;
1152 1154
1153 const Entry& entry = command_id_to_entry_.find(command_id)->second; 1155 const Entry& entry = command_id_to_entry_.find(command_id)->second;
1154 return entry.first->IsEnabledAt(entry.second); 1156 return entry.first->IsEnabledAt(entry.second);
1155 } 1157 }
1156 1158
1157 void WrenchMenu::ExecuteCommand(int command_id, int mouse_event_flags) { 1159 void WrenchMenu::ExecuteCommand(int command_id, int mouse_event_flags) {
1158 if (IsBookmarkCommand(command_id)) { 1160 if (IsBookmarkCommand(command_id)) {
1159 bookmark_menu_delegate_->ExecuteCommand(command_id, mouse_event_flags); 1161 bookmark_menu_delegate_->ExecuteCommand(command_id, mouse_event_flags);
1160 return; 1162 return;
1161 } 1163 }
1162 1164
1163 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { 1165 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS ||
1166 command_id == IDC_EXTENSIONS_OVERFLOW_MENU) {
1164 // These items are represented by child views. If ExecuteCommand is invoked 1167 // These items are represented by child views. If ExecuteCommand is invoked
1165 // it means the user clicked on the area around the buttons and we should 1168 // it means the user clicked on the area around the buttons and we should
1166 // not do anyting. 1169 // not do anyting.
1167 return; 1170 return;
1168 } 1171 }
1169 1172
1170 const Entry& entry = command_id_to_entry_.find(command_id)->second; 1173 const Entry& entry = command_id_to_entry_.find(command_id)->second;
1171 return entry.first->ActivatedAt(entry.second, mouse_event_flags); 1174 return entry.first->ActivatedAt(entry.second, mouse_event_flags);
1172 } 1175 }
1173 1176
1174 bool WrenchMenu::GetAccelerator(int command_id, 1177 bool WrenchMenu::GetAccelerator(int command_id,
1175 ui::Accelerator* accelerator) const { 1178 ui::Accelerator* accelerator) const {
1176 if (IsBookmarkCommand(command_id)) 1179 if (IsBookmarkCommand(command_id))
1177 return false; 1180 return false;
1178 1181
1179 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { 1182 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS ||
1183 command_id == IDC_EXTENSIONS_OVERFLOW_MENU) {
1180 // These have special child views; don't show the accelerator for them. 1184 // These have special child views; don't show the accelerator for them.
1181 return false; 1185 return false;
1182 } 1186 }
1183 1187
1184 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1188 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1185 const Entry& entry = ix->second; 1189 const Entry& entry = ix->second;
1186 ui::Accelerator menu_accelerator; 1190 ui::Accelerator menu_accelerator;
1187 if (!entry.first->GetAcceleratorAt(entry.second, &menu_accelerator)) 1191 if (!entry.first->GetAcceleratorAt(entry.second, &menu_accelerator))
1188 return false; 1192 return false;
1189 1193
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 MenuModel* model) { 1240 MenuModel* model) {
1237 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { 1241 for (int i = 0, max = model->GetItemCount(); i < max; ++i) {
1238 // The button container menu items have a special height which we have to 1242 // The button container menu items have a special height which we have to
1239 // use instead of the normal height. 1243 // use instead of the normal height.
1240 int height = 0; 1244 int height = 0;
1241 if (use_new_menu_ && 1245 if (use_new_menu_ &&
1242 (model->GetCommandIdAt(i) == IDC_CUT || 1246 (model->GetCommandIdAt(i) == IDC_CUT ||
1243 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS)) 1247 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS))
1244 height = kMenuItemContainingButtonsHeight; 1248 height = kMenuItemContainingButtonsHeight;
1245 1249
1250 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar_menu_view;
1251 if (model->GetCommandIdAt(i) == IDC_EXTENSIONS_OVERFLOW_MENU) {
1252 extension_toolbar_menu_view.reset(new ExtensionToolbarMenuView(browser_));
1253 height = extension_toolbar_menu_view->GetPreferredSize().height();
1254 }
1255
1246 // Add the menu item at the end. 1256 // Add the menu item at the end.
1247 int menu_index = parent->HasSubmenu() ? 1257 int menu_index = parent->HasSubmenu() ?
1248 parent->GetSubmenu()->child_count() : 0; 1258 parent->GetSubmenu()->child_count() : 0;
1249 MenuItemView* item = AddMenuItem( 1259 MenuItemView* item = AddMenuItem(
1250 parent, menu_index, model, i, model->GetTypeAt(i), height); 1260 parent, menu_index, model, i, model->GetTypeAt(i), height);
1251 1261
1252 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) 1262 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU)
1253 PopulateMenu(item, model->GetSubmenuModelAt(i)); 1263 PopulateMenu(item, model->GetSubmenuModelAt(i));
1254 1264
1255 switch (model->GetCommandIdAt(i)) { 1265 switch (model->GetCommandIdAt(i)) {
1266 case IDC_EXTENSIONS_OVERFLOW_MENU:
1267 if (height > 0)
1268 item->AddChildView(extension_toolbar_menu_view.release());
1269 else
1270 item->SetVisible(false);
1271 break;
1256 case IDC_CUT: 1272 case IDC_CUT:
1257 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); 1273 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i));
1258 DCHECK_LT(i + 2, max); 1274 DCHECK_LT(i + 2, max);
1259 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); 1275 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1));
1260 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); 1276 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2));
1261 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); 1277 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2));
1262 item->AddChildView(new CutCopyPasteView(this, model, 1278 item->AddChildView(new CutCopyPasteView(this, model,
1263 i, i + 1, i + 2)); 1279 i, i + 1, i + 2));
1264 i += 2; 1280 i += 2;
1265 break; 1281 break;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 } 1335 }
1320 command_id_to_entry_[command_id].first = model; 1336 command_id_to_entry_[command_id].first = model;
1321 command_id_to_entry_[command_id].second = model_index; 1337 command_id_to_entry_[command_id].second = model_index;
1322 } 1338 }
1323 1339
1324 MenuItemView* menu_item = NULL; 1340 MenuItemView* menu_item = NULL;
1325 if (height > 0) { 1341 if (height > 0) {
1326 // For menu items with a special menu height we use our special class to be 1342 // For menu items with a special menu height we use our special class to be
1327 // able to modify the item height. 1343 // able to modify the item height.
1328 menu_item = new ButtonContainerMenuItemView(parent, command_id, height); 1344 menu_item = new ButtonContainerMenuItemView(parent, command_id, height);
1345 if (!parent->GetSubmenu())
1346 parent->CreateSubmenu();
1329 parent->GetSubmenu()->AddChildViewAt(menu_item, menu_index); 1347 parent->GetSubmenu()->AddChildViewAt(menu_item, menu_index);
1330 } else { 1348 } else {
1331 // For all other cases we use the more generic way to add menu items. 1349 // For all other cases we use the more generic way to add menu items.
1332 menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt( 1350 menu_item = views::MenuModelAdapter::AddMenuItemFromModelAt(
1333 model, model_index, parent, menu_index, command_id); 1351 model, model_index, parent, menu_index, command_id);
1334 } 1352 }
1335 1353
1336 if (menu_item) { 1354 if (menu_item) {
1337 // Flush all buttons to the right side of the menu for the new menu type. 1355 // Flush all buttons to the right side of the menu for the new menu type.
1338 menu_item->set_use_right_margin(!use_new_menu_); 1356 menu_item->set_use_right_margin(!use_new_menu_);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 0, 1398 0,
1381 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1399 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1382 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); 1400 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU);
1383 } 1401 }
1384 1402
1385 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { 1403 int WrenchMenu::ModelIndexFromCommandId(int command_id) const {
1386 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1404 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1387 DCHECK(ix != command_id_to_entry_.end()); 1405 DCHECK(ix != command_id_to_entry_.end());
1388 return ix->second.second; 1406 return ix->second.second;
1389 } 1407 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_view.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698