OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/constrained_window/cw_button.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
6 | 6 |
7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
8 #include "skia/ext/skia_utils_mac.h" | 8 #include "skia/ext/skia_utils_mac.h" |
9 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h" | 9 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h" |
10 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 10 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 enum ButtonState { | 14 enum ButtonState { |
15 BUTTON_NORMAL, | 15 BUTTON_NORMAL, |
16 BUTTON_HOVER, | 16 BUTTON_HOVER, |
17 BUTTON_PRESSED, | 17 BUTTON_PRESSED, |
18 BUTTON_DISABLED, | 18 BUTTON_DISABLED, |
19 }; | 19 }; |
20 | 20 |
21 } // namespace | 21 } // namespace |
22 | 22 |
23 @interface CWButton() | 23 @interface ConstrainedWindowButton () |
24 - (BOOL)isMouseReallyInside; | 24 - (BOOL)isMouseReallyInside; |
25 @end | 25 @end |
26 | 26 |
27 @interface CWButtonCell() | 27 @interface ConstrainedWindowButtonCell () |
28 - (ButtonState)buttonState; | 28 - (ButtonState)buttonState; |
29 @end | 29 @end |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const CGFloat kButtonHeight = 28; | 33 const CGFloat kButtonHeight = 28; |
34 const CGFloat kButtonPaddingX = 14; | 34 const CGFloat kButtonPaddingX = 14; |
35 | 35 |
36 NSGradient* GetButtonGradient(ButtonState button_state) { | 36 NSGradient* GetButtonGradient(ButtonState button_state) { |
37 const SkColor start[] = {0xFFF0F0F0, 0xFFF4F4F4, 0xFFEBEBEB, 0xFFEDEDED}; | 37 const SkColor start[] = {0xFFF0F0F0, 0xFFF4F4F4, 0xFFEBEBEB, 0xFFEDEDED}; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 NSForegroundColorAttributeName, | 96 NSForegroundColorAttributeName, |
97 shadow.get(), NSShadowAttributeName, | 97 shadow.get(), NSShadowAttributeName, |
98 paragraphStyle.get(), NSParagraphStyleAttributeName, | 98 paragraphStyle.get(), NSParagraphStyleAttributeName, |
99 nil]; | 99 nil]; |
100 return [[[NSAttributedString alloc] initWithString:title | 100 return [[[NSAttributedString alloc] initWithString:title |
101 attributes:attributes] autorelease]; | 101 attributes:attributes] autorelease]; |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 @implementation CWButton | 106 @implementation ConstrainedWindowButton |
107 | 107 |
108 + (Class)cellClass { | 108 + (Class)cellClass { |
109 return [CWButtonCell class]; | 109 return [ConstrainedWindowButtonCell class]; |
110 } | 110 } |
111 | 111 |
112 - (void)updateTrackingAreas { | 112 - (void)updateTrackingAreas { |
113 BOOL mouseInView = [self isMouseReallyInside]; | 113 BOOL mouseInView = [self isMouseReallyInside]; |
114 | 114 |
115 if (trackingArea_.get()) | 115 if (trackingArea_.get()) |
116 [self removeTrackingArea:trackingArea_.get()]; | 116 [self removeTrackingArea:trackingArea_.get()]; |
117 | 117 |
118 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | | 118 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | |
119 NSTrackingActiveInActiveApp | | 119 NSTrackingActiveInActiveApp | |
(...skipping 30 matching lines...) Expand all Loading... |
150 if (window) { | 150 if (window) { |
151 NSPoint mousePoint = [window mouseLocationOutsideOfEventStream]; | 151 NSPoint mousePoint = [window mouseLocationOutsideOfEventStream]; |
152 mousePoint = [self convertPoint:mousePoint fromView:nil]; | 152 mousePoint = [self convertPoint:mousePoint fromView:nil]; |
153 mouseInView = [self mouse:mousePoint inRect:[self bounds]]; | 153 mouseInView = [self mouse:mousePoint inRect:[self bounds]]; |
154 } | 154 } |
155 return mouseInView; | 155 return mouseInView; |
156 } | 156 } |
157 | 157 |
158 @end | 158 @end |
159 | 159 |
160 @implementation CWButtonCell | 160 @implementation ConstrainedWindowButtonCell |
161 | 161 |
162 @synthesize isMouseInside = isMouseInside_; | 162 @synthesize isMouseInside = isMouseInside_; |
163 | 163 |
164 - (void)drawWithFrame:(NSRect)frame | 164 - (void)drawWithFrame:(NSRect)frame |
165 inView:(NSView *)controlView { | 165 inView:(NSView *)controlView { |
166 NSBezierPath* path = nil; | 166 NSBezierPath* path = nil; |
167 ButtonState buttonState = [self buttonState]; | 167 ButtonState buttonState = [self buttonState]; |
168 | 168 |
169 // Inset to leave room for shadow. | 169 // Inset to leave room for shadow. |
170 frame.size.height--; | 170 frame.size.height--; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 if (![self isEnabled]) | 215 if (![self isEnabled]) |
216 return BUTTON_DISABLED; | 216 return BUTTON_DISABLED; |
217 if ([self isHighlighted]) | 217 if ([self isHighlighted]) |
218 return BUTTON_PRESSED; | 218 return BUTTON_PRESSED; |
219 if (isMouseInside_) | 219 if (isMouseInside_) |
220 return BUTTON_HOVER; | 220 return BUTTON_HOVER; |
221 return BUTTON_NORMAL; | 221 return BUTTON_NORMAL; |
222 } | 222 } |
223 | 223 |
224 @end | 224 @end |
OLD | NEW |