diff options
Diffstat (limited to 'chrome/browser/ui/cocoa')
8 files changed, 118 insertions, 80 deletions
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. |