Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / browser_window_controller.h
blob28ee5f71ed9bfaef7ae6ef3211b6c68ce4026f6f
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_BROWSER_WINDOW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_H_
8 // A class acting as the Objective-C controller for the Browser
9 // object. Handles interactions between Cocoa and the cross-platform
10 // code. Each window has a single toolbar and, by virtue of being a
11 // TabWindowController, a tab strip along the top.
13 #import <Cocoa/Cocoa.h>
15 #include "base/mac/scoped_nsobject.h"
16 #include "base/memory/scoped_ptr.h"
17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
19 #import "chrome/browser/ui/cocoa/browser_command_executor.h"
20 #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h"
21 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
22 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
23 #import "chrome/browser/ui/cocoa/themed_window.h"
24 #import "chrome/browser/ui/cocoa/url_drop_target.h"
25 #import "chrome/browser/ui/cocoa/view_resizer.h"
26 #include "ui/gfx/rect.h"
28 @class AvatarButtonController;
29 class Browser;
30 class BrowserWindow;
31 class BrowserWindowCocoa;
32 @class DevToolsController;
33 @class DownloadShelfController;
34 class ExtensionKeybindingRegistryCocoa;
35 @class FindBarCocoaController;
36 @class FullscreenModeController;
37 @class FullscreenWindow;
38 @class InfoBarContainerController;
39 class LocationBarViewMac;
40 @class OverlayableContentsController;
41 @class PresentationModeController;
42 class StatusBubbleMac;
43 @class TabStripController;
44 @class TabStripView;
45 @class ToolbarController;
47 namespace content {
48 class WebContents;
51 @interface BrowserWindowController :
52 TabWindowController<NSUserInterfaceValidations,
53 BookmarkBarControllerDelegate,
54 BrowserCommandExecutor,
55 ViewResizer,
56 TabStripControllerDelegate> {
57 @private
58 // The ordering of these members is important as it determines the order in
59 // which they are destroyed. |browser_| needs to be destroyed last as most of
60 // the other objects hold weak references to it or things it owns
61 // (tab/toolbar/bookmark models, profiles, etc).
62 scoped_ptr<Browser> browser_;
63 NSWindow* savedRegularWindow_;
64 scoped_ptr<BrowserWindowCocoa> windowShim_;
65 base::scoped_nsobject<ToolbarController> toolbarController_;
66 base::scoped_nsobject<TabStripController> tabStripController_;
67 base::scoped_nsobject<FindBarCocoaController> findBarCocoaController_;
68 base::scoped_nsobject<InfoBarContainerController> infoBarContainerController_;
69 base::scoped_nsobject<DownloadShelfController> downloadShelfController_;
70 base::scoped_nsobject<BookmarkBarController> bookmarkBarController_;
71 base::scoped_nsobject<DevToolsController> devToolsController_;
72 base::scoped_nsobject<OverlayableContentsController>
73 overlayableContentsController_;
74 base::scoped_nsobject<PresentationModeController> presentationModeController_;
75 base::scoped_nsobject<FullscreenModeController> fullscreenModeController_;
76 base::scoped_nsobject<FullscreenExitBubbleController>
77 fullscreenExitBubbleController_;
79 // Strong. StatusBubble is a special case of a strong reference that
80 // we don't wrap in a scoped_ptr because it is acting the same
81 // as an NSWindowController in that it wraps a window that must
82 // be shut down before our destructors are called.
83 StatusBubbleMac* statusBubble_;
85 BookmarkBubbleController* bookmarkBubbleController_; // Weak.
86 BOOL initializing_; // YES while we are currently in initWithBrowser:
87 BOOL ownsBrowser_; // Only ever NO when testing
89 // The total amount by which we've grown the window up or down (to display a
90 // bookmark bar and/or download shelf), respectively; reset to 0 when moved
91 // away from the bottom/top or resized (or zoomed).
92 CGFloat windowTopGrowth_;
93 CGFloat windowBottomGrowth_;
95 // YES only if we're shrinking the window from an apparent zoomed state (which
96 // we'll only do if we grew it to the zoomed state); needed since we'll then
97 // restrict the amount of shrinking by the amounts specified above. Reset to
98 // NO on growth.
99 BOOL isShrinkingFromZoomed_;
101 // The raw accumulated zoom value and the actual zoom increments made for an
102 // an in-progress pinch gesture.
103 CGFloat totalMagnifyGestureAmount_;
104 NSInteger currentZoomStepDelta_;
106 // The view controller that manages the incognito badge or the multi-profile
107 // avatar icon. The view is always in the view hierarchy, but will be hidden
108 // unless it's appropriate to show it.
109 base::scoped_nsobject<AvatarButtonController> avatarButtonController_;
111 // Lazily created view which draws the background for the floating set of bars
112 // in presentation mode (for window types having a floating bar; it remains
113 // nil for those which don't).
114 base::scoped_nsobject<NSView> floatingBarBackingView_;
116 // The borderless window used in fullscreen mode. Lion reuses the original
117 // window in fullscreen mode, so this is always nil on Lion.
118 base::scoped_nsobject<NSWindow> fullscreenWindow_;
120 // Tracks whether presentation mode was entered from fullscreen mode or
121 // directly from normal windowed mode. Used to determine what to do when
122 // exiting presentation mode.
123 BOOL enteredPresentationModeFromFullscreen_;
125 // True between -windowWillEnterFullScreen and -windowDidEnterFullScreen.
126 // Only used on Lion and higher.
127 BOOL enteringFullscreen_;
129 // True between |-setPresentationMode:url:bubbleType:| and
130 // -windowDidEnterFullScreen. Only used on Lion and higher.
131 BOOL enteringPresentationMode_;
133 // The size of the original (non-fullscreen) window. This is saved just
134 // before entering fullscreen mode and is only valid when |-isFullscreen|
135 // returns YES.
136 NSRect savedRegularWindowFrame_;
138 // The proportion of the floating bar which is shown (in presentation mode).
139 CGFloat floatingBarShownFraction_;
141 // Various UI elements/events may want to ensure that the floating bar is
142 // visible (in presentation mode), e.g., because of where the mouse is or
143 // where keyboard focus is. Whenever an object requires bar visibility, it has
144 // itself added to |barVisibilityLocks_|. When it no longer requires bar
145 // visibility, it has itself removed.
146 base::scoped_nsobject<NSMutableSet> barVisibilityLocks_;
148 // Bar visibility locks and releases only result (when appropriate) in changes
149 // in visible state when the following is |YES|.
150 BOOL barVisibilityUpdatesEnabled_;
152 // When going fullscreen for a tab, we need to store the URL and the
153 // fullscreen type, since we can't show the bubble until
154 // -windowDidEnterFullScreen: gets called.
155 GURL fullscreenUrl_;
156 FullscreenExitBubbleType fullscreenBubbleType_;
158 // The Extension Command Registry used to determine which keyboard events to
159 // handle.
160 scoped_ptr<ExtensionKeybindingRegistryCocoa> extension_keybinding_registry_;
162 // The number of overlapped views being shown.
163 NSUInteger overlappedViewCount_;
166 // A convenience class method which gets the |BrowserWindowController| for a
167 // given window. This method returns nil if no window in the chain has a BWC.
168 + (BrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window;
170 // A convenience class method which gets the |BrowserWindowController| for a
171 // given view. This is the controller for the window containing |view|, if it
172 // is a BWC, or the first controller in the parent-window chain that is a
173 // BWC. This method returns nil if no window in the chain has a BWC.
174 + (BrowserWindowController*)browserWindowControllerForView:(NSView*)view;
176 // Helper method used to update the "Signin" menu item to reflect the current
177 // signed in state. Class-level function as it's still required even when there
178 // are no open browser windows.
179 + (void)updateSigninItem:(id)signinItem
180 shouldShow:(BOOL)showSigninMenuItem
181 currentProfile:(Profile*)profile;
183 // Load the browser window nib and do any Cocoa-specific initialization.
184 // Takes ownership of |browser|.
185 - (id)initWithBrowser:(Browser*)browser;
187 // Call to make the browser go away from other places in the cross-platform
188 // code.
189 - (void)destroyBrowser;
191 // Ensure bounds for the window abide by the minimum window size.
192 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds;
194 // Access the C++ bridge between the NSWindow and the rest of Chromium.
195 - (BrowserWindow*)browserWindow;
197 // Return a weak pointer to the toolbar controller.
198 - (ToolbarController*)toolbarController;
200 // Return a weak pointer to the tab strip controller.
201 - (TabStripController*)tabStripController;
203 // Return a weak pointer to the find bar controller.
204 - (FindBarCocoaController*)findBarCocoaController;
206 // Access the ObjC controller that contains the infobars.
207 - (InfoBarContainerController*)infoBarContainerController;
209 // Access the C++ bridge object representing the status bubble for the window.
210 - (StatusBubbleMac*)statusBubble;
212 // Access the C++ bridge object representing the location bar.
213 - (LocationBarViewMac*)locationBarBridge;
215 // Returns a weak pointer to the floating bar backing view;
216 - (NSView*)floatingBarBackingView;
218 // Returns a weak pointer to the overlayable contents controller.
219 - (OverlayableContentsController*)overlayableContentsController;
221 // Access the Profile object that backs this Browser.
222 - (Profile*)profile;
224 // Access the avatar button controller.
225 - (AvatarButtonController*)avatarButtonController;
227 // Forces the toolbar (and transitively the location bar) to update its current
228 // state. If |tab| is non-NULL, we're switching (back?) to this tab and should
229 // restore any previous location bar state (such as user editing) as well.
230 - (void)updateToolbarWithContents:(content::WebContents*)tab;
232 // Sets whether or not the current page in the frontmost tab is bookmarked.
233 - (void)setStarredState:(BOOL)isStarred;
235 // Happens when the zoom level is changed in the active tab, the active tab is
236 // changed, or a new browser window or tab is created. |canShowBubble| denotes
237 // whether it would be appropriate to show a zoom bubble or not.
238 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble;
240 // Return the rect, in WebKit coordinates (flipped), of the window's grow box
241 // in the coordinate system of the content area of the currently selected tab.
242 - (NSRect)selectedTabGrowBoxRect;
244 // Called to tell the selected tab to update its loading state.
245 // |force| is set if the update is due to changing tabs, as opposed to
246 // the page-load finishing. See comment in reload_button.h.
247 - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force;
249 // Brings this controller's window to the front.
250 - (void)activate;
252 // Make the location bar the first responder, if possible.
253 - (void)focusLocationBar:(BOOL)selectAll;
255 // Make the (currently-selected) tab contents the first responder, if possible.
256 - (void)focusTabContents;
258 // Returns the frame of the regular (non-fullscreened) window (even if the
259 // window is currently in fullscreen mode). The frame is returned in Cocoa
260 // coordinates (origin in bottom-left).
261 - (NSRect)regularWindowFrame;
263 // Whether or not to show the avatar, which is either the incognito guy or the
264 // user's profile avatar.
265 - (BOOL)shouldShowAvatar;
267 - (BOOL)isBookmarkBarVisible;
269 // Returns YES if the bookmark bar is currently animating.
270 - (BOOL)isBookmarkBarAnimating;
272 - (BookmarkBarController*)bookmarkBarController;
274 - (DevToolsController*)devToolsController;
276 - (BOOL)isDownloadShelfVisible;
278 // Lazily creates the download shelf in visible state if it doesn't exist yet.
279 - (DownloadShelfController*)downloadShelf;
281 // Retains the given FindBarCocoaController and adds its view to this
282 // browser window. Must only be called once per
283 // BrowserWindowController.
284 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController;
286 // The user changed the theme.
287 - (void)userChangedTheme;
289 // Executes the command in the context of the current browser.
290 // |command| is an integer value containing one of the constants defined in the
291 // "chrome/app/chrome_command_ids.h" file.
292 - (void)executeCommand:(int)command;
294 // Consults the Command Registry to see if this |event| needs to be handled as
295 // an extension command and returns YES if so (NO otherwise).
296 - (BOOL)handledByExtensionCommand:(NSEvent*)event;
298 // Delegate method for the status bubble to query its base frame.
299 - (NSRect)statusBubbleBaseFrame;
301 // Show the bookmark bubble (e.g. user just clicked on the STAR)
302 - (void)showBookmarkBubbleForURL:(const GURL&)url
303 alreadyBookmarked:(BOOL)alreadyBookmarked;
305 // Shows or hides the docked web inspector depending on |contents|'s state.
306 - (void)updateDevToolsForContents:(content::WebContents*)contents;
308 // Gets the current theme provider.
309 - (ui::ThemeProvider*)themeProvider;
311 // Gets the window style.
312 - (ThemedWindowStyle)themedWindowStyle;
314 // Returns the position in the coordinates of the root view
315 // ([[self contentView] superview]) that the top left of a theme image with
316 // |alignment| should be painted at. If the window does not have a tab strip,
317 // the offset for THEME_IMAGE_ALIGN_WITH_FRAME is always returned. The result of
318 // this method can be used in conjunction with
319 // [NSGraphicsContext cr_setPatternPhase:] to set the offset of pattern colors.
320 - (NSPoint)themeImagePositionForAlignment:(ThemeImageAlignment)alignment;
322 // Return the point to which a bubble window's arrow should point, in window
323 // coordinates.
324 - (NSPoint)bookmarkBubblePoint;
326 // Called when the Add Search Engine dialog is closed.
327 - (void)sheetDidEnd:(NSWindow*)sheet
328 returnCode:(NSInteger)code
329 context:(void*)context;
331 // Called when the find bar visibility changes. This is used to update the
332 // allowOverlappingViews state.
333 - (void)onFindBarVisibilityChanged;
335 // Called when an overlapped view is shown. This is used to update the
336 // allowOverlappingViews state. Currently used for history overlay and
337 // confirm bubble.
338 - (void)onOverlappedViewShown;
340 // Called when a history overlay is hidden. This is used to update the
341 // allowOverlappingViews state. Currently used for history overlay and
342 // confirm bubble.
343 - (void)onOverlappedViewHidden;
345 @end // @interface BrowserWindowController
348 // Methods having to do with the window type (normal/popup/app, and whether the
349 // window has various features; fullscreen and presentation mode methods are
350 // separate).
351 @interface BrowserWindowController(WindowType)
353 // Determines whether this controller's window supports a given feature (i.e.,
354 // whether a given feature is or can be shown in the window).
355 // TODO(viettrungluu): |feature| is really should be |Browser::Feature|, but I
356 // don't want to include browser.h (and you can't forward declare enums).
357 - (BOOL)supportsWindowFeature:(int)feature;
359 // Called to check whether or not this window has a normal title bar (YES if it
360 // does, NO otherwise). (E.g., normal browser windows do not, pop-ups do.)
361 - (BOOL)hasTitleBar;
363 // Called to check whether or not this window has a toolbar (YES if it does, NO
364 // otherwise). (E.g., normal browser windows do, pop-ups do not.)
365 - (BOOL)hasToolbar;
367 // Called to check whether or not this window has a location bar (YES if it
368 // does, NO otherwise). (E.g., normal browser windows do, pop-ups may or may
369 // not.)
370 - (BOOL)hasLocationBar;
372 // Called to check whether or not this window can have bookmark bar (YES if it
373 // does, NO otherwise). (E.g., normal browser windows may, pop-ups may not.)
374 - (BOOL)supportsBookmarkBar;
376 // Called to check if this controller's window is a tabbed window (e.g., not a
377 // pop-up window). Returns YES if it is, NO otherwise.
378 // Note: The |-has...| methods are usually preferred, so this method is largely
379 // deprecated.
380 - (BOOL)isTabbedWindow;
382 @end // @interface BrowserWindowController(WindowType)
385 // Methods having to do with fullscreen and presentation mode.
386 @interface BrowserWindowController(Fullscreen)
388 // Toggles fullscreen mode. Meant to be called by Lion windows when they enter
389 // or exit Lion fullscreen mode. Must not be called on Snow Leopard or earlier.
390 - (void)handleLionToggleFullscreen;
392 // Enters (or exits) fullscreen mode. This method is safe to call on all OS
393 // versions.
394 - (void)enterFullscreen;
395 - (void)exitFullscreen;
397 // Updates the contents of the fullscreen exit bubble with |url| and
398 // |bubbleType|.
399 - (void)updateFullscreenExitBubbleURL:(const GURL&)url
400 bubbleType:(FullscreenExitBubbleType)bubbleType;
402 // Returns fullscreen state. This method is safe to call on all OS versions.
403 - (BOOL)isFullscreen;
405 // Enters (or exits) presentation mode. Also enters fullscreen mode if this
406 // window is not already fullscreen. This method is safe to call on all OS
407 // versions.
408 - (void)enterPresentationModeForURL:(const GURL&)url
409 bubbleType:(FullscreenExitBubbleType)bubbleType;
410 - (void)exitPresentationMode;
412 // For simplified fullscreen: Enters fullscreen for a tab at a URL. The |url|
413 // is guaranteed to be non-empty; see -enterFullscreen for the user-initiated
414 // fullscreen mode. Called on Snow Leopard and Lion+.
415 - (void)enterFullscreenForURL:(const GURL&)url
416 bubbleType:(FullscreenExitBubbleType)bubbleType;
418 // Returns presentation mode state. This method is safe to call on all OS
419 // versions.
420 - (BOOL)inPresentationMode;
422 // Resizes the fullscreen window to fit the screen it's currently on. Called by
423 // the PresentationModeController when there is a change in monitor placement or
424 // resolution.
425 - (void)resizeFullscreenWindow;
427 // Gets or sets the fraction of the floating bar (presentation mode overlay)
428 // that is shown. 0 is completely hidden, 1 is fully shown.
429 - (CGFloat)floatingBarShownFraction;
430 - (void)setFloatingBarShownFraction:(CGFloat)fraction;
432 // Query/lock/release the requirement that the tab strip/toolbar/attached
433 // bookmark bar bar cluster is visible (e.g., when one of its elements has
434 // focus). This is required for the floating bar in presentation mode, but
435 // should also be called when not in presentation mode; see the comments for
436 // |barVisibilityLocks_| for more details. Double locks/releases by the same
437 // owner are ignored. If |animate:| is YES, then an animation may be performed,
438 // possibly after a small delay if |delay:| is YES. If |animate:| is NO,
439 // |delay:| will be ignored. In the case of multiple calls, later calls have
440 // precedence with the rule that |animate:NO| has precedence over |animate:YES|,
441 // and |delay:NO| has precedence over |delay:YES|.
442 - (BOOL)isBarVisibilityLockedForOwner:(id)owner;
443 - (void)lockBarVisibilityForOwner:(id)owner
444 withAnimation:(BOOL)animate
445 delay:(BOOL)delay;
446 - (void)releaseBarVisibilityForOwner:(id)owner
447 withAnimation:(BOOL)animate
448 delay:(BOOL)delay;
450 // Returns YES if any of the views in the floating bar currently has focus.
451 - (BOOL)floatingBarHasFocus;
453 // Opens the tabpose window.
454 - (void)openTabpose;
456 @end // @interface BrowserWindowController(Fullscreen)
459 // Methods which are either only for testing, or only public for testing.
460 @interface BrowserWindowController (TestingAPI)
462 // Put the incognito badge or multi-profile avatar on the browser and adjust the
463 // tab strip accordingly.
464 - (void)installAvatar;
466 // Allows us to initWithBrowser withOUT taking ownership of the browser.
467 - (id)initWithBrowser:(Browser*)browser takeOwnership:(BOOL)ownIt;
469 // Adjusts the window height by the given amount. If the window spans from the
470 // top of the current workspace to the bottom of the current workspace, the
471 // height is not adjusted. If growing the window by the requested amount would
472 // size the window to be taller than the current workspace, the window height is
473 // capped to be equal to the height of the current workspace. If the window is
474 // partially offscreen, its height is not adjusted at all. This function
475 // prefers to grow the window down, but will grow up if needed. Calls to this
476 // function should be followed by a call to |layoutSubviews|.
477 // Returns if the window height was changed.
478 - (BOOL)adjustWindowHeightBy:(CGFloat)deltaH;
480 // Return an autoreleased NSWindow suitable for fullscreen use.
481 - (NSWindow*)createFullscreenWindow;
483 // Resets any saved state about window growth (due to showing the bookmark bar
484 // or the download shelf), so that future shrinking will occur from the bottom.
485 - (void)resetWindowGrowthState;
487 // Computes by how far in each direction, horizontal and vertical, the
488 // |source| rect doesn't fit into |target|.
489 - (NSSize)overflowFrom:(NSRect)source
490 to:(NSRect)target;
492 // The fullscreen exit bubble controller, or nil if the bubble isn't showing.
493 - (FullscreenExitBubbleController*)fullscreenExitBubbleController;
495 // Gets the rect, in window base coordinates, that the omnibox popup should be
496 // positioned relative to.
497 - (NSRect)omniboxPopupAnchorRect;
499 // Force a layout of info bars.
500 - (void)layoutInfoBars;
502 @end // @interface BrowserWindowController (TestingAPI)
505 #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_CONTROLLER_H_