1 // Copyright (c) 2011 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.
5 #include "ui/base/models/button_menu_item_model.h"
7 #include "ui/base/l10n/l10n_util.h"
11 bool ButtonMenuItemModel::Delegate::IsItemForCommandIdDynamic(
12 int command_id
) const {
16 base::string16
ButtonMenuItemModel::Delegate::GetLabelForCommandId(
17 int command_id
) const {
18 return base::string16();
21 bool ButtonMenuItemModel::Delegate::IsCommandIdEnabled(int command_id
) const {
25 bool ButtonMenuItemModel::Delegate::DoesCommandIdDismissMenu(
26 int command_id
) const {
30 struct ButtonMenuItemModel::Item
{
38 ButtonMenuItemModel::ButtonMenuItemModel(
40 ButtonMenuItemModel::Delegate
* delegate
)
41 : item_label_(l10n_util::GetStringUTF16(string_id
)),
45 ButtonMenuItemModel::~ButtonMenuItemModel() {
48 void ButtonMenuItemModel::AddGroupItemWithStringId(
49 int command_id
, int string_id
) {
50 Item item
= { command_id
, TYPE_BUTTON
, l10n_util::GetStringUTF16(string_id
),
52 items_
.push_back(item
);
55 void ButtonMenuItemModel::AddItemWithImage(int command_id
,
57 Item item
= { command_id
, TYPE_BUTTON
, base::string16(), icon_idr
, false };
58 items_
.push_back(item
);
61 void ButtonMenuItemModel::AddButtonLabel(int command_id
, int string_id
) {
62 Item item
= { command_id
, TYPE_BUTTON_LABEL
,
63 l10n_util::GetStringUTF16(string_id
), -1, false };
64 items_
.push_back(item
);
67 void ButtonMenuItemModel::AddSpace() {
68 Item item
= { 0, TYPE_SPACE
, base::string16(), -1, false };
69 items_
.push_back(item
);
72 int ButtonMenuItemModel::GetItemCount() const {
73 return static_cast<int>(items_
.size());
76 ButtonMenuItemModel::ButtonType
ButtonMenuItemModel::GetTypeAt(
78 return items_
[index
].type
;
81 int ButtonMenuItemModel::GetCommandIdAt(int index
) const {
82 return items_
[index
].command_id
;
85 bool ButtonMenuItemModel::IsItemDynamicAt(int index
) const {
87 return delegate_
->IsItemForCommandIdDynamic(GetCommandIdAt(index
));
91 base::string16
ButtonMenuItemModel::GetLabelAt(int index
) const {
92 if (IsItemDynamicAt(index
))
93 return delegate_
->GetLabelForCommandId(GetCommandIdAt(index
));
94 return items_
[index
].label
;
97 bool ButtonMenuItemModel::GetIconAt(int index
, int* icon_idr
) const {
98 if (items_
[index
].icon_idr
== -1)
101 *icon_idr
= items_
[index
].icon_idr
;
105 bool ButtonMenuItemModel::PartOfGroup(int index
) const {
106 return items_
[index
].part_of_group
;
109 void ButtonMenuItemModel::ActivatedCommand(int command_id
) {
111 delegate_
->ExecuteCommand(command_id
, 0);
114 bool ButtonMenuItemModel::IsEnabledAt(int index
) const {
115 return IsCommandIdEnabled(items_
[index
].command_id
);
118 bool ButtonMenuItemModel::DismissesMenuAt(int index
) const {
119 return DoesCommandIdDismissMenu(items_
[index
].command_id
);
122 bool ButtonMenuItemModel::IsCommandIdEnabled(int command_id
) const {
124 return delegate_
->IsCommandIdEnabled(command_id
);
128 bool ButtonMenuItemModel::DoesCommandIdDismissMenu(int command_id
) const {
130 return delegate_
->DoesCommandIdDismissMenu(command_id
);