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

Side by Side Diff: ui/app_list/cocoa/apps_grid_view_item.mm

Issue 15294008: Drop shadows for packaged apps on the OSX App Launcher. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: colorWithCalibratedWhite Created 7 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/app_list/cocoa/apps_grid_view_item.h" 5 #import "ui/app_list/cocoa/apps_grid_view_item.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/memory/scoped_nsobject.h" 8 #include "base/memory/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "skia/ext/skia_utils_mac.h" 10 #include "skia/ext/skia_utils_mac.h"
11 #include "ui/app_list/app_list_constants.h" 11 #include "ui/app_list/app_list_constants.h"
12 #include "ui/app_list/app_list_item_model.h" 12 #include "ui/app_list/app_list_item_model.h"
13 #include "ui/app_list/app_list_item_model_observer.h" 13 #include "ui/app_list/app_list_item_model_observer.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/image/image_skia_util_mac.h" 15 #include "ui/gfx/image/image_skia_util_mac.h"
16 #include "ui/gfx/font.h" 16 #include "ui/gfx/font.h"
17 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
17 18
18 namespace { 19 namespace {
19 20
20 // Padding from the top of the tile to the top of the app icon. 21 // Padding from the top of the tile to the top of the app icon.
21 const CGFloat kTileTopPadding = 10; 22 const CGFloat kTileTopPadding = 10;
22 23
23 } // namespace 24 } // namespace
24 25
25 namespace app_list { 26 namespace app_list {
26 27
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 @private 84 @private
84 BOOL selected_; 85 BOOL selected_;
85 } 86 }
86 87
87 - (NSButton*)button; 88 - (NSButton*)button;
88 89
89 - (void)setSelected:(BOOL)flag; 90 - (void)setSelected:(BOOL)flag;
90 91
91 @end 92 @end
92 93
94 @interface AppsGridItemButtonCell : NSButtonCell {
95 @private
96 BOOL hasShadow_;
97 }
98
99 @property(assign, nonatomic) BOOL hasShadow;
100
101 @end
102
103 @interface AppsGridItemButton : NSButton;
104 @end
105
93 @implementation AppsGridItemBackgroundView 106 @implementation AppsGridItemBackgroundView
94 107
95 - (NSButton*)button { 108 - (NSButton*)button {
96 return base::mac::ObjCCastStrict<NSButton>([[self subviews] objectAtIndex:0]); 109 return base::mac::ObjCCastStrict<NSButton>([[self subviews] objectAtIndex:0]);
97 } 110 }
98 111
99 - (void)setSelected:(BOOL)flag { 112 - (void)setSelected:(BOOL)flag {
100 if (selected_ == flag) 113 if (selected_ == flag)
101 return; 114 return;
102 115
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 @interface AppsGridViewItem () 155 @interface AppsGridViewItem ()
143 156
144 - (AppsGridItemBackgroundView*)itemBackgroundView; 157 - (AppsGridItemBackgroundView*)itemBackgroundView;
145 158
146 @end 159 @end
147 160
148 @implementation AppsGridViewItem 161 @implementation AppsGridViewItem
149 162
150 - (id)initWithSize:(NSSize)tileSize { 163 - (id)initWithSize:(NSSize)tileSize {
151 if ((self = [super init])) { 164 if ((self = [super init])) {
152 scoped_nsobject<NSButton> prototypeButton( 165 scoped_nsobject<AppsGridItemButton> prototypeButton(
153 [[NSButton alloc] initWithFrame:NSMakeRect( 166 [[AppsGridItemButton alloc] initWithFrame:NSMakeRect(
154 0, 0, tileSize.width, tileSize.height - kTileTopPadding)]); 167 0, 0, tileSize.width, tileSize.height - kTileTopPadding)]);
155 168
156 // This NSButton style always positions the icon at the very top of the 169 // This NSButton style always positions the icon at the very top of the
157 // button frame. AppsGridViewItem uses an enclosing view so that it is 170 // button frame. AppsGridViewItem uses an enclosing view so that it is
158 // visually correct. 171 // visually correct.
159 [prototypeButton setImagePosition:NSImageAbove]; 172 [prototypeButton setImagePosition:NSImageAbove];
160 [prototypeButton setButtonType:NSMomentaryChangeButton]; 173 [prototypeButton setButtonType:NSMomentaryChangeButton];
161 [prototypeButton setBordered:NO]; 174 [prototypeButton setBordered:NO];
162 175
163 [[prototypeButton cell] 176 [[prototypeButton cell]
(...skipping 11 matching lines...) Expand all
175 188
176 - (void)setModel:(app_list::AppListItemModel*)itemModel { 189 - (void)setModel:(app_list::AppListItemModel*)itemModel {
177 if (!itemModel) { 190 if (!itemModel) {
178 observerBridge_.reset(); 191 observerBridge_.reset();
179 return; 192 return;
180 } 193 }
181 194
182 NSButton* button = [self button]; 195 NSButton* button = [self button];
183 [button setTitle:base::SysUTF8ToNSString(itemModel->title())]; 196 [button setTitle:base::SysUTF8ToNSString(itemModel->title())];
184 [button setImage:gfx::NSImageFromImageSkia(itemModel->icon())]; 197 [button setImage:gfx::NSImageFromImageSkia(itemModel->icon())];
198 [[button cell] setHasShadow:itemModel->has_shadow()];
185 observerBridge_.reset(new app_list::ItemModelObserverBridge(self, itemModel)); 199 observerBridge_.reset(new app_list::ItemModelObserverBridge(self, itemModel));
186 200
187 if (trackingArea_.get()) 201 if (trackingArea_.get())
188 [[self view] removeTrackingArea:trackingArea_.get()]; 202 [[self view] removeTrackingArea:trackingArea_.get()];
189 203
190 trackingArea_.reset( 204 trackingArea_.reset(
191 [[CrTrackingArea alloc] initWithRect:NSZeroRect 205 [[CrTrackingArea alloc] initWithRect:NSZeroRect
192 options:NSTrackingInVisibleRect | 206 options:NSTrackingInVisibleRect |
193 NSTrackingMouseEnteredAndExited | 207 NSTrackingMouseEnteredAndExited |
194 NSTrackingActiveInKeyWindow 208 NSTrackingActiveInKeyWindow
(...skipping 23 matching lines...) Expand all
218 - (void)mouseExited:(NSEvent*)theEvent { 232 - (void)mouseExited:(NSEvent*)theEvent {
219 [self setSelected:NO]; 233 [self setSelected:NO];
220 } 234 }
221 235
222 - (void)setSelected:(BOOL)flag { 236 - (void)setSelected:(BOOL)flag {
223 [[self itemBackgroundView] setSelected:flag]; 237 [[self itemBackgroundView] setSelected:flag];
224 [super setSelected:flag]; 238 [super setSelected:flag];
225 } 239 }
226 240
227 @end 241 @end
242
243 @implementation AppsGridItemButton
244
245 + (Class)cellClass {
246 return [AppsGridItemButtonCell class];
247 }
248
249 @end
250
251 @implementation AppsGridItemButtonCell
252
253 @synthesize hasShadow = hasShadow_;
254
255 - (void)drawImage:(NSImage*)image
256 withFrame:(NSRect)frame
257 inView:(NSView*)controlView {
258 if (!hasShadow_) {
259 [super drawImage:image
260 withFrame:frame
261 inView:controlView];
262 return;
263 }
264
265 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]);
266 gfx::ScopedNSGraphicsContextSaveGState context;
267 [shadow setShadowOffset:NSMakeSize(0, -2)];
268 [shadow setShadowBlurRadius:2.0];
269 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0
270 alpha:0.14]];
271 [shadow set];
272
273 [super drawImage:image
274 withFrame:frame
275 inView:controlView];
276 }
277
278 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698