Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: app/menus/simple_menu_model.cc

Issue 2879002: Reapply r50859 with chromeos fixes. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: add explicit menus:: to chromeos Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « app/menus/simple_menu_model.h ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/menus/simple_menu_model.h" 5 #include "app/menus/simple_menu_model.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 8
9 static const int kSeparatorId = -1; 9 static const int kSeparatorId = -1;
10 10
11 namespace menus { 11 namespace menus {
12 12
13 //////////////////////////////////////////////////////////////////////////////// 13 ////////////////////////////////////////////////////////////////////////////////
14 // SimpleMenuModel, public: 14 // SimpleMenuModel, public:
15 15
16 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) { 16 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) {
17 } 17 }
18 18
19 SimpleMenuModel::~SimpleMenuModel() { 19 SimpleMenuModel::~SimpleMenuModel() {
20 } 20 }
21 21
22 void SimpleMenuModel::AddItem(int command_id, const string16& label) { 22 void SimpleMenuModel::AddItem(int command_id, const string16& label) {
23 Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL }; 23 Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL, NULL };
24 AppendItem(item); 24 AppendItem(item);
25 } 25 }
26 26
27 void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { 27 void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) {
28 AddItem(command_id, l10n_util::GetStringUTF16(string_id)); 28 AddItem(command_id, l10n_util::GetStringUTF16(string_id));
29 } 29 }
30 30
31 void SimpleMenuModel::AddSeparator() { 31 void SimpleMenuModel::AddSeparator() {
32 Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1, 32 Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1,
33 NULL }; 33 NULL, NULL };
34 AppendItem(item); 34 AppendItem(item);
35 } 35 }
36 36
37 void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) { 37 void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) {
38 Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL }; 38 Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL };
39 AppendItem(item); 39 AppendItem(item);
40 } 40 }
41 41
42 void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { 42 void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) {
43 AddCheckItem(command_id, l10n_util::GetStringUTF16(string_id)); 43 AddCheckItem(command_id, l10n_util::GetStringUTF16(string_id));
44 } 44 }
45 45
46 void SimpleMenuModel::AddRadioItem(int command_id, const string16& label, 46 void SimpleMenuModel::AddRadioItem(int command_id, const string16& label,
47 int group_id) { 47 int group_id) {
48 Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL }; 48 Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL,
49 NULL };
49 AppendItem(item); 50 AppendItem(item);
50 } 51 }
51 52
52 void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id, 53 void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id,
53 int group_id) { 54 int group_id) {
54 AddRadioItem(command_id, l10n_util::GetStringUTF16(string_id), group_id); 55 AddRadioItem(command_id, l10n_util::GetStringUTF16(string_id), group_id);
55 } 56 }
56 57
58 void SimpleMenuModel::AddButtonItem(int command_id,
59 ButtonMenuItemModel* model) {
60 Item item = { 0, string16(), SkBitmap(), TYPE_BUTTON_ITEM, -1, NULL, model };
61 AppendItem(item);
62 }
63
57 void SimpleMenuModel::AddSubMenu(int command_id, const string16& label, 64 void SimpleMenuModel::AddSubMenu(int command_id, const string16& label,
58 MenuModel* model) { 65 MenuModel* model) {
59 Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model }; 66 Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model, NULL };
60 AppendItem(item); 67 AppendItem(item);
61 } 68 }
62 69
63 void SimpleMenuModel::AddSubMenuWithStringId(int command_id, 70 void SimpleMenuModel::AddSubMenuWithStringId(int command_id,
64 int string_id, MenuModel* model) { 71 int string_id, MenuModel* model) {
65 AddSubMenu(command_id, l10n_util::GetStringUTF16(string_id), model); 72 AddSubMenu(command_id, l10n_util::GetStringUTF16(string_id), model);
66 } 73 }
67 74
68 void SimpleMenuModel::InsertItemAt( 75 void SimpleMenuModel::InsertItemAt(
69 int index, int command_id, const string16& label) { 76 int index, int command_id, const string16& label) {
70 Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL }; 77 Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL, NULL };
71 InsertItemAtIndex(item, index); 78 InsertItemAtIndex(item, index);
72 } 79 }
73 80
74 void SimpleMenuModel::InsertItemWithStringIdAt( 81 void SimpleMenuModel::InsertItemWithStringIdAt(
75 int index, int command_id, int string_id) { 82 int index, int command_id, int string_id) {
76 InsertItemAt(index, command_id, l10n_util::GetStringUTF16(string_id)); 83 InsertItemAt(index, command_id, l10n_util::GetStringUTF16(string_id));
77 } 84 }
78 85
79 void SimpleMenuModel::InsertSeparatorAt(int index) { 86 void SimpleMenuModel::InsertSeparatorAt(int index) {
80 Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1, 87 Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1,
81 NULL }; 88 NULL, NULL };
82 InsertItemAtIndex(item, index); 89 InsertItemAtIndex(item, index);
83 } 90 }
84 91
85 void SimpleMenuModel::InsertCheckItemAt( 92 void SimpleMenuModel::InsertCheckItemAt(
86 int index, int command_id, const string16& label) { 93 int index, int command_id, const string16& label) {
87 Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL }; 94 Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL, NULL };
88 InsertItemAtIndex(item, index); 95 InsertItemAtIndex(item, index);
89 } 96 }
90 97
91 void SimpleMenuModel::InsertCheckItemWithStringIdAt( 98 void SimpleMenuModel::InsertCheckItemWithStringIdAt(
92 int index, int command_id, int string_id) { 99 int index, int command_id, int string_id) {
93 InsertCheckItemAt( 100 InsertCheckItemAt(
94 FlipIndex(index), command_id, l10n_util::GetStringUTF16(string_id)); 101 FlipIndex(index), command_id, l10n_util::GetStringUTF16(string_id));
95 } 102 }
96 103
97 void SimpleMenuModel::InsertRadioItemAt( 104 void SimpleMenuModel::InsertRadioItemAt(
98 int index, int command_id, const string16& label, int group_id) { 105 int index, int command_id, const string16& label, int group_id) {
99 Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL }; 106 Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL,
107 NULL };
100 InsertItemAtIndex(item, index); 108 InsertItemAtIndex(item, index);
101 } 109 }
102 110
103 void SimpleMenuModel::InsertRadioItemWithStringIdAt( 111 void SimpleMenuModel::InsertRadioItemWithStringIdAt(
104 int index, int command_id, int string_id, int group_id) { 112 int index, int command_id, int string_id, int group_id) {
105 InsertRadioItemAt( 113 InsertRadioItemAt(
106 index, command_id, l10n_util::GetStringUTF16(string_id), group_id); 114 index, command_id, l10n_util::GetStringUTF16(string_id), group_id);
107 } 115 }
108 116
109 void SimpleMenuModel::InsertSubMenuAt( 117 void SimpleMenuModel::InsertSubMenuAt(
110 int index, int command_id, const string16& label, MenuModel* model) { 118 int index, int command_id, const string16& label, MenuModel* model) {
111 Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model }; 119 Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model, NULL };
112 InsertItemAtIndex(item, index); 120 InsertItemAtIndex(item, index);
113 } 121 }
114 122
115 void SimpleMenuModel::InsertSubMenuWithStringIdAt( 123 void SimpleMenuModel::InsertSubMenuWithStringIdAt(
116 int index, int command_id, int string_id, MenuModel* model) { 124 int index, int command_id, int string_id, MenuModel* model) {
117 InsertSubMenuAt(index, command_id, l10n_util::GetStringUTF16(string_id), 125 InsertSubMenuAt(index, command_id, l10n_util::GetStringUTF16(string_id),
118 model); 126 model);
119 } 127 }
120 128
121 void SimpleMenuModel::SetIcon(int index, const SkBitmap& icon) { 129 void SimpleMenuModel::SetIcon(int index, const SkBitmap& icon) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 200 }
193 201
194 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const { 202 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const {
195 if (items_[index].icon.isNull()) 203 if (items_[index].icon.isNull())
196 return false; 204 return false;
197 205
198 *icon = items_[index].icon; 206 *icon = items_[index].icon;
199 return true; 207 return true;
200 } 208 }
201 209
210 ButtonMenuItemModel* SimpleMenuModel::GetButtonMenuItemAt(int index) const {
211 return items_.at(FlipIndex(index)).button_model;
212 }
213
202 bool SimpleMenuModel::IsEnabledAt(int index) const { 214 bool SimpleMenuModel::IsEnabledAt(int index) const {
203 int command_id = GetCommandIdAt(index); 215 int command_id = GetCommandIdAt(index);
204 if (!delegate_ || command_id == kSeparatorId) 216 if (!delegate_ || command_id == kSeparatorId ||
217 items_.at(FlipIndex(index)).button_model)
205 return true; 218 return true;
206 return delegate_->IsCommandIdEnabled(command_id); 219 return delegate_->IsCommandIdEnabled(command_id);
207 } 220 }
208 221
209 void SimpleMenuModel::HighlightChangedTo(int index) { 222 void SimpleMenuModel::HighlightChangedTo(int index) {
210 if (delegate_) 223 if (delegate_)
211 delegate_->CommandIdHighlighted(GetCommandIdAt(index)); 224 delegate_->CommandIdHighlighted(GetCommandIdAt(index));
212 } 225 }
213 226
214 void SimpleMenuModel::ActivatedAt(int index) { 227 void SimpleMenuModel::ActivatedAt(int index) {
(...skipping 22 matching lines...) Expand all
237 #ifndef NDEBUG 250 #ifndef NDEBUG
238 if (item.type == TYPE_SEPARATOR) { 251 if (item.type == TYPE_SEPARATOR) {
239 DCHECK_EQ(item.command_id, kSeparatorId); 252 DCHECK_EQ(item.command_id, kSeparatorId);
240 } else { 253 } else {
241 DCHECK_GE(item.command_id, 0); 254 DCHECK_GE(item.command_id, 0);
242 } 255 }
243 #endif // NDEBUG 256 #endif // NDEBUG
244 } 257 }
245 258
246 } // namespace menus 259 } // namespace menus
OLDNEW
« no previous file with comments | « app/menus/simple_menu_model.h ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698