Chromium Code Reviews| Index: chrome/browser/ui/toolbar/action_box_menu_model.cc |
| diff --git a/chrome/browser/ui/toolbar/action_box_menu_model.cc b/chrome/browser/ui/toolbar/action_box_menu_model.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..baa23f550b82d26c6543a5c07b3882def63be2e0 |
| --- /dev/null |
| +++ b/chrome/browser/ui/toolbar/action_box_menu_model.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/toolbar/action_box_menu_model.h" |
| + |
| +#include <algorithm> |
|
Peter Kasting
2012/07/14 02:08:01
Nit: Why are either of these #includes necessary?
yefimt
2012/07/17 18:20:37
Done.
|
| +#include <cmath> |
| + |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/extensions/extension_toolbar_model.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ActionBoxMenuModel |
| + |
| +ActionBoxMenuModel::ActionBoxMenuModel(ExtensionService* extension_service) |
| + : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| + extension_service_(extension_service) { |
| + Build(); |
| +} |
| + |
| +ActionBoxMenuModel::~ActionBoxMenuModel() { |
| +} |
| + |
| +void ActionBoxMenuModel::ExecuteCommand(int command_id) { |
| +} |
| + |
| +bool ActionBoxMenuModel::IsCommandIdChecked(int command_id) const { |
| + return false; |
| +} |
| + |
| +bool ActionBoxMenuModel::IsCommandIdEnabled(int command_id) const { |
| + return true; |
| +} |
| + |
| +bool ActionBoxMenuModel::GetAcceleratorForCommandId( |
| + int command_id, |
| + ui::Accelerator* accelerator) { |
| + return false; |
| +} |
| + |
| +void ActionBoxMenuModel::Observe(int type, |
| + const content::NotificationSource& source, |
|
Peter Kasting
2012/07/14 02:08:01
Nit: Incorrect indenting
yefimt
2012/07/17 18:20:37
Done.
|
| + const content::NotificationDetails& details) { |
| +} |
| + |
| +size_t ActionBoxMenuModel::action_box_extensions_size() { |
| + ExtensionToolbarModel* toolbar_model = extension_service_->toolbar_model(); |
|
Peter Kasting
2012/07/14 02:08:01
Nit: Inline into next line (2 places)
yefimt
2012/07/17 18:20:37
Done.
|
| + return toolbar_model->action_box_extensions_size(); |
| +} |
| + |
| +const extensions::Extension* |
| +ActionBoxMenuModel::GetActionBoxExtensionByIndex(int index) { |
|
Peter Kasting
2012/07/14 02:08:01
Nit: Indent 4
yefimt
2012/07/17 18:20:37
Done.
|
| + ExtensionToolbarModel* toolbar_model = extension_service_->toolbar_model(); |
| + return toolbar_model->GetActionBoxExtensionByIndex(index); |
| +} |
| + |
| +void ActionBoxMenuModel::Build() { |
| + int command_id = 1000; |
|
Peter Kasting
2012/07/14 02:08:01
Nit: What is this magic number?
yefimt
2012/07/17 18:20:37
Done.
|
| + size_t size = action_box_extensions_size(); |
|
Peter Kasting
2012/07/14 02:08:01
Nit: Inline into loop declaration
yefimt
2012/07/17 18:20:37
Done.
|
| + for (size_t i = 0; i < size; ++i) { |
| + const extensions::Extension* extension = GetActionBoxExtensionByIndex(i); |
| + string16 label = UTF8ToUTF16(extension->name()); |
|
Peter Kasting
2012/07/14 02:08:01
Nit: Inline into next line
yefimt
2012/07/17 18:20:37
Done.
|
| + AddItem(command_id, label); |
| + id_to_extension_id_[command_id++] = extension->id(); |
| + } |
| +} |