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