| 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 |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 FOR_EACH_OBSERVER(WrenchMenuObserver, observer_list_, WrenchMenuDestroyed()); | 810 FOR_EACH_OBSERVER(WrenchMenuObserver, observer_list_, WrenchMenuDestroyed()); |
| 811 } | 811 } |
| 812 | 812 |
| 813 void WrenchMenu::Init(ui::MenuModel* model) { | 813 void WrenchMenu::Init(ui::MenuModel* model) { |
| 814 DCHECK(!root_); | 814 DCHECK(!root_); |
| 815 root_ = new MenuItemView(this); | 815 root_ = new MenuItemView(this); |
| 816 root_->set_has_icons(true); // We have checks, radios and icons, set this | 816 root_->set_has_icons(true); // We have checks, radios and icons, set this |
| 817 // so we get the taller menu style. | 817 // so we get the taller menu style. |
| 818 PopulateMenu(root_, model); | 818 PopulateMenu(root_, model); |
| 819 | 819 |
| 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; | 820 int32 types = views::MenuRunner::HAS_MNEMONICS; |
| 828 if (for_drop()) { | 821 if (for_drop()) { |
| 829 // We add NESTED_DRAG since currently the only operation to open the wrench | 822 // 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 | 823 // menu for is an extension action drag, which is controlled by the child |
| 831 // BrowserActionsContainer view. | 824 // BrowserActionsContainer view. |
| 832 types |= views::MenuRunner::FOR_DROP | views::MenuRunner::NESTED_DRAG; | 825 types |= views::MenuRunner::FOR_DROP | views::MenuRunner::NESTED_DRAG; |
| 833 } | 826 } |
| 834 menu_runner_.reset(new views::MenuRunner(root_, types)); | 827 menu_runner_.reset(new views::MenuRunner(root_, types)); |
| 835 } | 828 } |
| 836 | 829 |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 MenuItemView* WrenchMenu::AddMenuItem(MenuItemView* parent, | 1184 MenuItemView* WrenchMenu::AddMenuItem(MenuItemView* parent, |
| 1192 int menu_index, | 1185 int menu_index, |
| 1193 MenuModel* model, | 1186 MenuModel* model, |
| 1194 int model_index, | 1187 int model_index, |
| 1195 MenuModel::ItemType menu_type) { | 1188 MenuModel::ItemType menu_type) { |
| 1196 int command_id = model->GetCommandIdAt(model_index); | 1189 int command_id = model->GetCommandIdAt(model_index); |
| 1197 DCHECK(command_id > -1 || | 1190 DCHECK(command_id > -1 || |
| 1198 (command_id == -1 && | 1191 (command_id == -1 && |
| 1199 model->GetTypeAt(model_index) == MenuModel::TYPE_SEPARATOR)); | 1192 model->GetTypeAt(model_index) == MenuModel::TYPE_SEPARATOR)); |
| 1200 | 1193 |
| 1194 DCHECK(command_id < WrenchMenuModel::kMinBookmarkCommandId || |
| 1195 command_id > WrenchMenuModel::kMaxBookmarkCommandId); |
| 1196 |
| 1201 if (command_id > -1) { // Don't add separators to |command_id_to_entry_|. | 1197 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 | 1198 // All command ID's should be unique except for IDC_SHOW_HISTORY which is |
| 1203 // in both wrench menu and RecentTabs submenu, | 1199 // in both wrench menu and RecentTabs submenu, |
| 1204 if (command_id != IDC_SHOW_HISTORY) { | 1200 if (command_id != IDC_SHOW_HISTORY) { |
| 1205 DCHECK(command_id_to_entry_.find(command_id) == | 1201 DCHECK(command_id_to_entry_.find(command_id) == |
| 1206 command_id_to_entry_.end()) | 1202 command_id_to_entry_.end()) |
| 1207 << "command ID " << command_id << " already exists!"; | 1203 << "command ID " << command_id << " already exists!"; |
| 1208 } | 1204 } |
| 1209 command_id_to_entry_[command_id].first = model; | 1205 command_id_to_entry_[command_id].first = model; |
| 1210 command_id_to_entry_[command_id].second = model_index; | 1206 command_id_to_entry_[command_id].second = model_index; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 0, | 1256 0, |
| 1261 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1257 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1262 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1258 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
| 1263 } | 1259 } |
| 1264 | 1260 |
| 1265 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1261 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
| 1266 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1262 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1267 DCHECK(ix != command_id_to_entry_.end()); | 1263 DCHECK(ix != command_id_to_entry_.end()); |
| 1268 return ix->second.second; | 1264 return ix->second.second; |
| 1269 } | 1265 } |
| OLD | NEW |