diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/app_base.gypi | 2 | ||||
-rw-r--r-- | app/menus/button_menu_item_model.cc | 65 | ||||
-rw-r--r-- | app/menus/button_menu_item_model.h | 103 | ||||
-rw-r--r-- | app/menus/menu_model.h | 5 | ||||
-rw-r--r-- | app/menus/simple_menu_model.cc | 33 | ||||
-rw-r--r-- | app/menus/simple_menu_model.h | 7 |
6 files changed, 10 insertions, 205 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi index 4cd5e66..facbd4c 100644 --- a/app/app_base.gypi +++ b/app/app_base.gypi @@ -159,8 +159,6 @@ 'menus/accelerator.h', 'menus/accelerator_gtk.h', 'menus/accelerator_cocoa.h', - 'menus/button_menu_item_model.cc', - 'menus/button_menu_item_model.h', 'menus/menu_model.cc', 'menus/menu_model.h', 'menus/simple_menu_model.cc', diff --git a/app/menus/button_menu_item_model.cc b/app/menus/button_menu_item_model.cc deleted file mode 100644 index c5064fb..0000000 --- a/app/menus/button_menu_item_model.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) 2010 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 "app/menus/button_menu_item_model.h" - -#include "app/l10n_util.h" - -namespace menus { - -ButtonMenuItemModel::ButtonMenuItemModel( - int string_id, - ButtonMenuItemModel::Delegate* delegate) - : item_label_(l10n_util::GetStringUTF16(string_id)), - delegate_(delegate) { -} - -void ButtonMenuItemModel::AddItemWithStringId(int command_id, int string_id) { - Item item = { command_id, TYPE_BUTTON, l10n_util::GetStringUTF16(string_id), - SIDE_BOTH, -1 }; - items_.push_back(item); -} - -void ButtonMenuItemModel::AddItemWithImage(int command_id, - int icon_idr) { - Item item = { command_id, TYPE_BUTTON, string16(), SIDE_BOTH, icon_idr }; - items_.push_back(item); -} - -void ButtonMenuItemModel::AddSpace() { - Item item = { 0, TYPE_SPACE, string16(), SIDE_NONE, -1 }; - items_.push_back(item); -} - -int ButtonMenuItemModel::GetItemCount() const { - return static_cast<int>(items_.size()); -} - -ButtonMenuItemModel::ButtonType ButtonMenuItemModel::GetTypeAt( - int index) const { - return items_[index].type; -} - -int ButtonMenuItemModel::GetCommandIdAt(int index) const { - return items_[index].command_id; -} - -const string16& ButtonMenuItemModel::GetLabelAt(int index) const { - return items_[index].label; -} - -bool ButtonMenuItemModel::GetIconAt(int index, int* icon_idr) const { - if (items_[index].icon_idr == -1) - return false; - - *icon_idr = items_[index].icon_idr; - return true; -} - -void ButtonMenuItemModel::ActivatedCommand(int command_id) { - if (delegate_) - delegate_->ExecuteCommand(command_id); -} - -} // namespace menus diff --git a/app/menus/button_menu_item_model.h b/app/menus/button_menu_item_model.h deleted file mode 100644 index b8418d1..0000000 --- a/app/menus/button_menu_item_model.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2010 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. - -#ifndef APP_MENUS_BUTTON_MENU_ITEM_MODEL_H_ -#define APP_MENUS_BUTTON_MENU_ITEM_MODEL_H_ - -#include <vector> - -#include "base/string16.h" -#include "third_party/skia/include/core/SkBitmap.h" - -namespace menus { - -// A model representing the rows of buttons that should be inserted in a button -// containing menu item. -// -// TODO(erg): There are still two major pieces missing from this model. It -// needs to be able to group buttons together so they all have the same -// width. ButtonSides needs to be used to communicate how buttons are squashed -// together. -class ButtonMenuItemModel { - public: - // Types of buttons. - enum ButtonType { - TYPE_SPACE, - TYPE_BUTTON - }; - - // Which sides of the button are visible. - enum ButtonSides { - SIDE_NONE = 0, - SIDE_LEFT = 1 << 0, - SIDE_RIGHT = 1 << 1, - SIDE_BOTH = SIDE_LEFT | SIDE_RIGHT - }; - - class Delegate { - public: - // Some command ids have labels that change over time. - virtual bool IsLabelForCommandIdDynamic(int command_id) const { - return false; - } - virtual string16 GetLabelForCommandId(int command_id) const { - return string16(); - } - - // Performs the action associated with the specified command id. - virtual void ExecuteCommand(int command_id) = 0; - }; - - ButtonMenuItemModel(int string_id, ButtonMenuItemModel::Delegate* delegate); - - // Adds a button that will emit |command_id|. - void AddItemWithStringId(int command_id, int string_id); - - // Adds a button that has an icon instead of a label. - void AddItemWithImage(int command_id, int icon_idr); - - // Adds a small horizontal space. - void AddSpace(); - - // Returns the number of items for iteration. - int GetItemCount() const; - - // Returns what kind of item is at |index|. - ButtonType GetTypeAt(int index) const; - - // Changes a position into a command ID. - int GetCommandIdAt(int index) const; - - const string16& GetLabelAt(int index) const; - - // If the button at |index| should have an icon instead, returns true and - // sets the IDR |icon|. - bool GetIconAt(int index, int* icon) const; - - // Called from implementations. - void ActivatedCommand(int command_id); - - const string16& label() const { return item_label_; } - - private: - // The non-clickable label to the left of the buttons. - string16 item_label_; - - struct Item { - int command_id; - ButtonType type; - string16 label; - int sides; - int icon_idr; - }; - std::vector<Item> items_; - - Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(ButtonMenuItemModel); -}; - -} // namespace menus - -#endif // APP_MENUS_BUTTON_MENU_ITEM_MODEL_H_ diff --git a/app/menus/menu_model.h b/app/menus/menu_model.h index f14c8b5..50f2e54 100644 --- a/app/menus/menu_model.h +++ b/app/menus/menu_model.h @@ -20,7 +20,6 @@ class Font; namespace menus { class Accelerator; -class ButtonMenuItemModel; // An interface implemented by an object that provides the content of a menu. class MenuModel { @@ -33,7 +32,6 @@ class MenuModel { TYPE_CHECK, TYPE_RADIO, TYPE_SEPARATOR, - TYPE_BUTTON_ITEM, TYPE_SUBMENU }; @@ -87,9 +85,6 @@ class MenuModel { // is an icon, false otherwise. virtual bool GetIconAt(int index, SkBitmap* icon) const = 0; - // Returns the model for a menu item with a line of buttons at |index|. - virtual ButtonMenuItemModel* GetButtonMenuItemAt(int index) const = 0; - // Returns the enabled state of the item at the specified index. virtual bool IsEnabledAt(int index) const = 0; diff --git a/app/menus/simple_menu_model.cc b/app/menus/simple_menu_model.cc index 3e51986..8631666 100644 --- a/app/menus/simple_menu_model.cc +++ b/app/menus/simple_menu_model.cc @@ -20,7 +20,7 @@ SimpleMenuModel::~SimpleMenuModel() { } void SimpleMenuModel::AddItem(int command_id, const string16& label) { - Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL, NULL }; + Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL }; AppendItem(item); } @@ -30,7 +30,7 @@ void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { void SimpleMenuModel::AddSeparator() { Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1, - NULL, NULL }; + NULL }; AppendItem(item); } @@ -45,8 +45,7 @@ void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { void SimpleMenuModel::AddRadioItem(int command_id, const string16& label, int group_id) { - Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL, - NULL }; + Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL }; AppendItem(item); } @@ -55,15 +54,9 @@ void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id, AddRadioItem(command_id, l10n_util::GetStringUTF16(string_id), group_id); } -void SimpleMenuModel::AddButtonItem(int command_id, - ButtonMenuItemModel* model) { - Item item = { 0, string16(), SkBitmap(), TYPE_BUTTON_ITEM, -1, NULL, model }; - AppendItem(item); -} - void SimpleMenuModel::AddSubMenu(int command_id, const string16& label, MenuModel* model) { - Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model, NULL }; + Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model }; AppendItem(item); } @@ -74,7 +67,7 @@ void SimpleMenuModel::AddSubMenuWithStringId(int command_id, void SimpleMenuModel::InsertItemAt( int index, int command_id, const string16& label) { - Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL, NULL }; + Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL }; InsertItemAtIndex(item, index); } @@ -85,13 +78,13 @@ void SimpleMenuModel::InsertItemWithStringIdAt( void SimpleMenuModel::InsertSeparatorAt(int index) { Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1, - NULL, NULL }; + NULL }; InsertItemAtIndex(item, index); } void SimpleMenuModel::InsertCheckItemAt( int index, int command_id, const string16& label) { - Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL, NULL }; + Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL }; InsertItemAtIndex(item, index); } @@ -103,8 +96,7 @@ void SimpleMenuModel::InsertCheckItemWithStringIdAt( void SimpleMenuModel::InsertRadioItemAt( int index, int command_id, const string16& label, int group_id) { - Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL, - NULL }; + Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL }; InsertItemAtIndex(item, index); } @@ -116,7 +108,7 @@ void SimpleMenuModel::InsertRadioItemWithStringIdAt( void SimpleMenuModel::InsertSubMenuAt( int index, int command_id, const string16& label, MenuModel* model) { - Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model, NULL }; + Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model }; InsertItemAtIndex(item, index); } @@ -207,14 +199,9 @@ bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const { return true; } -ButtonMenuItemModel* SimpleMenuModel::GetButtonMenuItemAt(int index) const { - return items_.at(FlipIndex(index)).button_model; -} - bool SimpleMenuModel::IsEnabledAt(int index) const { int command_id = GetCommandIdAt(index); - if (!delegate_ || command_id == kSeparatorId || - items_.at(FlipIndex(index)).button_model) + if (!delegate_ || command_id == kSeparatorId) return true; return delegate_->IsCommandIdEnabled(command_id); } diff --git a/app/menus/simple_menu_model.h b/app/menus/simple_menu_model.h index 79b2f8a..8dd6c64 100644 --- a/app/menus/simple_menu_model.h +++ b/app/menus/simple_menu_model.h @@ -8,7 +8,6 @@ #include <vector> #include "base/string16.h" -#include "app/menus/button_menu_item_model.h" #include "app/menus/menu_model.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -61,10 +60,6 @@ class SimpleMenuModel : public MenuModel { void AddCheckItemWithStringId(int command_id, int string_id); void AddRadioItem(int command_id, const string16& label, int group_id); void AddRadioItemWithStringId(int command_id, int string_id, int group_id); - - // These three methods take pointers to various sub-models. These models - // should be owned by the same owner of this SimpleMenuModel. - void AddButtonItem(int command_id, ButtonMenuItemModel* model); void AddSubMenu(int command_id, const string16& label, MenuModel* model); void AddSubMenuWithStringId(int command_id, int string_id, MenuModel* model); @@ -107,7 +102,6 @@ class SimpleMenuModel : public MenuModel { virtual bool IsItemCheckedAt(int index) const; virtual int GetGroupIdAt(int index) const; virtual bool GetIconAt(int index, SkBitmap* icon) const; - virtual ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; virtual bool IsEnabledAt(int index) const; virtual void HighlightChangedTo(int index); virtual void ActivatedAt(int index); @@ -131,7 +125,6 @@ class SimpleMenuModel : public MenuModel { ItemType type; int group_id; MenuModel* submenu; - ButtonMenuItemModel* button_model; }; std::vector<Item> items_; |