15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <Carbon/Carbon.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/mac/mac_util.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class BrowserWindowController;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class DropdownAnimation;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace fullscreen_mac {
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccienum SlidingStyle {
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  OMNIBOX_TABS_PRESENT = 0,  // Tab strip and omnibox both visible.
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  OMNIBOX_TABS_HIDDEN,       // Tab strip and omnibox both hidden.
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci};
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}  // namespace fullscreen_mac
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(erikchen): This controller is misnamed. It manages the sliding tab
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// strip and omnibox in all fullscreen modes.
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Provides a controller to manage presentation mode for a single browser
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// window.  This class handles running animations, showing and hiding the
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// floating dropdown bar, and managing the tracking area associated with the
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// dropdown.  This class does not directly manage any views -- the
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BrowserWindowController is responsible for positioning and z-ordering views.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Tracking areas are disabled while animations are running.  If
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |overlayFrameChanged:| is called while an animation is running, the
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// controller saves the new frame and installs the appropriate tracking area
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// when the animation finishes.  This is largely done for ease of
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// implementation; it is easier to check the mouse location at each animation
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// step than it is to manage a constantly-changing tracking area.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface PresentationModeController : NSObject<NSAnimationDelegate> {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @private
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Our parent controller.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrowserWindowController* browserController_;  // weak
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The content view for the window.  This is nil when not in presentation
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // mode.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NSView* contentView_;  // weak
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // YES while this controller is in the process of entering presentation mode.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BOOL enteringPresentationMode_;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Whether or not we are in presentation mode.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BOOL inPresentationMode_;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The tracking area associated with the floating dropdown bar.  This tracking
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // area is attached to |contentView_|, because when the dropdown is completely
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // hidden, we still need to keep a 1px tall tracking area visible.  Attaching
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the content view allows us to do this.  |trackingArea_| can be nil if
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not in presentation mode or during animations.
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSTrackingArea> trackingArea_;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Pointer to the currently running animation.  Is nil if no animation is
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // running.
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<DropdownAnimation> currentAnimation_;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Timers for scheduled showing/hiding of the bar (which are always done with
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // animation).
67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSTimer> showTimer_;
68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSTimer> hideTimer_;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Holds the current bounds of |trackingArea_|, even if |trackingArea_| is
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // currently nil.  Used to restore the tracking area when an animation
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // completes.
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NSRect trackingAreaBounds_;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tracks the currently requested system fullscreen mode, used to show or hide
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the menubar.  This should be |kFullScreenModeNormal| when the window is not
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // main or not fullscreen, |kFullScreenModeHideAll| while the overlay is
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // hidden, and |kFullScreenModeHideDock| while the overlay is shown.  If the
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // window is not on the primary screen, this should always be
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |kFullScreenModeNormal|.  This value can get out of sync with the correct
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // state if we miss a notification (which can happen when a window is closed).
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used to track the current state and make sure we properly restore the menu
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // bar when this controller is destroyed.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::mac::FullScreenMode systemFullscreenMode_;
851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Whether the omnibox is hidden in fullscreen.
871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  fullscreen_mac::SlidingStyle slidingStyle_;
881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The fraction of the AppKit Menubar that is showing. Ranges from 0 to 1.
901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Only used in AppKit Fullscreen.
911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CGFloat menubarFraction_;
921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The fraction of the omnibox/tabstrip that is showing. Ranges from 0 to 1.
941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Used in both AppKit and Immersive Fullscreen.
951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  CGFloat toolbarFraction_;
961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // A Carbon event handler that tracks the revealed fraction of the menu bar.
981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EventHandlerRef menuBarTrackingHandler_;
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@property(readonly, nonatomic) BOOL inPresentationMode;
1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle;
1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@property(nonatomic, assign) CGFloat toolbarFraction;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Designated initializer.
1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci- (id)initWithBrowserController:(BrowserWindowController*)controller
1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          style:(fullscreen_mac::SlidingStyle)style;
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Informs the controller that the browser has entered or exited presentation
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// mode. |-enterPresentationModeForContentView:showDropdown:| should be called
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// after the window is setup, just before it is shown. |-exitPresentationMode|
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// should be called before any views are moved back to the non-fullscreen
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// window.  If |-enterPresentationModeForContentView:showDropdown:| is called,
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// it must be balanced with a call to |-exitPresentationMode| before the
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// controller is released.
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)enterPresentationModeForContentView:(NSView*)contentView
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               showDropdown:(BOOL)showDropdown;
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)exitPresentationMode;
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the amount by which the floating bar should be offset downwards (to
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// avoid the menu) and by which the overlay view should be enlarged vertically.
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Generally, this is > 0 when the window is on the primary screen and 0
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// otherwise.
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (CGFloat)floatingBarVerticalOffset;
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Informs the controller that the overlay's frame has changed.  The controller
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// uses this information to update its tracking areas.
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)overlayFrameChanged:(NSRect)frame;
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Informs the controller that the overlay should be shown/hidden, possibly with
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// animation, possibly after a delay (only applicable for the animated case).
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay;
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay;
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Cancels any running animation and timers.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)cancelAnimationAndTimers;
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// In any fullscreen mode, the y offset to use for the content at the top of
1391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// the screen (tab strip, omnibox, bookmark bar, etc).
1401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Ranges from 0 to -22.
1411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci- (CGFloat)menubarOffset;
1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@end
1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Private methods exposed for testing.
1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@interface PresentationModeController (ExposedForTesting)
1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Adjusts the AppKit Fullscreen options of the application.
1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci- (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode;
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Callback for menu bar animations.
1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci- (void)setMenuBarRevealProgress:(CGFloat)progress;
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Updates the local state that reflects the fraction of the toolbar area that
1541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// is showing. This function has the side effect of changing the AppKit
1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Fullscreen option for whether the menu bar is shown.
1561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci- (void)changeToolbarFraction:(CGFloat)fraction;
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Notification posted when we're about to enter or leave fullscreen.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern NSString* const kWillEnterFullscreenNotification;
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern NSString* const kWillLeaveFullscreenNotification;
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
164