OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/cocoa/gradient_button_cell.h" | 5 #include "chrome/browser/cocoa/gradient_button_cell.h" |
6 #import "third_party/GTM/AppKit/GTMTheme.h" | 6 #import "third_party/GTM/AppKit/GTMTheme.h" |
7 #import "base/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
8 | 8 |
9 @interface GradientButtonCell (Private) | 9 @interface GradientButtonCell (Private) |
10 - (void)sharedInit; | |
10 - (void)drawUnderlayImageWithFrame:(NSRect)cellFrame | 11 - (void)drawUnderlayImageWithFrame:(NSRect)cellFrame |
11 inView:(NSView*)controlView; | 12 inView:(NSView*)controlView; |
12 @end | 13 @end |
13 | 14 |
14 | 15 |
15 @implementation GradientButtonCell | 16 @implementation GradientButtonCell |
16 | 17 |
17 // For nib instantiations | 18 // For nib instantiations |
18 - (id)initWithCoder:(NSCoder*)decoder { | 19 - (id)initWithCoder:(NSCoder*)decoder { |
19 if ((self = [super initWithCoder:decoder])) { | 20 if ((self = [super initWithCoder:decoder])) { |
20 shouldTheme_ = YES; | 21 [self sharedInit]; |
21 } | 22 } |
22 return self; | 23 return self; |
23 } | 24 } |
24 | 25 |
25 // For programmatic instantiations | 26 // For programmatic instantiations |
26 - (id)initTextCell:(NSString*)string { | 27 - (id)initTextCell:(NSString*)string { |
27 if ((self = [super initTextCell:string])) { | 28 if ((self = [super initTextCell:string])) { |
28 shouldTheme_ = YES; | 29 [self sharedInit]; |
29 } | 30 } |
30 return self; | 31 return self; |
31 } | 32 } |
32 | 33 |
34 - (void)sharedInit { | |
35 shouldTheme_ = YES; | |
Mark Mentovai
2009/08/26 01:25:49
Indent is weird.
pink (ping after 24hrs)
2009/08/26 14:55:56
Done.
| |
36 NSColor* startColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.666]; | |
37 NSColor* endColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.333]; | |
38 gradient_.reset([[NSGradient alloc] | |
39 initWithColorsAndLocations:startColor, 0.33, endColor, 1.0, nil]); | |
40 } | |
41 | |
33 - (void)setShouldTheme:(BOOL)shouldTheme { | 42 - (void)setShouldTheme:(BOOL)shouldTheme { |
34 shouldTheme_ = shouldTheme; | 43 shouldTheme_ = shouldTheme; |
35 } | 44 } |
36 | 45 |
37 - (NSImage*)underlayImage { | 46 - (NSImage*)underlayImage { |
38 return underlayImage_; | 47 return underlayImage_; |
39 } | 48 } |
40 | 49 |
41 - (void)setUnderlayImage:(NSImage*)image { | 50 - (void)setUnderlayImage:(NSImage*)image { |
42 underlayImage_.reset([image retain]); | 51 underlayImage_.reset([image retain]); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setFill]; | 142 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setFill]; |
134 | 143 |
135 // Draw the top inner highlight. | 144 // Draw the top inner highlight. |
136 NSAffineTransform* highlightTransform = [NSAffineTransform transform]; | 145 NSAffineTransform* highlightTransform = [NSAffineTransform transform]; |
137 [highlightTransform translateXBy:1 yBy:1]; | 146 [highlightTransform translateXBy:1 yBy:1]; |
138 scoped_nsobject<NSBezierPath> highlightPath([innerPath copy]); | 147 scoped_nsobject<NSBezierPath> highlightPath([innerPath copy]); |
139 [highlightPath transformUsingAffineTransform:highlightTransform]; | 148 [highlightPath transformUsingAffineTransform:highlightTransform]; |
140 | 149 |
141 [highlightPath stroke]; | 150 [highlightPath stroke]; |
142 | 151 |
143 NSColor* startColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.666]; | 152 [gradient_ drawInBezierPath:innerPath angle:90.0]; |
144 NSColor* endColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.333]; | |
145 scoped_nsobject<NSBezierPath> gradient([[NSGradient alloc] | |
146 initWithColorsAndLocations:startColor, 0.33, endColor, 1.0, nil]); | |
147 | |
148 [gradient drawInBezierPath:innerPath angle:90.0]; | |
149 | 153 |
150 [NSGraphicsContext restoreGraphicsState]; | 154 [NSGraphicsContext restoreGraphicsState]; |
151 } | 155 } |
152 | 156 |
153 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton | 157 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton |
154 state:active]; | 158 state:active]; |
155 [stroke setStroke]; | 159 [stroke setStroke]; |
156 | 160 |
157 [innerPath setLineWidth:1]; | 161 [innerPath setLineWidth:1]; |
158 [innerPath stroke]; | 162 [innerPath stroke]; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 imageRect.size = [underlayImage_ size]; | 289 imageRect.size = [underlayImage_ size]; |
286 [underlayImage_ setFlipped:[controlView isFlipped]]; | 290 [underlayImage_ setFlipped:[controlView isFlipped]]; |
287 [underlayImage_ drawInRect:[self imageRectForBounds:cellFrame] | 291 [underlayImage_ drawInRect:[self imageRectForBounds:cellFrame] |
288 fromRect:imageRect | 292 fromRect:imageRect |
289 operation:NSCompositeSourceOver | 293 operation:NSCompositeSourceOver |
290 fraction:[self isEnabled] ? 1.0 : 0.5]; | 294 fraction:[self isEnabled] ? 1.0 : 0.5]; |
291 } | 295 } |
292 } | 296 } |
293 | 297 |
294 @end | 298 @end |
OLD | NEW |