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/gradient_button_cell.mm | |
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/gradient_button_cell.mm')
-rw-r--r-- | chrome/browser/cocoa/gradient_button_cell.mm | 20 |
1 files changed, 12 insertions, 8 deletions
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]; } |