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 | |
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')
7 files changed, 88 insertions, 25 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])) { diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h index fe9c997..51ef250 100644 --- a/chrome/browser/cocoa/toolbar_controller.h +++ b/chrome/browser/cocoa/toolbar_controller.h @@ -18,6 +18,7 @@ class AppMenuModel; @class AutocompleteTextField; @class AutocompleteTextFieldEditor; +@class BrowserActionsContainerView; @class BackForwardMenuController; class Browser; @class BrowserActionsController; @@ -102,7 +103,7 @@ class ToolbarModel; IBOutlet MenuButton* pageButton_; IBOutlet MenuButton* wrenchButton_; IBOutlet AutocompleteTextField* locationBar_; - IBOutlet NSView* browserActionContainerView_; + IBOutlet BrowserActionsContainerView* browserActionsContainerView_; } // Initialize the toolbar and register for command updates. The profile is diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index 6ffa93e..2ca18eb 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -242,7 +242,7 @@ class PrefObserverBridge : public NotificationObserver { button:forwardButton_]); browserActionsController_.reset([[BrowserActionsController alloc] initWithBrowser:browser_ - containerView:browserActionContainerView_]); + containerView:browserActionsContainerView_]); // When new browser actions are added/removed, the container view for them is // resized, necessitating the probable resizing of surrounding elements // handled by this controller. @@ -492,7 +492,7 @@ class PrefObserverBridge : public NotificationObserver { - (NSArray*)toolbarViews { return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, homeButton_, starButton_, goButton_, pageButton_, wrenchButton_, - locationBar_, browserActionContainerView_, nil]; + locationBar_, browserActionsContainerView_, nil]; } // Moves |rect| to the right by |delta|, keeping the right side fixed by @@ -584,8 +584,8 @@ class PrefObserverBridge : public NotificationObserver { moveX *= -1; // Reverse the direction of the move. [self adjustLocationAndGoPositionsBy:moveX]; - [browserActionContainerView_ setFrame:NSOffsetRect( - [browserActionContainerView_ frame], moveX, 0)]; + [browserActionsContainerView_ setFrame:NSOffsetRect( + [browserActionsContainerView_ frame], moveX, 0)]; [pageButton_ setHidden:hide]; [wrenchButton_ setHidden:hide]; @@ -644,7 +644,7 @@ class PrefObserverBridge : public NotificationObserver { visibleCount = [browserActionsController_ visibleButtonCount]; if (visibleCount == buttonCount && !hide) return; - BrowserActionButton* button = [[browserActionContainerView_ subviews] + BrowserActionButton* button = [[browserActionsContainerView_ subviews] objectAtIndex:visibleCount + arrayOffset]; [button setHidden:hide]; [self browserActionsChanged]; @@ -657,13 +657,10 @@ class PrefObserverBridge : public NotificationObserver { int buttonCount = [browserActionsController_ visibleButtonCount]; CGFloat width = 0.0; - if (buttonCount > 0) { - width = (buttonCount * - (kBrowserActionWidth + kBrowserActionButtonPadding)) - - kBrowserActionButtonPadding; // No padding after last button. - } + if (buttonCount > 0) + width = buttonCount * (kBrowserActionWidth + kBrowserActionButtonPadding); - NSRect containerFrame = [browserActionContainerView_ frame]; + NSRect containerFrame = [browserActionsContainerView_ frame]; CGFloat buttonSpacing = [self interButtonSpacing]; CGFloat dX = containerFrame.size.width - width; containerFrame.size.width = width; @@ -685,7 +682,7 @@ class PrefObserverBridge : public NotificationObserver { } } - [browserActionContainerView_ setFrame:NSOffsetRect(containerFrame, dX, 0)]; + [browserActionsContainerView_ setFrame:NSOffsetRect(containerFrame, dX, 0)]; [self adjustLocationAndGoPositionsBy:dX]; } |