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_TABS_TAB_VIEW_H_
6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_
8 #include <ApplicationServices/ApplicationServices.h>
9 #import <Cocoa/Cocoa.h>
11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/mac/scoped_nsobject.h"
13 #import "chrome/browser/ui/cocoa/hover_close_button.h"
18 // Tabs _glow_ under two different circumstances, when they are _hovered_ (by
19 // the mouse) and when they are _alerted_ (to show that the tab's title has
22 // The state of alerting (to show a title change on an unselected, pinned tab).
23 // This is more complicated than a simple on/off since we want to allow the
24 // alert glow to go through a full rise-hold-fall cycle to avoid flickering (or
27 kAlertNone
= 0, // Obj-C initializes to this.
33 // When the window doesn't have focus then we want to draw the button with a
34 // slightly lighter color. We do this by just reducing the alpha.
35 const CGFloat kImageNoFocusAlpha
= 0.65;
39 @
class TabController
, TabWindowController
;
41 // A view that handles the event tracking (clicking and dragging) for a tab
42 // on the tab strip. Relies on an associated TabController to provide a
43 // target/action for selecting the tab.
45 @interface TabView
: NSView
{
47 TabController
* controller_
;
48 // TODO(rohitrao): Add this button to a CoreAnimation layer so we can fade it
49 // in and out on mouseovers.
50 HoverCloseButton
* closeButton_
; // Weak.
54 BOOL isMouseInside_
; // Is the mouse hovering over?
55 tabs::AlertState alertState_
;
57 CGFloat hoverAlpha_
; // How strong the hover glow is.
58 NSTimeInterval hoverHoldEndTime_
; // When the hover glow will begin dimming.
60 CGFloat alertAlpha_
; // How strong the alert glow is.
61 NSTimeInterval alertHoldEndTime_
; // When the hover glow will begin dimming.
63 NSTimeInterval lastGlowUpdate_
; // Time either glow was last updated.
65 NSPoint hoverPoint_
; // Current location of hover in view coords.
67 // The location of the current mouseDown event in window coordinates.
68 NSPoint mouseDownPoint_
;
70 NSCellStateValue state_
;
72 // The tool tip text for this tab view.
73 base::scoped_nsobject
<NSString
> toolTipText_
;
75 // A one-element mask image cache. This cache makes drawing roughly 16%
77 base::ScopedCFTypeRef
<CGImageRef
> maskCache_
;
78 CGFloat maskCacheWidth_
;
79 CGFloat maskCacheScale_
;
82 @
property(assign
, nonatomic
) NSCellStateValue state
;
83 @
property(assign
, nonatomic
) CGFloat hoverAlpha
;
84 @
property(assign
, nonatomic
) CGFloat alertAlpha
;
86 // Determines if the tab is in the process of animating closed. It may still
87 // be visible on-screen, but should not respond to/initiate any events. Upon
88 // setting to NO, clears the target/action of the close button to prevent
89 // clicks inside it from sending messages.
90 @
property(assign
, nonatomic
, getter
=isClosing
) BOOL closing
;
92 // Designated initializer.
93 - (id
)initWithFrame
:(NSRect
)frame
94 controller
:(TabController
*)controller
95 closeButton
:(HoverCloseButton
*)closeButton
;
97 // Returns the inset multiplier used to compute the inset of the top of the tab.
98 + (CGFloat
)insetMultiplier
;
100 // Enables/Disables tracking regions for the tab.
101 - (void)setTrackingEnabled
:(BOOL
)enabled
;
103 // Begin showing an "alert" glow (shown to call attention to an unselected
104 // pinned tab whose title changed).
107 // Stop showing the "alert" glow; this won't immediately wipe out any glow, but
108 // will make it fade away.
111 // Returns the tool tip text for this tab view.
112 - (NSString
*)toolTipText
;
116 // The TabController |controller_| is not the only owner of this view. If the
117 // controller is released before this view, then we could be hanging onto a
118 // garbage pointer. To prevent this, the TabController uses this interface to
119 // clear the |controller_| pointer when it is dying.
120 @interface
TabView (TabControllerInterface
)
121 - (void)setController
:(TabController
*)controller
;
124 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_