diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 18:01:08 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 18:01:08 +0000 |
commit | 3302102a21dcdae93f17f2db57ba32ba0e8dd1da (patch) | |
tree | e8f3b5e53324e77a3dc6502a0d555e93a25261b2 /chrome/browser/cocoa/bookmark_bar_toolbar_view.mm | |
parent | 9398185452c106c0f464747fd76d70f3d212143a (diff) | |
download | chromium_src-3302102a21dcdae93f17f2db57ba32ba0e8dd1da.zip chromium_src-3302102a21dcdae93f17f2db57ba32ba0e8dd1da.tar.gz chromium_src-3302102a21dcdae93f17f2db57ba32ba0e8dd1da.tar.bz2 |
Mac: Theme the bookmark bar on the new tab page.
- XIB change: The controller has a connection to buttonView_.
- BrowserThemeProviderMac: Fix a bug where we weren't returning
default colors; we returned nil instead.
- The majority of the implementation is actually the cross platform
NtpBackgroundUtil::PaintBackgroundDetachedMode. We do platform
specific drawing on top of the background, though.
TEST=BookmarkBarToolbarViewTest.DisplayAsFloatingBarWithNoImage
TEST=BookmarkBarToolbarViewTest.DisplayAsFloatingBarWithBgImage
BUG=http://crbug.com/17625
Review URL: http://codereview.chromium.org/266027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_bar_toolbar_view.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view.mm | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm index e40607b..4a652aa 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm @@ -4,18 +4,98 @@ #import "chrome/browser/cocoa/bookmark_bar_toolbar_view.h" +#include "app/gfx/canvas_paint.h" +#include "app/theme_provider.h" +#include "base/gfx/rect.h" +#include "chrome/browser/browser_theme_provider.h" +#import "chrome/browser/cocoa/browser_window_controller.h" +#import "chrome/browser/cocoa/bookmark_bar_constants.h" #import "chrome/browser/cocoa/bookmark_bar_controller.h" +#include "chrome/browser/ntp_background_util.h" +#import "third_party/GTM/AppKit/GTMTheme.h" + +const CGFloat kBorderRadius = 3.0; + +@interface BookmarkBarToolbarView (Private) +- (void)drawRectAsFloating:(NSRect)rect; +@end @implementation BookmarkBarToolbarView +- (BOOL)isOpaque { + return YES; +} + - (void)drawRect:(NSRect)rect { if ([controller_ drawAsFloatingBar]) { - // TODO(erg): Deal with themes. http://crbug.com/17625 - [[NSColor colorWithDeviceRed:1.0 green:1.0 blue:1.0 alpha:1.0] set]; - NSRectFill(rect); + [self drawRectAsFloating:rect]; } else { [super drawRect:rect]; } } +- (void)layoutViews { + if ([controller_ drawAsFloatingBar]) { + // The internal bookmark bar should have padding to center it. + NSRect frame = [self frame]; + [buttonView_ setFrame: + NSMakeRect(bookmarks::kNTPBookmarkBarPadding, + bookmarks::kNTPBookmarkBarPadding, + NSWidth(frame) - + bookmarks::kNTPBookmarkBarPadding, + NSHeight(frame) - + bookmarks::kNTPBookmarkBarPadding)]; + } else { + // The frame of our child should be equal to our frame. + NSRect frame = [self frame]; + [buttonView_ setFrame:NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame))]; + } +} + +@end + + +@implementation BookmarkBarToolbarView (Private) + +- (void)drawRectAsFloating:(NSRect)rect { + NSRect bounds = [self bounds]; + + ThemeProvider* themeProvider = [controller_ themeProvider]; + if (!themeProvider) + return; + + NSGraphicsContext* theContext = [NSGraphicsContext currentContext]; + [theContext saveGraphicsState]; + + // Draw the background + { + // CanvasPaint draws to the NSGraphicsContext during its destructor, so + // explicitly scope this. + gfx::CanvasPaint canvas(rect, true); + gfx::Rect area(0, 0, NSWidth(rect), NSHeight(rect)); + + NtpBackgroundUtil::PaintBackgroundDetachedMode(themeProvider, &canvas, + area, [controller_ currentTabContentsHeight]); + } + + // Draw our bookmark bar border on top of the background. + NSRect frame_rect = + NSMakeRect(bookmarks::kNTPBookmarkBarPadding, + bookmarks::kNTPBookmarkBarPadding, + NSWidth(bounds) - 2 * bookmarks::kNTPBookmarkBarPadding, + NSHeight(bounds) - 2 * bookmarks::kNTPBookmarkBarPadding); + // Now draw a beizer path with rounded rectangles around the area + NSBezierPath* border = + [NSBezierPath bezierPathWithRoundedRect:frame_rect + xRadius:kBorderRadius + yRadius:kBorderRadius]; + [themeProvider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR) set];; + [border fill]; + + [themeProvider->GetNSColor(BrowserThemeProvider::COLOR_NTP_HEADER) set]; + [border stroke]; + + [theContext restoreGraphicsState]; +} + @end // @implementation BookmarkBarToolbarView |