[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tabs / tab_view.h
bloba307bab75fec5fdad3e3144ff7744069ae26bfa1
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"
15 namespace tabs {
17 // Nomenclature:
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
20 // changed).
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
25 // always holding).
26 enum AlertState {
27 kAlertNone = 0, // Obj-C initializes to this.
28 kAlertRising,
29 kAlertHolding,
30 kAlertFalling
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;
37 } // namespace tabs
39 @class TabController, TabWindowController, GTMFadeTruncatingTextFieldCell;
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 {
46 @private
47 TabController* controller_;
48 base::scoped_nsobject<NSTextField> titleView_;
49 GTMFadeTruncatingTextFieldCell* titleViewCell_; // weak
51 // TODO(rohitrao): Add this button to a CoreAnimation layer so we can fade it
52 // in and out on mouseovers.
53 HoverCloseButton* closeButton_; // Weak.
55 BOOL closing_;
57 BOOL isMouseInside_; // Is the mouse hovering over?
58 tabs::AlertState alertState_;
60 CGFloat hoverAlpha_; // How strong the hover glow is.
61 NSTimeInterval hoverHoldEndTime_; // When the hover glow will begin dimming.
63 CGFloat alertAlpha_; // How strong the alert glow is.
64 NSTimeInterval alertHoldEndTime_; // When the hover glow will begin dimming.
66 NSTimeInterval lastGlowUpdate_; // Time either glow was last updated.
68 NSPoint hoverPoint_; // Current location of hover in view coords.
70 // The location of the current mouseDown event in window coordinates.
71 NSPoint mouseDownPoint_;
73 NSCellStateValue state_;
75 // The tool tip text for this tab view.
76 base::scoped_nsobject<NSString> toolTipText_;
78 // A one-element mask image cache. This cache makes drawing roughly 16%
79 // faster.
80 base::ScopedCFTypeRef<CGImageRef> maskCache_;
81 CGFloat maskCacheWidth_;
82 CGFloat maskCacheScale_;
85 @property(retain, nonatomic) NSString* title;
86 @property(assign, nonatomic) NSRect titleFrame;
87 @property(retain, nonatomic) NSColor* titleColor;
88 @property(assign, nonatomic) BOOL titleHidden;
90 // The state affects how the tab will be drawn.
91 // NSOnState -> active
92 // NSMixedState -> selected
93 // NSOffState -> none
94 @property(assign, nonatomic) NSCellStateValue state;
96 @property(assign, nonatomic) CGFloat hoverAlpha;
97 @property(assign, nonatomic) CGFloat alertAlpha;
99 // Determines if the tab is in the process of animating closed. It may still
100 // be visible on-screen, but should not respond to/initiate any events. Upon
101 // setting to NO, clears the target/action of the close button to prevent
102 // clicks inside it from sending messages.
103 @property(assign, nonatomic, getter=isClosing) BOOL closing;
105 // Designated initializer.
106 - (id)initWithFrame:(NSRect)frame
107 controller:(TabController*)controller
108 closeButton:(HoverCloseButton*)closeButton;
110 // Returns the inset multiplier used to compute the inset of the top of the tab.
111 + (CGFloat)insetMultiplier;
113 // Enables/Disables tracking regions for the tab.
114 - (void)setTrackingEnabled:(BOOL)enabled;
116 // Begin showing an "alert" glow (shown to call attention to an unselected
117 // pinned tab whose title changed).
118 - (void)startAlert;
120 // Stop showing the "alert" glow; this won't immediately wipe out any glow, but
121 // will make it fade away.
122 - (void)cancelAlert;
124 // Returns the tool tip text for this tab view.
125 - (NSString*)toolTipText;
127 @end
129 // The TabController |controller_| is not the only owner of this view. If the
130 // controller is released before this view, then we could be hanging onto a
131 // garbage pointer. To prevent this, the TabController uses this interface to
132 // clear the |controller_| pointer when it is dying.
133 @interface TabView (TabControllerInterface)
134 - (void)setController:(TabController*)controller;
135 @end
137 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_