diff options
-rw-r--r-- | app/theme_provider.h | 4 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 1 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_mac.mm | 26 | ||||
-rw-r--r-- | chrome/browser/cocoa/background_gradient_view.mm | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller_unittest.mm | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_frame_view.mm | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_item_cell.mm | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/download_shelf_view.mm | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.mm | 16 | ||||
-rw-r--r-- | chrome/browser/cocoa/styled_text_field_cell.mm | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_view.mm | 8 |
12 files changed, 70 insertions, 34 deletions
diff --git a/app/theme_provider.h b/app/theme_provider.h index 5659140..e26fd74 100644 --- a/app/theme_provider.h +++ b/app/theme_provider.h @@ -77,6 +77,10 @@ class ThemeProvider { // this function will return nil. virtual NSImage* GetNSImageNamed(int id, bool allow_default) const = 0; + // Gets the NSImage that GetNSImageNamed (above) would return, but returns it + // as a pattern color. + virtual NSColor* GetNSImageColorNamed(int id, bool allow_default) const = 0; + // Gets the NSColor with the specified |id|. // // The color is not assumed to exist. If a theme does not provide an color, if diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 20980a1..7545707 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -134,6 +134,7 @@ class BrowserThemeProvider : public NonThreadSafe, virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const; #elif defined(OS_MACOSX) virtual NSImage* GetNSImageNamed(int id, bool allow_default) const; + virtual NSColor* GetNSImageColorNamed(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; diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index f455d70..805952d 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -73,6 +73,32 @@ NSImage* BrowserThemeProvider::GetNSImageNamed(int id, return empty_image; } +NSColor* BrowserThemeProvider::GetNSImageColorNamed(int id, + bool allow_default) const { + DCHECK(CalledOnValidThread()); + + // Check to see if we already have the color in the cache. + NSColorMap::const_iterator nscolor_iter = nscolor_cache_.find(id); + if (nscolor_iter != nscolor_cache_.end()) { + bool cached_is_default = nscolor_iter->second.second; + if (!cached_is_default || allow_default) + return nscolor_iter->second.first; + } + + NSImage* image = GetNSImageNamed(id, allow_default); + if (!image) + return nil; + NSColor* image_color = [NSColor colorWithPatternImage:image]; + + // We loaded successfully. Cache the color. + if (image_color) { + nscolor_cache_[id] = std::make_pair([image_color retain], + !HasCustomImage(id)); + } + + return imageColor; +} + NSColor* BrowserThemeProvider::GetNSColor(int id, bool allow_default) const { DCHECK(CalledOnValidThread()); diff --git a/chrome/browser/cocoa/background_gradient_view.mm b/chrome/browser/cocoa/background_gradient_view.mm index 1ddd456..7dd93b6 100644 --- a/chrome/browser/cocoa/background_gradient_view.mm +++ b/chrome/browser/cocoa/background_gradient_view.mm @@ -35,11 +35,10 @@ BOOL isKey = [[self window] isKeyWindow]; ThemeProvider* themeProvider = [[self window] themeProvider]; if (themeProvider) { - NSImage* backgroundImage = - themeProvider->GetNSImageNamed(IDR_THEME_TOOLBAR, false); - if (backgroundImage) { - NSColor* color = [NSColor colorWithPatternImage:backgroundImage]; - [color set]; + NSColor* backgroundImageColor = + themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, false); + if (backgroundImageColor) { + [backgroundImageColor set]; NSRectFill([self bounds]); } else { CGFloat winHeight = NSHeight([[self window] frame]); diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm index 6a86c88..10fa215 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm @@ -98,6 +98,9 @@ class FakeTheme : public ThemeProvider { virtual NSImage* GetNSImageNamed(int id, bool allow_default) const { return nil; } + virtual NSColor* GetNSImageColorNamed(int id, bool allow_default) const { + return nil; + } virtual NSColor* GetNSColor(int id, bool allow_default) const { return color_.get(); } diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm index 4d49ee1..61ae836 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view_unittest.mm @@ -36,6 +36,7 @@ class MockThemeProvider : public ThemeProvider { // OSX stuff MOCK_CONST_METHOD2(GetNSImageNamed, NSImage*(int, bool)); + MOCK_CONST_METHOD2(GetNSImageColorNamed, NSColor*(int, bool)); MOCK_CONST_METHOD2(GetNSColor, NSColor*(int, bool)); MOCK_CONST_METHOD2(GetNSColorTint, NSColor*(int, bool)); MOCK_CONST_METHOD1(GetNSGradient, NSGradient*(int)); diff --git a/chrome/browser/cocoa/browser_frame_view.mm b/chrome/browser/cocoa/browser_frame_view.mm index 38c3501..1a445d3 100644 --- a/chrome/browser/cocoa/browser_frame_view.mm +++ b/chrome/browser/cocoa/browser_frame_view.mm @@ -137,7 +137,7 @@ BOOL incognito = [[view window] themeIsIncognito]; // Find a theme image. - NSImage* themeImage = nil; + NSColor* themeImageColor = nil; int themeImageID; if (active && incognito) themeImageID = IDR_THEME_FRAME_INCOGNITO; @@ -148,19 +148,17 @@ else themeImageID = IDR_THEME_FRAME_INACTIVE; if (themeProvider->HasCustomImage(IDR_THEME_FRAME)) - themeImage = themeProvider->GetNSImageNamed(themeImageID, true); + themeImageColor = themeProvider->GetNSImageColorNamed(themeImageID, true); // If no theme image, use a gradient if incognito. NSGradient* gradient = nil; - if (!themeImage && incognito) + if (!themeImageColor && incognito) gradient = themeProvider->GetNSGradient( active ? BrowserThemeProvider::GRADIENT_FRAME_INCOGNITO : BrowserThemeProvider::GRADIENT_FRAME_INCOGNITO_INACTIVE); BOOL themed = NO; - if (themeImage) { - NSColor* themeImageColor = [NSColor colorWithPatternImage:themeImage]; - + if (themeImageColor) { // 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 diff --git a/chrome/browser/cocoa/download_item_cell.mm b/chrome/browser/cocoa/download_item_cell.mm index 64ddc85..1fbf74b 100644 --- a/chrome/browser/cocoa/download_item_cell.mm +++ b/chrome/browser/cocoa/download_item_cell.mm @@ -96,6 +96,7 @@ public: 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* GetNSImageColorNamed(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; @@ -130,6 +131,11 @@ NSImage* BackgroundTheme::GetNSImageNamed(int id, bool allow_default) const { return nil; } +NSColor* BackgroundTheme::GetNSImageColorNamed(int id, + bool allow_default) const { + return nil; +} + NSColor* BackgroundTheme::GetNSColor(int id, bool allow_default) const { return provider_->GetNSColor(id, allow_default); } diff --git a/chrome/browser/cocoa/download_shelf_view.mm b/chrome/browser/cocoa/download_shelf_view.mm index db281cc..82b3ae8 100644 --- a/chrome/browser/cocoa/download_shelf_view.mm +++ b/chrome/browser/cocoa/download_shelf_view.mm @@ -26,15 +26,14 @@ if (!themeProvider) return; - NSImage* backgroundImage = themeProvider->GetNSImageNamed(IDR_THEME_TOOLBAR, - false); - if (backgroundImage) { + 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]; - NSColor* color = [NSColor colorWithPatternImage:backgroundImage]; - [color set]; + [backgroundImageColor set]; NSRectFill([self bounds]); } else { NSGradient* gradient = themeProvider->GetNSGradient( diff --git a/chrome/browser/cocoa/gradient_button_cell.mm b/chrome/browser/cocoa/gradient_button_cell.mm index ae4ab2b..c02d3c6 100644 --- a/chrome/browser/cocoa/gradient_button_cell.mm +++ b/chrome/browser/cocoa/gradient_button_cell.mm @@ -191,19 +191,20 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; // button background image, but the modest gradient used for themed buttons. // To make things even more modest, scale the hover alpha down by 40 percent // unless clicked. - NSImage* backgroundImage; + NSColor* backgroundImageColor; BOOL useThemeGradient; if (isFlatButton) { - backgroundImage = nil; + backgroundImageColor = nil; useThemeGradient = YES; if (!showClickedGradient) hoverAlpha *= 0.6; } else { - backgroundImage = + backgroundImageColor = themeProvider ? - themeProvider->GetNSImageNamed(IDR_THEME_BUTTON_BACKGROUND, false) : + themeProvider->GetNSImageColorNamed(IDR_THEME_BUTTON_BACKGROUND, + false) : nil; - useThemeGradient = backgroundImage ? YES : NO; + useThemeGradient = backgroundImageColor ? YES : NO; } // The basic gradient shown inside; see above. @@ -218,9 +219,8 @@ static const NSTimeInterval kAnimationHideDuration = 0.4; // If we're drawing a background image, show that; else possibly show the // clicked gradient. - if (backgroundImage) { - NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage]; - [patternColor set]; + if (backgroundImageColor) { + [backgroundImageColor set]; // Set the phase to match window. // TODO(avi) http://crbug.com/36485; base != window NSRect trueRect = [controlView convertRectToBase:cellFrame]; diff --git a/chrome/browser/cocoa/styled_text_field_cell.mm b/chrome/browser/cocoa/styled_text_field_cell.mm index 4b34d48..671a8e9 100644 --- a/chrome/browser/cocoa/styled_text_field_cell.mm +++ b/chrome/browser/cocoa/styled_text_field_cell.mm @@ -59,14 +59,13 @@ // Paint button background image if there is one (otherwise the border won't // look right). ThemeProvider* themeProvider = [[controlView window] themeProvider]; - NSImage* backgroundImage = nil; + NSColor* backgroundImageColor = nil; if (themeProvider) { - backgroundImage = - themeProvider->GetNSImageNamed(IDR_THEME_BUTTON_BACKGROUND, false); + backgroundImageColor = + themeProvider->GetNSImageColorNamed(IDR_THEME_BUTTON_BACKGROUND, false); } - if (backgroundImage) { - NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage]; - [patternColor set]; + if (backgroundImageColor) { + [backgroundImageColor set]; // Set the phase to match window. // TODO(avi) http://crbug.com/36485; base != window NSRect trueRect = [controlView convertRectToBase:cellFrame]; diff --git a/chrome/browser/cocoa/tab_view.mm b/chrome/browser/cocoa/tab_view.mm index cc2df73..a05d059 100644 --- a/chrome/browser/cocoa/tab_view.mm +++ b/chrome/browser/cocoa/tab_view.mm @@ -662,12 +662,12 @@ const CGFloat kRapidCloseDist = 2.5; (themeProvider->HasCustomImage(IDR_THEME_TAB_BACKGROUND) || themeProvider->HasCustomImage(IDR_THEME_FRAME)); - NSImage* backgroundImage = + NSColor* backgroundImageColor = hasBackgroundImage ? - themeProvider->GetNSImageNamed(IDR_THEME_TAB_BACKGROUND, true) : + themeProvider->GetNSImageColorNamed(IDR_THEME_TAB_BACKGROUND, true) : nil; - if (backgroundImage) { - [[NSColor colorWithPatternImage:backgroundImage] set]; + if (backgroundImageColor) { + [backgroundImageColor set]; [path fill]; } else { [[NSColor windowBackgroundColor] set]; |