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

Side by Side Diff: chrome/browser/ui/cocoa/menu_controller.mm

Issue 5697005: Change SimpleMenuModel on OSX to support dynamic icons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback 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
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 #import "chrome/browser/ui/cocoa/menu_controller.h" 5 #import "chrome/browser/ui/cocoa/menu_controller.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "app/menus/accelerator_cocoa.h" 8 #include "app/menus/accelerator_cocoa.h"
9 #include "app/menus/simple_menu_model.h" 9 #include "app/menus/simple_menu_model.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 NSInteger modelIndex = [item tag]; 137 NSInteger modelIndex = [item tag];
138 menus::MenuModel* model = 138 menus::MenuModel* model =
139 static_cast<menus::MenuModel*>( 139 static_cast<menus::MenuModel*>(
140 [[(id)item representedObject] pointerValue]); 140 [[(id)item representedObject] pointerValue]);
141 DCHECK(model); 141 DCHECK(model);
142 if (model) { 142 if (model) {
143 BOOL checked = model->IsItemCheckedAt(modelIndex); 143 BOOL checked = model->IsItemCheckedAt(modelIndex);
144 DCHECK([(id)item isKindOfClass:[NSMenuItem class]]); 144 DCHECK([(id)item isKindOfClass:[NSMenuItem class]]);
145 [(id)item setState:(checked ? NSOnState : NSOffState)]; 145 [(id)item setState:(checked ? NSOnState : NSOffState)];
146 [(id)item setHidden:(!model->IsVisibleAt(modelIndex))]; 146 [(id)item setHidden:(!model->IsVisibleAt(modelIndex))];
147 if (model->IsLabelDynamicAt(modelIndex)) { 147 if (model->IsItemDynamicAt(modelIndex)) {
148 // Update the label and the icon.
148 NSString* label = 149 NSString* label =
149 l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex)); 150 l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex));
150 [(id)item setTitle:label]; 151 [(id)item setTitle:label];
152 SkBitmap skiaIcon;
Evan Stade 2010/12/14 21:28:57 SkBitmap skiaIcon; NSImage* icon = nil; if (model-
153 if (model->GetIconAt(modelIndex, &skiaIcon) && !skiaIcon.isNull()) {
154 // We have an icon.
155 NSImage* icon = gfx::SkBitmapToNSImage(skiaIcon);
156 if (icon)
157 [(id)item setImage:icon];
158 else
159 [(id)item setImage:nil];
160 } else {
161 // No icon.
162 [(id)item setImage:nil];
163 }
151 } 164 }
152 return model->IsEnabledAt(modelIndex); 165 return model->IsEnabledAt(modelIndex);
153 } 166 }
154 return NO; 167 return NO;
155 } 168 }
156 169
157 // Called when the user chooses a particular menu item. |sender| is the menu 170 // Called when the user chooses a particular menu item. |sender| is the menu
158 // item chosen. 171 // item chosen.
159 - (void)itemSelected:(id)sender { 172 - (void)itemSelected:(id)sender {
160 NSInteger modelIndex = [sender tag]; 173 NSInteger modelIndex = [sender tag];
(...skipping 15 matching lines...) Expand all
176 if (useWithPopUpButtonCell_) { 189 if (useWithPopUpButtonCell_) {
177 scoped_nsobject<NSMenuItem> blankItem( 190 scoped_nsobject<NSMenuItem> blankItem(
178 [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]); 191 [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]);
179 [menu_ insertItem:blankItem atIndex:0]; 192 [menu_ insertItem:blankItem atIndex:0];
180 } 193 }
181 } 194 }
182 return menu_.get(); 195 return menu_.get();
183 } 196 }
184 197
185 @end 198 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698