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

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: Moved background page badge fix to another CL. 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;
153 if (model->GetIconAt(modelIndex, &skiaIcon) && !skiaIcon.isNull()) {
154 // We have an icon.
155 NSImage* icon = gfx::SkBitmapToNSImage(skiaIcon);
156 if (icon) {
Evan Stade 2010/12/14 01:20:13 no {}
Andrew T Wilson (Slow) 2010/12/14 18:23:27 Done.
157 [(id)item setImage:icon];
Evan Stade 2010/12/14 01:20:13 it strikes me that you'll either want to setImage
Andrew T Wilson (Slow) 2010/12/14 18:23:27 Good point - my previous code was just leaving the
158 }
159 } else {
160 // No icon.
161 [(id)item setImage:nil];
162 }
151 } 163 }
152 return model->IsEnabledAt(modelIndex); 164 return model->IsEnabledAt(modelIndex);
153 } 165 }
154 return NO; 166 return NO;
155 } 167 }
156 168
157 // Called when the user chooses a particular menu item. |sender| is the menu 169 // Called when the user chooses a particular menu item. |sender| is the menu
158 // item chosen. 170 // item chosen.
159 - (void)itemSelected:(id)sender { 171 - (void)itemSelected:(id)sender {
160 NSInteger modelIndex = [sender tag]; 172 NSInteger modelIndex = [sender tag];
(...skipping 15 matching lines...) Expand all
176 if (useWithPopUpButtonCell_) { 188 if (useWithPopUpButtonCell_) {
177 scoped_nsobject<NSMenuItem> blankItem( 189 scoped_nsobject<NSMenuItem> blankItem(
178 [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]); 190 [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]);
179 [menu_ insertItem:blankItem atIndex:0]; 191 [menu_ insertItem:blankItem atIndex:0];
180 } 192 }
181 } 193 }
182 return menu_.get(); 194 return menu_.get();
183 } 195 }
184 196
185 @end 197 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698