Update V8 to version 4.7.45.
[chromium-blink-merge.git] / ui / base / models / button_menu_item_model.cc
blobdd05fe2640e982c09b2022f7b1b90d05dc9e0f87
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"
9 namespace ui {
11 bool ButtonMenuItemModel::Delegate::IsItemForCommandIdDynamic(
12 int command_id) const {
13 return false;
16 base::string16 ButtonMenuItemModel::Delegate::GetLabelForCommandId(
17 int command_id) const {
18 return base::string16();
21 bool ButtonMenuItemModel::Delegate::IsCommandIdEnabled(int command_id) const {
22 return true;
25 bool ButtonMenuItemModel::Delegate::DoesCommandIdDismissMenu(
26 int command_id) const {
27 return true;
30 struct ButtonMenuItemModel::Item {
31 int command_id;
32 ButtonType type;
33 base::string16 label;
34 int icon_idr;
35 bool part_of_group;
38 ButtonMenuItemModel::ButtonMenuItemModel(
39 int string_id,
40 ButtonMenuItemModel::Delegate* delegate)
41 : item_label_(l10n_util::GetStringUTF16(string_id)),
42 delegate_(delegate) {
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),
51 -1, true };
52 items_.push_back(item);
55 void ButtonMenuItemModel::AddItemWithImage(int command_id,
56 int icon_idr) {
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(
77 int index) const {
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 {
86 if (delegate_)
87 return delegate_->IsItemForCommandIdDynamic(GetCommandIdAt(index));
88 return false;
91 bool ButtonMenuItemModel::GetAcceleratorAt(int index,
92 ui::Accelerator* accelerator) const {
93 if (delegate_) {
94 return delegate_->GetAcceleratorForCommandId(GetCommandIdAt(index),
95 accelerator);
97 return false;
100 base::string16 ButtonMenuItemModel::GetLabelAt(int index) const {
101 if (IsItemDynamicAt(index))
102 return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
103 return items_[index].label;
106 bool ButtonMenuItemModel::GetIconAt(int index, int* icon_idr) const {
107 if (items_[index].icon_idr == -1)
108 return false;
110 *icon_idr = items_[index].icon_idr;
111 return true;
114 bool ButtonMenuItemModel::PartOfGroup(int index) const {
115 return items_[index].part_of_group;
118 void ButtonMenuItemModel::ActivatedAt(int index) {
119 if (delegate_)
120 delegate_->ExecuteCommand(GetCommandIdAt(index), 0);
123 bool ButtonMenuItemModel::IsEnabledAt(int index) const {
124 return IsCommandIdEnabled(items_[index].command_id);
127 bool ButtonMenuItemModel::DismissesMenuAt(int index) const {
128 return DoesCommandIdDismissMenu(items_[index].command_id);
131 bool ButtonMenuItemModel::IsCommandIdEnabled(int command_id) const {
132 if (delegate_)
133 return delegate_->IsCommandIdEnabled(command_id);
134 return true;
137 bool ButtonMenuItemModel::DoesCommandIdDismissMenu(int command_id) const {
138 if (delegate_)
139 return delegate_->DoesCommandIdDismissMenu(command_id);
140 return true;
144 } // namespace ui