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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/browser_action_button.mm

Issue 10907212: mac: Switch browser action backgrounds from vectors to bitmaps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/browser_action_button.h ('k') | 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 (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/extensions/browser_action_button.h" 5 #import "chrome/browser/ui/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 18 matching lines...) Expand all
29 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 29 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
30 #include "ui/gfx/size.h" 30 #include "ui/gfx/size.h"
31 31
32 using extensions::Extension; 32 using extensions::Extension;
33 33
34 NSString* const kBrowserActionButtonDraggingNotification = 34 NSString* const kBrowserActionButtonDraggingNotification =
35 @"BrowserActionButtonDraggingNotification"; 35 @"BrowserActionButtonDraggingNotification";
36 NSString* const kBrowserActionButtonDragEndNotification = 36 NSString* const kBrowserActionButtonDragEndNotification =
37 @"BrowserActionButtonDragEndNotification"; 37 @"BrowserActionButtonDragEndNotification";
38 38
39 static const CGFloat kBrowserActionBadgeOriginYOffset = 5; 39 const CGFloat kBrowserActionBadgeOriginYOffset = 5;
40
41 namespace {
42 const CGFloat kAnimationDuration = 0.2; 40 const CGFloat kAnimationDuration = 0.2;
43 } // anonymous namespace
44 41
45 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to 42 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to
46 // the extension's button. 43 // the extension's button.
47 class ExtensionImageTrackerBridge : public content::NotificationObserver, 44 class ExtensionImageTrackerBridge : public content::NotificationObserver,
48 public ImageLoadingTracker::Observer { 45 public ImageLoadingTracker::Observer {
49 public: 46 public:
50 ExtensionImageTrackerBridge(BrowserActionButton* owner, 47 ExtensionImageTrackerBridge(BrowserActionButton* owner,
51 const Extension* extension) 48 const Extension* extension)
52 : owner_(owner), 49 : owner_(owner),
53 tracker_(this), 50 tracker_(this),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // initializer of a control. However, we are using a basic 127 // initializer of a control. However, we are using a basic
131 // NSButton whose initializer does not take an NSCell as an 128 // NSButton whose initializer does not take an NSCell as an
132 // object. To honor the assumed semantics, we do nothing with 129 // object. To honor the assumed semantics, we do nothing with
133 // NSButton between alloc/init and setCell:. 130 // NSButton between alloc/init and setCell:.
134 [self setCell:cell]; 131 [self setCell:cell];
135 [cell setTabId:tabId]; 132 [cell setTabId:tabId];
136 [cell setExtensionAction:extension->browser_action()]; 133 [cell setExtensionAction:extension->browser_action()];
137 [cell 134 [cell
138 accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name()) 135 accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name())
139 forAttribute:NSAccessibilityDescriptionAttribute]; 136 forAttribute:NSAccessibilityDescriptionAttribute];
137 [cell setImageID:IDR_BROWSER_ACTION
138 forButtonState:image_button_cell::kDefaultState];
139 [cell setImageID:IDR_BROWSER_ACTION_H
140 forButtonState:image_button_cell::kHoverState];
141 [cell setImageID:IDR_BROWSER_ACTION_P
142 forButtonState:image_button_cell::kPressedState];
140 143
141 [self setTitle:@""]; 144 [self setTitle:@""];
142 [self setButtonType:NSMomentaryChangeButton]; 145 [self setButtonType:NSMomentaryChangeButton];
143 [self setShowsBorderOnlyWhileMouseInside:YES]; 146 [self setShowsBorderOnlyWhileMouseInside:YES];
144 147
145 [self setMenu:[[[ExtensionActionContextMenu alloc] 148 [self setMenu:[[[ExtensionActionContextMenu alloc]
146 initWithExtension:extension 149 initWithExtension:extension
147 browser:browser 150 browser:browser
148 extensionAction:extension->browser_action()] autorelease]]; 151 extensionAction:extension->browser_action()] autorelease]];
149 152
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 [self endDrag]; 210 [self endDrag];
208 } else { 211 } else {
209 [super mouseUp:theEvent]; 212 [super mouseUp:theEvent];
210 } 213 }
211 } 214 }
212 } 215 }
213 216
214 - (void)endDrag { 217 - (void)endDrag {
215 isBeingDragged_ = NO; 218 isBeingDragged_ = NO;
216 [[NSNotificationCenter defaultCenter] 219 [[NSNotificationCenter defaultCenter]
217 postNotificationName:kBrowserActionButtonDragEndNotification 220 postNotificationName:kBrowserActionButtonDragEndNotification object:self];
218 object:self];
219 [[self cell] setHighlighted:NO]; 221 [[self cell] setHighlighted:NO];
220 } 222 }
221 223
222 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate { 224 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate {
223 if (!animate) { 225 if (!animate) {
224 [self setFrame:frameRect]; 226 [self setFrame:frameRect];
225 } else { 227 } else {
226 if ([moveAnimation_ isAnimating]) 228 if ([moveAnimation_ isAnimating])
227 [moveAnimation_ stopAnimation]; 229 [moveAnimation_ stopAnimation];
228 230
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 @synthesize tabId = tabId_; 301 @synthesize tabId = tabId_;
300 @synthesize extensionAction = extensionAction_; 302 @synthesize extensionAction = extensionAction_;
301 303
302 - (void)drawBadgeWithinFrame:(NSRect)frame { 304 - (void)drawBadgeWithinFrame:(NSRect)frame {
303 gfx::CanvasSkiaPaint canvas(frame, false); 305 gfx::CanvasSkiaPaint canvas(frame, false);
304 canvas.set_composite_alpha(true); 306 canvas.set_composite_alpha(true);
305 gfx::Rect boundingRect(NSRectToCGRect(frame)); 307 gfx::Rect boundingRect(NSRectToCGRect(frame));
306 extensionAction_->PaintBadge(&canvas, boundingRect, tabId_); 308 extensionAction_->PaintBadge(&canvas, boundingRect, tabId_);
307 } 309 }
308 310
309 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 311 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
310 gfx::ScopedNSGraphicsContextSaveGState scopedGState; 312 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
311 [super drawInteriorWithFrame:cellFrame inView:controlView]; 313 [super drawWithFrame:cellFrame inView:controlView];
314 const NSSize imageSize = self.image.size;
315 const NSRect imageRect =
316 NSMakeRect(std::floor((NSWidth(cellFrame) - imageSize.width) / 2.0),
317 std::floor((NSHeight(cellFrame) - imageSize.height) / 2.0),
318 imageSize.width, imageSize.height);
319 [self.image drawInRect:imageRect
320 fromRect:NSZeroRect
321 operation:NSCompositeSourceOver
322 fraction:1.0
323 neverFlipped:YES];
324
312 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; 325 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset;
313 [self drawBadgeWithinFrame:cellFrame]; 326 [self drawBadgeWithinFrame:cellFrame];
314 } 327 }
315 328
316 @end 329 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/browser_action_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698