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 #import "chrome/browser/cocoa/tab_cell.h" | 5 #import "chrome/browser/cocoa/tab_cell.h" |
6 #import "third_party/GTM/AppKit/GTMTheme.h" | 6 #import "third_party/GTM/AppKit/GTMTheme.h" |
7 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 7 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
8 | 8 |
9 #define INSET_MULTIPLIER 2.0/3.0 | 9 #define INSET_MULTIPLIER 2.0/3.0 |
10 #define CP1_MULTIPLIER 1.0/3.0 | 10 #define CP1_MULTIPLIER 1.0/3.0 |
11 #define CP2_MULTIPLIER 3.0/8.0 | 11 #define CP2_MULTIPLIER 3.0/8.0 |
12 | 12 |
13 namespace { | |
14 NSGradient *getGradientForStyle(bool selected, bool active) { | |
15 // Workaround for | |
16 // rdar://6857649 - NSGradient fails when using LAB Colorspace | |
17 // Once that's fixed we can remove this function and just call through | |
18 // to -[GTMTheme gradientForStyle:active:] directly with | |
19 // GTMThemeStyleTabBarSelected/GTMThemeStyleTabBarDeselected | |
20 NSUInteger startHighlight, endHighlight; | |
21 if (selected) { | |
22 startHighlight = GTMColorationLightHighlight; | |
23 endHighlight = GTMColorationLightMidtone; | |
24 } else { | |
25 startHighlight = GTMColorationLightShadow; | |
26 endHighlight = GTMColorationLightShadow; | |
27 } | |
28 | |
29 NSColor *backgroundColor = [[GTMTheme defaultTheme] backgroundColor]; | |
30 NSColor *startColor = [backgroundColor gtm_colorAdjustedFor:startHighlight | |
31 faded:!active]; | |
32 NSColor *endColor = [backgroundColor gtm_colorAdjustedFor:endHighlight | |
33 faded:!active]; | |
34 NSColorSpace *genericRGB = [NSColorSpace genericRGBColorSpace]; | |
35 startColor = [startColor colorUsingColorSpace:genericRGB]; | |
36 endColor = [endColor colorUsingColorSpace:genericRGB]; | |
37 | |
38 return [[[NSGradient alloc] initWithStartingColor:startColor | |
39 endingColor:endColor] | |
40 autorelease]; | |
41 | |
42 } | |
43 } // namespace | |
44 | |
45 @implementation TabCell | 13 @implementation TabCell |
46 | 14 |
47 - (id)initTextCell:(NSString *)aString { | 15 - (id)initTextCell:(NSString *)aString { |
48 self = [super initTextCell:aString]; | 16 self = [super initTextCell:aString]; |
49 if (self != nil) { | 17 if (self != nil) { |
50 // nothing for now... | 18 // nothing for now... |
51 } | 19 } |
52 return self; | 20 return self; |
53 } | 21 } |
54 | 22 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 topLeft.y)]; | 68 topLeft.y)]; |
101 [path lineToPoint:topRight]; | 69 [path lineToPoint:topRight]; |
102 [path curveToPoint:bottomRight | 70 [path curveToPoint:bottomRight |
103 controlPoint1:NSMakePoint(topRight.x + bottomControlPointInset, | 71 controlPoint1:NSMakePoint(topRight.x + bottomControlPointInset, |
104 topRight.y) | 72 topRight.y) |
105 controlPoint2:NSMakePoint(bottomRight.x - baseControlPointOutset, | 73 controlPoint2:NSMakePoint(bottomRight.x - baseControlPointOutset, |
106 bottomRight.y)]; | 74 bottomRight.y)]; |
107 [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y)]; | 75 [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y)]; |
108 [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y + 1)]; | 76 [path lineToPoint:NSMakePoint(bottomRight.x + 1, bottomRight.y + 1)]; |
109 | 77 |
| 78 GTMTheme *theme = [GTMTheme defaultTheme]; |
110 NSGradient *gradient = nil; | 79 NSGradient *gradient = nil; |
111 | 80 |
112 if (selected) { | 81 if (selected) { |
113 gradient = getGradientForStyle(true, active); | 82 gradient = [theme gradientForStyle:GTMThemeStyleTabBarSelected |
| 83 active:active]; |
114 // Stroke with a translucent black | 84 // Stroke with a translucent black |
115 [[NSColor colorWithCalibratedWhite:0.0 alpha:active ? 0.5 : 0.3] set]; | 85 [[NSColor colorWithCalibratedWhite:0.0 alpha:active ? 0.5 : 0.3] set]; |
116 [[NSGraphicsContext currentContext] saveGraphicsState]; | 86 [[NSGraphicsContext currentContext] saveGraphicsState]; |
117 NSShadow *shadow = [[[NSShadow alloc] init] autorelease]; | 87 NSShadow *shadow = [[[NSShadow alloc] init] autorelease]; |
118 [shadow setShadowOffset:NSMakeSize(2, -1)]; | 88 [shadow setShadowOffset:NSMakeSize(2, -1)]; |
119 [shadow setShadowBlurRadius:2.0]; | 89 [shadow setShadowBlurRadius:2.0]; |
120 [path fill]; | 90 [path fill]; |
121 [[NSGraphicsContext currentContext] restoreGraphicsState]; | 91 [[NSGraphicsContext currentContext] restoreGraphicsState]; |
122 } else { | 92 } else { |
123 gradient = getGradientForStyle(false, active); | 93 gradient = [theme gradientForStyle:GTMThemeStyleTabBarDeselected |
| 94 active:active]; |
124 // Stroke with a translucent black | 95 // Stroke with a translucent black |
125 [[NSColor colorWithCalibratedWhite:0.0 alpha:active ? 0.3 : 0.1] set]; | 96 [[NSColor colorWithCalibratedWhite:0.0 alpha:active ? 0.3 : 0.1] set]; |
126 } | 97 } |
127 | 98 |
128 [[NSGraphicsContext currentContext] saveGraphicsState]; | 99 [[NSGraphicsContext currentContext] saveGraphicsState]; |
129 [[NSBezierPath bezierPathWithRect:NSOffsetRect(cellFrame, 0, -1)] addClip]; | 100 [[NSBezierPath bezierPathWithRect:NSOffsetRect(cellFrame, 0, -1)] addClip]; |
130 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.2] set]; | 101 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.2] set]; |
131 [path setLineWidth:selected ? 2.0 : 1.0]; | 102 [path setLineWidth:selected ? 2.0 : 1.0]; |
132 [path stroke]; | 103 [path stroke]; |
133 | 104 |
(...skipping 23 matching lines...) Expand all Loading... |
157 inView:controlView]; | 128 inView:controlView]; |
158 } | 129 } |
159 | 130 |
160 - (void)highlight:(BOOL)flag | 131 - (void)highlight:(BOOL)flag |
161 withFrame:(NSRect)cellFrame | 132 withFrame:(NSRect)cellFrame |
162 inView:(NSView *)controlView { | 133 inView:(NSView *)controlView { |
163 // Don't do normal highlighting | 134 // Don't do normal highlighting |
164 } | 135 } |
165 | 136 |
166 @end | 137 @end |
OLD | NEW |