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

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: 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
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 NSImage* icon = nil;
154 if (model->GetIconAt(modelIndex, &skiaIcon) && !skiaIcon.isNull())
155 icon = gfx::SkBitmapToNSImage(skiaIcon);
156 [(id)item setImage:icon];
151 } 157 }
152 return model->IsEnabledAt(modelIndex); 158 return model->IsEnabledAt(modelIndex);
153 } 159 }
154 return NO; 160 return NO;
155 } 161 }
156 162
157 // Called when the user chooses a particular menu item. |sender| is the menu 163 // Called when the user chooses a particular menu item. |sender| is the menu
158 // item chosen. 164 // item chosen.
159 - (void)itemSelected:(id)sender { 165 - (void)itemSelected:(id)sender {
160 NSInteger modelIndex = [sender tag]; 166 NSInteger modelIndex = [sender tag];
(...skipping 15 matching lines...) Expand all
176 if (useWithPopUpButtonCell_) { 182 if (useWithPopUpButtonCell_) {
177 scoped_nsobject<NSMenuItem> blankItem( 183 scoped_nsobject<NSMenuItem> blankItem(
178 [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]); 184 [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]);
179 [menu_ insertItem:blankItem atIndex:0]; 185 [menu_ insertItem:blankItem atIndex:0];
180 } 186 }
181 } 187 }
182 return menu_.get(); 188 return menu_.get();
183 } 189 }
184 190
185 @end 191 @end
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_options_menu_model.cc ('k') | chrome/browser/ui/cocoa/menu_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698