diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 23:30:58 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 23:30:58 +0000 |
commit | cc7af20c86badaa22495bfa7d0c1e7b97a318cbc (patch) | |
tree | 39979b05d8eee368e98519417e37361319247660 /chrome/browser/cocoa/extensions | |
parent | ab6c890e9f217c8e91d9119755a61c25ec7e41b8 (diff) | |
download | chromium_src-cc7af20c86badaa22495bfa7d0c1e7b97a318cbc.zip chromium_src-cc7af20c86badaa22495bfa7d0c1e7b97a318cbc.tar.gz chromium_src-cc7af20c86badaa22495bfa7d0c1e7b97a318cbc.tar.bz2 |
[Mac] o Adds a slight drop shadow to the drawn images within Browser Action buttons.
o Adds initial BrowserActionsContainerView class that simply draws a right border at this time but will be used for more complex UI later.
o Alters Toolbar.xib to use the new view class instead of a plain NSView.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/565048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/extensions')
5 files changed, 77 insertions, 12 deletions
diff --git a/chrome/browser/cocoa/extensions/browser_action_button.mm b/chrome/browser/cocoa/extensions/browser_action_button.mm index 00cdd86..2c6cb67 100644 --- a/chrome/browser/cocoa/extensions/browser_action_button.mm +++ b/chrome/browser/cocoa/extensions/browser_action_button.mm @@ -165,17 +165,29 @@ class ExtensionImageTrackerBridge : public NotificationObserver, @implementation BrowserActionCell -- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { - [super drawWithFrame:cellFrame inView:controlView]; +- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { + [NSGraphicsContext saveGraphicsState]; + + // Create the shadow below and to the right of the drawn image. + scoped_nsobject<NSShadow> imgShadow([[NSShadow alloc] init]); + [imgShadow setShadowOffset:NSMakeSize(2.0, -2.0)]; + [imgShadow setShadowBlurRadius:2.0]; + [imgShadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:0.3]]; + [imgShadow set]; + + [super drawInteriorWithFrame:cellFrame inView:controlView]; // CanvasPaint draws its content to the current NSGraphicsContext in its - // destructor. If anything needs to be drawn afterwards, then enclose this - // in a nested block. - cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; - gfx::CanvasPaint canvas(cellFrame, false); - canvas.set_composite_alpha(true); - gfx::Rect boundingRect(NSRectToCGRect(cellFrame)); - extensionAction_->PaintBadge(&canvas, boundingRect, tabId_); + // destructor, so it is enclosed in a nested block. + { + cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; + gfx::CanvasPaint canvas(cellFrame, false); + canvas.set_composite_alpha(true); + gfx::Rect boundingRect(NSRectToCGRect(cellFrame)); + extensionAction_->PaintBadge(&canvas, boundingRect, tabId_); + } + + [NSGraphicsContext restoreGraphicsState]; } @synthesize tabId = tabId_; diff --git a/chrome/browser/cocoa/extensions/browser_actions_container_view.h b/chrome/browser/cocoa/extensions/browser_actions_container_view.h new file mode 100644 index 0000000..4b92601 --- /dev/null +++ b/chrome/browser/cocoa/extensions/browser_actions_container_view.h @@ -0,0 +1,14 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> + +@interface BrowserActionsContainerView : NSView { + // Whether there is a border to the right of the last Browser Action. + BOOL rightBorderShown_; +} + +@property(nonatomic) BOOL rightBorderShown; + +@end diff --git a/chrome/browser/cocoa/extensions/browser_actions_container_view.mm b/chrome/browser/cocoa/extensions/browser_actions_container_view.mm new file mode 100644 index 0000000..9ef509c0 --- /dev/null +++ b/chrome/browser/cocoa/extensions/browser_actions_container_view.mm @@ -0,0 +1,37 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/cocoa/extensions/browser_actions_container_view.h" + +namespace { + const CGFloat kRightBorderWidth = 1.0; + const CGFloat kRightBorderGrayscale = 0.5; + const CGFloat kUpperPadding = 9.0; + const CGFloat kLowerPadding = 5.0; +} // namespace + +@implementation BrowserActionsContainerView + +@synthesize rightBorderShown = rightBorderShown_; + +- (void)drawRect:(NSRect)dirtyRect { + NSRect bounds = [self bounds]; + if (rightBorderShown_) { + NSColor* middleColor = + [NSColor colorWithCalibratedWhite:kRightBorderGrayscale alpha:1.0]; + NSColor* endPointColor = + [NSColor colorWithCalibratedWhite:kRightBorderGrayscale alpha:0.0]; + NSGradient* borderGradient = [[[NSGradient alloc] + initWithColorsAndLocations:endPointColor, (CGFloat)0.0, + middleColor, (CGFloat)0.5, + endPointColor, (CGFloat)1.0, + nil] autorelease]; + CGFloat xPos = bounds.origin.x + bounds.size.width - kRightBorderWidth; + NSRect borderRect = NSMakeRect(xPos, kLowerPadding, kRightBorderWidth, + bounds.size.height - kUpperPadding); + [borderGradient drawInRect:borderRect angle:90.0]; + } +} + +@end diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.h b/chrome/browser/cocoa/extensions/browser_actions_controller.h index 8daf35e..3be6814 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_controller.h +++ b/chrome/browser/cocoa/extensions/browser_actions_controller.h @@ -12,6 +12,7 @@ class Browser; @class BrowserActionButton; +@class BrowserActionsContainerView; class Extension; @class ExtensionPopupController; class ExtensionsServiceObserverBridge; @@ -27,7 +28,7 @@ extern NSString* const kBrowserActionsChangedNotification; Browser* browser_; // The view from Toolbar.xib we'll be rendering our browser actions in. Weak. - NSView* containerView_; + BrowserActionsContainerView* containerView_; // The current profile. Weak. Profile* profile_; @@ -47,7 +48,7 @@ extern NSString* const kBrowserActionsChangedNotification; // Initializes the controller given the current browser and container view that // will hold the browser action buttons. - (id)initWithBrowser:(Browser*)browser - containerView:(NSView*)container; + containerView:(BrowserActionsContainerView*)container; // Creates and appends any existing browser action buttons present within the // extensions service to the toolbar. diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm index e28d69f..79f3724 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm +++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm @@ -9,6 +9,7 @@ #include "base/sys_string_conversions.h" #include "chrome/browser/browser.h" #include "chrome/browser/cocoa/extensions/browser_action_button.h" +#include "chrome/browser/cocoa/extensions/browser_actions_container_view.h" #include "chrome/browser/cocoa/extensions/extension_popup_controller.h" #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extensions_service.h" @@ -90,7 +91,7 @@ class ExtensionsServiceObserverBridge : public NotificationObserver { @implementation BrowserActionsController - (id)initWithBrowser:(Browser*)browser - containerView:(NSView*)container { + containerView:(BrowserActionsContainerView*)container { DCHECK(browser && container); if ((self = [super init])) { |