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

Side by Side Diff: ui/base/models/simple_menu_model.cc

Issue 10837317: Setting the touch wrench menu as default menu for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/models/simple_menu_model.h" 5 #include "ui/base/models/simple_menu_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/image/image_skia.h" 10 #include "ui/gfx/image/image_skia.h"
11 11
12 namespace ui { 12 namespace ui {
13 13
14 const int kSeparatorId = -1; 14 const int kSeparatorId = -1;
15 15
16 struct SimpleMenuModel::Item { 16 struct SimpleMenuModel::Item {
17 int command_id; 17 int command_id;
18 string16 label; 18 string16 label;
19 gfx::ImageSkia icon; 19 gfx::ImageSkia icon;
20 ItemType type; 20 ItemType type;
21 int group_id; 21 int group_id;
22 MenuModel* submenu; 22 MenuModel* submenu;
23 ButtonMenuItemModel* button_model; 23 ButtonMenuItemModel* button_model;
24 MenuSeparatorStyle separator_style;
24 }; 25 };
25 26
26 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
27 // SimpleMenuModel::Delegate, public: 28 // SimpleMenuModel::Delegate, public:
28 29
29 bool SimpleMenuModel::Delegate::IsCommandIdVisible(int command_id) const { 30 bool SimpleMenuModel::Delegate::IsCommandIdVisible(int command_id) const {
30 return true; 31 return true;
31 } 32 }
32 33
33 bool SimpleMenuModel::Delegate::IsItemForCommandIdDynamic( 34 bool SimpleMenuModel::Delegate::IsItemForCommandIdDynamic(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 : delegate_(delegate), 66 : delegate_(delegate),
66 menu_model_delegate_(NULL), 67 menu_model_delegate_(NULL),
67 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 68 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
68 } 69 }
69 70
70 SimpleMenuModel::~SimpleMenuModel() { 71 SimpleMenuModel::~SimpleMenuModel() {
71 } 72 }
72 73
73 void SimpleMenuModel::AddItem(int command_id, const string16& label) { 74 void SimpleMenuModel::AddItem(int command_id, const string16& label) {
74 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL, 75 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL,
75 NULL }; 76 NULL, NO_SEPARATOR };
76 AppendItem(item); 77 AppendItem(item);
77 } 78 }
78 79
79 void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { 80 void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) {
80 AddItem(command_id, l10n_util::GetStringUTF16(string_id)); 81 AddItem(command_id, l10n_util::GetStringUTF16(string_id));
81 } 82 }
82 83
83 void SimpleMenuModel::AddSeparator() { 84 void SimpleMenuModel::AddSeparator(MenuSeparatorStyle separator_type) {
84 Item item = { kSeparatorId, string16(), gfx::ImageSkia(), TYPE_SEPARATOR, -1, 85 #if defined(OS_WINDOWS)
sky 2012/08/21 03:03:25 if !defined(USE_AURA) right? Also, instead of the
Mr4D (OOO till 08-26) 2012/08/21 15:37:16 Actually - no? The new separator style should be u
sky 2012/08/21 19:36:29 This is what NOTIMPLEMENTED is meant for, it means
Mr4D (OOO till 08-26) 2012/08/21 21:34:54 No - you got me wrong here. I was not referring to
sky 2012/08/21 22:35:22 Agreed. My first comment was this define should be
85 NULL, NULL }; 86 DCHECK(separator_type == NORMAL_SEPARATOR)
87 #endif
88 Item item = { kSeparatorId, string16(), gfx::ImageSkia(), TYPE_SEPARATOR,
89 -1, NULL, NULL , separator_type };
86 AppendItem(item); 90 AppendItem(item);
87 } 91 }
88 92
89 void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) { 93 void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) {
90 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL, 94 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL,
91 NULL }; 95 NULL, NO_SEPARATOR };
92 AppendItem(item); 96 AppendItem(item);
93 } 97 }
94 98
95 void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { 99 void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) {
96 AddCheckItem(command_id, l10n_util::GetStringUTF16(string_id)); 100 AddCheckItem(command_id, l10n_util::GetStringUTF16(string_id));
97 } 101 }
98 102
99 void SimpleMenuModel::AddRadioItem(int command_id, const string16& label, 103 void SimpleMenuModel::AddRadioItem(int command_id, const string16& label,
100 int group_id) { 104 int group_id) {
101 Item item = { command_id, label, gfx::ImageSkia(), TYPE_RADIO, group_id, NULL, 105 Item item = { command_id, label, gfx::ImageSkia(), TYPE_RADIO, group_id, NULL,
102 NULL }; 106 NULL, NO_SEPARATOR };
103 AppendItem(item); 107 AppendItem(item);
104 } 108 }
105 109
106 void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id, 110 void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id,
107 int group_id) { 111 int group_id) {
108 AddRadioItem(command_id, l10n_util::GetStringUTF16(string_id), group_id); 112 AddRadioItem(command_id, l10n_util::GetStringUTF16(string_id), group_id);
109 } 113 }
110 114
111 void SimpleMenuModel::AddButtonItem(int command_id, 115 void SimpleMenuModel::AddButtonItem(int command_id,
112 ButtonMenuItemModel* model) { 116 ButtonMenuItemModel* model) {
113 Item item = { command_id, string16(), gfx::ImageSkia(), TYPE_BUTTON_ITEM, -1, 117 Item item = { command_id, string16(), gfx::ImageSkia(), TYPE_BUTTON_ITEM, -1,
114 NULL, model }; 118 NULL, model, NO_SEPARATOR };
115 AppendItem(item); 119 AppendItem(item);
116 } 120 }
117 121
118 void SimpleMenuModel::AddSubMenu(int command_id, const string16& label, 122 void SimpleMenuModel::AddSubMenu(int command_id, const string16& label,
119 MenuModel* model) { 123 MenuModel* model) {
120 Item item = { command_id, label, gfx::ImageSkia(), TYPE_SUBMENU, -1, model, 124 Item item = { command_id, label, gfx::ImageSkia(), TYPE_SUBMENU, -1, model,
121 NULL }; 125 NULL, NO_SEPARATOR };
122 AppendItem(item); 126 AppendItem(item);
123 } 127 }
124 128
125 void SimpleMenuModel::AddSubMenuWithStringId(int command_id, 129 void SimpleMenuModel::AddSubMenuWithStringId(int command_id,
126 int string_id, MenuModel* model) { 130 int string_id, MenuModel* model) {
127 AddSubMenu(command_id, l10n_util::GetStringUTF16(string_id), model); 131 AddSubMenu(command_id, l10n_util::GetStringUTF16(string_id), model);
128 } 132 }
129 133
130 void SimpleMenuModel::InsertItemAt( 134 void SimpleMenuModel::InsertItemAt(
131 int index, int command_id, const string16& label) { 135 int index, int command_id, const string16& label) {
132 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL, 136 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL,
133 NULL }; 137 NULL, NO_SEPARATOR };
134 InsertItemAtIndex(item, index); 138 InsertItemAtIndex(item, index);
135 } 139 }
136 140
137 void SimpleMenuModel::InsertItemWithStringIdAt( 141 void SimpleMenuModel::InsertItemWithStringIdAt(
138 int index, int command_id, int string_id) { 142 int index, int command_id, int string_id) {
139 InsertItemAt(index, command_id, l10n_util::GetStringUTF16(string_id)); 143 InsertItemAt(index, command_id, l10n_util::GetStringUTF16(string_id));
140 } 144 }
141 145
142 void SimpleMenuModel::InsertSeparatorAt(int index) { 146 void SimpleMenuModel::InsertSeparatorAt(int index,
143 Item item = { kSeparatorId, string16(), gfx::ImageSkia(), TYPE_SEPARATOR, -1, 147 MenuSeparatorStyle separator_type) {
144 NULL, NULL }; 148 #if defined(OS_WINDOWS)
sky 2012/08/21 03:03:25 Same comment about define.
Mr4D (OOO till 08-26) 2012/08/21 15:37:16 Done.
149 DCHECK(separator_type == NORMAL_SEPARATOR)
150 #endif
151 Item item = { kSeparatorId, string16(), gfx::ImageSkia(), TYPE_SEPARATOR,
152 -1, NULL, NULL, separator_type };
145 InsertItemAtIndex(item, index); 153 InsertItemAtIndex(item, index);
146 } 154 }
147 155
148 void SimpleMenuModel::InsertCheckItemAt( 156 void SimpleMenuModel::InsertCheckItemAt(
149 int index, int command_id, const string16& label) { 157 int index, int command_id, const string16& label) {
150 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL, 158 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL,
151 NULL }; 159 NULL, NO_SEPARATOR };
152 InsertItemAtIndex(item, index); 160 InsertItemAtIndex(item, index);
153 } 161 }
154 162
155 void SimpleMenuModel::InsertCheckItemWithStringIdAt( 163 void SimpleMenuModel::InsertCheckItemWithStringIdAt(
156 int index, int command_id, int string_id) { 164 int index, int command_id, int string_id) {
157 InsertCheckItemAt( 165 InsertCheckItemAt(
158 FlipIndex(index), command_id, l10n_util::GetStringUTF16(string_id)); 166 FlipIndex(index), command_id, l10n_util::GetStringUTF16(string_id));
159 } 167 }
160 168
161 void SimpleMenuModel::InsertRadioItemAt( 169 void SimpleMenuModel::InsertRadioItemAt(
162 int index, int command_id, const string16& label, int group_id) { 170 int index, int command_id, const string16& label, int group_id) {
163 Item item = { command_id, label, gfx::ImageSkia(), TYPE_RADIO, group_id, NULL, 171 Item item = { command_id, label, gfx::ImageSkia(), TYPE_RADIO, group_id, NULL,
164 NULL }; 172 NULL, NO_SEPARATOR };
165 InsertItemAtIndex(item, index); 173 InsertItemAtIndex(item, index);
166 } 174 }
167 175
168 void SimpleMenuModel::InsertRadioItemWithStringIdAt( 176 void SimpleMenuModel::InsertRadioItemWithStringIdAt(
169 int index, int command_id, int string_id, int group_id) { 177 int index, int command_id, int string_id, int group_id) {
170 InsertRadioItemAt( 178 InsertRadioItemAt(
171 index, command_id, l10n_util::GetStringUTF16(string_id), group_id); 179 index, command_id, l10n_util::GetStringUTF16(string_id), group_id);
172 } 180 }
173 181
174 void SimpleMenuModel::InsertSubMenuAt( 182 void SimpleMenuModel::InsertSubMenuAt(
175 int index, int command_id, const string16& label, MenuModel* model) { 183 int index, int command_id, const string16& label, MenuModel* model) {
176 Item item = { command_id, label, gfx::ImageSkia(), TYPE_SUBMENU, -1, model, 184 Item item = { command_id, label, gfx::ImageSkia(), TYPE_SUBMENU, -1, model,
177 NULL }; 185 NULL, NO_SEPARATOR };
178 InsertItemAtIndex(item, index); 186 InsertItemAtIndex(item, index);
179 } 187 }
180 188
181 void SimpleMenuModel::InsertSubMenuWithStringIdAt( 189 void SimpleMenuModel::InsertSubMenuWithStringIdAt(
182 int index, int command_id, int string_id, MenuModel* model) { 190 int index, int command_id, int string_id, MenuModel* model) {
183 InsertSubMenuAt(index, command_id, l10n_util::GetStringUTF16(string_id), 191 InsertSubMenuAt(index, command_id, l10n_util::GetStringUTF16(string_id),
184 model); 192 model);
185 } 193 }
186 194
187 void SimpleMenuModel::SetIcon(int index, const gfx::ImageSkia& icon) { 195 void SimpleMenuModel::SetIcon(int index, const gfx::ImageSkia& icon) {
(...skipping 26 matching lines...) Expand all
214 } 222 }
215 223
216 int SimpleMenuModel::GetItemCount() const { 224 int SimpleMenuModel::GetItemCount() const {
217 return static_cast<int>(items_.size()); 225 return static_cast<int>(items_.size());
218 } 226 }
219 227
220 MenuModel::ItemType SimpleMenuModel::GetTypeAt(int index) const { 228 MenuModel::ItemType SimpleMenuModel::GetTypeAt(int index) const {
221 return items_[ValidateItemIndex(FlipIndex(index))].type; 229 return items_[ValidateItemIndex(FlipIndex(index))].type;
222 } 230 }
223 231
232 ui::MenuSeparatorStyle SimpleMenuModel::GetSeparatorStyleAt(int index) const {
233 return items_[ValidateItemIndex(FlipIndex(index))].separator_style;
234 }
235
224 int SimpleMenuModel::GetCommandIdAt(int index) const { 236 int SimpleMenuModel::GetCommandIdAt(int index) const {
225 return items_[ValidateItemIndex(FlipIndex(index))].command_id; 237 return items_[ValidateItemIndex(FlipIndex(index))].command_id;
226 } 238 }
227 239
228 string16 SimpleMenuModel::GetLabelAt(int index) const { 240 string16 SimpleMenuModel::GetLabelAt(int index) const {
229 if (IsItemDynamicAt(index)) 241 if (IsItemDynamicAt(index))
230 return delegate_->GetLabelForCommandId(GetCommandIdAt(index)); 242 return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
231 return items_[ValidateItemIndex(FlipIndex(index))].label; 243 return items_[ValidateItemIndex(FlipIndex(index))].label;
232 } 244 }
233 245
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 #ifndef NDEBUG 370 #ifndef NDEBUG
359 if (item.type == TYPE_SEPARATOR) { 371 if (item.type == TYPE_SEPARATOR) {
360 DCHECK_EQ(item.command_id, kSeparatorId); 372 DCHECK_EQ(item.command_id, kSeparatorId);
361 } else { 373 } else {
362 DCHECK_GE(item.command_id, 0); 374 DCHECK_GE(item.command_id, 0);
363 } 375 }
364 #endif // NDEBUG 376 #endif // NDEBUG
365 } 377 }
366 378
367 } // namespace ui 379 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698