OLD | NEW |
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/mac/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 #import "ui/base/cocoa/menu_controller.h" | 14 #import "ui/base/cocoa/menu_controller.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/font.h" |
16 #include "ui/gfx/image/image_skia_util_mac.h" | 17 #include "ui/gfx/image/image_skia_util_mac.h" |
17 #include "ui/gfx/font.h" | |
18 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 18 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Padding from the top of the tile to the top of the app icon. | 22 // Padding from the top of the tile to the top of the app icon. |
23 const CGFloat kTileTopPadding = 10; | 23 const CGFloat kTileTopPadding = 10; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 namespace app_list { | 27 namespace app_list { |
28 | 28 |
29 class ItemModelObserverBridge : public app_list::AppListItemModelObserver { | 29 class ItemModelObserverBridge : public app_list::AppListItemModelObserver { |
30 public: | 30 public: |
31 ItemModelObserverBridge(AppsGridViewItem* parent, AppListItemModel* model); | 31 ItemModelObserverBridge(AppsGridViewItem* parent, AppListItemModel* model); |
32 virtual ~ItemModelObserverBridge(); | 32 virtual ~ItemModelObserverBridge(); |
33 | 33 |
34 AppListItemModel* model() { return model_; } | 34 AppListItemModel* model() { return model_; } |
35 NSMenu* GetContextMenu(); | 35 NSMenu* GetContextMenu(); |
36 | 36 |
37 virtual void ItemIconChanged() OVERRIDE; | 37 virtual void ItemIconChanged() OVERRIDE; |
38 virtual void ItemTitleChanged() OVERRIDE; | 38 virtual void ItemTitleChanged() OVERRIDE; |
39 virtual void ItemHighlightedChanged() OVERRIDE; | 39 virtual void ItemHighlightedChanged() OVERRIDE; |
40 virtual void ItemIsInstallingChanged() OVERRIDE; | 40 virtual void ItemIsInstallingChanged() OVERRIDE; |
41 virtual void ItemPercentDownloadedChanged() OVERRIDE; | 41 virtual void ItemPercentDownloadedChanged() OVERRIDE; |
42 | 42 |
43 private: | 43 private: |
44 AppsGridViewItem* parent_; // Weak. Owns us. | 44 AppsGridViewItem* parent_; // Weak. Owns us. |
45 AppListItemModel* model_; // Weak. Owned by AppListModel::Apps. | 45 AppListItemModel* model_; // Weak. Owned by AppListModel::Apps. |
46 scoped_nsobject<MenuController> context_menu_controller_; | 46 base::scoped_nsobject<MenuController> context_menu_controller_; |
47 | 47 |
48 DISALLOW_COPY_AND_ASSIGN(ItemModelObserverBridge); | 48 DISALLOW_COPY_AND_ASSIGN(ItemModelObserverBridge); |
49 }; | 49 }; |
50 | 50 |
51 ItemModelObserverBridge::ItemModelObserverBridge(AppsGridViewItem* parent, | 51 ItemModelObserverBridge::ItemModelObserverBridge(AppsGridViewItem* parent, |
52 AppListItemModel* model) | 52 AppListItemModel* model) |
53 : parent_(parent), | 53 : parent_(parent), |
54 model_(model) { | 54 model_(model) { |
55 model_->AddObserver(this); | 55 model_->AddObserver(this); |
56 } | 56 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 @interface AppsGridViewItem () | 165 @interface AppsGridViewItem () |
166 | 166 |
167 - (AppsGridItemBackgroundView*)itemBackgroundView; | 167 - (AppsGridItemBackgroundView*)itemBackgroundView; |
168 | 168 |
169 @end | 169 @end |
170 | 170 |
171 @implementation AppsGridViewItem | 171 @implementation AppsGridViewItem |
172 | 172 |
173 - (id)initWithSize:(NSSize)tileSize { | 173 - (id)initWithSize:(NSSize)tileSize { |
174 if ((self = [super init])) { | 174 if ((self = [super init])) { |
175 scoped_nsobject<AppsGridItemButton> prototypeButton( | 175 base::scoped_nsobject<AppsGridItemButton> prototypeButton( |
176 [[AppsGridItemButton alloc] initWithFrame:NSMakeRect( | 176 [[AppsGridItemButton alloc] initWithFrame:NSMakeRect( |
177 0, 0, tileSize.width, tileSize.height - kTileTopPadding)]); | 177 0, 0, tileSize.width, tileSize.height - kTileTopPadding)]); |
178 | 178 |
179 // This NSButton style always positions the icon at the very top of the | 179 // This NSButton style always positions the icon at the very top of the |
180 // button frame. AppsGridViewItem uses an enclosing view so that it is | 180 // button frame. AppsGridViewItem uses an enclosing view so that it is |
181 // visually correct. | 181 // visually correct. |
182 [prototypeButton setImagePosition:NSImageAbove]; | 182 [prototypeButton setImagePosition:NSImageAbove]; |
183 [prototypeButton setButtonType:NSMomentaryChangeButton]; | 183 [prototypeButton setButtonType:NSMomentaryChangeButton]; |
184 [prototypeButton setBordered:NO]; | 184 [prototypeButton setBordered:NO]; |
185 | 185 |
186 scoped_nsobject<AppsGridItemBackgroundView> prototypeButtonBackground( | 186 base::scoped_nsobject<AppsGridItemBackgroundView> prototypeButtonBackground( |
187 [[AppsGridItemBackgroundView alloc] initWithFrame:NSMakeRect( | 187 [[AppsGridItemBackgroundView alloc] |
188 0, 0, tileSize.width, tileSize.height)]); | 188 initWithFrame:NSMakeRect(0, 0, tileSize.width, tileSize.height)]); |
189 [prototypeButtonBackground addSubview:prototypeButton]; | 189 [prototypeButtonBackground addSubview:prototypeButton]; |
190 [self setView:prototypeButtonBackground]; | 190 [self setView:prototypeButtonBackground]; |
191 } | 191 } |
192 return self; | 192 return self; |
193 } | 193 } |
194 | 194 |
195 - (NSString*)buttonTitle { | 195 - (NSString*)buttonTitle { |
196 return [[[self button] attributedTitle] string]; | 196 return [[[self button] attributedTitle] string]; |
197 } | 197 } |
198 | 198 |
199 - (void)setButtonTitle:(NSString*)newTitle { | 199 - (void)setButtonTitle:(NSString*)newTitle { |
200 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 200 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
201 [[NSMutableParagraphStyle alloc] init]); | 201 [[NSMutableParagraphStyle alloc] init]); |
202 [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; | 202 [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; |
203 [paragraphStyle setAlignment:NSCenterTextAlignment]; | 203 [paragraphStyle setAlignment:NSCenterTextAlignment]; |
204 NSDictionary* titleAttributes = @{ | 204 NSDictionary* titleAttributes = @{ |
205 NSParagraphStyleAttributeName : paragraphStyle, | 205 NSParagraphStyleAttributeName : paragraphStyle, |
206 NSFontAttributeName : ui::ResourceBundle::GetSharedInstance().GetFont( | 206 NSFontAttributeName : ui::ResourceBundle::GetSharedInstance().GetFont( |
207 app_list::kItemTextFontStyle).GetNativeFont(), | 207 app_list::kItemTextFontStyle).GetNativeFont(), |
208 NSForegroundColorAttributeName : [self isSelected] ? | 208 NSForegroundColorAttributeName : [self isSelected] ? |
209 gfx::SkColorToCalibratedNSColor(app_list::kGridTitleHoverColor) : | 209 gfx::SkColorToCalibratedNSColor(app_list::kGridTitleHoverColor) : |
210 gfx::SkColorToCalibratedNSColor(app_list::kGridTitleColor) | 210 gfx::SkColorToCalibratedNSColor(app_list::kGridTitleColor) |
211 }; | 211 }; |
212 scoped_nsobject<NSAttributedString> attributedTitle( | 212 base::scoped_nsobject<NSAttributedString> attributedTitle( |
213 [[NSAttributedString alloc] initWithString:newTitle | 213 [[NSAttributedString alloc] initWithString:newTitle |
214 attributes:titleAttributes]); | 214 attributes:titleAttributes]); |
215 [[self button] setAttributedTitle:attributedTitle]; | 215 [[self button] setAttributedTitle:attributedTitle]; |
216 } | 216 } |
217 | 217 |
218 - (void)setModel:(app_list::AppListItemModel*)itemModel { | 218 - (void)setModel:(app_list::AppListItemModel*)itemModel { |
219 if (!itemModel) { | 219 if (!itemModel) { |
220 observerBridge_.reset(); | 220 observerBridge_.reset(); |
221 return; | 221 return; |
222 } | 222 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 - (void)drawImage:(NSImage*)image | 293 - (void)drawImage:(NSImage*)image |
294 withFrame:(NSRect)frame | 294 withFrame:(NSRect)frame |
295 inView:(NSView*)controlView { | 295 inView:(NSView*)controlView { |
296 if (!hasShadow_) { | 296 if (!hasShadow_) { |
297 [super drawImage:image | 297 [super drawImage:image |
298 withFrame:frame | 298 withFrame:frame |
299 inView:controlView]; | 299 inView:controlView]; |
300 return; | 300 return; |
301 } | 301 } |
302 | 302 |
303 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); | 303 base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); |
304 gfx::ScopedNSGraphicsContextSaveGState context; | 304 gfx::ScopedNSGraphicsContextSaveGState context; |
305 [shadow setShadowOffset:NSMakeSize(0, -2)]; | 305 [shadow setShadowOffset:NSMakeSize(0, -2)]; |
306 [shadow setShadowBlurRadius:2.0]; | 306 [shadow setShadowBlurRadius:2.0]; |
307 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0 | 307 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0 |
308 alpha:0.14]]; | 308 alpha:0.14]]; |
309 [shadow set]; | 309 [shadow set]; |
310 | 310 |
311 [super drawImage:image | 311 [super drawImage:image |
312 withFrame:frame | 312 withFrame:frame |
313 inView:controlView]; | 313 inView:controlView]; |
314 } | 314 } |
315 | 315 |
316 @end | 316 @end |
OLD | NEW |