Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tabs / tab_view.h
blobb4605a6477193af6d949e0ed11207f1ada9c1101
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"
14 #import "chrome/browser/ui/cocoa/themed_window.h"
16 namespace tabs {
18 // Nomenclature:
19 // Tabs _glow_ under two different circumstances, when they are _hovered_ (by
20 // the mouse) and when they are _alerted_ (to show that the tab's title has
21 // changed).
23 // The state of alerting (to show a title change on an unselected, pinned tab).
24 // This is more complicated than a simple on/off since we want to allow the
25 // alert glow to go through a full rise-hold-fall cycle to avoid flickering (or
26 // always holding).
27 enum AlertState {
28 kAlertNone = 0, // Obj-C initializes to this.
29 kAlertRising,
30 kAlertHolding,
31 kAlertFalling
34 // When the window doesn't have focus then we want to draw the button with a
35 // slightly lighter color. We do this by just reducing the alpha.
36 const CGFloat kImageNoFocusAlpha = 0.65;
38 } // namespace tabs
40 @class TabController, TabWindowController, GTMFadeTruncatingTextFieldCell;
42 // A view that handles the event tracking (clicking and dragging) for a tab
43 // on the tab strip. Relies on an associated TabController to provide a
44 // target/action for selecting the tab.
46 @interface TabView : NSView<ThemedWindowDrawing> {
47 @private
48 TabController* controller_;
49 base::scoped_nsobject<NSTextField> titleView_;
50 GTMFadeTruncatingTextFieldCell* titleViewCell_; // weak
52 // TODO(rohitrao): Add this button to a CoreAnimation layer so we can fade it
53 // in and out on mouseovers.
54 HoverCloseButton* closeButton_; // Weak.
56 BOOL closing_;
58 BOOL isMouseInside_; // Is the mouse hovering over?
59 tabs::AlertState alertState_;
61 CGFloat hoverAlpha_; // How strong the hover glow is.
62 NSTimeInterval hoverHoldEndTime_; // When the hover glow will begin dimming.
64 CGFloat alertAlpha_; // How strong the alert glow is.
65 NSTimeInterval alertHoldEndTime_; // When the hover glow will begin dimming.
67 NSTimeInterval lastGlowUpdate_; // Time either glow was last updated.
69 NSPoint hoverPoint_; // Current location of hover in view coords.
71 // The location of the current mouseDown event in window coordinates.
72 NSPoint mouseDownPoint_;
74 NSCellStateValue state_;
76 // The tool tip text for this tab view.
77 base::scoped_nsobject<NSString> toolTipText_;
80 @property(retain, nonatomic) NSString* title;
81 @property(assign, nonatomic) NSRect titleFrame;
82 @property(retain, nonatomic) NSColor* titleColor;
83 @property(assign, nonatomic) BOOL titleHidden;
85 // The state affects how the tab will be drawn.
86 // NSOnState -> active
87 // NSMixedState -> selected
88 // NSOffState -> none
89 @property(assign, nonatomic) NSCellStateValue state;
91 @property(assign, nonatomic) CGFloat hoverAlpha;
92 @property(assign, nonatomic) CGFloat alertAlpha;
94 // Determines if the tab is in the process of animating closed. It may still
95 // be visible on-screen, but should not respond to/initiate any events. Upon
96 // setting to NO, clears the target/action of the close button to prevent
97 // clicks inside it from sending messages.
98 @property(assign, nonatomic, getter=isClosing) BOOL closing;
100 // The tool tip text for this tab view.
101 @property(copy, nonatomic) NSString* toolTipText;
103 // Designated initializer.
104 - (id)initWithFrame:(NSRect)frame
105 controller:(TabController*)controller
106 closeButton:(HoverCloseButton*)closeButton;
108 // Enables/Disables tracking regions for the tab.
109 - (void)setTrackingEnabled:(BOOL)enabled;
111 // Begin showing an "alert" glow (shown to call attention to an unselected
112 // pinned tab whose title changed).
113 - (void)startAlert;
115 // Stop showing the "alert" glow; this won't immediately wipe out any glow, but
116 // will make it fade away.
117 - (void)cancelAlert;
119 // Returns the width of the largest part of the tab that is available for the
120 // user to click to select/activate the tab.
121 - (int)widthOfLargestSelectableRegion;
123 @end
125 // The TabController |controller_| is not the only owner of this view. If the
126 // controller is released before this view, then we could be hanging onto a
127 // garbage pointer. To prevent this, the TabController uses this interface to
128 // clear the |controller_| pointer when it is dying.
129 @interface TabView (TabControllerInterface)
130 - (void)setController:(TabController*)controller;
131 @end
133 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_