• 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 #pragma once
8 
9 #import <Cocoa/Cocoa.h>
10 #include <ApplicationServices/ApplicationServices.h>
11 
12 #include <map>
13 
14 #include "base/memory/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   BOOL closing_;
52 
53   // Tracking area for close button mouseover images.
54   scoped_nsobject<NSTrackingArea> closeTrackingArea_;
55 
56   BOOL isMouseInside_;  // Is the mouse hovering over?
57   tabs::AlertState alertState_;
58 
59   CGFloat hoverAlpha_;  // How strong the hover glow is.
60   NSTimeInterval hoverHoldEndTime_;  // When the hover glow will begin dimming.
61 
62   CGFloat alertAlpha_;  // How strong the alert glow is.
63   NSTimeInterval alertHoldEndTime_;  // When the hover glow will begin dimming.
64 
65   NSTimeInterval lastGlowUpdate_;  // Time either glow was last updated.
66 
67   NSPoint hoverPoint_;  // Current location of hover in view coords.
68 
69   // All following variables are valid for the duration of a drag.
70   // These are released on mouseUp:
71   BOOL moveWindowOnDrag_;  // Set if the only tab of a window is dragged.
72   BOOL tabWasDragged_;  // Has the tab been dragged?
73   BOOL draggingWithinTabStrip_;  // Did drag stay in the current tab strip?
74   BOOL chromeIsVisible_;
75 
76   NSTimeInterval tearTime_;  // Time since tear happened
77   NSPoint tearOrigin_;  // Origin of the tear rect
78   NSPoint dragOrigin_;  // Origin point of the drag
79   // TODO(alcor): these references may need to be strong to avoid crashes
80   // due to JS closing windows
81   TabWindowController* sourceController_;  // weak. controller starting the drag
82   NSWindow* sourceWindow_;  // weak. The window starting the drag
83   NSRect sourceWindowFrame_;
84   NSRect sourceTabFrame_;
85 
86   TabWindowController* draggedController_;  // weak. Controller being dragged.
87   NSWindow* dragWindow_;  // weak. The window being dragged
88   NSWindow* dragOverlay_;  // weak. The overlay being dragged
89   // Cache workspace IDs per-drag because computing them on 10.5 with
90   // CGWindowListCreateDescriptionFromArray is expensive.
91   // resetDragControllers clears this cache.
92   //
93   // TODO(davidben): When 10.5 becomes unsupported, remove this.
94   std::map<CGWindowID, int> workspaceIDCache_;
95 
96   TabWindowController* targetController_;  // weak. Controller being targeted
97   NSCellStateValue state_;
98 }
99 
100 @property(assign, nonatomic) NSCellStateValue state;
101 @property(assign, nonatomic) CGFloat hoverAlpha;
102 @property(assign, nonatomic) CGFloat alertAlpha;
103 
104 // Determines if the tab is in the process of animating closed. It may still
105 // be visible on-screen, but should not respond to/initiate any events. Upon
106 // setting to NO, clears the target/action of the close button to prevent
107 // clicks inside it from sending messages.
108 @property(assign, nonatomic, getter=isClosing) BOOL closing;
109 
110 // Enables/Disables tracking regions for the tab.
111 - (void)setTrackingEnabled:(BOOL)enabled;
112 
113 // Begin showing an "alert" glow (shown to call attention to an unselected
114 // pinned tab whose title changed).
115 - (void)startAlert;
116 
117 // Stop showing the "alert" glow; this won't immediately wipe out any glow, but
118 // will make it fade away.
119 - (void)cancelAlert;
120 
121 @end
122 
123 // The TabController |controller_| is not the only owner of this view. If the
124 // controller is released before this view, then we could be hanging onto a
125 // garbage pointer. To prevent this, the TabController uses this interface to
126 // clear the |controller_| pointer when it is dying.
127 @interface TabView (TabControllerInterface)
128 - (void)setController:(TabController*)controller;
129 @end
130 
131 #endif  // CHROME_BROWSER_UI_COCOA_TABS_TAB_VIEW_H_
132