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

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

Issue 5697005: Change SimpleMenuModel on OSX to support dynamic icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update after merge Created 10 years 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
« no previous file with comments | « app/menus/simple_menu_model.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.h » ('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 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 9
10 static const int kSeparatorId = -1; 10 static const int kSeparatorId = -1;
(...skipping 10 matching lines...) Expand all
21 ButtonMenuItemModel* button_model; 21 ButtonMenuItemModel* button_model;
22 }; 22 };
23 23
24 //////////////////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////////////////
25 // SimpleMenuModel::Delegate, public: 25 // SimpleMenuModel::Delegate, public:
26 26
27 bool SimpleMenuModel::Delegate::IsCommandIdVisible(int command_id) const { 27 bool SimpleMenuModel::Delegate::IsCommandIdVisible(int command_id) const {
28 return true; 28 return true;
29 } 29 }
30 30
31 bool SimpleMenuModel::Delegate::IsLabelForCommandIdDynamic( 31 bool SimpleMenuModel::Delegate::IsItemForCommandIdDynamic(
32 int command_id) const { 32 int command_id) const {
33 return false; 33 return false;
34 } 34 }
35 35
36 string16 SimpleMenuModel::Delegate::GetLabelForCommandId(int command_id) const { 36 string16 SimpleMenuModel::Delegate::GetLabelForCommandId(int command_id) const {
37 return string16(); 37 return string16();
38 } 38 }
39 39
40 bool SimpleMenuModel::Delegate::GetIconForCommandId(
41 int command_id, SkBitmap* bitmap) const {
42 return false;
43 }
44
40 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { 45 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) {
41 } 46 }
42 47
43 //////////////////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////////////////
44 // SimpleMenuModel, public: 49 // SimpleMenuModel, public:
45 50
46 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) { 51 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) {
47 } 52 }
48 53
49 SimpleMenuModel::~SimpleMenuModel() { 54 SimpleMenuModel::~SimpleMenuModel() {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 199
195 MenuModel::ItemType SimpleMenuModel::GetTypeAt(int index) const { 200 MenuModel::ItemType SimpleMenuModel::GetTypeAt(int index) const {
196 return items_.at(FlipIndex(index)).type; 201 return items_.at(FlipIndex(index)).type;
197 } 202 }
198 203
199 int SimpleMenuModel::GetCommandIdAt(int index) const { 204 int SimpleMenuModel::GetCommandIdAt(int index) const {
200 return items_.at(FlipIndex(index)).command_id; 205 return items_.at(FlipIndex(index)).command_id;
201 } 206 }
202 207
203 string16 SimpleMenuModel::GetLabelAt(int index) const { 208 string16 SimpleMenuModel::GetLabelAt(int index) const {
204 if (IsLabelDynamicAt(index)) 209 if (IsItemDynamicAt(index))
205 return delegate_->GetLabelForCommandId(GetCommandIdAt(index)); 210 return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
206 return items_.at(FlipIndex(index)).label; 211 return items_.at(FlipIndex(index)).label;
207 } 212 }
208 213
209 bool SimpleMenuModel::IsLabelDynamicAt(int index) const { 214 bool SimpleMenuModel::IsItemDynamicAt(int index) const {
210 if (delegate_) 215 if (delegate_)
211 return delegate_->IsLabelForCommandIdDynamic(GetCommandIdAt(index)); 216 return delegate_->IsItemForCommandIdDynamic(GetCommandIdAt(index));
212 return false; 217 return false;
213 } 218 }
214 219
215 bool SimpleMenuModel::GetAcceleratorAt(int index, 220 bool SimpleMenuModel::GetAcceleratorAt(int index,
216 menus::Accelerator* accelerator) const { 221 menus::Accelerator* accelerator) const {
217 if (delegate_) { 222 if (delegate_) {
218 return delegate_->GetAcceleratorForCommandId(GetCommandIdAt(index), 223 return delegate_->GetAcceleratorForCommandId(GetCommandIdAt(index),
219 accelerator); 224 accelerator);
220 } 225 }
221 return false; 226 return false;
222 } 227 }
223 228
224 bool SimpleMenuModel::IsItemCheckedAt(int index) const { 229 bool SimpleMenuModel::IsItemCheckedAt(int index) const {
225 if (!delegate_) 230 if (!delegate_)
226 return false; 231 return false;
227 int item_index = FlipIndex(index); 232 int item_index = FlipIndex(index);
228 MenuModel::ItemType item_type = items_[item_index].type; 233 MenuModel::ItemType item_type = items_[item_index].type;
229 return (item_type == TYPE_CHECK || item_type == TYPE_RADIO) ? 234 return (item_type == TYPE_CHECK || item_type == TYPE_RADIO) ?
230 delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false; 235 delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false;
231 } 236 }
232 237
233 int SimpleMenuModel::GetGroupIdAt(int index) const { 238 int SimpleMenuModel::GetGroupIdAt(int index) const {
234 return items_.at(FlipIndex(index)).group_id; 239 return items_.at(FlipIndex(index)).group_id;
235 } 240 }
236 241
237 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const { 242 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const {
243 if (IsItemDynamicAt(index))
244 return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon);
245
238 if (items_[index].icon.isNull()) 246 if (items_[index].icon.isNull())
239 return false; 247 return false;
240 248
241 *icon = items_[index].icon; 249 *icon = items_[index].icon;
242 return true; 250 return true;
243 } 251 }
244 252
245 ButtonMenuItemModel* SimpleMenuModel::GetButtonMenuItemAt(int index) const { 253 ButtonMenuItemModel* SimpleMenuModel::GetButtonMenuItemAt(int index) const {
246 return items_.at(FlipIndex(index)).button_model; 254 return items_.at(FlipIndex(index)).button_model;
247 } 255 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 #ifndef NDEBUG 305 #ifndef NDEBUG
298 if (item.type == TYPE_SEPARATOR) { 306 if (item.type == TYPE_SEPARATOR) {
299 DCHECK_EQ(item.command_id, kSeparatorId); 307 DCHECK_EQ(item.command_id, kSeparatorId);
300 } else { 308 } else {
301 DCHECK_GE(item.command_id, 0); 309 DCHECK_GE(item.command_id, 0);
302 } 310 }
303 #endif // NDEBUG 311 #endif // NDEBUG
304 } 312 }
305 313
306 } // namespace menus 314 } // namespace menus
OLDNEW
« no previous file with comments | « app/menus/simple_menu_model.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698