From 9bc8295aefb56b29672e9cf7e6326a7133524195 Mon Sep 17 00:00:00 2001 From: "thakis@chromium.org" Date: Thu, 13 Sep 2012 13:24:05 +0000 Subject: mac: Switch browser action backgrounds from vectors to bitmaps Based on a patch from Andrew Bonventre BUG=111101 TEST=hover a browser action. highlight looks like the highlight on the reload button. NOTRY=true Review URL: https://chromiumcodereview.appspot.com/10907212 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156539 0039d316-1c4b-4281-b951-d872f2087c98 --- .../ui/cocoa/extensions/browser_action_button.h | 4 +-- .../ui/cocoa/extensions/browser_action_button.mm | 29 ++++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/ui/cocoa/extensions/browser_action_button.h b/chrome/browser/ui/cocoa/extensions/browser_action_button.h index 4ee5231..359ec7a 100644 --- a/chrome/browser/ui/cocoa/extensions/browser_action_button.h +++ b/chrome/browser/ui/cocoa/extensions/browser_action_button.h @@ -9,7 +9,7 @@ #import "base/memory/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" -#import "chrome/browser/ui/cocoa/gradient_button_cell.h" +#import "chrome/browser/ui/cocoa/image_button_cell.h" class Browser; class ExtensionAction; @@ -69,7 +69,7 @@ extern NSString* const kBrowserActionButtonDragEndNotification; @end -@interface BrowserActionCell : GradientButtonCell { +@interface BrowserActionCell : ImageButtonCell { @private // The current tab ID used when drawing the cell. int tabId_; diff --git a/chrome/browser/ui/cocoa/extensions/browser_action_button.mm b/chrome/browser/ui/cocoa/extensions/browser_action_button.mm index a2d31c3..14fe67e 100644 --- a/chrome/browser/ui/cocoa/extensions/browser_action_button.mm +++ b/chrome/browser/ui/cocoa/extensions/browser_action_button.mm @@ -36,11 +36,8 @@ NSString* const kBrowserActionButtonDraggingNotification = NSString* const kBrowserActionButtonDragEndNotification = @"BrowserActionButtonDragEndNotification"; -static const CGFloat kBrowserActionBadgeOriginYOffset = 5; - -namespace { +const CGFloat kBrowserActionBadgeOriginYOffset = 5; const CGFloat kAnimationDuration = 0.2; -} // anonymous namespace // A helper class to bridge the asynchronous Skia bitmap loading mechanism to // the extension's button. @@ -137,6 +134,12 @@ class ExtensionImageTrackerBridge : public content::NotificationObserver, [cell accessibilitySetOverrideValue:base::SysUTF8ToNSString(extension->name()) forAttribute:NSAccessibilityDescriptionAttribute]; + [cell setImageID:IDR_BROWSER_ACTION + forButtonState:image_button_cell::kDefaultState]; + [cell setImageID:IDR_BROWSER_ACTION_H + forButtonState:image_button_cell::kHoverState]; + [cell setImageID:IDR_BROWSER_ACTION_P + forButtonState:image_button_cell::kPressedState]; [self setTitle:@""]; [self setButtonType:NSMomentaryChangeButton]; @@ -214,8 +217,7 @@ class ExtensionImageTrackerBridge : public content::NotificationObserver, - (void)endDrag { isBeingDragged_ = NO; [[NSNotificationCenter defaultCenter] - postNotificationName:kBrowserActionButtonDragEndNotification - object:self]; + postNotificationName:kBrowserActionButtonDragEndNotification object:self]; [[self cell] setHighlighted:NO]; } @@ -306,9 +308,20 @@ class ExtensionImageTrackerBridge : public content::NotificationObserver, extensionAction_->PaintBadge(&canvas, boundingRect, tabId_); } -- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { gfx::ScopedNSGraphicsContextSaveGState scopedGState; - [super drawInteriorWithFrame:cellFrame inView:controlView]; + [super drawWithFrame:cellFrame inView:controlView]; + const NSSize imageSize = self.image.size; + const NSRect imageRect = + NSMakeRect(std::floor((NSWidth(cellFrame) - imageSize.width) / 2.0), + std::floor((NSHeight(cellFrame) - imageSize.height) / 2.0), + imageSize.width, imageSize.height); + [self.image drawInRect:imageRect + fromRect:NSZeroRect + operation:NSCompositeSourceOver + fraction:1.0 + neverFlipped:YES]; + cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; [self drawBadgeWithinFrame:cellFrame]; } -- cgit v1.1