OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 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_TAB_VIEW_H_ | |
6 #define CHROME_BROWSER_UI_COCOA_TAB_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #import <Cocoa/Cocoa.h> | |
10 #include <ApplicationServices/ApplicationServices.h> | |
11 | |
12 #include <map> | |
13 | |
14 #include "base/scoped_nsobject.h" | |
15 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | |
16 #import "chrome/browser/ui/cocoa/hover_close_button.h" | |
17 | |
18 namespace tabs { | |
19 | |
20 // Nomenclature: | |
21 // Tabs _glow_ under two different circumstances, when they are _hovered_ (by | |
22 // the mouse) and when they are _alerted_ (to show that the tab's title has | |
23 // changed). | |
24 | |
25 // The state of alerting (to show a title change on an unselected, pinned tab). | |
26 // This is more complicated than a simple on/off since we want to allow the | |
27 // alert glow to go through a full rise-hold-fall cycle to avoid flickering (or | |
28 // always holding). | |
29 enum AlertState { | |
30 kAlertNone = 0, // Obj-C initializes to this. | |
31 kAlertRising, | |
32 kAlertHolding, | |
33 kAlertFalling | |
34 }; | |
35 | |
36 } // namespace tabs | |
37 | |
38 @class TabController, TabWindowController; | |
39 | |
40 // A view that handles the event tracking (clicking and dragging) for a tab | |
41 // on the tab strip. Relies on an associated TabController to provide a | |
42 // target/action for selecting the tab. | |
43 | |
44 @interface TabView : BackgroundGradientView { | |
45 @private | |
46 IBOutlet TabController* controller_; | |
47 // TODO(rohitrao): Add this button to a CoreAnimation layer so we can fade it | |
48 // in and out on mouseovers. | |
49 IBOutlet HoverCloseButton* closeButton_; | |
50 | |
51 // See awakeFromNib for purpose. | |
52 scoped_nsobject<HoverCloseButton> closeButtonRetainer_; | |
53 | |
54 BOOL closing_; | |
55 | |
56 // Tracking area for close button mouseover images. | |
57 scoped_nsobject<NSTrackingArea> closeTrackingArea_; | |
58 | |
59 BOOL isMouseInside_; // Is the mouse hovering over? | |
60 tabs::AlertState alertState_; | |
61 | |
62 CGFloat hoverAlpha_; // How strong the hover glow is. | |
63 NSTimeInterval hoverHoldEndTime_; // When the hover glow will begin dimming. | |
64 | |
65 CGFloat alertAlpha_; // How strong the alert glow is. | |
66 NSTimeInterval alertHoldEndTime_; // When the hover glow will begin dimming. | |
67 | |
68 NSTimeInterval lastGlowUpdate_; // Time either glow was last updated. | |
69 | |
70 NSPoint hoverPoint_; // Current location of hover in view coords. | |
71 | |
72 // All following variables are valid for the duration of a drag. | |
73 // These are released on mouseUp: | |
74 BOOL moveWindowOnDrag_; // Set if the only tab of a window is dragged. | |
75 BOOL tabWasDragged_; // Has the tab been dragged? | |
76 BOOL draggingWithinTabStrip_; // Did drag stay in the current tab strip? | |
77 BOOL chromeIsVisible_; | |
78 | |
79 NSTimeInterval tearTime_; // Time since tear happened | |
80 NSPoint tearOrigin_; // Origin of the tear rect | |
81 NSPoint dragOrigin_; // Origin point of the drag | |
82 // TODO(alcor): these references may need to be strong to avoid crashes | |
83 // due to JS closing windows | |
84 TabWindowController* sourceController_; // weak. controller starting the drag | |
85 NSWindow* sourceWindow_; // weak. The window starting the drag | |
86 NSRect sourceWindowFrame_; | |
87 NSRect sourceTabFrame_; | |
88 | |
89 TabWindowController* draggedController_; // weak. Controller being dragged. | |
90 NSWindow* dragWindow_; // weak. The window being dragged | |
91 NSWindow* dragOverlay_; // weak. The overlay being dragged | |
92 // Cache workspace IDs per-drag because computing them on 10.5 with | |
93 // CGWindowListCreateDescriptionFromArray is expensive. | |
94 // resetDragControllers clears this cache. | |
95 // | |
96 // TODO(davidben): When 10.5 becomes unsupported, remove this. | |
97 std::map<CGWindowID, int> workspaceIDCache_; | |
98 | |
99 TabWindowController* targetController_; // weak. Controller being targeted | |
100 NSCellStateValue state_; | |
101 } | |
102 | |
103 @property(assign, nonatomic) NSCellStateValue state; | |
104 @property(assign, nonatomic) CGFloat hoverAlpha; | |
105 @property(assign, nonatomic) CGFloat alertAlpha; | |
106 | |
107 // Determines if the tab is in the process of animating closed. It may still | |
108 // be visible on-screen, but should not respond to/initiate any events. Upon | |
109 // setting to NO, clears the target/action of the close button to prevent | |
110 // clicks inside it from sending messages. | |
111 @property(assign, nonatomic, getter=isClosing) BOOL closing; | |
112 | |
113 // Enables/Disables tracking regions for the tab. | |
114 - (void)setTrackingEnabled:(BOOL)enabled; | |
115 | |
116 // Begin showing an "alert" glow (shown to call attention to an unselected | |
117 // pinned tab whose title changed). | |
118 - (void)startAlert; | |
119 | |
120 // Stop showing the "alert" glow; this won't immediately wipe out any glow, but | |
121 // will make it fade away. | |
122 - (void)cancelAlert; | |
123 | |
124 @end | |
125 | |
126 // The TabController |controller_| is not the only owner of this view. If the | |
127 // controller is released before this view, then we could be hanging onto a | |
128 // garbage pointer. To prevent this, the TabController uses this interface to | |
129 // clear the |controller_| pointer when it is dying. | |
130 @interface TabView (TabControllerInterface) | |
131 - (void)setController:(TabController*)controller; | |
132 @end | |
133 | |
134 #endif // CHROME_BROWSER_UI_COCOA_TAB_VIEW_H_ | |
OLD | NEW |