diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 15:12:50 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 15:12:50 +0000 |
commit | 60aeeae2c236f22833fa9e8c9372227db2595cc1 (patch) | |
tree | 078147bf042a6144283f2b3412afbbd349597be7 /chrome/browser/cocoa | |
parent | 1224ec28b4355cceffb872eaa045daa97c8b9ade (diff) | |
download | chromium_src-60aeeae2c236f22833fa9e8c9372227db2595cc1.zip chromium_src-60aeeae2c236f22833fa9e8c9372227db2595cc1.tar.gz chromium_src-60aeeae2c236f22833fa9e8c9372227db2595cc1.tar.bz2 |
Cache GTMTheme across windows to avoid re-creating it every time we create a new window. Cache gradient to avoid re-creating it every time we draw a button cell.
BUG=none
TEST=switch themes, ensure it works. Make sure buttons draw correctly.
Review URL: http://codereview.chromium.org/173445
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.h | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.mm | 20 |
3 files changed, 24 insertions, 10 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 6d80425..03c6146 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -1202,7 +1202,17 @@ willPositionSheet:(NSWindow*)sheet @implementation GTMTheme (BrowserThemeProviderInitialization) + (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider isOffTheRecord:(BOOL)isOffTheRecord { - GTMTheme *theme = [[[GTMTheme alloc] init] autorelease]; + // First check if it's in the cache. + // TODO(pinkerton): This might be a good candidate for a singleton. + 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; if (isOffTheRecord) { NSColor* incognitoColor = [NSColor colorWithCalibratedRed:83/255.0 green:108.0/255.0 diff --git a/chrome/browser/cocoa/gradient_button_cell.h b/chrome/browser/cocoa/gradient_button_cell.h index 7492649..e9b4e79 100644 --- a/chrome/browser/cocoa/gradient_button_cell.h +++ b/chrome/browser/cocoa/gradient_button_cell.h @@ -34,7 +34,7 @@ typedef NSInteger ButtonType; BOOL isMouseInside_; scoped_nsobject<NSTrackingArea> trackingArea_; BOOL shouldTheme_; - + scoped_nsobject<NSGradient> gradient_; scoped_nsobject<NSImage> underlayImage_; } diff --git a/chrome/browser/cocoa/gradient_button_cell.mm b/chrome/browser/cocoa/gradient_button_cell.mm index 99a0dc1..17d4998 100644 --- a/chrome/browser/cocoa/gradient_button_cell.mm +++ b/chrome/browser/cocoa/gradient_button_cell.mm @@ -7,6 +7,7 @@ #import "base/scoped_nsobject.h" @interface GradientButtonCell (Private) +- (void)sharedInit; - (void)drawUnderlayImageWithFrame:(NSRect)cellFrame inView:(NSView*)controlView; @end @@ -17,7 +18,7 @@ // For nib instantiations - (id)initWithCoder:(NSCoder*)decoder { if ((self = [super initWithCoder:decoder])) { - shouldTheme_ = YES; + [self sharedInit]; } return self; } @@ -25,11 +26,19 @@ // For programmatic instantiations - (id)initTextCell:(NSString*)string { if ((self = [super initTextCell:string])) { - shouldTheme_ = YES; + [self sharedInit]; } return self; } +- (void)sharedInit { + shouldTheme_ = YES; + NSColor* startColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.666]; + NSColor* endColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.333]; + gradient_.reset([[NSGradient alloc] + initWithColorsAndLocations:startColor, 0.33, endColor, 1.0, nil]); +} + - (void)setShouldTheme:(BOOL)shouldTheme { shouldTheme_ = shouldTheme; } @@ -140,12 +149,7 @@ [highlightPath stroke]; - NSColor* startColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.666]; - NSColor* endColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.333]; - scoped_nsobject<NSBezierPath> gradient([[NSGradient alloc] - initWithColorsAndLocations:startColor, 0.33, endColor, 1.0, nil]); - - [gradient drawInBezierPath:innerPath angle:90.0]; + [gradient_ drawInBezierPath:innerPath angle:90.0]; [NSGraphicsContext restoreGraphicsState]; } |