Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tabs / tab_strip_controller.h
blob86e01bd25c62ac7b870870210a975a8b4a59595c
1 // Copyright (c) 2012 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_STRIP_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h"
13 #import "chrome/browser/ui/cocoa/url_drop_target.h"
14 #include "chrome/browser/ui/tabs/hover_tab_selector.h"
16 @class CrTrackingArea;
17 @class NewTabButton;
18 @class TabContentsController;
19 @class TabView;
20 @class TabStripDragController;
21 @class TabStripView;
23 class Browser;
24 class TabStripModelObserverBridge;
25 class TabStripModel;
27 namespace content {
28 class WebContents;
31 // The interface for the tab strip controller's delegate.
32 // Delegating TabStripModelObserverBridge's events (in lieu of directly
33 // subscribing to TabStripModelObserverBridge events, as TabStripController
34 // does) is necessary to guarantee a proper order of subviews layout updates,
35 // otherwise it might trigger unnesessary content relayout, UI flickering etc.
36 @protocol TabStripControllerDelegate
38 // Stripped down version of TabStripModelObserverBridge:selectTabWithContents.
39 - (void)onActivateTabWithContents:(content::WebContents*)contents;
41 // Stripped down version of TabStripModelObserverBridge:tabChangedWithContents.
42 - (void)onTabChanged:(TabStripModelObserver::TabChangeType)change
43 withContents:(content::WebContents*)contents;
45 // Stripped down version of TabStripModelObserverBridge:tabDetachedWithContents.
46 - (void)onTabDetachedWithContents:(content::WebContents*)contents;
48 @end
50 // A class that handles managing the tab strip in a browser window. It uses
51 // a supporting C++ bridge object to register for notifications from the
52 // TabStripModel. The Obj-C part of this class handles drag and drop and all
53 // the other Cocoa-y aspects.
55 // For a full description of the design, see
56 // http://www.chromium.org/developers/design-documents/tab-strip-mac
57 @interface TabStripController :
58 NSObject<TabControllerTarget,
59 URLDropTargetController> {
60 @private
61 base::scoped_nsobject<TabStripView> tabStripView_;
62 NSView* switchView_; // weak
63 base::scoped_nsobject<NSView> dragBlockingView_; // avoid bad window server
64 // drags
65 NewTabButton* newTabButton_; // weak, obtained from the nib.
67 // The controller that manages all the interactions of dragging tabs.
68 base::scoped_nsobject<TabStripDragController> dragController_;
70 // Tracks the newTabButton_ for rollovers.
71 base::scoped_nsobject<CrTrackingArea> newTabTrackingArea_;
72 scoped_ptr<TabStripModelObserverBridge> bridge_;
73 Browser* browser_; // weak
74 TabStripModel* tabStripModel_; // weak
75 // Delegate that is informed about tab state changes.
76 id<TabStripControllerDelegate> delegate_; // weak
78 // YES if the new tab button is currently displaying the hover image (if the
79 // mouse is currently over the button).
80 BOOL newTabButtonShowingHoverImage_;
82 // Access to the TabContentsControllers (which own the parent view
83 // for the toolbar and associated tab contents) given an index. Call
84 // |indexFromModelIndex:| to convert a |tabStripModel_| index to a
85 // |tabContentsArray_| index. Do NOT assume that the indices of
86 // |tabStripModel_| and this array are identical, this is e.g. not true while
87 // tabs are animating closed (closed tabs are removed from |tabStripModel_|
88 // immediately, but from |tabContentsArray_| only after their close animation
89 // has completed).
90 base::scoped_nsobject<NSMutableArray> tabContentsArray_;
91 // An array of TabControllers which manage the actual tab views. See note
92 // above |tabContentsArray_|. |tabContentsArray_| and |tabArray_| always
93 // contain objects belonging to the same tabs at the same indices.
94 base::scoped_nsobject<NSMutableArray> tabArray_;
96 // Set of TabControllers that are currently animating closed.
97 base::scoped_nsobject<NSMutableSet> closingControllers_;
99 // These values are only used during a drag, and override tab positioning.
100 TabView* placeholderTab_; // weak. Tab being dragged
101 NSRect placeholderFrame_; // Frame to use
102 NSRect droppedTabFrame_; // Initial frame of a dropped tab, for animation.
103 // Frame targets for all the current views.
104 // target frames are used because repeated requests to [NSView animator].
105 // aren't coalesced, so we store frames to avoid redundant calls.
106 base::scoped_nsobject<NSMutableDictionary> targetFrames_;
107 NSRect newTabTargetFrame_;
108 // If YES, do not show the new tab button during layout.
109 BOOL forceNewTabButtonHidden_;
110 // YES if we've successfully completed the initial layout. When this is
111 // NO, we probably don't want to do any animation because we're just coming
112 // into being.
113 BOOL initialLayoutComplete_;
115 // Width available for resizing the tabs (doesn't include the new tab
116 // button). Used to restrict the available width when closing many tabs at
117 // once to prevent them from resizing to fit the full width. If the entire
118 // width should be used, this will have a value of |kUseFullAvailableWidth|.
119 float availableResizeWidth_;
120 // A tracking area that's the size of the tab strip used to be notified
121 // when the mouse moves in the tab strip
122 base::scoped_nsobject<CrTrackingArea> trackingArea_;
123 TabView* hoveredTab_; // weak. Tab that the mouse is hovering over
125 // Array of subviews which are permanent (and which should never be removed),
126 // such as the new-tab button, but *not* the tabs themselves.
127 base::scoped_nsobject<NSMutableArray> permanentSubviews_;
129 // The default favicon, so we can use one copy for all buttons.
130 base::scoped_nsobject<NSImage> defaultFavicon_;
132 // The amount by which to indent the tabs on the sides (to make room for the
133 // red/yellow/green and incognito/fullscreen buttons).
134 CGFloat leftIndentForControls_;
135 CGFloat rightIndentForControls_;
137 // Is the mouse currently inside the strip;
138 BOOL mouseInside_;
140 // Helper for performing tab selection as a result of dragging over a tab.
141 scoped_ptr<HoverTabSelector> hoverTabSelector_;
144 @property(nonatomic) CGFloat leftIndentForControls;
145 @property(nonatomic) CGFloat rightIndentForControls;
147 // Initialize the controller with a view and browser that contains
148 // everything else we'll need. |switchView| is the view whose contents get
149 // "switched" every time the user switches tabs. The children of this view
150 // will be released, so if you want them to stay around, make sure
151 // you have retained them.
152 // |delegate| is the one listening to filtered TabStripModelObserverBridge's
153 // events (see TabStripControllerDelegate for more details).
154 - (id)initWithView:(TabStripView*)view
155 switchView:(NSView*)switchView
156 browser:(Browser*)browser
157 delegate:(id<TabStripControllerDelegate>)delegate;
159 // Returns the model behind this controller.
160 - (TabStripModel*)tabStripModel;
162 // Return the view for the currently active tab.
163 - (NSView*)activeTabView;
165 // Set the frame of the active tab, also updates the internal frame dict.
166 - (void)setFrameOfActiveTab:(NSRect)frame;
168 // Move the given tab at index |from| in this window to the location of the
169 // current placeholder.
170 - (void)moveTabFromIndex:(NSInteger)from;
172 // Drop a given WebContents at the location of the current placeholder.
173 // If there is no placeholder, it will go at the end. Used when dragging from
174 // another window when we don't have access to the WebContents as part of our
175 // strip. |frame| is in the coordinate system of the tab strip view and
176 // represents where the user dropped the new tab so it can be animated into its
177 // correct location when the tab is added to the model. If the tab was pinned in
178 // its previous window, setting |pinned| to YES will propagate that state to the
179 // new window. Mini-tabs are either app or pinned tabs; the app state is stored
180 // by the |contents|, but the |pinned| state is the caller's responsibility.
181 - (void)dropWebContents:(content::WebContents*)contents
182 withFrame:(NSRect)frame
183 asPinnedTab:(BOOL)pinned;
185 // Returns the index of the subview |view|. Returns -1 if not present. Takes
186 // closing tabs into account such that this index will correctly match the tab
187 // model. If |view| is in the process of closing, returns -1, as closing tabs
188 // are no longer in the model.
189 - (NSInteger)modelIndexForTabView:(NSView*)view;
191 // Return the view at a given index.
192 - (NSView*)viewAtIndex:(NSUInteger)index;
194 // Return the number of tab views in the tab strip. It's same as number of tabs
195 // in the model, except when a tab is closing, which will be counted in views
196 // count, but no longer in the model.
197 - (NSUInteger)viewsCount;
199 // Set the placeholder for a dragged tab, allowing the |frame| to be specified.
200 // This causes this tab to be rendered in an arbitrary position.
201 - (void)insertPlaceholderForTab:(TabView*)tab frame:(NSRect)frame;
203 // Returns whether a tab is being dragged within the tab strip.
204 - (BOOL)isDragSessionActive;
206 // Returns whether or not |tab| can still be fully seen in the tab strip or if
207 // its current position would cause it be obscured by things such as the edge
208 // of the window or the window decorations. Returns YES only if the entire tab
209 // is visible.
210 - (BOOL)isTabFullyVisible:(TabView*)tab;
212 // Show or hide the new tab button. The button is hidden immediately, but
213 // waits until the next call to |-layoutTabs| to show it again.
214 - (void)showNewTabButton:(BOOL)show;
216 // Force the tabs to rearrange themselves to reflect the current model.
217 - (void)layoutTabs;
218 - (void)layoutTabsWithoutAnimation;
220 // Are we in rapid (tab) closure mode? I.e., is a full layout deferred (while
221 // the user closes tabs)? Needed to overcome missing clicks during rapid tab
222 // closure.
223 - (BOOL)inRapidClosureMode;
225 // Returns YES if the user is allowed to drag tabs on the strip at this moment.
226 // For example, this returns NO if there are any pending tab close animtations.
227 - (BOOL)tabDraggingAllowed;
229 // Default height for tabs.
230 + (CGFloat)defaultTabHeight;
232 // Default indentation for tabs (see |leftIndentForControls_|).
233 + (CGFloat)defaultLeftIndentForControls;
235 // Returns the currently active TabContentsController.
236 - (TabContentsController*)activeTabContentsController;
238 @end
240 @interface TabStripController(TestingAPI)
241 - (void)setTabTitle:(TabController*)tab
242 withContents:(content::WebContents*)contents;
243 @end
245 // Returns the parent view to use when showing a sheet for a given web contents.
246 NSView* GetSheetParentViewForWebContents(content::WebContents* web_contents);
248 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_CONTROLLER_H_