OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_COCOA_GRADIENT_BUTTON_CELL_H_ | 5 #ifndef CHROME_BROWSER_COCOA_GRADIENT_BUTTON_CELL_H_ |
6 #define CHROME_BROWSER_COCOA_GRADIENT_BUTTON_CELL_H_ | 6 #define CHROME_BROWSER_COCOA_GRADIENT_BUTTON_CELL_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/scoped_nsobject.h" | 10 #include "base/scoped_nsobject.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 kStandardButtonType = 0, | 24 kStandardButtonType = 0, |
25 kRightButtonType = 1, | 25 kRightButtonType = 1, |
26 kMiddleButtonType = 2, | 26 kMiddleButtonType = 2, |
27 // Draws like a standard button, except when clicked where the interior | 27 // Draws like a standard button, except when clicked where the interior |
28 // doesn't darken using the theme's "pressed" gradient. Instead uses the | 28 // doesn't darken using the theme's "pressed" gradient. Instead uses the |
29 // normal un-pressed gradient. | 29 // normal un-pressed gradient. |
30 kStandardButtonTypeWithLimitedClickFeedback = 3, | 30 kStandardButtonTypeWithLimitedClickFeedback = 3, |
31 }; | 31 }; |
32 typedef NSInteger ButtonType; | 32 typedef NSInteger ButtonType; |
33 | 33 |
| 34 namespace gradient_button_cell { |
| 35 |
| 36 // Pulsing state for this button. |
| 37 typedef enum { |
| 38 // Stable states. |
| 39 kPulsedOn, |
| 40 kPulsedOff, |
| 41 // In motion which will end in a stable state. |
| 42 kPulsingOn, |
| 43 kPulsingOff, |
| 44 // In continuous motion. |
| 45 kPulsingContinuous, |
| 46 } PulseState; |
| 47 |
| 48 }; |
| 49 |
| 50 |
34 @interface GradientButtonCell : NSButtonCell { | 51 @interface GradientButtonCell : NSButtonCell { |
35 @private | 52 @private |
36 // Custom drawing means we need to perform our own mouse tracking if | 53 // Custom drawing means we need to perform our own mouse tracking if |
37 // the cell is setShowsBorderOnlyWhileMouseInside:YES. | 54 // the cell is setShowsBorderOnlyWhileMouseInside:YES. |
38 BOOL isMouseInside_; | 55 BOOL isMouseInside_; |
39 scoped_nsobject<NSTrackingArea> trackingArea_; | 56 scoped_nsobject<NSTrackingArea> trackingArea_; |
40 BOOL shouldTheme_; | 57 BOOL shouldTheme_; |
41 CGFloat hoverAlpha_; // 0-1. Controls the alpha during mouse hover | 58 CGFloat hoverAlpha_; // 0-1. Controls the alpha during mouse hover |
42 NSTimeInterval lastHoverUpdate_; | 59 NSTimeInterval lastHoverUpdate_; |
43 scoped_nsobject<NSGradient> gradient_; | 60 scoped_nsobject<NSGradient> gradient_; |
| 61 gradient_button_cell::PulseState pulseState_; |
| 62 CGFloat pulseMultiplier_; // for selecting pulse direction when continuous. |
| 63 CGFloat outerStrokeAlphaMult_; // For pulsing. |
44 scoped_nsobject<NSImage> overlayImage_; | 64 scoped_nsobject<NSImage> overlayImage_; |
45 } | 65 } |
46 | 66 |
47 // Turn off theming. Temporary work-around. | 67 // Turn off theming. Temporary work-around. |
48 - (void)setShouldTheme:(BOOL)shouldTheme; | 68 - (void)setShouldTheme:(BOOL)shouldTheme; |
49 | 69 |
50 - (void)drawBorderAndFillForTheme:(ThemeProvider*)themeProvider | 70 - (void)drawBorderAndFillForTheme:(ThemeProvider*)themeProvider |
51 controlView:(NSView*)controlView | 71 controlView:(NSView*)controlView |
52 innerPath:(NSBezierPath*)innerPath | 72 innerPath:(NSBezierPath*)innerPath |
53 showClickedGradient:(BOOL)showClickedGradient | 73 showClickedGradient:(BOOL)showClickedGradient |
54 showHighlightGradient:(BOOL)showHighlightGradient | 74 showHighlightGradient:(BOOL)showHighlightGradient |
55 hoverAlpha:(CGFloat)hoverAlpha | 75 hoverAlpha:(CGFloat)hoverAlpha |
56 active:(BOOL)active | 76 active:(BOOL)active |
57 cellFrame:(NSRect)cellFrame | 77 cellFrame:(NSRect)cellFrame |
58 defaultGradient:(NSGradient*)defaultGradient; | 78 defaultGradient:(NSGradient*)defaultGradient; |
59 | 79 |
60 // Let the view know when the mouse moves in and out. A timer will update | 80 // Let the view know when the mouse moves in and out. A timer will update |
61 // the current hoverAlpha_ based on these events. | 81 // the current hoverAlpha_ based on these events. |
62 - (void)setMouseInside:(BOOL)flag animate:(BOOL)animate; | 82 - (void)setMouseInside:(BOOL)flag animate:(BOOL)animate; |
63 | 83 |
64 // Gets the path which tightly bounds the outside of the button. This is needed | 84 // Gets the path which tightly bounds the outside of the button. This is needed |
65 // to produce images of clear buttons which only include the area inside, since | 85 // to produce images of clear buttons which only include the area inside, since |
66 // the background of the button is drawn by someone else. | 86 // the background of the button is drawn by someone else. |
67 - (NSBezierPath*)clipPathForFrame:(NSRect)cellFrame | 87 - (NSBezierPath*)clipPathForFrame:(NSRect)cellFrame |
68 inView:(NSView*)controlView; | 88 inView:(NSView*)controlView; |
69 | 89 |
| 90 // Turn on or off continuous pulsing. When turning off continuous |
| 91 // pulsing, leave our pulse state in the correct ending position for |
| 92 // our isMouseInside_ property. Public since it's called from the |
| 93 // bookmark bubble. |
| 94 - (void)setIsContinuousPulsing:(BOOL)continuous; |
| 95 |
| 96 // Returns continuous pulse state. |
| 97 - (BOOL)isContinuousPulsing; |
| 98 |
| 99 // Safely stop continuous pulsing by turning off all timers. |
| 100 // May leave the cell in an odd state. |
| 101 // Needed by an owning control's dealloc routine. |
| 102 - (void)safelyStopPulsing; |
| 103 |
70 @property(assign, nonatomic) CGFloat hoverAlpha; | 104 @property(assign, nonatomic) CGFloat hoverAlpha; |
71 | 105 |
72 // An image that will be drawn after the normal content of the button cell, | 106 // An image that will be drawn after the normal content of the button cell, |
73 // overlaying it. Never themed. | 107 // overlaying it. Never themed. |
74 @property(retain, nonatomic) NSImage* overlayImage; | 108 @property(retain, nonatomic) NSImage* overlayImage; |
| 109 |
75 @end | 110 @end |
76 | 111 |
77 @interface GradientButtonCell(TestingAPI) | 112 @interface GradientButtonCell(TestingAPI) |
78 - (BOOL)isMouseInside; | 113 - (BOOL)isMouseInside; |
| 114 - (BOOL)pulsing; |
| 115 - (gradient_button_cell::PulseState)pulseState; |
| 116 - (void)setPulseState:(gradient_button_cell::PulseState)pstate; |
79 @end | 117 @end |
80 | 118 |
81 #endif // CHROME_BROWSER_COCOA_GRADIENT_BUTTON_CELL_H_ | 119 #endif // CHROME_BROWSER_COCOA_GRADIENT_BUTTON_CELL_H_ |
OLD | NEW |