OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/context_menu_matcher.h" | 5 #include "chrome/browser/extensions/context_menu_matcher.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/extensions/extension_util.h" | 9 #include "chrome/browser/extensions/extension_util.h" |
10 #include "chrome/common/extensions/api/context_menus.h" | 10 #include "chrome/common/extensions/api/context_menus.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 // If last item was of type radio but the current one isn't, auto-insert | 239 // If last item was of type radio but the current one isn't, auto-insert |
240 // a separator. The converse case is handled below. | 240 // a separator. The converse case is handled below. |
241 if (last_type == MenuItem::RADIO && | 241 if (last_type == MenuItem::RADIO && |
242 item->type() != MenuItem::RADIO) { | 242 item->type() != MenuItem::RADIO) { |
243 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | 243 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); |
244 last_type = MenuItem::SEPARATOR; | 244 last_type = MenuItem::SEPARATOR; |
245 } | 245 } |
246 | 246 |
247 int menu_id = ConvertToExtensionsCustomCommandId(*index); | 247 int menu_id = ConvertToExtensionsCustomCommandId(*index); |
248 ++(*index); | |
249 ++num_items; | |
250 // Action context menus have a limit for top level extension items to | 248 // Action context menus have a limit for top level extension items to |
251 // prevent control items from being pushed off the screen, since extension | 249 // prevent control items from being pushed off the screen, since extension |
252 // items will not be placed in a submenu. | 250 // items will not be placed in a submenu. |
253 const int top_level_limit = api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT; | 251 const int top_level_limit = api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT; |
254 if (menu_id >= extensions_context_custom_last || | 252 if (menu_id >= extensions_context_custom_last || |
255 (is_action_menu_top_level && num_items >= top_level_limit)) | 253 (is_action_menu_top_level && num_items >= top_level_limit)) |
256 return; | 254 return; |
257 | 255 |
| 256 ++(*index); |
| 257 ++num_items; |
| 258 |
258 extension_item_map_[menu_id] = item->id(); | 259 extension_item_map_[menu_id] = item->id(); |
259 base::string16 title = item->TitleWithReplacement(selection_text, | 260 base::string16 title = item->TitleWithReplacement(selection_text, |
260 kMaxExtensionItemTitleLength); | 261 kMaxExtensionItemTitleLength); |
261 if (item->type() == MenuItem::NORMAL) { | 262 if (item->type() == MenuItem::NORMAL) { |
262 MenuItem::List children = | 263 MenuItem::List children = |
263 GetRelevantExtensionItems(item->children(), can_cross_incognito); | 264 GetRelevantExtensionItems(item->children(), can_cross_incognito); |
264 if (children.empty()) { | 265 if (children.empty()) { |
265 menu_model->AddItem(menu_id, title); | 266 menu_model->AddItem(menu_id, title); |
266 } else { | 267 } else { |
267 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(delegate_); | 268 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(delegate_); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 DCHECK_GE(index, 0); | 313 DCHECK_GE(index, 0); |
313 | 314 |
314 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | 315 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); |
315 DCHECK(icon.width() == gfx::kFaviconSize); | 316 DCHECK(icon.width() == gfx::kFaviconSize); |
316 DCHECK(icon.height() == gfx::kFaviconSize); | 317 DCHECK(icon.height() == gfx::kFaviconSize); |
317 | 318 |
318 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); | 319 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); |
319 } | 320 } |
320 | 321 |
321 } // namespace extensions | 322 } // namespace extensions |
OLD | NEW |