diff options
24 files changed, 170 insertions, 976 deletions
diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 41edf09..20980a1 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -93,6 +93,8 @@ class BrowserThemeProvider : public NonThreadSafe, COLOR_TOOLBAR_STROKE_INACTIVE, COLOR_TOOLBAR_BUTTON_STROKE, COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE, + GRADIENT_FRAME_INCOGNITO, + GRADIENT_FRAME_INCOGNITO_INACTIVE, GRADIENT_TOOLBAR, GRADIENT_TOOLBAR_INACTIVE, GRADIENT_TOOLBAR_BUTTON, diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index ad521ac..f455d70 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -167,6 +167,42 @@ NSGradient* BrowserThemeProvider::GetNSGradient(int id) const { // Note that we are not leaking when we assign a retained object to // |gradient|; in all cases we cache it before we return. switch (id) { + case GRADIENT_FRAME_INCOGNITO: + case GRADIENT_FRAME_INCOGNITO_INACTIVE: { + // TODO(avi): can we simplify this? + BOOL active = id == GRADIENT_FRAME_INCOGNITO; + NSColor* base_color = [NSColor colorWithCalibratedRed:83/255.0 + green:108.0/255.0 + blue:140/255.0 + alpha:1.0]; + + CGFloat luminance = [base_color gtm_luminance]; + + // Adjust luminance so it never hits black. + if (luminance < 0.5) { + CGFloat adjustment = (0.5 - luminance) / 1.5; + base_color = [base_color gtm_colorByAdjustingLuminance:adjustment]; + } + + NSColor *start_color = + [base_color gtm_colorAdjustedFor:GTMColorationBaseMidtone + faded:!active]; + NSColor *end_color = + [base_color gtm_colorAdjustedFor:GTMColorationBaseShadow + faded:!active]; + + if (!active) { + start_color = [start_color gtm_colorByAdjustingLuminance:0.1 + saturation:0.5]; + end_color = [end_color gtm_colorByAdjustingLuminance:0.1 + saturation:0.5]; + } + + gradient = [[NSGradient alloc] initWithStartingColor:start_color + endingColor:end_color]; + break; + } + case GRADIENT_TOOLBAR: case GRADIENT_TOOLBAR_INACTIVE: { NSColor* base_color = [NSColor colorWithCalibratedWhite:0.5 alpha:1.0]; diff --git a/chrome/browser/cocoa/GTMTheme.h b/chrome/browser/cocoa/GTMTheme.h deleted file mode 100644 index 3399fbf..0000000 --- a/chrome/browser/cocoa/GTMTheme.h +++ /dev/null @@ -1,124 +0,0 @@ -// 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. - -// Derived from the GTMTheme in Google Toolbox for Mac. This file should -// go away: http://crbug.com/35554 - -#import "GTMDefines.h" -#import <AppKit/AppKit.h> - -// Sent whenever the theme changes. Object => GTMTheme that changed -GTM_EXTERN NSString *const kGTMThemeDidChangeNotification; - -// Key for user defaults defining background color -GTM_EXTERN NSString *const kGTMThemeBackgroundColorKey; - -enum { - GTMThemeStyleTabBarSelected, - GTMThemeStyleTabBarDeselected, - GTMThemeStyleWindow, - GTMThemeStyleToolBar, - GTMThemeStyleToolBarButton, - GTMThemeStyleToolBarButtonPressed, - GTMThemeStyleBookmarksBarButton, -}; -typedef NSUInteger GTMThemeStyle; - -enum { - GTMThemeStateInactiveWindow = 0, - GTMThemeStateActiveWindow = 1 << 0 -}; -typedef NSUInteger GTMThemeState; - -// GTMTheme provides a range of values for procedural drawing of UI elements -// based on interpolation of a single background color - -@interface GTMTheme : NSObject { - @private - NSColor *backgroundColor_; // bound to user defaults - NSImage *backgroundImage_; // bound to user defaults - NSMutableDictionary *values_; // cached values -} - -// Access the global theme. By default this is bound to user defaults -+ (GTMTheme *)defaultTheme; -+ (void)setDefaultTheme:(GTMTheme *)theme; - -// Bind this theme to user defaults -- (void)bindToUserDefaults; - -// returns base theme color -- (NSColor *)backgroundColor; - -// sets the base theme color -- (void)setBackgroundColor:(NSColor *)value; - -// base background image -- (NSImage *)backgroundImage; - -// set base background image -- (void)setBackgroundImage:(NSImage *)value; - -// NSImage pattern background -- (NSImage *)backgroundImageForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// NSColor of the above image, if present, else gradientForStyle -- (NSColor *)backgroundPatternColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// NSGradient for specific usage -- (NSGradient *)gradientForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// Outline color for stroke -- (NSColor *)strokeColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// Text color -- (NSColor *)textColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// Base background color (a plain (non pattern/gradient) NSColor) -- (NSColor *)backgroundColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// Indicates whether luminance is dark or light -- (BOOL)styleIsDark:(GTMThemeStyle)style state:(GTMThemeState)state; - -// Background style for this style and state -- (NSBackgroundStyle)interiorBackgroundStyleForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -- (NSColor *)iconColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// Manually set a theme value -- (void)setValue:(id)value - forAttribute:(NSString *)attribute - style:(GTMThemeStyle)style - state:(GTMThemeState)state; - -// Manually extract a theme value -- (id)valueForAttribute:(NSString *)attribute - style:(GTMThemeStyle)style - state:(GTMThemeState)state; -@end - -// Convenience categories for NSWindow and NSView to access the current theme -// Default implementation polls the window delegate -@interface NSWindow (GTMTheme) -- (GTMTheme *)gtm_theme; -- (NSPoint)gtm_themePatternPhase; -@end - -@interface NSView (GTMTheme) -- (GTMTheme *)gtm_theme; -- (NSPoint)gtm_themePatternPhase; -@end - -@protocol GTMThemeDelegate -- (GTMTheme *)gtm_themeForWindow:(NSWindow *)window; -- (NSPoint)gtm_themePatternPhaseForWindow:(NSWindow *)window; -@end diff --git a/chrome/browser/cocoa/GTMTheme.m b/chrome/browser/cocoa/GTMTheme.m deleted file mode 100644 index c3062812..0000000 --- a/chrome/browser/cocoa/GTMTheme.m +++ /dev/null @@ -1,510 +0,0 @@ -// 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. - -// Derived from the GTMTheme in Google Toolbox for Mac. This file should -// go away: http://crbug.com/35554 - -#import "chrome/browser/cocoa/GTMTheme.h" -#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" -#import <QuartzCore/QuartzCore.h> - -static GTMTheme *gGTMDefaultTheme = nil; -NSString *const kGTMThemeDidChangeNotification = - @"GTMThemeDidChangeNotification"; -NSString *const kGTMThemeBackgroundColorKey = @"GTMThemeBackgroundColor"; - -@interface GTMTheme () -- (void)sendChangeNotification; -@end - -@implementation NSWindow (GTMTheme) -- (id<GTMThemeDelegate>)gtm_themeDelegate { - id delegate = nil; - id tempDelegate = [self delegate]; - if ([tempDelegate conformsToProtocol:@protocol(GTMThemeDelegate)]) { - delegate = tempDelegate; - } - if (!delegate) { - tempDelegate = [self windowController]; - if ([tempDelegate conformsToProtocol:@protocol(GTMThemeDelegate)]) { - delegate = tempDelegate; - } - } - return delegate; -} - -- (GTMTheme *)gtm_theme { - GTMTheme *theme = nil; - id<GTMThemeDelegate>delegate = [self gtm_themeDelegate]; - if (delegate) { - theme = [delegate gtm_themeForWindow:self]; - } - return theme; -} - -- (NSPoint)gtm_themePatternPhase { - NSPoint phase = NSZeroPoint; - id<GTMThemeDelegate>delegate = [self gtm_themeDelegate]; - if (delegate) { - phase = [delegate gtm_themePatternPhaseForWindow:self]; - } - return phase; -} -@end - -@implementation NSView (GTMTheme) -- (GTMTheme *)gtm_theme { - return [[self window] gtm_theme]; -} - -- (NSPoint)gtm_themePatternPhase { - return [[self window] gtm_themePatternPhase]; -} -@end - -@implementation GTMTheme - -+ (void)setDefaultTheme:(GTMTheme *)theme { - if (gGTMDefaultTheme != theme) { - [gGTMDefaultTheme release]; - gGTMDefaultTheme = [theme retain]; - [gGTMDefaultTheme sendChangeNotification]; - } -} - -+ (GTMTheme *)defaultTheme { - @synchronized (self) { - if (!gGTMDefaultTheme) { - gGTMDefaultTheme = [[self alloc] init]; - [gGTMDefaultTheme bindToUserDefaults]; - } - } - return gGTMDefaultTheme; -} - -- (void)bindToUserDefaults { - NSUserDefaultsController * controller = - [NSUserDefaultsController sharedUserDefaultsController]; - [self bind:@"backgroundColor" - toObject:controller - withKeyPath:@"values.GTMThemeBackgroundColor" - options:[NSDictionary dictionaryWithObjectsAndKeys: - NSUnarchiveFromDataTransformerName, - NSValueTransformerNameBindingOption, - nil]]; - - [self bind:@"backgroundImage" - toObject:controller - withKeyPath:@"values.GTMThemeBackgroundImageData" - options:[NSDictionary dictionaryWithObjectsAndKeys: - NSUnarchiveFromDataTransformerName, - NSValueTransformerNameBindingOption, - nil]]; -} - -- (id)init { - self = [super init]; - if (self != nil) { - values_ = [[NSMutableDictionary alloc] init]; - } - return self; -} - -- (void)finalize { - [self unbind:@"backgroundColor"]; - [self unbind:@"backgroundImage"]; - [super finalize]; -} - -- (void)dealloc { - [self unbind:@"backgroundColor"]; - [self unbind:@"backgroundImage"]; - [values_ release]; - [super dealloc]; -} - -- (void)sendChangeNotification { - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc postNotificationName:kGTMThemeDidChangeNotification - object:self]; -} - -- (id)keyForSelector:(SEL)selector - style:(GTMThemeStyle)style - state:(GTMThemeState)state { - return [NSString stringWithFormat:@"%p.%d.%d", selector, style, state]; -} - -- (id)valueForSelector:(SEL)selector - style:(GTMThemeStyle)style - state:(GTMThemeState)state { - id value = [values_ objectForKey: - [self keyForSelector:selector style:style state:state]]; - return value; -} - -- (void)cacheValue:(id)value - forSelector:(SEL)selector - style:(GTMThemeStyle)style - state:(GTMThemeState)state { - id key = [self keyForSelector:selector style:style state:state]; - if (key && value) [values_ setObject:value forKey:key]; -} - -- (void)setValue:(id)value - forAttribute:(NSString *)attribute - style:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSString *selectorString = [NSString stringWithFormat:@"%@ForStyle:state:", - attribute]; - [self cacheValue:value - forSelector:NSSelectorFromString(selectorString) - style:style - state:state]; -} - -- (id)valueForAttribute:(NSString *)attribute - style:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSString *selectorString = [NSString stringWithFormat:@"%@ForStyle:state:", - attribute]; - id key = [self keyForSelector:NSSelectorFromString(selectorString) - style:style - state:state]; - return [values_ objectForKey:key]; -} - -- (void)setBackgroundColor:(NSColor *)value { - if (backgroundColor_ != value) { - [backgroundColor_ release]; - backgroundColor_ = [value retain]; - } -} -- (NSColor *)backgroundColor { - // For nil, we return a color that works with a normal textured window - if (!backgroundColor_) - return [NSColor colorWithCalibratedWhite:0.5 alpha:1.0]; - return backgroundColor_; -} - -- (void)setBackgroundImage:(NSImage *)value { - if (backgroundImage_ != value) { - [backgroundImage_ release]; - backgroundImage_ = [value retain]; - } -} - -- (NSImage *)backgroundImage { - return backgroundImage_; -} - -- (NSImage *)backgroundImageForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - id value = [self valueForSelector:_cmd style:style state:state]; - if (value) return value; - - if (style == GTMThemeStyleWindow) { - NSColor *color = nil; - if (!state) { - // TODO(alcor): dim images when disabled - color = [NSColor colorWithPatternImage:backgroundImage_]; - // TODO(alcor): |color| is never used! - - if ((state & GTMThemeStateActiveWindow) != GTMThemeStateActiveWindow) { - // TODO(alcor): this recursive call will also return nil since when you - // ask for the active style, it never returns anything. - NSImage *image = - [self backgroundImageForStyle:style - state:GTMThemeStateActiveWindow]; - NSBitmapImageRep *rep = (NSBitmapImageRep *)[image - bestRepresentationForDevice:nil]; - if ([rep respondsToSelector:@selector(CGImage)]) { - CIImage *ciimage = [CIImage imageWithCGImage:[rep CGImage]]; - CIFilter *filter = [CIFilter filterWithName:@"CIColorControls" - keysAndValues: - @"inputSaturation", - [NSNumber numberWithFloat:0.8f], - @"inputBrightness", - [NSNumber numberWithFloat:0.2f], - @"inputContrast", - [NSNumber numberWithFloat:0.8f], - @"inputImage", - ciimage, - nil]; - - ciimage = [filter valueForKey:@"outputImage"]; - - value = [[[NSImage alloc] init] autorelease]; - [value addRepresentation:[NSCIImageRep imageRepWithCIImage:ciimage]]; - } - } - } - } - - [self cacheValue:value forSelector:_cmd style:style state:state]; - return value; -} - -- (NSBackgroundStyle)interiorBackgroundStyleForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - id value = [self valueForSelector:_cmd style:style state:state]; - if (value) return [value intValue]; - - NSGradient *gradient = [self gradientForStyle:style state:state]; - NSColor *color = [gradient interpolatedColorAtLocation:0.5]; - BOOL dark = [color gtm_isDarkColor]; - value = [NSNumber numberWithInt: dark ? NSBackgroundStyleLowered - : NSBackgroundStyleRaised]; - [self cacheValue:value forSelector:_cmd style:style state:state]; - return [value intValue]; -} - -- (BOOL)styleIsDark:(GTMThemeStyle)style state:(GTMThemeState)state { - id value = [self valueForSelector:_cmd style:style state:state]; - if (value) return [value boolValue]; - - if (style == GTMThemeStyleToolBarButtonPressed) { - value = [NSNumber numberWithBool:YES]; - } else { - value = [NSNumber numberWithBool:[[self backgroundColor] gtm_isDarkColor]]; - } - [self cacheValue:value forSelector:_cmd style:style state:state]; - return [value boolValue]; -} - -- (NSColor *)backgroundPatternColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSColor *color = [self valueForSelector:_cmd style:style state:state]; - if (color) return color; - - NSImage *image = [self backgroundImageForStyle:style state:state]; - if (!image && backgroundColor_) { - NSGradient *gradient = [self gradientForStyle:style state:state]; - if (gradient) { - // create a gradient image for the background - CGRect r = CGRectZero; - // TODO(alcor): figure out a better way to get an image that is the right - // size. - r.size = CGSizeMake(4, 36); - size_t bytesPerRow = 4 * r.size.width; - - CGColorSpaceRef space - = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - CGContextRef context - = CGBitmapContextCreate(NULL, - r.size.width, - r.size.height, - 8, - bytesPerRow, - space, - kCGImageAlphaPremultipliedFirst); - CGColorSpaceRelease(space); - NSGraphicsContext *nsContext = - [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES]; - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:nsContext]; - [gradient drawInRect:NSMakeRect(0, 0, r.size.width, r.size.height) - angle:270]; - [NSGraphicsContext restoreGraphicsState]; - - CGImageRef cgImage = CGBitmapContextCreateImage(context); - CGContextRelease(context); - NSBitmapImageRep *rep = nil; - if (cgImage) { - rep = [[[NSBitmapImageRep alloc] initWithCGImage:cgImage] - autorelease]; - CGImageRelease(cgImage); - } - - image = [[[NSImage alloc] initWithSize:NSSizeFromCGSize(r.size)] - autorelease]; - [image addRepresentation:rep]; - } - } - if (image) - color = [NSColor colorWithPatternImage:image]; - [self cacheValue:color forSelector:_cmd style:style state:state]; - return color; -} - -- (NSGradient *)gradientForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSGradient *gradient = [self valueForSelector:_cmd style:style state:state]; - if (gradient) return gradient; - - BOOL useDarkColors = backgroundImage_ != nil || style == GTMThemeStyleWindow; - - NSUInteger uses[4]; - if (useDarkColors) { - uses[0] = GTMColorationBaseHighlight; - uses[1] = GTMColorationBaseMidtone; - uses[2] = GTMColorationBaseShadow; - uses[3] = GTMColorationBasePenumbra; - } else { - uses[0] = GTMColorationLightHighlight; - uses[1] = GTMColorationLightMidtone; - uses[2] = GTMColorationLightShadow; - uses[3] = GTMColorationLightPenumbra; - } - NSColor *backgroundColor = [self backgroundColor]; - - BOOL active = - (state & GTMThemeStateActiveWindow) == GTMThemeStateActiveWindow; - switch (style) { - case GTMThemeStyleTabBarDeselected: { - NSColor *startColor = [backgroundColor gtm_colorAdjustedFor:uses[2] - faded:!active]; - NSColor *endColor = [backgroundColor gtm_colorAdjustedFor:uses[3] - faded:!active]; - - gradient = [[[NSGradient alloc] initWithStartingColor:startColor - endingColor:endColor] - autorelease]; - break; - } - case GTMThemeStyleTabBarSelected: { - NSColor *startColor = [backgroundColor gtm_colorAdjustedFor:uses[0] - faded:!active]; - NSColor *endColor = [backgroundColor gtm_colorAdjustedFor:uses[1] - faded:!active]; - gradient = [[[NSGradient alloc] initWithStartingColor:startColor - endingColor:endColor] - autorelease]; - break; - } - case GTMThemeStyleWindow: { - CGFloat luminance = [backgroundColor gtm_luminance]; - - // Adjust luminance so it never hits black - if (luminance < 0.5) { - CGFloat adjustment = (0.5 - luminance) / 1.5; - backgroundColor - = [backgroundColor gtm_colorByAdjustingLuminance:adjustment]; - } - NSColor *startColor = [backgroundColor gtm_colorAdjustedFor:uses[1] - faded:!active]; - NSColor *endColor = [backgroundColor gtm_colorAdjustedFor:uses[2] - faded:!active]; - - - if (!active) { - startColor = [startColor gtm_colorByAdjustingLuminance:0.1 - saturation:0.5]; - endColor = [endColor gtm_colorByAdjustingLuminance:0.1 - saturation:0.5]; - - } - gradient = [[[NSGradient alloc] initWithStartingColor:startColor - endingColor:endColor] - autorelease]; - break; - } - case GTMThemeStyleToolBar: - case GTMThemeStyleToolBarButton: { - NSColor *startColor = [backgroundColor gtm_colorAdjustedFor:uses[0] - faded:!active]; - NSColor *midColor = [backgroundColor gtm_colorAdjustedFor:uses[1] - faded:!active]; - NSColor *endColor = [backgroundColor gtm_colorAdjustedFor:uses[2] - faded:!active]; - NSColor *glowColor = [backgroundColor gtm_colorAdjustedFor:uses[3] - faded:!active]; - - gradient = [[[NSGradient alloc] initWithColorsAndLocations: - startColor, 0.0, - midColor, 0.25, - endColor, 0.5, - glowColor, 0.75, - nil] autorelease]; - break; - } - case GTMThemeStyleToolBarButtonPressed: { - NSColor *startColor = [backgroundColor - gtm_colorAdjustedFor:GTMColorationBaseShadow - faded:!active]; - NSColor *endColor = [backgroundColor - gtm_colorAdjustedFor:GTMColorationBaseMidtone - faded:!active]; - gradient = [[[NSGradient alloc] initWithStartingColor:startColor - endingColor:endColor] - autorelease]; - break; - } - default: - _GTMDevLog(@"Unexpected style: %d", style); - break; - } - - [self cacheValue:gradient forSelector:_cmd style:style state:state]; - return gradient; -} - -- (NSColor *)strokeColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSColor *color = [self valueForSelector:_cmd style:style state:state]; - if (color) return color; - NSColor *backgroundColor = [self backgroundColor]; - BOOL active = (state & GTMThemeStateActiveWindow) - == GTMThemeStateActiveWindow; - switch (style) { - case GTMThemeStyleToolBarButton: - color = [[backgroundColor gtm_colorAdjustedFor:GTMColorationDarkShadow - faded:!active] - colorWithAlphaComponent:0.3]; - break; - case GTMThemeStyleToolBar: - default: - color = [[self backgroundColor] - gtm_colorAdjustedFor:GTMColorationBaseShadow - faded:!active]; - break; - } - - [self cacheValue:color forSelector:_cmd style:style state:state]; - return color; -} - -- (NSColor *)iconColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSColor *color = [self valueForSelector:_cmd style:style state:state]; - if (color) return color; - - if ([self styleIsDark:style state:state]) { - color = [NSColor whiteColor]; - } else { - color = [NSColor blackColor]; - } - - [self cacheValue:color forSelector:_cmd style:style state:state]; - return color; -} - -- (NSColor *)textColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSColor *color = [self valueForSelector:_cmd style:style state:state]; - if (color) return color; - - if ([self styleIsDark:style state:state]) { - color = [NSColor whiteColor]; - } else { - color = [NSColor blackColor]; - } - - [self cacheValue:color forSelector:_cmd style:style state:state]; - return color; -} - -- (NSColor *)backgroundColorForStyle:(GTMThemeStyle)style - state:(GTMThemeState)state { - NSColor *color = [self valueForSelector:_cmd style:style state:state]; - if (color) return color; - - // TODO(alcor): calculate this based off base background color - // Generally this will be set by a theme provider - color = [self backgroundColor]; - - [self cacheValue:color forSelector:_cmd style:style state:state]; - return color; -} -@end diff --git a/chrome/browser/cocoa/background_gradient_view.h b/chrome/browser/cocoa/background_gradient_view.h index 177967d..8ebddc6f 100644 --- a/chrome/browser/cocoa/background_gradient_view.h +++ b/chrome/browser/cocoa/background_gradient_view.h @@ -6,7 +6,6 @@ #define CHROME_BROWSER_COCOA_BACKGROUND_GRADIENT_VIEW_H_ #import <Cocoa/Cocoa.h> -#import "chrome/browser/cocoa/GTMTheme.h" // A custom view that draws a 'standard' background gradient. // Base class for other Chromium views. diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm index bf0d9fc..81af0a7 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm @@ -32,7 +32,7 @@ const CGFloat kBorderRadius = 3.0; [controller_ isAnimatingFromState:bookmarks::kDetachedState]) { [self drawRectAsBubble:rect]; } else { - NSPoint phase = [self gtm_themePatternPhase]; + NSPoint phase = [[self window] themePatternPhase]; [[NSGraphicsContext currentContext] setPatternPhase:phase]; [self drawBackground]; } @@ -100,7 +100,7 @@ const CGFloat kBorderRadius = 3.0; CGContextRef cgContext = (CGContextRef)[context graphicsPort]; CGContextBeginTransparencyLayer(cgContext, NULL); CGContextSetAlpha(cgContext, 1 - morph); - [context setPatternPhase:[self gtm_themePatternPhase]]; + [context setPatternPhase:[[self window] themePatternPhase]]; [self drawBackground]; CGContextEndTransparencyLayer(cgContext); [context restoreGraphicsState]; diff --git a/chrome/browser/cocoa/browser_frame_view.h b/chrome/browser/cocoa/browser_frame_view.h index 277a96b..3ae13ea0 100644 --- a/chrome/browser/cocoa/browser_frame_view.h +++ b/chrome/browser/cocoa/browser_frame_view.h @@ -49,4 +49,10 @@ // check that everything is safe, and attempt to fallback gracefully if it is // not. @interface BrowserFrameView : NSView + +// Draws the window theme into the specified rect. ++ (void)drawWindowThemeInDirtyRect:(NSRect)dirtyRect + forView:(NSView*)view + bounds:(NSRect)bounds; + @end diff --git a/chrome/browser/cocoa/browser_frame_view.mm b/chrome/browser/cocoa/browser_frame_view.mm index c4bcf53..bf999c6 100644 --- a/chrome/browser/cocoa/browser_frame_view.mm +++ b/chrome/browser/cocoa/browser_frame_view.mm @@ -9,8 +9,10 @@ #include "base/logging.h" #include "base/scoped_nsautorelease_pool.h" +#import "chrome/browser/browser_theme_provider.h" #import "chrome/browser/cocoa/chrome_browser_window.h" -#import "chrome/browser/cocoa/GTMTheme.h" +#import "chrome/browser/cocoa/themed_window.h" +#include "grit/theme_resources.h" @interface NSView (Swizzles) - (void)drawRectOriginal:(NSRect)rect; @@ -87,14 +89,14 @@ // Here is our custom drawing for our frame. - (void)drawRect:(NSRect)rect { + [self drawRectOriginal:rect]; // If this isn't the window class we expect, then pass it on to the // original implementation. - [self drawRectOriginal:rect]; if (![[self window] isKindOfClass:[ChromeBrowserWindow class]]) { return; } - // Set up our clip + // Set up our clip. NSWindow* window = [self window]; NSRect windowRect = [window frame]; windowRect.origin = NSMakePoint(0, 0); @@ -103,15 +105,45 @@ yRadius:4] addClip]; [[NSBezierPath bezierPathWithRect:rect] addClip]; - // Draw our background color if we have one, otherwise fall back on - // system drawing. - GTMTheme* theme = [self gtm_theme]; - GTMThemeState state = [window isMainWindow] ? GTMThemeStateActiveWindow - : GTMThemeStateInactiveWindow; - NSColor* color = [theme backgroundPatternColorForStyle:GTMThemeStyleWindow - state:state]; - if (color) { - // If there is a theme pattern, draw it here. + // Do the theming. + [BrowserFrameView drawWindowThemeInDirtyRect:rect + forView:self + bounds:windowRect]; +} + ++ (void)drawWindowThemeInDirtyRect:(NSRect)dirtyRect + forView:(NSView*)view + bounds:(NSRect)bounds { + ThemeProvider* themeProvider = [[view window] themeProvider]; + if (!themeProvider) + return; + + BOOL active = [[view window] isMainWindow]; + BOOL incognito = [[view window] themeIsIncognito]; + + // Find a theme image. + NSImage* themeImage = nil; + int themeImageID; + if (active && incognito) + themeImageID = IDR_THEME_FRAME_INCOGNITO; + else if (active && !incognito) + themeImageID = IDR_THEME_FRAME; + else if (!active && incognito) + themeImageID = IDR_THEME_FRAME_INCOGNITO_INACTIVE; + else + themeImageID = IDR_THEME_FRAME_INACTIVE; + if (themeProvider->HasCustomImage(IDR_THEME_FRAME)) + themeImage = themeProvider->GetNSImageNamed(themeImageID, true); + + // If no theme image, use a gradient if incognito. + NSGradient* gradient = nil; + if (!themeImage && incognito) + gradient = themeProvider->GetNSGradient( + active ? BrowserThemeProvider::GRADIENT_FRAME_INCOGNITO : + BrowserThemeProvider::GRADIENT_FRAME_INCOGNITO_INACTIVE); + + if (themeImage) { + NSColor* themeImageColor = [NSColor colorWithPatternImage:themeImage]; // The titlebar/tabstrip header on the mac is slightly smaller than on // Windows. To keep the window background lined up with the tab and toolbar @@ -122,27 +154,41 @@ // This will make the themes look slightly different than in Windows/Linux // because of the differing heights between window top and tab top, but this // has been approved by UI. - static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 2 }; + static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; NSPoint phase = kBrowserFrameViewPatternPhaseOffset; - phase.y += NSHeight(windowRect); + phase.y += NSHeight(bounds); + + phase = [view convertPoint:phase toView:nil]; + [[NSGraphicsContext currentContext] setPatternPhase:phase]; - [color set]; - NSRectFill(rect); + [themeImageColor set]; + NSRectFill(dirtyRect); + } else if (gradient) { + // Only paint the gradient at the top of the window. (This is at the maximum + // when fullscreening; before adjusting check this case.) + static const CGFloat kBrowserFrameViewGradientHeight = 52.0; + NSRect gradientRect = bounds; + gradientRect.origin.y = NSMaxY(gradientRect) - + kBrowserFrameViewGradientHeight; + gradientRect.size.height = kBrowserFrameViewGradientHeight; + + [gradient drawInRect:gradientRect angle:270]; } // Check to see if we have an overlay image. - NSImage* overlayImage = [theme valueForAttribute:@"overlay" - style:GTMThemeStyleWindow - state:state]; + NSImage* overlayImage = + themeProvider->GetNSImageNamed(active ? IDR_THEME_FRAME_OVERLAY : + IDR_THEME_FRAME_OVERLAY_INACTIVE, + false); if (overlayImage) { // Anchor to top-left and don't scale. NSSize overlaySize = [overlayImage size]; NSRect imageFrame = NSMakeRect(0, 0, overlaySize.width, overlaySize.height); - [overlayImage drawAtPoint:NSMakePoint(0, NSHeight(windowRect) - - overlaySize.height) + [overlayImage drawAtPoint:NSMakePoint(0, NSHeight(bounds) - + overlaySize.height) fromRect:imageFrame - operation:NSCompositeSourceOver - fraction:1.0]; + operation:NSCompositeSourceOver + fraction:1.0]; } } diff --git a/chrome/browser/cocoa/browser_theme_provider_init.h b/chrome/browser/cocoa/browser_theme_provider_init.h deleted file mode 100644 index aeb6466..0000000 --- a/chrome/browser/cocoa/browser_theme_provider_init.h +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -#ifndef CHROME_BROWSER_COCOA_BROWSER_THEME_PROVIDER_INIT_H_ -#define CHROME_BROWSER_COCOA_BROWSER_THEME_PROVIDER_INIT_H_ - -#import "chrome/browser/cocoa/GTMTheme.h" - -class BrowserThemeProvider; - -// Provides a routine to initialize GTMTheme with data from a provided -// |BrowserThemeProvider|. -@interface GTMTheme(BrowserThemeProviderInitialization) -+ (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider - isOffTheRecord:(BOOL)offTheRecord; -@end - -#endif // CHROME_BROWSER_COCOA_BROWSER_THEME_PROVIDER_INIT_H_ diff --git a/chrome/browser/cocoa/browser_theme_provider_init.mm b/chrome/browser/cocoa/browser_theme_provider_init.mm deleted file mode 100644 index 69f6c79..0000000 --- a/chrome/browser/cocoa/browser_theme_provider_init.mm +++ /dev/null @@ -1,178 +0,0 @@ -// 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/browser_theme_provider_init.h" - -#import <Cocoa/Cocoa.h> - -#include <map> -#include <string> -#include <utility> - -#import "base/scoped_nsobject.h" -#include "chrome/browser/browser_theme_provider.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "grit/theme_resources.h" - - -@implementation GTMTheme(BrowserThemeProviderInitialization) - -+ (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider - isOffTheRecord:(BOOL)isOffTheRecord { - // First check if it's in the cache. - typedef std::pair<std::string, BOOL> ThemeKey; - static std::map<ThemeKey, GTMTheme*> cache; - ThemeKey key(provider->GetThemeID(), isOffTheRecord); - GTMTheme* theme = cache[key]; - if (theme) - return theme; - - theme = [[GTMTheme alloc] init]; // "Leak" it in the cache. - cache[key] = theme; - - // TODO(pinkerton): Need to be able to theme the entire incognito window - // http://crbug.com/18568 The hardcoding of the colors here will need to be - // removed when that bug is addressed, but are here in order for things to be - // usable in the meantime. - if (isOffTheRecord) { - NSColor* incognitoColor = [NSColor colorWithCalibratedRed:83/255.0 - green:108.0/255.0 - blue:140/255.0 - alpha:1.0]; - [theme setBackgroundColor:incognitoColor]; - [theme setValue:[NSColor blackColor] - forAttribute:@"textColor" - style:GTMThemeStyleTabBarSelected - state:GTMThemeStateActiveWindow]; - [theme setValue:[NSColor blackColor] - forAttribute:@"textColor" - style:GTMThemeStyleTabBarDeselected - state:GTMThemeStateActiveWindow]; - [theme setValue:[NSColor blackColor] - forAttribute:@"textColor" - style:GTMThemeStyleBookmarksBarButton - state:GTMThemeStateActiveWindow]; - [theme setValue:[NSColor blackColor] - forAttribute:@"iconColor" - style:GTMThemeStyleToolBarButton - state:GTMThemeStateActiveWindow]; - return theme; - } - - NSImage* frameImage = provider->GetNSImageNamed(IDR_THEME_FRAME, false); - if (frameImage) { - NSImage* frameInactiveImage = - provider->GetNSImageNamed(IDR_THEME_FRAME_INACTIVE, true); - [theme setValue:frameImage - forAttribute:@"backgroundImage" - style:GTMThemeStyleWindow - state:GTMThemeStateActiveWindow]; - [theme setValue:frameInactiveImage - forAttribute:@"backgroundImage" - style:GTMThemeStyleWindow - state:0]; - } - - NSColor* tabTextColor = - provider->GetNSColor(BrowserThemeProvider::COLOR_TAB_TEXT, false); - [theme setValue:tabTextColor - forAttribute:@"textColor" - style:GTMThemeStyleTabBarSelected - state:GTMThemeStateActiveWindow]; - - NSColor* tabInactiveTextColor = - provider->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT, - false); - [theme setValue:tabInactiveTextColor - forAttribute:@"textColor" - style:GTMThemeStyleTabBarDeselected - state:GTMThemeStateActiveWindow]; - - NSColor* bookmarkBarTextColor = - provider->GetNSColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT, false); - [theme setValue:bookmarkBarTextColor - forAttribute:@"textColor" - style:GTMThemeStyleBookmarksBarButton - state:GTMThemeStateActiveWindow]; - - - NSImage* toolbarImage = provider->GetNSImageNamed(IDR_THEME_TOOLBAR, false); - [theme setValue:toolbarImage - forAttribute:@"backgroundImage" - style:GTMThemeStyleToolBar - state:GTMThemeStateActiveWindow]; - NSImage* toolbarBackgroundImage = - provider->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND, false); - [theme setValue:toolbarBackgroundImage - forAttribute:@"backgroundImage" - style:GTMThemeStyleTabBarDeselected - state:GTMThemeStateActiveWindow]; - - NSImage* toolbarButtonImage = - provider->GetNSImageNamed(IDR_THEME_BUTTON_BACKGROUND, false); - if (toolbarButtonImage) { - [theme setValue:toolbarButtonImage - forAttribute:@"backgroundImage" - style:GTMThemeStyleToolBarButton - state:GTMThemeStateActiveWindow]; - } else { - NSColor* startColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.0]; - NSColor* endColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.3]; - scoped_nsobject<NSGradient> gradient([[NSGradient alloc] - initWithStartingColor:startColor - endingColor:endColor]); - - [theme setValue:gradient - forAttribute:@"gradient" - style:GTMThemeStyleToolBarButton - state:GTMThemeStateActiveWindow]; - - [theme setValue:gradient - forAttribute:@"gradient" - style:GTMThemeStyleToolBarButton - state:GTMThemeStateActiveWindow]; - } - - NSColor* toolbarButtonIconColor = - provider->GetNSColorTint(BrowserThemeProvider::TINT_BUTTONS, false); - [theme setValue:toolbarButtonIconColor - forAttribute:@"iconColor" - style:GTMThemeStyleToolBarButton - state:GTMThemeStateActiveWindow]; - - NSColor* toolbarButtonBorderColor = toolbarButtonIconColor; - [theme setValue:toolbarButtonBorderColor - forAttribute:@"borderColor" - style:GTMThemeStyleToolBar - state:GTMThemeStateActiveWindow]; - - NSColor* toolbarBackgroundColor = - provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR, false); - [theme setValue:toolbarBackgroundColor - forAttribute:@"backgroundColor" - style:GTMThemeStyleToolBar - state:GTMThemeStateActiveWindow]; - - NSImage* frameOverlayImage = - provider->GetNSImageNamed(IDR_THEME_FRAME_OVERLAY, false); - if (frameOverlayImage) { - [theme setValue:frameOverlayImage - forAttribute:@"overlay" - style:GTMThemeStyleWindow - state:GTMThemeStateActiveWindow]; - NSImage* frameOverlayInactiveImage = - provider->GetNSImageNamed(IDR_THEME_FRAME_OVERLAY_INACTIVE, true); - if (frameOverlayInactiveImage) { - [theme setValue:frameOverlayInactiveImage - forAttribute:@"overlay" - style:GTMThemeStyleWindow - state:GTMThemeStateInactiveWindow]; - } - } - - return theme; -} - -@end // @implementation GTMTheme(BrowserThemeProviderInitialization) diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 0a41e61..f3207f3 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -19,7 +19,6 @@ #import "chrome/browser/cocoa/bookmark_bubble_controller.h" #import "chrome/browser/cocoa/browser_command_executor.h" #import "chrome/browser/cocoa/url_drop_target.h" -#import "chrome/browser/cocoa/GTMTheme.h" #import "chrome/browser/cocoa/view_resizer.h" #include "chrome/browser/sync/sync_ui_util.h" @@ -48,8 +47,7 @@ class TabStripModelObserverBridge; TabWindowController<NSUserInterfaceValidations, BookmarkBarControllerDelegate, BrowserCommandExecutor, - ViewResizer, - GTMThemeDelegate> { + ViewResizer> { @private // The ordering of these members is important as it determines the order in // which they are destroyed. |browser_| needs to be destroyed last as most of @@ -75,7 +73,6 @@ class TabStripModelObserverBridge; StatusBubbleMac* statusBubble_; BookmarkBubbleController* bookmarkBubbleController_; // Weak. - scoped_nsobject<GTMTheme> theme_; BOOL initializing_; // YES while we are currently in initWithBrowser: BOOL ownsBrowser_; // Only ever NO when testing CGFloat verticalOffsetForStatusBubble_; @@ -226,6 +223,9 @@ class TabStripModelObserverBridge; // Gets the current theme provider. - (ThemeProvider*)themeProvider; +// Gets whether the current theme is incognito. +- (BOOL)themeIsIncognito; + // Gets the pattern phase for the window. - (NSPoint)themePatternPhase; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 547960d..f795ce9 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -194,8 +194,6 @@ if ([window respondsToSelector:@selector(setBottomCornerRounded:)]) [window setBottomCornerRounded:NO]; - [self setTheme]; - // Get the most appropriate size for the window, then enforce the // minimum width and height. The window shim will handle flipping // the coordinates for us so we can use it to save some code. @@ -1295,27 +1293,19 @@ } - (void)userChangedTheme { - [self setTheme]; - NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; - [defaultCenter postNotificationName:kGTMThemeDidChangeNotification - object:theme_]; // TODO(dmaclach): Instead of redrawing the whole window, views that care // about the active window state should be registering for notifications. [[self window] setViewsNeedDisplay:YES]; } -- (GTMTheme*)gtm_themeForWindow:(NSWindow*)window { - return theme_ ? theme_ : [GTMTheme defaultTheme]; -} - -- (NSPoint)gtm_themePatternPhaseForWindow:(NSWindow*)window { - return [self themePatternPhase]; -} - - (ThemeProvider*)themeProvider { return browser_->profile()->GetThemeProvider(); } +- (BOOL)themeIsIncognito { + return browser_->profile()->IsOffTheRecord(); +} + - (NSPoint)themePatternPhase { // Our patterns want to be drawn from the upper left hand corner of the view. // Cocoa wants to do it from the lower left of the window. @@ -1324,7 +1314,7 @@ // will phase their patterns relative to this so all the views look right. // // To line up the background pattern with the pattern in the browser window - // the background pattern for the tabs needs to be moved left by 5 pixels. + // the background pattern for the tabs needs to be moved left by 5 pixels. const CGFloat kPatternHorizontalOffset = -5; NSView* tabStripView = [self tabStripView]; NSRect tabStripViewWindowBounds = [tabStripView bounds]; diff --git a/chrome/browser/cocoa/browser_window_controller_private.h b/chrome/browser/cocoa/browser_window_controller_private.h index 5d84b66f..26bab84 100644 --- a/chrome/browser/cocoa/browser_window_controller_private.h +++ b/chrome/browser/cocoa/browser_window_controller_private.h @@ -28,9 +28,6 @@ willPositionSheet:(NSWindow*)sheet usingRect:(NSRect)defaultSheetRect; -// Assign a theme to the window. -- (void)setTheme; - // Repositions the window's subviews. From the top down: toolbar, normal // bookmark bar (if shown), infobar, NTP detached bookmark bar (if shown), // content area, download shelf (if any). diff --git a/chrome/browser/cocoa/browser_window_controller_private.mm b/chrome/browser/cocoa/browser_window_controller_private.mm index 75fc2fb..e4ab513 100644 --- a/chrome/browser/cocoa/browser_window_controller_private.mm +++ b/chrome/browser/cocoa/browser_window_controller_private.mm @@ -10,7 +10,6 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_theme_provider.h" -#import "chrome/browser/cocoa/browser_theme_provider_init.h" #import "chrome/browser/cocoa/chrome_browser_window.h" #import "chrome/browser/cocoa/fast_resize_view.h" #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" @@ -121,19 +120,6 @@ willPositionSheet:(NSWindow*)sheet return defaultSheetRect; } -- (void)setTheme { - ThemeProvider* theme_provider = browser_->profile()->GetThemeProvider(); - BrowserThemeProvider* browser_theme_provider = - static_cast<BrowserThemeProvider*>(theme_provider); - if (browser_theme_provider) { - bool offtheRecord = browser_->profile()->IsOffTheRecord(); - GTMTheme* theme = - [GTMTheme themeWithBrowserThemeProvider:browser_theme_provider - isOffTheRecord:offtheRecord]; - theme_.reset([theme retain]); - } -} - - (void)layoutSubviews { // With the exception of the tab strip, the subviews which we lay out are // subviews of the content view, so we mainly work in the content view's diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index 911153c..4e63700 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -122,11 +122,6 @@ TEST_F(BrowserWindowControllerTest, TestNormal) { [controller close]; } -@interface GTMTheme (BrowserThemeProviderInitialization) -+ (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider *)provider - isOffTheRecord:(BOOL)isOffTheRecord; -@end - TEST_F(BrowserWindowControllerTest, TestTheme) { [controller_ userChangedTheme]; } diff --git a/chrome/browser/cocoa/chrome_browser_window.mm b/chrome/browser/cocoa/chrome_browser_window.mm index 4002cb7..e66a606 100644 --- a/chrome/browser/cocoa/chrome_browser_window.mm +++ b/chrome/browser/cocoa/chrome_browser_window.mm @@ -347,6 +347,10 @@ namespace { return [[self windowController] themeProvider]; } +- (BOOL)themeIsIncognito { + return [[self windowController] themeIsIncognito]; +} + - (NSPoint)themePatternPhase { return [[self windowController] themePatternPhase]; } diff --git a/chrome/browser/cocoa/find_bar_view.mm b/chrome/browser/cocoa/find_bar_view.mm index 93b0c0c..deb4d58 100644 --- a/chrome/browser/cocoa/find_bar_view.mm +++ b/chrome/browser/cocoa/find_bar_view.mm @@ -4,6 +4,8 @@ #import "chrome/browser/cocoa/find_bar_view.h" +#import "chrome/browser/cocoa/themed_window.h" + namespace { CGFloat kCurveSize = 8; } // end namespace @@ -53,7 +55,7 @@ CGFloat kCurveSize = 8; [path addClip]; // Set the pattern phase - NSPoint phase = [self gtm_themePatternPhase]; + NSPoint phase = [[self window] themePatternPhase]; [context setPatternPhase:phase]; [super drawBackground]; diff --git a/chrome/browser/cocoa/floating_bar_backing_view.mm b/chrome/browser/cocoa/floating_bar_backing_view.mm index 6289099..3864d76 100644 --- a/chrome/browser/cocoa/floating_bar_backing_view.mm +++ b/chrome/browser/cocoa/floating_bar_backing_view.mm @@ -3,7 +3,8 @@ // found in the LICENSE file. #include "chrome/browser/cocoa/floating_bar_backing_view.h" -#import "chrome/browser/cocoa/GTMTheme.h" + +#import "chrome/browser/cocoa/browser_frame_view.h" @implementation FloatingBarBackingView @@ -17,56 +18,9 @@ [[NSColor windowBackgroundColor] set]; NSRectFill(rect); - // The code here mirrors the code in browser_frame_view.mm, with modifications - // to not use window rect and not draw rounded corners. - NSRect bounds = [self bounds]; - - // Draw our background image or theme pattern, if one exists. - GTMTheme* theme = [self gtm_theme]; - GTMThemeState state = isMainWindow ? GTMThemeStateActiveWindow - : GTMThemeStateInactiveWindow; - NSColor* color = [theme backgroundPatternColorForStyle:GTMThemeStyleWindow - state:state]; - if (color) { - // The titlebar/tabstrip header on the mac is slightly smaller than on - // Windows. To keep the window background lined up with the tab and toolbar - // patterns, we have to shift the pattern slightly, rather than simply - // drawing it from the top left corner. The offset below was empirically - // determined in order to line these patterns up. - // - // This will make the themes look slightly different than in Windows/Linux - // because of the differing heights between window top and tab top, but this - // has been approved by UI. - static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 2 }; - NSPoint offsetTopLeft = kBrowserFrameViewPatternPhaseOffset; - offsetTopLeft.y += NSHeight(bounds); - - // We want the pattern to start at the upper left corner of the floating - // bar, but the phase needs to be in the coordinate system of - // |windowChromeView|. - NSView* windowChromeView = [[[self window] contentView] superview]; - NSPoint phase = [self convertPoint:offsetTopLeft toView:windowChromeView]; - - // Apply the offset. - [[NSGraphicsContext currentContext] setPatternPhase:phase]; - [color set]; - NSRectFill(rect); - } - - // Check to see if we have an overlay image. - NSImage* overlayImage = [theme valueForAttribute:@"overlay" - style:GTMThemeStyleWindow - state:state]; - if (overlayImage) { - // Anchor to top-left and don't scale. - NSSize overlaySize = [overlayImage size]; - NSRect imageFrame = NSMakeRect(0, 0, overlaySize.width, overlaySize.height); - [overlayImage drawAtPoint:NSMakePoint(0, NSHeight(bounds) - - overlaySize.height) - fromRect:imageFrame - operation:NSCompositeSourceOver - fraction:1.0]; - } + [BrowserFrameView drawWindowThemeInDirtyRect:rect + forView:self + bounds:[self bounds]]; } // Eat all mouse events (and do *not* pass them on to the next responder!). diff --git a/chrome/browser/cocoa/fullscreen_window.mm b/chrome/browser/cocoa/fullscreen_window.mm index e015572..cd0b656 100644 --- a/chrome/browser/cocoa/fullscreen_window.mm +++ b/chrome/browser/cocoa/fullscreen_window.mm @@ -82,6 +82,10 @@ return [[self windowController] themeProvider]; } +- (BOOL)themeIsIncognito { + return [[self windowController] themeIsIncognito]; +} + - (NSPoint)themePatternPhase { return [[self windowController] themePatternPhase]; } diff --git a/chrome/browser/cocoa/tab_view.mm b/chrome/browser/cocoa/tab_view.mm index 1b5528f..7fef685 100644 --- a/chrome/browser/cocoa/tab_view.mm +++ b/chrome/browser/cocoa/tab_view.mm @@ -6,8 +6,11 @@ #include "base/logging.h" #include "base/nsimage_cache_mac.h" +#include "chrome/browser/browser_theme_provider.h" #import "chrome/browser/cocoa/tab_controller.h" #import "chrome/browser/cocoa/tab_window_controller.h" +#import "chrome/browser/cocoa/themed_window.h" +#include "grit/theme_resources.h" namespace { @@ -57,8 +60,7 @@ const CGFloat kRapidCloseDist = 2.5; self = [super initWithFrame:frame]; if (self) { [self setShowsDivider:NO]; - // TODO(alcor): register for theming, either here or the cell - // [self gtm_registerForThemeNotifications]; + // TODO(alcor): register for theming } return self; } @@ -642,30 +644,28 @@ const CGFloat kRapidCloseDist = 2.5; [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y)]; [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y - 2)]; - GTMTheme* theme = [self gtm_theme]; + ThemeProvider* themeProvider = [[self window] themeProvider]; // Set the pattern phase. - NSPoint phase = [self gtm_themePatternPhase]; + NSPoint phase = [[self window] themePatternPhase]; [context setPatternPhase:phase]; // Don't draw the window/tab bar background when selected, since the tab // background overlay drawn over it (see below) will be fully opaque. if (!selected) { - NSColor* windowColor = - [theme backgroundPatternColorForStyle:GTMThemeStyleWindow - state:GTMThemeStateActiveWindow]; - if (!windowColor) - windowColor = [NSColor windowBackgroundColor]; - [windowColor set]; - [path fill]; - - NSColor* tabColor = - [theme backgroundPatternColorForStyle:GTMThemeStyleTabBarDeselected - state:GTMThemeStateActiveWindow]; - if (!tabColor) - tabColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.3]; - [tabColor set]; - [path fill]; + NSImage* backgroundImage = + themeProvider ? themeProvider->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND, + false) : + nil; + if (backgroundImage) { + [[NSColor colorWithPatternImage:backgroundImage] set]; + [path fill]; + } else { + [[NSColor windowBackgroundColor] set]; + [path fill]; + [[NSColor colorWithCalibratedWhite:1.0 alpha:0.3] set]; + [path fill]; + } } [context saveGraphicsState]; @@ -693,10 +693,10 @@ const CGFloat kRapidCloseDist = 2.5; [super drawBackground]; [context restoreGraphicsState]; - // Draw a mouse hover gradient for the default themes + // Draw a mouse hover gradient for the default themes. if (!selected && hoverAlpha > 0) { - if (![theme backgroundImageForStyle:GTMThemeStyleTabBarDeselected - state:GTMThemeStateActiveWindow]) { + if (themeProvider && + !themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND)) { scoped_nsobject<NSGradient> glow([NSGradient alloc]); [glow initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0 * hoverAlpha] diff --git a/chrome/browser/cocoa/themed_window.h b/chrome/browser/cocoa/themed_window.h index 5319d3c..affd452 100644 --- a/chrome/browser/cocoa/themed_window.h +++ b/chrome/browser/cocoa/themed_window.h @@ -13,6 +13,7 @@ class ThemeProvider; @interface NSWindow (ThemeProvider) - (ThemeProvider*)themeProvider; +- (BOOL)themeIsIncognito; - (NSPoint)themePatternPhase; @end diff --git a/chrome/browser/cocoa/themed_window.mm b/chrome/browser/cocoa/themed_window.mm index c110cac..141f3e4 100644 --- a/chrome/browser/cocoa/themed_window.mm +++ b/chrome/browser/cocoa/themed_window.mm @@ -12,6 +12,10 @@ return NULL; } +- (BOOL)themeIsIncognito { + return NO; +} + - (NSPoint)themePatternPhase { return NSZeroPoint; } diff --git a/chrome/browser/cocoa/toolbar_view.mm b/chrome/browser/cocoa/toolbar_view.mm index c8fe807..75a893f 100644 --- a/chrome/browser/cocoa/toolbar_view.mm +++ b/chrome/browser/cocoa/toolbar_view.mm @@ -4,6 +4,8 @@ #import "chrome/browser/cocoa/toolbar_view.h" +#import "chrome/browser/cocoa/themed_window.h" + @implementation ToolbarView @synthesize dividerOpacity = dividerOpacity_; @@ -16,7 +18,7 @@ - (void)drawRect:(NSRect)rect { // The toolbar's background pattern is phased relative to the // tab strip view's background pattern. - NSPoint phase = [self gtm_themePatternPhase]; + NSPoint phase = [[self window] themePatternPhase]; [[NSGraphicsContext currentContext] setPatternPhase:phase]; [self drawBackground]; } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ffdac13..1e0fb0c1 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -473,8 +473,6 @@ 'browser/cocoa/browser_command_executor.h', 'browser/cocoa/browser_frame_view.h', 'browser/cocoa/browser_frame_view.mm', - 'browser/cocoa/browser_theme_provider_init.h', - 'browser/cocoa/browser_theme_provider_init.mm', 'browser/cocoa/browser_window_cocoa.h', 'browser/cocoa/browser_window_cocoa.mm', 'browser/cocoa/browser_window_controller.h', @@ -589,7 +587,6 @@ 'browser/cocoa/fullscreen_window.mm', 'browser/cocoa/gradient_button_cell.h', 'browser/cocoa/gradient_button_cell.mm', - 'browser/cocoa/GTMTheme.m', 'browser/cocoa/history_menu_bridge.h', 'browser/cocoa/history_menu_bridge.mm', 'browser/cocoa/history_menu_cocoa_controller.h', |