OLD | NEW |
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/cocoa/extensions/browser_action_button.h" | 5 #import "chrome/browser/cocoa/extensions/browser_action_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 NSString* const kBrowserActionButtonUpdatedNotification = | 28 NSString* const kBrowserActionButtonUpdatedNotification = |
29 @"BrowserActionButtonUpdatedNotification"; | 29 @"BrowserActionButtonUpdatedNotification"; |
30 | 30 |
31 NSString* const kBrowserActionButtonDraggingNotification = | 31 NSString* const kBrowserActionButtonDraggingNotification = |
32 @"BrowserActionButtonDraggingNotification"; | 32 @"BrowserActionButtonDraggingNotification"; |
33 NSString* const kBrowserActionButtonDragEndNotification = | 33 NSString* const kBrowserActionButtonDragEndNotification = |
34 @"BrowserActionButtonDragEndNotification"; | 34 @"BrowserActionButtonDragEndNotification"; |
35 | 35 |
36 static const CGFloat kBrowserActionBadgeOriginYOffset = 5; | 36 static const CGFloat kBrowserActionBadgeOriginYOffset = 5; |
37 | 37 |
38 // Since the container is the maximum height of the toolbar, we have to move the | |
39 // buttons up by this amount in order to have them look vertically centered | |
40 // within the toolbar. | |
41 static const CGFloat kBrowserActionOriginYOffset = 6.0; | |
42 | |
43 // The size of each button on the toolbar. | |
44 static const CGFloat kBrowserActionHeight = 27; | |
45 const CGFloat kBrowserActionWidth = 29; | |
46 | |
47 namespace { | 38 namespace { |
48 const CGFloat kAnimationDuration = 0.2; | 39 const CGFloat kAnimationDuration = 0.2; |
49 const CGFloat kShadowOffset = 2.0; | 40 const CGFloat kShadowOffset = 2.0; |
50 } // anonymous namespace | 41 } // anonymous namespace |
51 | 42 |
52 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to | 43 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to |
53 // the extension's button. | 44 // the extension's button. |
54 class ExtensionImageTrackerBridge : public NotificationObserver, | 45 class ExtensionImageTrackerBridge : public NotificationObserver, |
55 public ImageLoadingTracker::Observer { | 46 public ImageLoadingTracker::Observer { |
56 public: | 47 public: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 @implementation BrowserActionButton | 105 @implementation BrowserActionButton |
115 | 106 |
116 @synthesize isBeingDragged = isBeingDragged_; | 107 @synthesize isBeingDragged = isBeingDragged_; |
117 @synthesize extension = extension_; | 108 @synthesize extension = extension_; |
118 @synthesize tabId = tabId_; | 109 @synthesize tabId = tabId_; |
119 | 110 |
120 + (Class)cellClass { | 111 + (Class)cellClass { |
121 return [BrowserActionCell class]; | 112 return [BrowserActionCell class]; |
122 } | 113 } |
123 | 114 |
124 - (id)initWithExtension:(Extension*)extension | 115 - (id)initWithFrame:(NSRect)frame |
125 profile:(Profile*)profile | 116 extension:(Extension*)extension |
126 tabId:(int)tabId { | 117 profile:(Profile*)profile |
127 NSRect frame = NSMakeRect(0.0, | 118 tabId:(int)tabId { |
128 kBrowserActionOriginYOffset, | |
129 kBrowserActionWidth, | |
130 kBrowserActionHeight); | |
131 if ((self = [super initWithFrame:frame])) { | 119 if ((self = [super initWithFrame:frame])) { |
132 BrowserActionCell* cell = [[[BrowserActionCell alloc] init] autorelease]; | 120 BrowserActionCell* cell = [[[BrowserActionCell alloc] init] autorelease]; |
133 // [NSButton setCell:] warns to NOT use setCell: other than in the | 121 // [NSButton setCell:] warns to NOT use setCell: other than in the |
134 // initializer of a control. However, we are using a basic | 122 // initializer of a control. However, we are using a basic |
135 // NSButton whose initializer does not take an NSCell as an | 123 // NSButton whose initializer does not take an NSCell as an |
136 // object. To honor the assumed semantics, we do nothing with | 124 // object. To honor the assumed semantics, we do nothing with |
137 // NSButton between alloc/init and setCell:. | 125 // NSButton between alloc/init and setCell:. |
138 [self setCell:cell]; | 126 [self setCell:cell]; |
139 [cell setTabId:tabId]; | 127 [cell setTabId:tabId]; |
140 [cell setExtensionAction:extension->browser_action()]; | 128 [cell setExtensionAction:extension->browser_action()]; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 [[NSNotificationCenter defaultCenter] | 261 [[NSNotificationCenter defaultCenter] |
274 postNotificationName:kBrowserActionButtonUpdatedNotification | 262 postNotificationName:kBrowserActionButtonUpdatedNotification |
275 object:self]; | 263 object:self]; |
276 } | 264 } |
277 | 265 |
278 - (BOOL)isAnimating { | 266 - (BOOL)isAnimating { |
279 return [moveAnimation_ isAnimating]; | 267 return [moveAnimation_ isAnimating]; |
280 } | 268 } |
281 | 269 |
282 - (NSImage*)compositedImage { | 270 - (NSImage*)compositedImage { |
283 NSRect bounds = NSMakeRect(0, 0, kBrowserActionWidth, kBrowserActionHeight); | 271 NSRect bounds = [self bounds]; |
284 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; | 272 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; |
285 [image lockFocus]; | 273 [image lockFocus]; |
286 | 274 |
287 [[NSColor clearColor] set]; | 275 [[NSColor clearColor] set]; |
288 NSRectFill(bounds); | 276 NSRectFill(bounds); |
289 [[self cell] setIconShadow]; | 277 [[self cell] setIconShadow]; |
290 | 278 |
291 NSImage* actionImage = [self image]; | 279 NSImage* actionImage = [self image]; |
292 const NSSize imageSize = [actionImage size]; | 280 const NSSize imageSize = [actionImage size]; |
293 const NSRect imageRect = | 281 const NSRect imageRect = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 323 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
336 [NSGraphicsContext saveGraphicsState]; | 324 [NSGraphicsContext saveGraphicsState]; |
337 [self setIconShadow]; | 325 [self setIconShadow]; |
338 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 326 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
339 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 327 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
340 [self drawBadgeWithinFrame:cellFrame]; | 328 [self drawBadgeWithinFrame:cellFrame]; |
341 [NSGraphicsContext restoreGraphicsState]; | 329 [NSGraphicsContext restoreGraphicsState]; |
342 } | 330 } |
343 | 331 |
344 @end | 332 @end |
OLD | NEW |