diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 21:43:25 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 21:43:25 +0000 |
commit | e9210915326b600a7efc8aa6d1befba549347fe5 (patch) | |
tree | 93b86527830652c00a602d1c324b3078257c1372 | |
parent | f9fc33227ea65b9b199a1fc7cc1055d362e5594a (diff) | |
download | chromium_src-e9210915326b600a7efc8aa6d1befba549347fe5.zip chromium_src-e9210915326b600a7efc8aa6d1befba549347fe5.tar.gz chromium_src-e9210915326b600a7efc8aa6d1befba549347fe5.tar.bz2 |
Removal of GTMTheme gradient use. Unthemed incognito windows now are fully drawn as they should be.
BUG=http://crbug.com/35554 ; http://crbug.com/26983
TEST=no visible change in normal mode; themed incognito windows should look almost correct (missing theme header)
Review URL: http://codereview.chromium.org/661097
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40050 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | app/theme_provider.h | 5 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 17 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_mac.mm | 111 | ||||
-rw-r--r-- | chrome/browser/cocoa/background_gradient_view.mm | 73 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller_unittest.mm | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_folder_controller.mm | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_folder_window.mm | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_cell.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_cell.mm | 150 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_shelf_view.mm | 23 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.mm | 56 | ||||
-rw-r--r-- | chrome/browser/cocoa/info_bubble_view.mm | 29 |
14 files changed, 340 insertions, 148 deletions
diff --git a/app/theme_provider.h b/app/theme_provider.h index 1db73e1..5659140 100644 --- a/app/theme_provider.h +++ b/app/theme_provider.h @@ -13,9 +13,11 @@ #if defined(OS_MACOSX) #ifdef __OBJC__ @class NSColor; +@class NSGradient; @class NSImage; #else class NSColor; +class NSGradient; class NSImage; #endif // __OBJC__ #elif !defined(OS_WIN) @@ -88,6 +90,9 @@ class ThemeProvider { // that id, if |allow_default| is true, then the default tint will be // returned, else this function will return nil. virtual NSColor* GetNSColorTint(int id, bool allow_default) const = 0; + + // Gets the NSGradient with the specified |id|. + virtual NSGradient* GetNSGradient(int id) const = 0; #elif defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) // Gets the GdkPixbuf with the specified |id|. Returns a pointer to a shared // instance of the GdkPixbuf. This shared GdkPixbuf is owned by the theme diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 26a556d..41edf09 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -89,10 +89,16 @@ class BrowserThemeProvider : public NonThreadSafe, NTP_LOGO_ALTERNATE #if defined(OS_MACOSX) , - COLOR_TOOLBAR_BUTTON_STROKE = 1000, + COLOR_TOOLBAR_STROKE = 1000, + COLOR_TOOLBAR_STROKE_INACTIVE, + COLOR_TOOLBAR_BUTTON_STROKE, COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE, - COLOR_TOOLBAR_STROKE, - COLOR_TOOLBAR_STROKE_INACTIVE + GRADIENT_TOOLBAR, + GRADIENT_TOOLBAR_INACTIVE, + GRADIENT_TOOLBAR_BUTTON, + GRADIENT_TOOLBAR_BUTTON_INACTIVE, + GRADIENT_TOOLBAR_BUTTON_PRESSED, + GRADIENT_TOOLBAR_BUTTON_PRESSED_INACTIVE #endif // OS_MACOSX }; @@ -128,6 +134,7 @@ class BrowserThemeProvider : public NonThreadSafe, virtual NSImage* GetNSImageNamed(int id, bool allow_default) const; virtual NSColor* GetNSColor(int id, bool allow_default) const; virtual NSColor* GetNSColorTint(int id, bool allow_default) const; + virtual NSGradient* GetNSGradient(int id) const; #endif // Set the current theme to the theme defined in |extension|. @@ -234,9 +241,13 @@ class BrowserThemeProvider : public NonThreadSafe, #elif defined(OS_MACOSX) typedef std::map<int, NSImage*> NSImageMap; mutable NSImageMap nsimage_cache_; + // The bool member of the pair is whether the color is a default color. typedef std::map<int, std::pair<NSColor*, bool> > NSColorMap; mutable NSColorMap nscolor_cache_; + + typedef std::map<int, NSGradient*> NSGradientMap; + mutable NSGradientMap nsgradient_cache_; #endif ResourceBundle& rb_; diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index 22de117..ad521ac 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -10,6 +10,7 @@ #include "base/logging.h" #include "chrome/browser/browser_theme_pack.h" #include "skia/ext/skia_utils_mac.h" +#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" NSString* const kBrowserThemeDidChangeNotification = @"BrowserThemeDidChangeNotification"; @@ -103,12 +104,10 @@ NSColor* BrowserThemeProvider::GetNSColor(int id, alpha:SkColorGetA(sk_color)/255.0]; // We loaded successfully. Cache the color. - if (color) { + if (color) nscolor_cache_[id] = std::make_pair([color retain], is_default); - return color; - } - return nil; + return color; } NSColor* BrowserThemeProvider::GetNSColorTint(int id, @@ -135,21 +134,100 @@ NSColor* BrowserThemeProvider::GetNSColorTint(int id, if (is_default && !allow_default) return nil; - CGFloat hue, saturation, brightness; - HSLToHSB(tint, &hue, &saturation, &brightness); + NSColor* tint_color = nil; + if (tint.h == -1 && tint.s == -1 && tint.l == -1) { + tint_color = [NSColor blackColor]; + } else { + CGFloat hue, saturation, brightness; + HSLToHSB(tint, &hue, &saturation, &brightness); - NSColor* tint_color = [NSColor colorWithCalibratedHue:hue - saturation:saturation - brightness:brightness - alpha:1.0]; + tint_color = [NSColor colorWithCalibratedHue:hue + saturation:saturation + brightness:brightness + alpha:1.0]; + } // We loaded successfully. Cache the color. - if (tint_color) { + if (tint_color) nscolor_cache_[id] = std::make_pair([tint_color retain], is_default); - return tint_color; + + return tint_color; +} + +NSGradient* BrowserThemeProvider::GetNSGradient(int id) const { + DCHECK(CalledOnValidThread()); + + // Check to see if we already have the gradient in the cache. + NSGradientMap::const_iterator nsgradient_iter = nsgradient_cache_.find(id); + if (nsgradient_iter != nsgradient_cache_.end()) + return nsgradient_iter->second; + + NSGradient* gradient = nil; + + // 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_TOOLBAR: + case GRADIENT_TOOLBAR_INACTIVE: { + NSColor* base_color = [NSColor colorWithCalibratedWhite:0.5 alpha:1.0]; + BOOL faded = (id == GRADIENT_TOOLBAR_INACTIVE ) || + (id == GRADIENT_TOOLBAR_BUTTON_INACTIVE); + NSColor* start_color = + [base_color gtm_colorAdjustedFor:GTMColorationLightHighlight + faded:faded]; + NSColor* mid_color = + [base_color gtm_colorAdjustedFor:GTMColorationLightMidtone + faded:faded]; + NSColor* end_color = + [base_color gtm_colorAdjustedFor:GTMColorationLightShadow + faded:faded]; + NSColor* glow_color = + [base_color gtm_colorAdjustedFor:GTMColorationLightPenumbra + faded:faded]; + + gradient = + [[NSGradient alloc] initWithColorsAndLocations:start_color, 0.0, + mid_color, 0.25, + end_color, 0.5, + glow_color, 0.75, + nil]; + break; + } + + case GRADIENT_TOOLBAR_BUTTON: + case GRADIENT_TOOLBAR_BUTTON_INACTIVE: { + NSColor* start_color = [NSColor colorWithCalibratedWhite:1.0 alpha:0.0]; + NSColor* end_color = [NSColor colorWithCalibratedWhite:1.0 alpha:0.3]; + gradient = [[NSGradient alloc] initWithStartingColor:start_color + endingColor:end_color]; + break; + } + case GRADIENT_TOOLBAR_BUTTON_PRESSED: + case GRADIENT_TOOLBAR_BUTTON_PRESSED_INACTIVE: { + NSColor* base_color = [NSColor colorWithCalibratedWhite:0.5 alpha:1.0]; + BOOL faded = id == GRADIENT_TOOLBAR_BUTTON_PRESSED_INACTIVE; + NSColor* start_color = + [base_color gtm_colorAdjustedFor:GTMColorationBaseShadow + faded:faded]; + NSColor* end_color = + [base_color gtm_colorAdjustedFor:GTMColorationBaseMidtone + faded:faded]; + + gradient = [[NSGradient alloc] initWithStartingColor:start_color + endingColor:end_color]; + break; + } + default: + LOG(WARNING) << "Gradient request with unknown id " << id; + NOTREACHED(); // Want to assert in debug mode. + break; } - return nil; + // We loaded successfully. Cache the gradient. + if (gradient) + nsgradient_cache_[id] = gradient; // created retained + + return gradient; } // Let all the browser views know that themes have changed in a platform way. @@ -175,4 +253,11 @@ void BrowserThemeProvider::FreePlatformCaches() { [i->second.first release]; } nscolor_cache_.clear(); + + // Free gradients. + for (NSGradientMap::iterator i = nsgradient_cache_.begin(); + i != nsgradient_cache_.end(); i++) { + [i->second release]; + } + nsgradient_cache_.clear(); } diff --git a/chrome/browser/cocoa/background_gradient_view.mm b/chrome/browser/cocoa/background_gradient_view.mm index ba7a760..1ddd456 100644 --- a/chrome/browser/cocoa/background_gradient_view.mm +++ b/chrome/browser/cocoa/background_gradient_view.mm @@ -4,6 +4,10 @@ #include "chrome/browser/cocoa/background_gradient_view.h" +#import "chrome/browser/browser_theme_provider.h" +#import "chrome/browser/cocoa/themed_window.h" +#include "grit/theme_resources.h" + #define kToolbarTopOffset 12 #define kToolbarMaxHeight 100 @@ -29,43 +33,50 @@ - (void)drawBackground { BOOL isKey = [[self window] isKeyWindow]; - GTMTheme* theme = [[self window] gtm_theme]; - NSImage* backgroundImage = - [theme backgroundImageForStyle:GTMThemeStyleToolBar - state:GTMThemeStateActiveWindow]; - if (backgroundImage) { - NSColor* color = [NSColor colorWithPatternImage:backgroundImage]; - [color set]; - NSRectFill([self bounds]); - } else { - CGFloat winHeight = NSHeight([[self window] frame]); - NSGradient* gradient = [theme gradientForStyle:GTMThemeStyleToolBar - state:isKey]; - NSPoint startPoint = - [self convertPoint:NSMakePoint(0, winHeight - kToolbarTopOffset) - fromView:nil]; - NSPoint endPoint = - NSMakePoint(0, winHeight - kToolbarTopOffset - kToolbarMaxHeight); - endPoint = [self convertPoint:endPoint fromView:nil]; + ThemeProvider* themeProvider = [[self window] themeProvider]; + if (themeProvider) { + NSImage* backgroundImage = + themeProvider->GetNSImageNamed(IDR_THEME_TOOLBAR, false); + if (backgroundImage) { + NSColor* color = [NSColor colorWithPatternImage:backgroundImage]; + [color set]; + NSRectFill([self bounds]); + } else { + CGFloat winHeight = NSHeight([[self window] frame]); + NSGradient* gradient = themeProvider->GetNSGradient( + isKey ? BrowserThemeProvider::GRADIENT_TOOLBAR : + BrowserThemeProvider::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)]; - } + [gradient drawFromPoint:startPoint + toPoint:endPoint + options:(NSGradientDrawsBeforeStartingLocation | + NSGradientDrawsAfterEndingLocation)]; + } - if (showsDivider_) { - // Draw bottom stroke - [[self strokeColor] set]; - NSRect borderRect, contentRect; - NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); - NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); + if (showsDivider_) { + // Draw bottom stroke + [[self strokeColor] set]; + NSRect borderRect, contentRect; + NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); + NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); + } } } - (NSColor*)strokeColor { - return [[self gtm_theme] strokeColorForStyle:GTMThemeStyleToolBar - state:[[self window] isKeyWindow]]; + BOOL isKey = [[self window] isKeyWindow]; + ThemeProvider* themeProvider = [[self window] themeProvider]; + if (!themeProvider) + return [NSColor blackColor]; + return themeProvider->GetNSColor( + isKey ? BrowserThemeProvider::COLOR_TOOLBAR_STROKE : + BrowserThemeProvider::COLOR_TOOLBAR_STROKE_INACTIVE, true); } @end diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm index 5f460a7..6a86c88 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm @@ -104,6 +104,9 @@ class FakeTheme : public ThemeProvider { virtual NSColor* GetNSColorTint(int id, bool allow_default) const { return nil; } + virtual NSGradient* GetNSGradient(int id) const { + return nil; + } }; diff --git a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm index 4c50976..64488cf 100644 --- a/chrome/browser/cocoa/bookmark_bar_folder_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_folder_controller.mm @@ -224,10 +224,6 @@ return [parentController_ themeProvider]; } -- (GTMTheme*)gtm_theme { - return [[parentController_ parentWindow] gtm_theme]; -} - // Recursively close all bookmark folders. - (void)closeAllBookmarkFolders { // Closing the top level implicitly closes all children. diff --git a/chrome/browser/cocoa/bookmark_bar_folder_window.mm b/chrome/browser/cocoa/bookmark_bar_folder_window.mm index 73ca780..9d056f5 100644 --- a/chrome/browser/cocoa/bookmark_bar_folder_window.mm +++ b/chrome/browser/cocoa/bookmark_bar_folder_window.mm @@ -5,7 +5,7 @@ #import "chrome/browser/cocoa/bookmark_bar_folder_window.h" #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" -#import "chrome/browser/cocoa/GTMTheme.h" +#import "chrome/browser/cocoa/themed_window.h" @implementation BookmarkBarFolderWindow @@ -19,8 +19,8 @@ defer:deferCreation]; } -- (GTMTheme*)gtm_theme { - return [[self windowController] gtm_theme]; +- (ThemeProvider*)themeProvider { + return [[self windowController] themeProvider]; } @end diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm index a030b3b..4d49ee1 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm @@ -32,12 +32,13 @@ class MockThemeProvider : public ThemeProvider { MOCK_CONST_METHOD2(GetDisplayProperty, bool(int, int*)); MOCK_CONST_METHOD0(ShouldUseNativeFrame, bool()); MOCK_CONST_METHOD1(HasCustomImage, bool(int)); - MOCK_CONST_METHOD1(GetRawData, RefCountedMemory*(int)); + MOCK_CONST_METHOD1(GetRawData, RefCountedMemory*(int)); // OSX stuff MOCK_CONST_METHOD2(GetNSImageNamed, NSImage*(int, bool)); MOCK_CONST_METHOD2(GetNSColor, NSColor*(int, bool)); MOCK_CONST_METHOD2(GetNSColorTint, NSColor*(int, bool)); + MOCK_CONST_METHOD1(GetNSGradient, NSGradient*(int)); }; // Allows us to inject our fake controller below. diff --git a/chrome/browser/cocoa/download_item_cell.h b/chrome/browser/cocoa/download_item_cell.h index 8cfca82..7ebc02f 100644 --- a/chrome/browser/cocoa/download_item_cell.h +++ b/chrome/browser/cocoa/download_item_cell.h @@ -6,12 +6,12 @@ #define CHROME_BROWSER_COCOA_DOWNLOAD_ITEM_CELL_H_ #import "base/cocoa_protocols_mac.h" +#include "base/scoped_ptr.h" #import "chrome/browser/cocoa/gradient_button_cell.h" #include "base/file_path.h" class BaseDownloadItemModel; -@class GTMTheme; // A button cell that implements the weird button/popup button hybrid that is // used by the download items. @@ -44,7 +44,7 @@ enum DownloadItemMousePosition { CGFloat statusAlpha_; scoped_nsobject<NSAnimation> hideStatusAnimation_; - scoped_nsobject<GTMTheme> theme_; + scoped_ptr<ThemeProvider> themeProvider_; } - (void)setStateFromDownload:(BaseDownloadItemModel*)downloadModel; diff --git a/chrome/browser/cocoa/download_item_cell.mm b/chrome/browser/cocoa/download_item_cell.mm index f434e5e..64ddc85 100644 --- a/chrome/browser/cocoa/download_item_cell.mm +++ b/chrome/browser/cocoa/download_item_cell.mm @@ -9,11 +9,13 @@ #include "app/l10n_util.h" #include "base/mac_util.h" #include "base/sys_string_conversions.h" +#import "chrome/browser/browser_theme_provider.h" #import "chrome/browser/cocoa/download_item_cell.h" +#import "chrome/browser/cocoa/themed_window.h" #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_util.h" -#import "chrome/browser/cocoa/GTMTheme.h" +#include "grit/theme_resources.h" #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" @@ -82,6 +84,76 @@ const int kCompleteAnimationDuration = 2.5; animationCurve:(NSAnimationCurve)animationCurve; @end +class BackgroundTheme : public ThemeProvider { +public: + BackgroundTheme(ThemeProvider* provider); + + virtual void Init(Profile* profile) { } + virtual SkBitmap* GetBitmapNamed(int id) const { return nil; } + virtual SkColor GetColor(int id) const { return SkColor(); } + virtual bool GetDisplayProperty(int id, int* result) const { return false; } + virtual bool ShouldUseNativeFrame() const { return false; } + virtual bool HasCustomImage(int id) const { return false; } + virtual RefCountedMemory* GetRawData(int id) const { return NULL; } + virtual NSImage* GetNSImageNamed(int id, bool allow_default) const; + virtual NSColor* GetNSColor(int id, bool allow_default) const; + virtual NSColor* GetNSColorTint(int id, bool allow_default) const; + virtual NSGradient* GetNSGradient(int id) const; + +private: + ThemeProvider* provider_; + scoped_nsobject<NSGradient> buttonGradient_; + scoped_nsobject<NSGradient> buttonPressedGradient_; + scoped_nsobject<NSColor> borderColor_; +}; + +BackgroundTheme::BackgroundTheme(ThemeProvider* provider) : + provider_(provider) { + NSColor* bgColor = [NSColor colorWithCalibratedRed:241/255.0 + green:245/255.0 + blue:250/255.0 + alpha:77/255.0]; + NSColor* clickedColor = [NSColor colorWithCalibratedRed:239/255.0 + green:245/255.0 + blue:252/255.0 + alpha:51/255.0]; + + borderColor_.reset( + [[NSColor colorWithCalibratedWhite:0 alpha:36/255.0] retain]); + buttonGradient_.reset([[NSGradient alloc] + initWithColors:[NSArray arrayWithObject:bgColor]]); + buttonPressedGradient_.reset([[NSGradient alloc] + initWithColors:[NSArray arrayWithObject:clickedColor]]); +} + +NSImage* BackgroundTheme::GetNSImageNamed(int id, bool allow_default) const { + return nil; +} + +NSColor* BackgroundTheme::GetNSColor(int id, bool allow_default) const { + return provider_->GetNSColor(id, allow_default); +} + +NSColor* BackgroundTheme::GetNSColorTint(int id, bool allow_default) const { + if (id == BrowserThemeProvider::TINT_BUTTONS) + return borderColor_.get(); + + return provider_->GetNSColorTint(id, allow_default); +} + +NSGradient* BackgroundTheme::GetNSGradient(int id) const { + switch (id) { + case BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON: + case BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON_INACTIVE: + return buttonGradient_.get(); + case BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON_PRESSED: + case BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON_PRESSED_INACTIVE: + return buttonPressedGradient_.get(); + default: + return provider_->GetNSGradient(id); + } +} + @interface DownloadItemCell(Private) - (void)updateTrackingAreas:(id)sender; - (void)hideSecondaryTitle; @@ -89,7 +161,7 @@ const int kCompleteAnimationDuration = 2.5; progressed:(NSAnimationProgress)progress; - (NSString*)elideTitle:(int)availableWidth; - (NSString*)elideStatus:(int)availableWidth; -- (GTMTheme*)backgroundTheme:(NSView*)controlView; +- (ThemeProvider*)backgroundThemeWrappingProvider:(ThemeProvider*)provider; - (BOOL)pressedWithDefaultThemeOnPart:(DownloadItemMousePosition)part; - (NSColor*)titleColorForPart:(DownloadItemMousePosition)part; - (void)drawSecondaryTitleInRect:(NSRect)innerFrame; @@ -327,61 +399,28 @@ const int kCompleteAnimationDuration = 2.5; availableWidth)); } -- (GTMTheme*)backgroundTheme:(NSView*)controlView { - if (!theme_) { - theme_.reset([[GTMTheme alloc] init]); - NSColor* bgColor = [NSColor colorWithCalibratedRed:241/255.0 - green:245/255.0 - blue:250/255.0 - alpha:77/255.0]; - NSColor* clickedColor = [NSColor colorWithCalibratedRed:239/255.0 - green:245/255.0 - blue:252/255.0 - alpha:51/255.0]; - - NSColor* borderColor = [NSColor colorWithCalibratedWhite:0 alpha:36/255.0]; - scoped_nsobject<NSGradient> bgGradient([[NSGradient alloc] - initWithColors:[NSArray arrayWithObject:bgColor]]); - scoped_nsobject<NSGradient> clickedGradient([[NSGradient alloc] - initWithColors:[NSArray arrayWithObject:clickedColor]]); - - GTMThemeState states[] = { - GTMThemeStateActiveWindow, GTMThemeStateInactiveWindow - }; - - for (size_t i = 0; i < arraysize(states); ++i) { - [theme_.get() setValue:bgGradient - forAttribute:@"gradient" - style:GTMThemeStyleToolBarButton - state:states[i]]; - - [theme_.get() setValue:clickedGradient - forAttribute:@"gradient" - style:GTMThemeStyleToolBarButtonPressed - state:states[i]]; - - [theme_.get() setValue:borderColor - forAttribute:@"iconColor" - style:GTMThemeStyleToolBarButton - state:states[i]]; - } +- (ThemeProvider*)backgroundThemeWrappingProvider:(ThemeProvider*)provider { + if (!themeProvider_.get()) { + themeProvider_.reset(new BackgroundTheme(provider)); } - return theme_.get(); + + return themeProvider_.get(); } // Returns if |part| was pressed while the default theme was active. - (BOOL)pressedWithDefaultThemeOnPart:(DownloadItemMousePosition)part { - GTMTheme* theme = [[self controlView] gtm_theme]; - bool isDefaultTheme = [theme - backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES] == nil; + ThemeProvider* themeProvider = [[[self controlView] window] themeProvider]; + bool isDefaultTheme = + !themeProvider->HasCustomImage(IDR_THEME_BUTTON_BACKGROUND); return isDefaultTheme && [self isHighlighted] && mousePosition_ == part; } // Returns the text color that should be used to draw text on |part|. - (NSColor*)titleColorForPart:(DownloadItemMousePosition)part { - NSColor* themeTextColor = [[[self controlView] gtm_theme] - textColorForStyle:GTMThemeStyleBookmarksBarButton - state:GTMThemeStateActiveWindow]; + ThemeProvider* themeProvider = [[[self controlView] window] themeProvider]; + NSColor* themeTextColor = + themeProvider->GetNSColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT, + true); return [self pressedWithDefaultThemeOnPart:part] ? [NSColor alternateSelectedControlTextColor] : themeTextColor; } @@ -427,15 +466,16 @@ const int kCompleteAnimationDuration = 2.5; // with a background that looks like windows (some transparent white) if a // theme is used. Use custom theme object with a white color gradient to trick // the superclass into drawing what we want. - GTMTheme* theme = [controlView gtm_theme]; - bool isDefaultTheme = [theme - backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES] == nil; + ThemeProvider* themeProvider = [[[self controlView] window] themeProvider]; + bool isDefaultTheme = + !themeProvider->HasCustomImage(IDR_THEME_BUTTON_BACKGROUND); NSGradient* bgGradient = nil; if (!isDefaultTheme) { - theme = [self backgroundTheme:controlView]; - bgGradient = [theme gradientForStyle:GTMThemeStyleToolBarButton - state:active]; + themeProvider = [self backgroundThemeWrappingProvider:themeProvider]; + bgGradient = themeProvider->GetNSGradient( + active ? BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON : + BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON_INACTIVE); } NSRect buttonDrawRect, dropdownDrawRect; @@ -456,7 +496,7 @@ const int kCompleteAnimationDuration = 2.5; [self drawSecondaryTitleInRect:innerFrame]; // Stroke the borders and appropriate fill gradient. - [self drawBorderAndFillForTheme:theme + [self drawBorderAndFillForTheme:themeProvider controlView:controlView innerPath:buttonInnerPath showClickedGradient:[self isButtonPartPressed] @@ -466,7 +506,7 @@ const int kCompleteAnimationDuration = 2.5; cellFrame:cellFrame defaultGradient:bgGradient]; - [self drawBorderAndFillForTheme:theme + [self drawBorderAndFillForTheme:themeProvider controlView:controlView innerPath:dropdownInnerPath showClickedGradient:[self isDropdownPartPressed] diff --git a/chrome/browser/cocoa/download_shelf_view.mm b/chrome/browser/cocoa/download_shelf_view.mm index 521ff33..4894442 100644 --- a/chrome/browser/cocoa/download_shelf_view.mm +++ b/chrome/browser/cocoa/download_shelf_view.mm @@ -5,22 +5,26 @@ #import "chrome/browser/cocoa/download_shelf_view.h" #include "base/scoped_nsobject.h" -#import "chrome/browser/cocoa/GTMTheme.h" +#include "chrome/browser/browser_theme_provider.h" +#import "chrome/browser/cocoa/themed_window.h" +#include "grit/theme_resources.h" @implementation DownloadShelfView - (NSColor*)strokeColor { - return [[self gtm_theme] strokeColorForStyle:GTMThemeStyleToolBar - state:[[self window] isKeyWindow]]; + BOOL isKey = [[self window] isKeyWindow]; + ThemeProvider* themeProvider = [[self window] themeProvider]; + return themeProvider->GetNSColor( + isKey ? BrowserThemeProvider::COLOR_TOOLBAR_STROKE : + BrowserThemeProvider::COLOR_TOOLBAR_STROKE_INACTIVE, true); } - (void)drawRect:(NSRect)rect { BOOL isKey = [[self window] isKeyWindow]; + ThemeProvider* themeProvider = [[self window] themeProvider]; - GTMTheme* theme = [self gtm_theme]; - - NSImage* backgroundImage = [theme backgroundImageForStyle:GTMThemeStyleToolBar - state:GTMThemeStateActiveWindow]; + NSImage* backgroundImage = themeProvider->GetNSImageNamed(IDR_THEME_TOOLBAR, + false); if (backgroundImage) { // We want our backgrounds for the shelf to be phased from the upper // left hand corner of the view. @@ -30,8 +34,9 @@ [color set]; NSRectFill([self bounds]); } else { - NSGradient* gradient = [theme gradientForStyle:GTMThemeStyleToolBar - state:isKey]; + NSGradient* gradient = themeProvider->GetNSGradient( + isKey ? BrowserThemeProvider::GRADIENT_TOOLBAR : + BrowserThemeProvider::GRADIENT_TOOLBAR_INACTIVE); // TODO(avi) http://crbug.com/36485; base != window NSPoint startPoint = [self convertPointFromBase:NSMakePoint(0, 0)]; NSPoint endPoint = [self convertPointFromBase: diff --git a/chrome/browser/cocoa/gradient_button_cell.h b/chrome/browser/cocoa/gradient_button_cell.h index 27909a0..fc79c09 100644 --- a/chrome/browser/cocoa/gradient_button_cell.h +++ b/chrome/browser/cocoa/gradient_button_cell.h @@ -9,7 +9,7 @@ #include "base/scoped_nsobject.h" -@class GTMTheme; +class ThemeProvider; // Base class for button cells for toolbar and bookmark bar. // @@ -43,7 +43,7 @@ typedef NSInteger ButtonType; // Turn off theming. Temporary work-around. - (void)setShouldTheme:(BOOL)shouldTheme; -- (void)drawBorderAndFillForTheme:(GTMTheme*)theme +- (void)drawBorderAndFillForTheme:(ThemeProvider*)themeProvider controlView:(NSView*)controlView innerPath:(NSBezierPath*)innerPath showClickedGradient:(BOOL)showClickedGradient diff --git a/chrome/browser/cocoa/gradient_button_cell.mm b/chrome/browser/cocoa/gradient_button_cell.mm index e0c90c6..ae4ab2b 100644 --- a/chrome/browser/cocoa/gradient_button_cell.mm +++ b/chrome/browser/cocoa/gradient_button_cell.mm @@ -2,10 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/cocoa/gradient_button_cell.h" + #include "base/logging.h" #import "base/scoped_nsobject.h" -#include "chrome/browser/cocoa/gradient_button_cell.h" -#import "chrome/browser/cocoa/GTMTheme.h" +#import "chrome/browser/browser_theme_provider.h" +#import "chrome/browser/cocoa/themed_window.h" +#include "grit/theme_resources.h" #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" @interface GradientButtonCell (Private) @@ -173,7 +176,7 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; } // TODO(viettrungluu): clean up/reorganize. -- (void)drawBorderAndFillForTheme:(GTMTheme*)theme +- (void)drawBorderAndFillForTheme:(ThemeProvider*)themeProvider controlView:(NSView*)controlView innerPath:(NSBezierPath*)innerPath showClickedGradient:(BOOL)showClickedGradient @@ -196,8 +199,10 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; if (!showClickedGradient) hoverAlpha *= 0.6; } else { - backgroundImage = [theme backgroundImageForStyle:GTMThemeStyleToolBarButton - state:YES]; + backgroundImage = + themeProvider ? + themeProvider->GetNSImageNamed(IDR_THEME_BUTTON_BACKGROUND, false) : + nil; useThemeGradient = backgroundImage ? YES : NO; } @@ -228,9 +233,11 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; if (isFlatButton) { clickedGradient = gradient; } else { - clickedGradient = - [theme gradientForStyle:GTMThemeStyleToolBarButtonPressed - state:active]; + clickedGradient = themeProvider ? themeProvider->GetNSGradient( + active ? + BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON_PRESSED : + BrowserThemeProvider::GRADIENT_TOOLBAR_BUTTON_PRESSED_INACTIVE) : + nil; } [clickedGradient drawInBezierPath:innerPath angle:90.0]; } @@ -263,9 +270,15 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; } // Draw the outer stroke. - NSColor* strokeColor = showClickedGradient ? - [NSColor colorWithCalibratedWhite:0.0 alpha:0.3] : - [theme strokeColorForStyle:GTMThemeStyleToolBarButton state:active]; + NSColor* strokeColor = nil; + if (showClickedGradient) { + strokeColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.3]; + } else { + strokeColor = themeProvider ? themeProvider->GetNSColor( + active ? BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE : + BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE, + true) : [NSColor blackColor]; + } [strokeColor setStroke]; [innerPath setLineWidth:1]; @@ -335,17 +348,16 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; BOOL pressed = [self isHighlighted]; NSWindow* window = [controlView window]; + ThemeProvider* themeProvider = [window themeProvider]; BOOL active = [window isKeyWindow] || [window isMainWindow]; - GTMTheme* theme = [controlView gtm_theme]; - // Stroke the borders and appropriate fill gradient. If we're borderless, // the only time we want to draw the inner gradient is if we're highlighted. if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || pressed || [self isMouseInside]) { - [self drawBorderAndFillForTheme:theme + [self drawBorderAndFillForTheme:themeProvider controlView:controlView innerPath:innerPath showClickedGradient:pressed @@ -361,8 +373,11 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; if (type == kLeftButtonWithShadowType) { NSRect borderRect, contentRect; NSDivideRect(cellFrame, &borderRect, &contentRect, 1.0, NSMaxXEdge); - NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton - state:active]; + NSColor* stroke = themeProvider ? themeProvider->GetNSColor( + active ? BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE : + BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE, + true) : [NSColor blackColor]; + [[stroke colorWithAlphaComponent:0.2] set]; NSRectFillUsingOperation(NSInsetRect(borderRect, 0, 2), NSCompositeSourceOver); @@ -371,8 +386,6 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; } - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { - GTMTheme* theme = [controlView gtm_theme]; - if (shouldTheme_) { BOOL isTemplate = [[self image] isTemplate]; @@ -381,8 +394,11 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]); - NSColor* color = [theme iconColorForStyle:GTMThemeStyleToolBarButton - state:YES]; + ThemeProvider* themeProvider = [[controlView window] themeProvider]; + NSColor* color = themeProvider ? + themeProvider->GetNSColorTint(BrowserThemeProvider::TINT_BUTTONS, + true) : + [NSColor blackColor]; if (isTemplate) { scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); diff --git a/chrome/browser/cocoa/info_bubble_view.mm b/chrome/browser/cocoa/info_bubble_view.mm index 12d9293..58cd923 100644 --- a/chrome/browser/cocoa/info_bubble_view.mm +++ b/chrome/browser/cocoa/info_bubble_view.mm @@ -5,7 +5,8 @@ #import "chrome/browser/cocoa/info_bubble_view.h" #include "base/logging.h" -#import "chrome/browser/cocoa/GTMTheme.h" +#include "base/scoped_nsobject.h" +#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" // TODO(andybons): confirm constants with UI dudes. extern const CGFloat kBubbleArrowHeight = 8.0; @@ -63,10 +64,28 @@ extern const CGFloat kBubbleCornerRadius = 8.0; // Then fill the inside depending on the type of bubble. if (bubbleType_ == kGradientInfoBubble) { - GTMTheme *theme = [GTMTheme defaultTheme]; - NSGradient *gradient = [theme gradientForStyle:GTMThemeStyleToolBar - state:NO]; - [gradient drawInBezierPath:bezier angle:0.0]; + NSColor* base_color = [NSColor colorWithCalibratedWhite:0.5 alpha:1.0]; + NSColor* startColor = + [base_color gtm_colorAdjustedFor:GTMColorationLightHighlight + faded:YES]; + NSColor* midColor = + [base_color gtm_colorAdjustedFor:GTMColorationLightMidtone + faded:YES]; + NSColor* endColor = + [base_color gtm_colorAdjustedFor:GTMColorationLightShadow + faded:YES]; + NSColor* glowColor = + [base_color gtm_colorAdjustedFor:GTMColorationLightPenumbra + faded:YES]; + + scoped_nsobject<NSGradient> gradient( + [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0, + midColor, 0.25, + endColor, 0.5, + glowColor, 0.75, + nil]); + + [gradient.get() drawInBezierPath:bezier angle:0.0]; } else if (bubbleType_ == kWhiteInfoBubble) { [[NSColor whiteColor] set]; [bezier fill]; |