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

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

Issue 10824402: Convert ui::MenuModel to use gfx::Image instead of ImageSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another day, another rebase 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 #import "chrome/browser/ui/cocoa/menu_controller.h" 5 #import "chrome/browser/ui/cocoa/menu_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #import "chrome/browser/ui/cocoa/event_utils.h" 9 #import "chrome/browser/ui/cocoa/event_utils.h"
10 #include "ui/base/accelerators/accelerator_cocoa.h" 10 #include "ui/base/accelerators/accelerator_cocoa.h"
11 #include "ui/base/l10n/l10n_util_mac.h" 11 #include "ui/base/l10n/l10n_util_mac.h"
12 #include "ui/base/models/simple_menu_model.h" 12 #include "ui/base/models/simple_menu_model.h"
13 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image.h"
14 #include "ui/gfx/image/image_skia_util_mac.h"
15 14
16 @interface MenuController (Private) 15 @interface MenuController (Private)
17 - (void)addSeparatorToMenu:(NSMenu*)menu 16 - (void)addSeparatorToMenu:(NSMenu*)menu
18 atIndex:(int)index; 17 atIndex:(int)index;
19 @end 18 @end
20 19
21 @implementation MenuController 20 @implementation MenuController
22 21
23 @synthesize model = model_; 22 @synthesize model = model_;
24 @synthesize useWithPopUpButtonCell = useWithPopUpButtonCell_; 23 @synthesize useWithPopUpButtonCell = useWithPopUpButtonCell_;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 fromModel:(ui::MenuModel*)model 98 fromModel:(ui::MenuModel*)model
100 modelIndex:(int)modelIndex { 99 modelIndex:(int)modelIndex {
101 NSString* label = 100 NSString* label =
102 l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex)); 101 l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex));
103 scoped_nsobject<NSMenuItem> item( 102 scoped_nsobject<NSMenuItem> item(
104 [[NSMenuItem alloc] initWithTitle:label 103 [[NSMenuItem alloc] initWithTitle:label
105 action:@selector(itemSelected:) 104 action:@selector(itemSelected:)
106 keyEquivalent:@""]); 105 keyEquivalent:@""]);
107 106
108 // If the menu item has an icon, set it. 107 // If the menu item has an icon, set it.
109 gfx::ImageSkia skiaIcon; 108 gfx::Image icon;
110 if (model->GetIconAt(modelIndex, &skiaIcon) && !skiaIcon.isNull()) { 109 if (model->GetIconAt(modelIndex, &icon) && !icon.IsEmpty())
111 NSImage* icon = gfx::NSImageFromImageSkia(skiaIcon); 110 [item setImage:icon.ToNSImage()];
112 if (icon) {
113 [item setImage:icon];
114 }
115 }
116 111
117 ui::MenuModel::ItemType type = model->GetTypeAt(modelIndex); 112 ui::MenuModel::ItemType type = model->GetTypeAt(modelIndex);
118 if (type == ui::MenuModel::TYPE_SUBMENU) { 113 if (type == ui::MenuModel::TYPE_SUBMENU) {
119 // Recursively build a submenu from the sub-model at this index. 114 // Recursively build a submenu from the sub-model at this index.
120 [item setTarget:nil]; 115 [item setTarget:nil];
121 [item setAction:nil]; 116 [item setAction:nil];
122 ui::MenuModel* submenuModel = model->GetSubmenuModelAt(modelIndex); 117 ui::MenuModel* submenuModel = model->GetSubmenuModelAt(modelIndex);
123 NSMenu* submenu = 118 NSMenu* submenu =
124 [self menuFromModel:(ui::SimpleMenuModel*)submenuModel]; 119 [self menuFromModel:(ui::SimpleMenuModel*)submenuModel];
125 [item setSubmenu:submenu]; 120 [item setSubmenu:submenu];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (model) { 153 if (model) {
159 BOOL checked = model->IsItemCheckedAt(modelIndex); 154 BOOL checked = model->IsItemCheckedAt(modelIndex);
160 DCHECK([(id)item isKindOfClass:[NSMenuItem class]]); 155 DCHECK([(id)item isKindOfClass:[NSMenuItem class]]);
161 [(id)item setState:(checked ? NSOnState : NSOffState)]; 156 [(id)item setState:(checked ? NSOnState : NSOffState)];
162 [(id)item setHidden:(!model->IsVisibleAt(modelIndex))]; 157 [(id)item setHidden:(!model->IsVisibleAt(modelIndex))];
163 if (model->IsItemDynamicAt(modelIndex)) { 158 if (model->IsItemDynamicAt(modelIndex)) {
164 // Update the label and the icon. 159 // Update the label and the icon.
165 NSString* label = 160 NSString* label =
166 l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex)); 161 l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex));
167 [(id)item setTitle:label]; 162 [(id)item setTitle:label];
168 gfx::ImageSkia skiaIcon; 163
169 NSImage* icon = nil; 164 gfx::Image icon;
170 if (model->GetIconAt(modelIndex, &skiaIcon) && !skiaIcon.isNull()) 165 model->GetIconAt(modelIndex, &icon);
171 icon = gfx::NSImageFromImageSkia(skiaIcon); 166 [(id)item setImage:icon.IsEmpty() ? nil : icon.ToNSImage()];
172 [(id)item setImage:icon];
173 } 167 }
174 return model->IsEnabledAt(modelIndex); 168 return model->IsEnabledAt(modelIndex);
175 } 169 }
176 return NO; 170 return NO;
177 } 171 }
178 172
179 // Called when the user chooses a particular menu item. |sender| is the menu 173 // Called when the user chooses a particular menu item. |sender| is the menu
180 // item chosen. 174 // item chosen.
181 - (void)itemSelected:(id)sender { 175 - (void)itemSelected:(id)sender {
182 NSInteger modelIndex = [sender tag]; 176 NSInteger modelIndex = [sender tag];
(...skipping 30 matching lines...) Expand all
213 } 207 }
214 208
215 - (void)menuDidClose:(NSMenu*)menu { 209 - (void)menuDidClose:(NSMenu*)menu {
216 if (isMenuOpen_) { 210 if (isMenuOpen_) {
217 model_->MenuClosed(); 211 model_->MenuClosed();
218 isMenuOpen_ = NO; 212 isMenuOpen_ = NO;
219 } 213 }
220 } 214 }
221 215
222 @end 216 @end
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.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