OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <cmath> |
| 9 |
| 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 |
| 14 //////////////////////////////////////////////////////////////////////////////// |
| 15 // ActionBoxMenuModel |
| 16 |
| 17 ActionBoxMenuModel::ActionBoxMenuModel(ExtensionService* extension_service) |
| 18 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| 19 extension_service_(extension_service) { |
| 20 Build(); |
| 21 } |
| 22 |
| 23 ActionBoxMenuModel::~ActionBoxMenuModel() { |
| 24 } |
| 25 |
| 26 void ActionBoxMenuModel::ExecuteCommand(int command_id) { |
| 27 } |
| 28 |
| 29 bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const { |
| 30 return false; |
| 31 } |
| 32 |
| 33 bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const { |
| 34 return true; |
| 35 } |
| 36 |
| 37 bool ActionBoxMenuModel::GetAcceleratorForCommandId( |
| 38 int command_id, |
| 39 ui::Accelerator* accelerator) { |
| 40 return false; |
| 41 } |
| 42 |
| 43 void ActionBoxMenuModel::Observe(int type, |
| 44 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) { |
| 46 } |
| 47 |
| 48 size_t ActionBoxMenuModel::action_box_extensions_size() { |
| 49 ExtensionToolbarModel* toolbar_model = extension_service_->toolbar_model(); |
| 50 return toolbar_model->action_box_extensions_size(); |
| 51 } |
| 52 |
| 53 const extensions::Extension* |
| 54 ActionBoxMenuModel::GetActionBoxExtensionByIndex(int index) { |
| 55 ExtensionToolbarModel* toolbar_model = extension_service_->toolbar_model(); |
| 56 return toolbar_model->GetActionBoxExtensionByIndex(index); |
| 57 } |
| 58 |
| 59 void ActionBoxMenuModel::Build() { |
| 60 int command_id = 1000; |
| 61 size_t size = action_box_extensions_size(); |
| 62 for (size_t i = 0; i < size; ++i) { |
| 63 const extensions::Extension* extension = GetActionBoxExtensionByIndex(i); |
| 64 string16 label = UTF8ToUTF16(extension->name()); |
| 65 AddItem(command_id, label); |
| 66 id_to_extension_id_[command_id++] = extension->id(); |
| 67 } |
| 68 } |
OLD | NEW |