diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 20:37:12 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 20:37:12 +0000 |
commit | e14a81f29534e88cae95844c3fe0eeb5c3d3b185 (patch) | |
tree | 3a6cf6db0e0f0a8aa290b180110e409971e6948f | |
parent | b35b26b360b5d84d064d63440590902d4974b59d (diff) | |
download | chromium_src-e14a81f29534e88cae95844c3fe0eeb5c3d3b185.zip chromium_src-e14a81f29534e88cae95844c3fe0eeb5c3d3b185.tar.gz chromium_src-e14a81f29534e88cae95844c3fe0eeb5c3d3b185.tar.bz2 |
Mac: Use bitmaps to draw toolbar background
This is a part of the general change to remove the use of programatically drawn controls and use bitmaps instead.
With this change we now draw the toolbar and download shelf using bitmaps. Note, we didn't have a pre-existing bitmap for inactive toolbars so I create one myself. I'll ping Cole for a better one later.
While I was in this area of code I made some other changes as well:
- added a white highlight at the top of the download shelf
- change the look of the download shelf a bit. Previously the download shelf looked curved (light -> drak -> light). I offset the patter a bit to give a simpler light -> dark look instead. This matches the Windows look as well.
- fill the background using NSRectFillUsingOperation(rect, NSCompositeSourceOver) to properly blend semi-transparent theme images with the background.
Mac Screenshots:
http://www.dropmocks.com/mUnyO
Window screenshot for comparison:
http://www.dropmocks.com/mUni5
BUG=53217
TEST=Ran with and with out themes. Verified that things looked good.
Review URL: http://codereview.chromium.org/6931002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84304 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/theme/large_theme_toolbar_default_inactive2.png | bin | 0 -> 11306 bytes | |||
-rw-r--r-- | chrome/app/theme/theme_resources_large.grd | 7 | ||||
-rw-r--r-- | chrome/app/theme/theme_resources_standard.grd | 7 | ||||
-rw-r--r-- | chrome/app/theme/theme_toolbar_default_inactive2.png | bin | 0 -> 3820 bytes | |||
-rw-r--r-- | chrome/browser/ui/cocoa/background_gradient_view.h | 11 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/background_gradient_view.mm | 88 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/background_gradient_view_unittest.mm | 16 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm | 4 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/download/download_shelf_view.mm | 71 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/find_bar/find_bar_view.mm | 2 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/tabs/tab_view.mm | 2 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/toolbar_view.mm | 4 |
12 files changed, 128 insertions, 84 deletions
diff --git a/chrome/app/theme/large_theme_toolbar_default_inactive2.png b/chrome/app/theme/large_theme_toolbar_default_inactive2.png Binary files differnew file mode 100644 index 0000000..6968a47 --- /dev/null +++ b/chrome/app/theme/large_theme_toolbar_default_inactive2.png diff --git a/chrome/app/theme/theme_resources_large.grd b/chrome/app/theme/theme_resources_large.grd index fbd039c..38fb793 100644 --- a/chrome/app/theme/theme_resources_large.grd +++ b/chrome/app/theme/theme_resources_large.grd @@ -123,12 +123,15 @@ <if expr="not pp_ifdef('chromeos')"> <include name="IDR_THEME_TAB_BACKGROUND" file="theme_tab_background.png" type="BINDATA" /> </if> - <if expr="pp_ifdef('chromeos')"> + <if expr="pp_ifdef('chromeos') or os == 'darwin'"> <include name="IDR_THEME_TOOLBAR" file="large_theme_toolbar_default2.png" type="BINDATA" /> </if> - <if expr="not pp_ifdef('chromeos')"> + <if expr="not pp_ifdef('chromeos') and os != 'darwin'"> <include name="IDR_THEME_TOOLBAR" file="theme_toolbar_default.png" type="BINDATA" /> </if> + <if expr="os == 'darwin'"> + <include name="IDR_THEME_TOOLBAR_INACTIVE" file="large_theme_toolbar_default_inactive2.png" type="BINDATA" /> + </if> <include name="IDR_THROBBER_WAITING" file="large_throbber_waiting.png" type="BINDATA" /> <include name="IDR_TOOLS" file="large_tools.png" type="BINDATA" /> <include name="IDR_TOOLS_H" file="large_tools_h.png" type="BINDATA" /> diff --git a/chrome/app/theme/theme_resources_standard.grd b/chrome/app/theme/theme_resources_standard.grd index 603e2d0..eea6644 100644 --- a/chrome/app/theme/theme_resources_standard.grd +++ b/chrome/app/theme/theme_resources_standard.grd @@ -123,12 +123,15 @@ <if expr="not pp_ifdef('chromeos')"> <include name="IDR_THEME_TAB_BACKGROUND" file="theme_tab_background.png" type="BINDATA" /> </if> - <if expr="pp_ifdef('chromeos')"> + <if expr="pp_ifdef('chromeos') or os == 'darwin'"> <include name="IDR_THEME_TOOLBAR" file="theme_toolbar_default2.png" type="BINDATA" /> </if> - <if expr="not pp_ifdef('chromeos')"> + <if expr="not pp_ifdef('chromeos') and os != 'darwin'"> <include name="IDR_THEME_TOOLBAR" file="theme_toolbar_default.png" type="BINDATA" /> </if> + <if expr="os == 'darwin'"> + <include name="IDR_THEME_TOOLBAR_INACTIVE" file="theme_toolbar_default_inactive2.png" type="BINDATA" /> + </if> <include name="IDR_THROBBER_WAITING" file="throbber_waiting.png" type="BINDATA" /> <include name="IDR_TOOLS" file="tools.png" type="BINDATA" /> <include name="IDR_TOOLS_H" file="tools_h.png" type="BINDATA" /> diff --git a/chrome/app/theme/theme_toolbar_default_inactive2.png b/chrome/app/theme/theme_toolbar_default_inactive2.png Binary files differnew file mode 100644 index 0000000..845fd79 --- /dev/null +++ b/chrome/app/theme/theme_toolbar_default_inactive2.png diff --git a/chrome/browser/ui/cocoa/background_gradient_view.h b/chrome/browser/ui/cocoa/background_gradient_view.h index d72fa57..671168a 100644 --- a/chrome/browser/ui/cocoa/background_gradient_view.h +++ b/chrome/browser/ui/cocoa/background_gradient_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -16,11 +16,16 @@ } // The color used for the bottom stroke. Public so subclasses can use. -- (NSColor *)strokeColor; +- (NSColor*)strokeColor; // Draws the background for this view. Make sure that your patternphase // is set up correctly in your graphics context before calling. -- (void)drawBackground; +// If |opaque| is true then the background image is forced to be opaque. +// Otherwise the background image could be semi-transparent and blend against +// subviews and sublayers. This is different from -[NSView isOpaque] since +// a view may want a opaque non-rectangular background. The find bar is an +// example of this. +- (void)drawBackgroundWithOpaque:(BOOL)opaque; // Controls whether the bar draws a dividing line at the bottom. @property(nonatomic, assign) BOOL showsDivider; diff --git a/chrome/browser/ui/cocoa/background_gradient_view.mm b/chrome/browser/ui/cocoa/background_gradient_view.mm index 936e3c0..f0a72a0 100644 --- a/chrome/browser/ui/cocoa/background_gradient_view.mm +++ b/chrome/browser/ui/cocoa/background_gradient_view.mm @@ -10,22 +10,25 @@ #include "grit/theme_resources.h" #include "grit/theme_resources_standard.h" -#define kToolbarTopOffset 12 -#define kToolbarMaxHeight 100 +@interface BackgroundGradientView (Private) +- (NSColor*)backgroundImageColor; +@end @implementation BackgroundGradientView @synthesize showsDivider = showsDivider_; - (id)initWithFrame:(NSRect)frameRect { - self = [super initWithFrame:frameRect]; - if (self != nil) { + if ((self = [super initWithFrame:frameRect])) { showsDivider_ = YES; } return self; } -- (void)awakeFromNib { - showsDivider_ = YES; +- (id)initWithCoder:(NSCoder*)decoder { + if ((self = [super initWithCoder:decoder])) { + showsDivider_ = YES; + } + return self; } - (void)setShowsDivider:(BOOL)show { @@ -33,41 +36,26 @@ [self setNeedsDisplay:YES]; } -- (void)drawBackground { - BOOL isKey = [[self window] isKeyWindow]; - ui::ThemeProvider* themeProvider = [[self window] themeProvider]; - if (themeProvider) { - NSColor* backgroundImageColor = - themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, false); - if (backgroundImageColor) { - [backgroundImageColor set]; - NSRectFill([self bounds]); - } else { - CGFloat winHeight = NSHeight([[self window] frame]); - NSGradient* gradient = themeProvider->GetNSGradient( - isKey ? ThemeService::GRADIENT_TOOLBAR : - ThemeService::GRADIENT_TOOLBAR_INACTIVE); - NSPoint startPoint = - [self convertPoint:NSMakePoint(0, winHeight - kToolbarTopOffset) - fromView:nil]; - NSPoint endPoint = - NSMakePoint(0, winHeight - kToolbarTopOffset - kToolbarMaxHeight); - endPoint = [self convertPoint:endPoint fromView:nil]; - - [gradient drawFromPoint:startPoint - toPoint:endPoint - options:(NSGradientDrawsBeforeStartingLocation | - NSGradientDrawsAfterEndingLocation)]; - } - - if (showsDivider_) { - // Draw bottom stroke - [[self strokeColor] set]; - NSRect borderRect, contentRect; - NSDivideRect([self bounds], &borderRect, &contentRect, - [self cr_lineWidth], NSMinYEdge); - NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); - } +- (void)drawBackgroundWithOpaque:(BOOL)opaque { + const NSRect bounds = [self bounds]; + + if (opaque) { + // If the background image is semi transparent then we need something + // to blend against. Using 20% black gives us a color similar to Windows. + [[NSColor colorWithCalibratedWhite:0.2 alpha:1.0] set]; + NSRectFill(bounds); + } + + [[self backgroundImageColor] set]; + NSRectFillUsingOperation(bounds, NSCompositeSourceOver); + + if (showsDivider_) { + // Draw bottom stroke + [[self strokeColor] set]; + NSRect borderRect, contentRect; + NSDivideRect(bounds, &borderRect, &contentRect, [self cr_lineWidth], + NSMinYEdge); + NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); } } @@ -81,4 +69,22 @@ ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE, true); } +- (NSColor*)backgroundImageColor { + ThemeService* themeProvider = + static_cast<ThemeService*>([[self window] themeProvider]); + if (!themeProvider) + return [[self window] backgroundColor]; + + // Themes don't have an inactive image so only look for one if there's no + // theme. + if (![[self window] isKeyWindow] && themeProvider->UsingDefaultTheme()) { + NSColor* color = themeProvider->GetNSImageColorNamed( + IDR_THEME_TOOLBAR_INACTIVE, true); + if (color) + return color; + } + + return themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, true); +} + @end diff --git a/chrome/browser/ui/cocoa/background_gradient_view_unittest.mm b/chrome/browser/ui/cocoa/background_gradient_view_unittest.mm index 73040d2..d1cda6c 100644 --- a/chrome/browser/ui/cocoa/background_gradient_view_unittest.mm +++ b/chrome/browser/ui/cocoa/background_gradient_view_unittest.mm @@ -12,13 +12,22 @@ // Since BackgroundGradientView doesn't do any drawing by default, we // create a subclass to call its draw method for us. -@interface BackgroundGradientSubClassTest : BackgroundGradientView +@interface BackgroundGradientSubClassTest : BackgroundGradientView { + BOOL backgroundIsOpaque; +} + +@property BOOL backgroundIsOpaque; + @end @implementation BackgroundGradientSubClassTest + +@synthesize backgroundIsOpaque; + - (void)drawRect:(NSRect)rect { - [self drawBackground]; + [self drawBackgroundWithOpaque:backgroundIsOpaque]; } + @end namespace { @@ -41,6 +50,9 @@ TEST_VIEW(BackgroundGradientViewTest, view_) // Test drawing, mostly to ensure nothing leaks or crashes. TEST_F(BackgroundGradientViewTest, DisplayWithDivider) { [view_ setShowsDivider:YES]; + [view_ setBackgroundIsOpaque:YES]; + [view_ display]; + [view_ setBackgroundIsOpaque:NO]; [view_ display]; } diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm index 8ae613d..6be1a30 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm @@ -41,7 +41,7 @@ const CGFloat kBorderRadius = 3.0; } else { NSPoint phase = [[self window] themePatternPhase]; [[NSGraphicsContext currentContext] setPatternPhase:phase]; - [self drawBackground]; + [self drawBackgroundWithOpaque:YES]; } } @@ -109,7 +109,7 @@ const CGFloat kBorderRadius = 3.0; CGContextBeginTransparencyLayer(cgContext, NULL); CGContextSetAlpha(cgContext, 1 - morph); [context setPatternPhase:[[self window] themePatternPhase]]; - [self drawBackground]; + [self drawBackgroundWithOpaque:YES]; CGContextEndTransparencyLayer(cgContext); } diff --git a/chrome/browser/ui/cocoa/download/download_shelf_view.mm b/chrome/browser/ui/cocoa/download/download_shelf_view.mm index 0d9c72e..edff123 100644 --- a/chrome/browser/ui/cocoa/download/download_shelf_view.mm +++ b/chrome/browser/ui/cocoa/download/download_shelf_view.mm @@ -6,13 +6,32 @@ #include "base/memory/scoped_nsobject.h" #include "chrome/browser/themes/theme_service.h" +#import "chrome/browser/ui/cocoa/nsview_additions.h" +#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" #import "chrome/browser/ui/cocoa/themed_window.h" #import "chrome/browser/ui/cocoa/view_id_util.h" #include "grit/theme_resources.h" #include "grit/theme_resources_standard.h" +#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" @implementation DownloadShelfView +// For programmatic instantiations in unit tests. +- (id)initWithFrame:(NSRect)frameRect { + if ((self = [super initWithFrame:frameRect])) { + [self setShowsDivider:NO]; + } + return self; +} + +// For nib instantiations in production. +- (id)initWithCoder:(NSCoder*)decoder { + if ((self = [super initWithCoder:decoder])) { + [self setShowsDivider:NO]; + } + return self; +} + - (NSColor*)strokeColor { BOOL isKey = [[self window] isKeyWindow]; ui::ThemeProvider* themeProvider = [[self window] themeProvider]; @@ -23,40 +42,36 @@ } - (void)drawRect:(NSRect)rect { - BOOL isKey = [[self window] isKeyWindow]; - ui::ThemeProvider* themeProvider = [[self window] themeProvider]; - if (!themeProvider) - return; - - NSColor* backgroundImageColor = - themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, false); - if (backgroundImageColor) { - // We want our backgrounds for the shelf to be phased from the upper - // left hand corner of the view. - NSPoint phase = NSMakePoint(0, NSHeight([self bounds])); - [[NSGraphicsContext currentContext] setPatternPhase:phase]; - [backgroundImageColor set]; - NSRectFill([self bounds]); - } else { - NSGradient* gradient = themeProvider->GetNSGradient( - isKey ? ThemeService::GRADIENT_TOOLBAR : - ThemeService::GRADIENT_TOOLBAR_INACTIVE); - NSPoint startPoint = [self convertPoint:NSMakePoint(0, 0) fromView:nil]; - NSPoint endPoint = - [self convertPoint:NSMakePoint(0, [self frame].size.height) - fromView:nil]; + gfx::ScopedNSGraphicsContextSaveGState saveGState; - [gradient drawFromPoint:startPoint - toPoint:endPoint - options:NSGradientDrawsBeforeStartingLocation | - NSGradientDrawsAfterEndingLocation]; - } + // We want our backgrounds for the shelf to be phased from the upper + // left hand corner of the view. Offset it by tab height so that the + // background matches the toolbar background. + NSPoint phase = NSMakePoint( + 0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]); + [[NSGraphicsContext currentContext] setPatternPhase:phase]; + [self drawBackgroundWithOpaque:YES]; // Draw top stroke [[self strokeColor] set]; NSRect borderRect, contentRect; - NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMaxYEdge); + NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], + NSMaxYEdge); NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); + + // Draw the top highlight + ThemeService* themeProvider = + static_cast<ThemeService*>([[self window] themeProvider]); + if (themeProvider) { + int resourceName = themeProvider->UsingDefaultTheme() ? + ThemeService::COLOR_TOOLBAR_BEZEL : ThemeService::COLOR_TOOLBAR; + NSColor* highlightColor = themeProvider->GetNSColor(resourceName, true); + if (highlightColor) { + [highlightColor set]; + borderRect.origin.y -= [self cr_lineWidth]; + NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); + } + } } // Mouse down events on the download shelf should not allow dragging the parent diff --git a/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm b/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm index 478f6c1..dd9bd8b 100644 --- a/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm +++ b/chrome/browser/ui/cocoa/find_bar/find_bar_view.mm @@ -72,7 +72,7 @@ CGFloat kCurveSize = 8; NSPoint phase = [[self window] themePatternPhase]; [context setPatternPhase:phase]; - [super drawBackground]; + [super drawBackgroundWithOpaque:YES]; } [[self strokeColor] set]; diff --git a/chrome/browser/ui/cocoa/tabs/tab_view.mm b/chrome/browser/ui/cocoa/tabs/tab_view.mm index 8e88fef..15d1fdb 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_view.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_view.mm @@ -715,7 +715,7 @@ const CGFloat kRapidCloseDist = 2.5; [path addClip]; { gfx::ScopedNSGraphicsContextSaveGState drawBackgroundState(context); - [super drawBackground]; + [super drawBackgroundWithOpaque:NO]; } // Draw a mouse hover gradient for the default themes. diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm index 75f25e0..69702e7 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_view.mm @@ -1,4 +1,4 @@ - // Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -21,7 +21,7 @@ // tab strip view's background pattern. NSPoint phase = [[self window] themePatternPhase]; [[NSGraphicsContext currentContext] setPatternPhase:phase]; - [self drawBackground]; + [self drawBackgroundWithOpaque:YES]; } // Override of |-[BackgroundGradientView strokeColor]|; make it respect opacity. |