| 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 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 ui::Accelerator menu_accelerator; | 1055 ui::Accelerator menu_accelerator; |
| 1056 if (!entry.first->GetAcceleratorAt(entry.second, &menu_accelerator)) | 1056 if (!entry.first->GetAcceleratorAt(entry.second, &menu_accelerator)) |
| 1057 return false; | 1057 return false; |
| 1058 | 1058 |
| 1059 *accelerator = ui::Accelerator(menu_accelerator.key_code(), | 1059 *accelerator = ui::Accelerator(menu_accelerator.key_code(), |
| 1060 menu_accelerator.modifiers()); | 1060 menu_accelerator.modifiers()); |
| 1061 return true; | 1061 return true; |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 void WrenchMenu::WillShowMenu(MenuItemView* menu) { | 1064 void WrenchMenu::WillShowMenu(MenuItemView* menu) { |
| 1065 // If we're showing the root menu, we need to initialize the extension |
| 1066 // overflow container, because it needs to know the width of other |
| 1067 // children in the menu before it can size itself. |
| 1068 // Ideally, we'd do this earlier, but other menu sizes aren't fully set until |
| 1069 // after the menu is told to run. |
| 1070 if (menu == root_ && extension_overflow_.get()) |
| 1071 extension_overflow_->Init(root_); |
| 1065 if (menu == bookmark_menu_) | 1072 if (menu == bookmark_menu_) |
| 1066 CreateBookmarkMenu(); | 1073 CreateBookmarkMenu(); |
| 1067 } | 1074 } |
| 1068 | 1075 |
| 1069 void WrenchMenu::WillHideMenu(MenuItemView* menu) { | 1076 void WrenchMenu::WillHideMenu(MenuItemView* menu) { |
| 1070 // Turns off the fade out animation of the wrench menus if | 1077 // Turns off the fade out animation of the wrench menus if |
| 1071 // |feedback_menu_item_| is selected. This excludes the wrench menu itself | 1078 // |feedback_menu_item_| is selected. This excludes the wrench menu itself |
| 1072 // from the snapshot in the feedback UI. | 1079 // from the snapshot in the feedback UI. |
| 1073 if (menu->HasSubmenu() && feedback_menu_item_ && | 1080 if (menu->HasSubmenu() && feedback_menu_item_ && |
| 1074 feedback_menu_item_->IsSelected()) { | 1081 feedback_menu_item_->IsSelected()) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 #endif | 1135 #endif |
| 1129 | 1136 |
| 1130 item->SetMargins(top_margin, bottom_margin); | 1137 item->SetMargins(top_margin, bottom_margin); |
| 1131 } | 1138 } |
| 1132 | 1139 |
| 1133 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) | 1140 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) |
| 1134 PopulateMenu(item, model->GetSubmenuModelAt(i)); | 1141 PopulateMenu(item, model->GetSubmenuModelAt(i)); |
| 1135 | 1142 |
| 1136 switch (model->GetCommandIdAt(i)) { | 1143 switch (model->GetCommandIdAt(i)) { |
| 1137 case IDC_EXTENSIONS_OVERFLOW_MENU: { | 1144 case IDC_EXTENSIONS_OVERFLOW_MENU: { |
| 1138 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar( | 1145 extension_overflow_.reset(new ExtensionToolbarMenuView(browser_, this)); |
| 1139 new ExtensionToolbarMenuView(browser_, this)); | 1146 if (extension_overflow_->GetPreferredSize().height() > 0) { |
| 1140 if (extension_toolbar->GetPreferredSize().height() > 0) | 1147 extension_overflow_->set_owned_by_client(); |
| 1141 item->AddChildView(extension_toolbar.release()); | 1148 item->AddChildView(extension_overflow_.get()); |
| 1142 else | 1149 } else { |
| 1150 extension_overflow_.reset(); |
| 1143 item->SetVisible(false); | 1151 item->SetVisible(false); |
| 1152 } |
| 1144 break; | 1153 break; |
| 1145 } | 1154 } |
| 1146 | 1155 |
| 1147 case IDC_CUT: | 1156 case IDC_CUT: |
| 1148 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); | 1157 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); |
| 1149 DCHECK_LT(i + 2, max); | 1158 DCHECK_LT(i + 2, max); |
| 1150 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); | 1159 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); |
| 1151 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); | 1160 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); |
| 1152 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); | 1161 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); |
| 1153 item->AddChildView(new CutCopyPasteView(this, model, | 1162 item->AddChildView(new CutCopyPasteView(this, model, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 0, | 1270 0, |
| 1262 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1271 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1263 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1272 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
| 1264 } | 1273 } |
| 1265 | 1274 |
| 1266 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1275 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
| 1267 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1276 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1268 DCHECK(ix != command_id_to_entry_.end()); | 1277 DCHECK(ix != command_id_to_entry_.end()); |
| 1269 return ix->second.second; | 1278 return ix->second.second; |
| 1270 } | 1279 } |
| OLD | NEW |