Home | History | Annotate | Download | only in cocoa
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
      6 #define CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
      7 
      8 #import <Cocoa/Cocoa.h>
      9 
     10 #include "base/mac/mac_util.h"
     11 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
     12 
     13 @class BrowserWindowController;
     14 @class DropdownAnimation;
     15 
     16 // Provides a controller to manage presentation mode for a single browser
     17 // window.  This class handles running animations, showing and hiding the
     18 // floating dropdown bar, and managing the tracking area associated with the
     19 // dropdown.  This class does not directly manage any views -- the
     20 // BrowserWindowController is responsible for positioning and z-ordering views.
     21 //
     22 // Tracking areas are disabled while animations are running.  If
     23 // |overlayFrameChanged:| is called while an animation is running, the
     24 // controller saves the new frame and installs the appropriate tracking area
     25 // when the animation finishes.  This is largely done for ease of
     26 // implementation; it is easier to check the mouse location at each animation
     27 // step than it is to manage a constantly-changing tracking area.
     28 @interface PresentationModeController : NSObject<NSAnimationDelegate> {
     29  @private
     30   // Our parent controller.
     31   BrowserWindowController* browserController_;  // weak
     32 
     33   // The content view for the window.  This is nil when not in presentation
     34   // mode.
     35   NSView* contentView_;  // weak
     36 
     37   // YES while this controller is in the process of entering presentation mode.
     38   BOOL enteringPresentationMode_;
     39 
     40   // Whether or not we are in presentation mode.
     41   BOOL inPresentationMode_;
     42 
     43   // The tracking area associated with the floating dropdown bar.  This tracking
     44   // area is attached to |contentView_|, because when the dropdown is completely
     45   // hidden, we still need to keep a 1px tall tracking area visible.  Attaching
     46   // to the content view allows us to do this.  |trackingArea_| can be nil if
     47   // not in presentation mode or during animations.
     48   base::scoped_nsobject<NSTrackingArea> trackingArea_;
     49 
     50   // Pointer to the currently running animation.  Is nil if no animation is
     51   // running.
     52   base::scoped_nsobject<DropdownAnimation> currentAnimation_;
     53 
     54   // Timers for scheduled showing/hiding of the bar (which are always done with
     55   // animation).
     56   base::scoped_nsobject<NSTimer> showTimer_;
     57   base::scoped_nsobject<NSTimer> hideTimer_;
     58 
     59   // Holds the current bounds of |trackingArea_|, even if |trackingArea_| is
     60   // currently nil.  Used to restore the tracking area when an animation
     61   // completes.
     62   NSRect trackingAreaBounds_;
     63 
     64   // Tracks the currently requested system fullscreen mode, used to show or hide
     65   // the menubar.  This should be |kFullScreenModeNormal| when the window is not
     66   // main or not fullscreen, |kFullScreenModeHideAll| while the overlay is
     67   // hidden, and |kFullScreenModeHideDock| while the overlay is shown.  If the
     68   // window is not on the primary screen, this should always be
     69   // |kFullScreenModeNormal|.  This value can get out of sync with the correct
     70   // state if we miss a notification (which can happen when a window is closed).
     71   // Used to track the current state and make sure we properly restore the menu
     72   // bar when this controller is destroyed.
     73   base::mac::FullScreenMode systemFullscreenMode_;
     74 }
     75 
     76 @property(readonly, nonatomic) BOOL inPresentationMode;
     77 
     78 // Designated initializer.
     79 - (id)initWithBrowserController:(BrowserWindowController*)controller;
     80 
     81 // Informs the controller that the browser has entered or exited presentation
     82 // mode. |-enterPresentationModeForContentView:showDropdown:| should be called
     83 // after the window is setup, just before it is shown. |-exitPresentationMode|
     84 // should be called before any views are moved back to the non-fullscreen
     85 // window.  If |-enterPresentationModeForContentView:showDropdown:| is called,
     86 // it must be balanced with a call to |-exitPresentationMode| before the
     87 // controller is released.
     88 - (void)enterPresentationModeForContentView:(NSView*)contentView
     89                                showDropdown:(BOOL)showDropdown;
     90 - (void)exitPresentationMode;
     91 
     92 // Returns the amount by which the floating bar should be offset downwards (to
     93 // avoid the menu) and by which the overlay view should be enlarged vertically.
     94 // Generally, this is > 0 when the window is on the primary screen and 0
     95 // otherwise.
     96 - (CGFloat)floatingBarVerticalOffset;
     97 
     98 // Informs the controller that the overlay's frame has changed.  The controller
     99 // uses this information to update its tracking areas.
    100 - (void)overlayFrameChanged:(NSRect)frame;
    101 
    102 // Informs the controller that the overlay should be shown/hidden, possibly with
    103 // animation, possibly after a delay (only applicable for the animated case).
    104 - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay;
    105 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay;
    106 
    107 // Cancels any running animation and timers.
    108 - (void)cancelAnimationAndTimers;
    109 
    110 // Gets the current floating bar shown fraction.
    111 - (CGFloat)floatingBarShownFraction;
    112 
    113 // Sets a new current floating bar shown fraction.  NOTE: This function has side
    114 // effects, such as modifying the system fullscreen mode (menu bar shown state).
    115 - (void)changeFloatingBarShownFraction:(CGFloat)fraction;
    116 
    117 @end
    118 
    119 // Notification posted when we're about to enter or leave fullscreen.
    120 extern NSString* const kWillEnterFullscreenNotification;
    121 extern NSString* const kWillLeaveFullscreenNotification;
    122 
    123 #endif  // CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
    124