OLD | NEW |
---|---|
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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 | 675 |
674 fullscreen_button_->SetFocusable(true); | 676 fullscreen_button_->SetFocusable(true); |
675 fullscreen_button_->set_request_focus_on_press(false); | 677 fullscreen_button_->set_request_focus_on_press(false); |
676 fullscreen_button_->set_tag(fullscreen_index); | 678 fullscreen_button_->set_tag(fullscreen_index); |
677 fullscreen_button_->SetImageAlignment( | 679 fullscreen_button_->SetImageAlignment( |
678 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | 680 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
679 int horizontal_padding = | 681 int horizontal_padding = |
680 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; | 682 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; |
681 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder( | 683 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder( |
682 0, horizontal_padding, 0, horizontal_padding)); | 684 0, horizontal_padding, 0, horizontal_padding)); |
683 fullscreen_button_->set_background( | 685 fullscreen_button_->set_background(new InMenuButtonBackground( |
684 new InMenuButtonBackground(InMenuButtonBackground::SINGLE_BUTTON, | 686 InMenuButtonBackground::SINGLE_BUTTON, menu->use_new_menu())); |
685 menu->use_new_menu())); | |
686 fullscreen_button_->SetAccessibleName( | 687 fullscreen_button_->SetAccessibleName( |
687 GetAccessibleNameForWrenchMenuItem( | 688 GetAccessibleNameForWrenchMenuItem( |
688 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); | 689 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); |
689 AddChildView(fullscreen_button_); | 690 AddChildView(fullscreen_button_); |
690 | 691 |
691 // Need to set a font list for the zoom label width calculations. | 692 // Need to set a font list for the zoom label width calculations. |
692 OnNativeThemeChanged(NULL); | 693 OnNativeThemeChanged(NULL); |
693 UpdateZoomControls(); | 694 UpdateZoomControls(); |
694 } | 695 } |
695 | 696 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1141 | 1142 |
1142 bool WrenchMenu::IsCommandEnabled(int command_id) const { | 1143 bool WrenchMenu::IsCommandEnabled(int command_id) const { |
1143 if (IsBookmarkCommand(command_id)) | 1144 if (IsBookmarkCommand(command_id)) |
1144 return true; | 1145 return true; |
1145 | 1146 |
1146 if (command_id == 0) | 1147 if (command_id == 0) |
1147 return false; // The root item. | 1148 return false; // The root item. |
1148 | 1149 |
1149 // The items representing the cut menu (cut/copy/paste) and zoom menu | 1150 // The items representing the cut menu (cut/copy/paste) and zoom menu |
1150 // (increment/decrement/reset) are always enabled. The child views of these | 1151 // (increment/decrement/reset) are always enabled. The child views of these |
1151 // items enabled state updates appropriately. | 1152 // items enabled state updates appropriately. |
Devlin
2014/06/23 17:55:29
does this comment need updating?
| |
1152 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) | 1153 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS || |
1154 command_id == IDC_EXTENSIONS_OVERFLOW_MENU) | |
1153 return true; | 1155 return true; |
1154 | 1156 |
1155 const Entry& entry = command_id_to_entry_.find(command_id)->second; | 1157 const Entry& entry = command_id_to_entry_.find(command_id)->second; |
1156 return entry.first->IsEnabledAt(entry.second); | 1158 return entry.first->IsEnabledAt(entry.second); |
1157 } | 1159 } |
1158 | 1160 |
1159 void WrenchMenu::ExecuteCommand(int command_id, int mouse_event_flags) { | 1161 void WrenchMenu::ExecuteCommand(int command_id, int mouse_event_flags) { |
1160 if (IsBookmarkCommand(command_id)) { | 1162 if (IsBookmarkCommand(command_id)) { |
1161 bookmark_menu_delegate_->ExecuteCommand(command_id, mouse_event_flags); | 1163 bookmark_menu_delegate_->ExecuteCommand(command_id, mouse_event_flags); |
1162 return; | 1164 return; |
1163 } | 1165 } |
1164 | 1166 |
1165 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { | 1167 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS || |
1168 command_id == IDC_EXTENSIONS_OVERFLOW_MENU) { | |
1166 // These items are represented by child views. If ExecuteCommand is invoked | 1169 // These items are represented by child views. If ExecuteCommand is invoked |
1167 // it means the user clicked on the area around the buttons and we should | 1170 // it means the user clicked on the area around the buttons and we should |
1168 // not do anyting. | 1171 // not do anyting. |
1169 return; | 1172 return; |
1170 } | 1173 } |
1171 | 1174 |
1172 const Entry& entry = command_id_to_entry_.find(command_id)->second; | 1175 const Entry& entry = command_id_to_entry_.find(command_id)->second; |
1173 return entry.first->ActivatedAt(entry.second, mouse_event_flags); | 1176 return entry.first->ActivatedAt(entry.second, mouse_event_flags); |
1174 } | 1177 } |
1175 | 1178 |
1176 bool WrenchMenu::GetAccelerator(int command_id, | 1179 bool WrenchMenu::GetAccelerator(int command_id, |
1177 ui::Accelerator* accelerator) const { | 1180 ui::Accelerator* accelerator) const { |
1178 if (IsBookmarkCommand(command_id)) | 1181 if (IsBookmarkCommand(command_id)) |
1179 return false; | 1182 return false; |
1180 | 1183 |
1181 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS) { | 1184 if (command_id == IDC_CUT || command_id == IDC_ZOOM_MINUS || |
1185 command_id == IDC_EXTENSIONS_OVERFLOW_MENU) { | |
1182 // These have special child views; don't show the accelerator for them. | 1186 // These have special child views; don't show the accelerator for them. |
1183 return false; | 1187 return false; |
1184 } | 1188 } |
1185 | 1189 |
1186 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1190 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1187 const Entry& entry = ix->second; | 1191 const Entry& entry = ix->second; |
1188 ui::Accelerator menu_accelerator; | 1192 ui::Accelerator menu_accelerator; |
1189 if (!entry.first->GetAcceleratorAt(entry.second, &menu_accelerator)) | 1193 if (!entry.first->GetAcceleratorAt(entry.second, &menu_accelerator)) |
1190 return false; | 1194 return false; |
1191 | 1195 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1238 MenuModel* model) { | 1242 MenuModel* model) { |
1239 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { | 1243 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { |
1240 // The button container menu items have a special height which we have to | 1244 // The button container menu items have a special height which we have to |
1241 // use instead of the normal height. | 1245 // use instead of the normal height. |
1242 int height = 0; | 1246 int height = 0; |
1243 if (use_new_menu_ && | 1247 if (use_new_menu_ && |
1244 (model->GetCommandIdAt(i) == IDC_CUT || | 1248 (model->GetCommandIdAt(i) == IDC_CUT || |
1245 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS)) | 1249 model->GetCommandIdAt(i) == IDC_ZOOM_MINUS)) |
1246 height = kMenuItemContainingButtonsHeight; | 1250 height = kMenuItemContainingButtonsHeight; |
1247 | 1251 |
1252 if (model->GetCommandIdAt(i) == IDC_EXTENSIONS_OVERFLOW_MENU) { | |
1253 extension_toolbar_menu_view_.reset( | |
Devlin
2014/06/23 17:55:29
If this variable is only ever created and then rel
Finnur
2014/06/25 16:18:11
Nope.
| |
1254 new ExtensionToolbarMenuView(browser_)); | |
1255 height = extension_toolbar_menu_view_->GetPreferredSize().height(); | |
1256 } | |
1257 | |
1248 // Add the menu item at the end. | 1258 // Add the menu item at the end. |
1249 int menu_index = parent->HasSubmenu() ? | 1259 int menu_index = parent->HasSubmenu() ? |
1250 parent->GetSubmenu()->child_count() : 0; | 1260 parent->GetSubmenu()->child_count() : 0; |
1251 MenuItemView* item = AddMenuItem( | 1261 MenuItemView* item = AddMenuItem( |
1252 parent, menu_index, model, i, model->GetTypeAt(i), height); | 1262 parent, menu_index, model, i, model->GetTypeAt(i), height); |
Finnur
2014/06/24 17:00:50
It crashes because parent->GetSubmenu() returns NU
| |
1253 | 1263 |
1254 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) | 1264 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) |
1255 PopulateMenu(item, model->GetSubmenuModelAt(i)); | 1265 PopulateMenu(item, model->GetSubmenuModelAt(i)); |
1256 | 1266 |
1257 switch (model->GetCommandIdAt(i)) { | 1267 switch (model->GetCommandIdAt(i)) { |
1268 case IDC_EXTENSIONS_OVERFLOW_MENU: | |
1269 if (height > 0) | |
1270 item->AddChildView(extension_toolbar_menu_view_.release()); | |
1271 else | |
1272 item->SetVisible(false); | |
1273 break; | |
1258 case IDC_CUT: | 1274 case IDC_CUT: |
1259 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); | 1275 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); |
1260 DCHECK_LT(i + 2, max); | 1276 DCHECK_LT(i + 2, max); |
1261 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); | 1277 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); |
1262 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); | 1278 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); |
1263 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); | 1279 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); |
1264 item->AddChildView(new CutCopyPasteView(this, model, | 1280 item->AddChildView(new CutCopyPasteView(this, model, |
1265 i, i + 1, i + 2)); | 1281 i, i + 1, i + 2)); |
1266 i += 2; | 1282 i += 2; |
1267 break; | 1283 break; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1382 0, | 1398 0, |
1383 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1399 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1384 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1400 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
1385 } | 1401 } |
1386 | 1402 |
1387 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1403 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
1388 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1404 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1389 DCHECK(ix != command_id_to_entry_.end()); | 1405 DCHECK(ix != command_id_to_entry_.end()); |
1390 return ix->second.second; | 1406 return ix->second.second; |
1391 } | 1407 } |
OLD | NEW |