1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_GRADIENT_BUTTON_CELL_H_
6 #define CHROME_BROWSER_UI_COCOA_GRADIENT_BUTTON_CELL_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
16 // Base class for button cells for toolbar and bookmark bar.
18 // This is a button cell that handles drawing/highlighting of buttons.
19 // The appearance is determined by setting the cell's tag (not the
20 // view's) to one of the constants below (ButtonType).
22 // Set this as the cell's tag.
25 kLeftButtonWithShadowType
= -2,
26 kStandardButtonType
= 0,
28 kMiddleButtonType
= 2,
29 // Draws like a standard button, except when clicked where the interior
30 // doesn't darken using the theme's "pressed" gradient. Instead uses the
31 // normal un-pressed gradient.
32 kStandardButtonTypeWithLimitedClickFeedback
= 3,
34 typedef NSInteger ButtonType
;
36 namespace gradient_button_cell
{
38 // Pulsing state for this button.
43 // In motion which will end in a stable state.
46 // In continuous motion.
53 @interface GradientButtonCell
: NSButtonCell
{
55 // Custom drawing means we need to perform our own mouse tracking if
56 // the cell is setShowsBorderOnlyWhileMouseInside:YES.
58 base::scoped_nsobject
<NSTrackingArea
> trackingArea_
;
60 CGFloat hoverAlpha_
; // 0-1. Controls the alpha during mouse hover
61 NSTimeInterval lastHoverUpdate_
;
62 base::scoped_nsobject
<NSGradient
> gradient_
;
63 gradient_button_cell::PulseState pulseState_
;
64 CGFloat pulseMultiplier_
; // for selecting pulse direction when continuous.
65 CGFloat outerStrokeAlphaMult_
; // For pulsing.
66 base::scoped_nsobject
<NSImage
> overlayImage_
;
69 // Turn off theming. Temporary work-around.
70 - (void)setShouldTheme
:(BOOL
)shouldTheme
;
72 - (void)drawBorderAndFillForTheme
:(ui::ThemeProvider
*)themeProvider
73 controlView
:(NSView
*)controlView
74 innerPath
:(NSBezierPath
*)innerPath
75 showClickedGradient
:(BOOL
)showClickedGradient
76 showHighlightGradient
:(BOOL
)showHighlightGradient
77 hoverAlpha
:(CGFloat
)hoverAlpha
79 cellFrame
:(NSRect
)cellFrame
80 defaultGradient
:(NSGradient
*)defaultGradient
;
82 // Let the view know when the mouse moves in and out. A timer will update
83 // the current hoverAlpha_ based on these events.
84 - (void)setMouseInside
:(BOOL
)flag animate
:(BOOL
)animate
;
86 // Gets the path which tightly bounds the outside of the button. This is needed
87 // to produce images of clear buttons which only include the area inside, since
88 // the background of the button is drawn by someone else.
89 - (NSBezierPath
*)clipPathForFrame
:(NSRect
)cellFrame
90 inView
:(NSView
*)controlView
;
92 // Turn on or off continuous pulsing. When turning off continuous
93 // pulsing, leave our pulse state in the correct ending position for
94 // our isMouseInside_ property. Public since it's called from the
96 - (void)setIsContinuousPulsing
:(BOOL
)continuous
;
98 // Returns continuous pulse state.
99 - (BOOL
)isContinuousPulsing
;
101 // Safely stop continuous pulsing by turning off all timers.
102 // May leave the cell in an odd state.
103 // Needed by an owning control's dealloc routine.
104 - (void)safelyStopPulsing
;
106 // Actually fetches current mouse position and does a hit test.
107 - (BOOL
)isMouseReallyInside
;
109 // Defines the top offset of text within the cell. Used by drawTitle and can
110 // be overriden by objects that inherit this class for placement of text.
111 - (int)verticalTextOffset
;
113 @
property(assign
, nonatomic
) CGFloat hoverAlpha
;
115 // An image that will be drawn after the normal content of the button cell,
116 // overlaying it. Never themed.
117 @
property(retain
, nonatomic
) NSImage
* overlayImage
;
121 @interface
GradientButtonCell(TestingAPI
)
122 - (BOOL
)isMouseInside
;
124 - (gradient_button_cell::PulseState
)pulseState
;
125 - (void)setPulseState
:(gradient_button_cell::PulseState
)pstate
;
128 #endif // CHROME_BROWSER_UI_COCOA_GRADIENT_BUTTON_CELL_H_