mac: Use a full-size content view (reland 1).
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tabs / tab_window_controller.h
blob1c4e9e1b92a03116c967c8f7af536aaf75fd37bd
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_WINDOW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_WINDOW_CONTROLLER_H_
8 // A class acting as the Objective-C window controller for a window that has
9 // tabs which can be dragged around. Tabs can be re-arranged within the same
10 // window or dragged into other TabWindowController windows. This class doesn't
11 // know anything about the actual tab implementation or model, as that is fairly
12 // application-specific. It only provides an API to be overridden by subclasses
13 // to fill in the details.
15 #import <Cocoa/Cocoa.h>
17 #include "base/mac/scoped_nsobject.h"
19 @class FastResizeView;
20 @class FocusTracker;
21 @class TabStripView;
22 @class TabView;
24 @interface TabWindowController : NSWindowController<NSWindowDelegate> {
25 @private
26 // Wrapper view around web content, and the developer tools view.
27 base::scoped_nsobject<FastResizeView> tabContentArea_;
28 base::scoped_nsobject<NSView> tabStripBackgroundView_;
30 // The tab strip overlaps the titlebar of the window.
31 base::scoped_nsobject<TabStripView> tabStripView_;
33 // No views should be added directly to the root view. Views that overlap
34 // the title bar should be added to the window's contentView. All other views
35 // should be added to chromeContentView_. This allows tab dragging and
36 // fullscreen logic to easily move the views that don't need special
37 // treatment.
38 base::scoped_nsobject<NSView> chromeContentView_;
40 // The child window used during dragging to achieve the opacity tricks.
41 NSWindow* overlayWindow_;
43 // The contentView of the original window that is moved (for the duration
44 // of the drag) to the |overlayWindow_|.
45 NSView* originalContentView_; // weak
47 base::scoped_nsobject<FocusTracker> focusBeforeOverlay_;
48 BOOL closeDeferred_; // If YES, call performClose: in removeOverlay:.
50 @property(readonly, nonatomic) NSView* tabStripBackgroundView;
51 @property(readonly, nonatomic) TabStripView* tabStripView;
52 @property(readonly, nonatomic) FastResizeView* tabContentArea;
53 @property(readonly, nonatomic) NSView* chromeContentView;
55 // This is the designated initializer for this class.
56 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip;
58 // Used during tab dragging to turn on/off the overlay window when a tab
59 // is torn off. If -deferPerformClose (below) is used, -removeOverlay will
60 // cause the controller to be autoreleased before returning.
61 - (void)showOverlay;
62 - (void)removeOverlay;
63 - (NSWindow*)overlayWindow;
65 // Returns YES if it is ok to constrain the window's frame to fit the screen.
66 - (BOOL)shouldConstrainFrameRect;
68 // A collection of methods, stubbed out in this base class, that provide
69 // the implementation of tab dragging based on whatever model is most
70 // appropriate.
72 // Layout the tabs based on the current ordering of the model.
73 - (void)layoutTabs;
75 // Creates a new window by pulling the given tabs out and placing it in
76 // the new window. Returns the controller for the new window. The size of the
77 // new window will be the same size as this window.
78 - (TabWindowController*)detachTabsToNewWindow:(NSArray*)tabViews
79 draggedTab:(NSView*)draggedTab;
81 // Make room in the tab strip for |tab| at the given x coordinate. Will hide the
82 // new tab button while there's a placeholder. Subclasses need to call the
83 // superclass implementation.
84 - (void)insertPlaceholderForTab:(TabView*)tab frame:(NSRect)frame;
86 // Removes the placeholder installed by |-insertPlaceholderForTab:atLocation:|
87 // and restores the new tab button. Subclasses need to call the superclass
88 // implementation.
89 - (void)removePlaceholder;
91 // Returns whether one of the window's tabs is being dragged.
92 - (BOOL)isDragSessionActive;
94 // The follow return YES if tab dragging/tab tearing (off the tab strip)/window
95 // movement is currently allowed. Any number of things can choose to disable it,
96 // such as pending animations. The default implementations always return YES.
97 // Subclasses should override as appropriate.
98 - (BOOL)tabDraggingAllowed;
99 - (BOOL)tabTearingAllowed;
100 - (BOOL)windowMovementAllowed;
102 // Show or hide the new tab button. The button is hidden immediately, but
103 // waits until the next call to |-layoutTabs| to show it again.
104 - (void)showNewTabButton:(BOOL)show;
106 // Returns whether or not |tab| can still be fully seen in the tab strip or if
107 // its current position would cause it be obscured by things such as the edge
108 // of the window or the window decorations. Returns YES only if the entire tab
109 // is visible. The default implementation always returns YES.
110 - (BOOL)isTabFullyVisible:(TabView*)tab;
112 // Called to check if the receiver can receive dragged tabs from
113 // source. Return YES if so. The default implementation returns NO.
114 - (BOOL)canReceiveFrom:(TabWindowController*)source;
116 // Move given tab views to the location of the current placeholder. If there is
117 // no placeholder, it will go at the end. |controller| is the window controller
118 // of a tab being dropped from a different window. It will be nil if the drag is
119 // within the window, otherwise the tab is removed from that window before being
120 // placed into this one. The implementation will call |-removePlaceholder| since
121 // the drag is now complete. This also calls |-layoutTabs| internally so
122 // clients do not need to call it again.
123 - (void)moveTabViews:(NSArray*)views
124 fromController:(TabWindowController*)controller;
126 // Number of tabs in the tab strip. Useful, for example, to know if we're
127 // dragging the only tab in the window. This includes pinned tabs (both live
128 // and not).
129 - (NSInteger)numberOfTabs;
131 // YES if there are tabs in the tab strip which have content, allowing for
132 // the notion of tabs in the tab strip that are placeholders but currently have
133 // no content.
134 - (BOOL)hasLiveTabs;
136 // Returns all tab views.
137 - (NSArray*)tabViews;
139 // Return the view of the active tab.
140 - (NSView*)activeTabView;
142 // The title of the active tab.
143 - (NSString*)activeTabTitle;
145 // Called to check whether or not this controller's window has a tab strip (YES
146 // if it does, NO otherwise). The default implementation returns YES.
147 - (BOOL)hasTabStrip;
149 // Gets whether a particular tab is draggable between windows.
150 - (BOOL)isTabDraggable:(NSView*)tabView;
152 // Tell the window that it needs to call performClose: as soon as the current
153 // drag is complete. This prevents a window (and its overlay) from going away
154 // during a drag.
155 - (void)deferPerformClose;
157 // There are 2 view hierarchy constraints that must be enforced:
158 // - The tab strip must be above the content view.
159 // - The tab strip must be below the traffic lights.
160 // AppKit does not enforce these constraints, because it assumes that Chrome
161 // does not mess with the NSThemeFrame. Chrome must manually enforce these
162 // constraints.
164 // Immediately after creation of the window, or after the window's content view
165 // is changed, the content view must be moved to the back.
166 - (void)moveContentViewToBack:(NSView*)contentView;
168 // The tab strip should always be inserted directly above the content view.
169 - (void)insertTabStripView:(NSView*)tabStripView intoWindow:(NSWindow*)window;
171 // The tab strip background view should always be inserted as the back-most
172 // subview of the root view. It cannot be a subview of the contentView, as that
173 // would cause it to become layer backed, which would cause it to draw on top
174 // of non-layer backed content like the window controls.
175 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window;
177 @end
179 @interface TabWindowController(ProtectedMethods)
180 // Tells the tab strip to forget about this tab in preparation for it being
181 // put into a different tab strip, such as during a drop on another window.
182 - (void)detachTabView:(NSView*)view;
184 // Called when the size of the window content area has changed. Override to
185 // position specific views. Base class implementation does nothing.
186 - (void)layoutSubviews;
187 @end
189 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_WINDOW_CONTROLLER_H_