• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TABS_TAB_VIEW_H_
6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_
7 
8 #include <ApplicationServices/ApplicationServices.h>
9 #import <Cocoa/Cocoa.h>
10 
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 
15 namespace tabs {
16 
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).
21 
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
31 };
32 
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;
36 
37 }  // namespace tabs
38 
39 @class TabController, TabWindowController;
40 
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.
44 
45 @interface TabView : NSView {
46  @private
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.
51 
52   BOOL closing_;
53 
54   BOOL isMouseInside_;  // Is the mouse hovering over?
55   tabs::AlertState alertState_;
56 
57   CGFloat hoverAlpha_;  // How strong the hover glow is.
58   NSTimeInterval hoverHoldEndTime_;  // When the hover glow will begin dimming.
59 
60   CGFloat alertAlpha_;  // How strong the alert glow is.
61   NSTimeInterval alertHoldEndTime_;  // When the hover glow will begin dimming.
62 
63   NSTimeInterval lastGlowUpdate_;  // Time either glow was last updated.
64 
65   NSPoint hoverPoint_;  // Current location of hover in view coords.
66 
67   // The location of the current mouseDown event in window coordinates.
68   NSPoint mouseDownPoint_;
69 
70   NSCellStateValue state_;
71 
72   // The tool tip text for this tab view.
73   base::scoped_nsobject<NSString> toolTipText_;
74 
75   // A one-element mask image cache.  This cache makes drawing roughly 16%
76   // faster.
77   base::ScopedCFTypeRef<CGImageRef> maskCache_;
78   CGFloat maskCacheWidth_;
79   CGFloat maskCacheScale_;
80 }
81 
82 @property(assign, nonatomic) NSCellStateValue state;
83 @property(assign, nonatomic) CGFloat hoverAlpha;
84 @property(assign, nonatomic) CGFloat alertAlpha;
85 
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;
91 
92 // Designated initializer.
93 - (id)initWithFrame:(NSRect)frame
94          controller:(TabController*)controller
95         closeButton:(HoverCloseButton*)closeButton;
96 
97 // Returns the inset multiplier used to compute the inset of the top of the tab.
98 + (CGFloat)insetMultiplier;
99 
100 // Enables/Disables tracking regions for the tab.
101 - (void)setTrackingEnabled:(BOOL)enabled;
102 
103 // Begin showing an "alert" glow (shown to call attention to an unselected
104 // pinned tab whose title changed).
105 - (void)startAlert;
106 
107 // Stop showing the "alert" glow; this won't immediately wipe out any glow, but
108 // will make it fade away.
109 - (void)cancelAlert;
110 
111 // Returns the tool tip text for this tab view.
112 - (NSString*)toolTipText;
113 
114 @end
115 
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;
122 @end
123 
124 #endif  // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_
125