| OLD | NEW |
| (Empty) |
| 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 #include <Carbon/Carbon.h> | |
| 9 #import <Cocoa/Cocoa.h> | |
| 10 | |
| 11 #include "base/mac/mac_util.h" | |
| 12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | |
| 13 | |
| 14 @class BrowserWindowController; | |
| 15 @class DropdownAnimation; | |
| 16 | |
| 17 namespace fullscreen_mac { | |
| 18 enum SlidingStyle { | |
| 19 OMNIBOX_TABS_PRESENT = 0, // Tab strip and omnibox both visible. | |
| 20 OMNIBOX_TABS_HIDDEN, // Tab strip and omnibox both hidden. | |
| 21 OMNIBOX_TABS_NONE, // Tab strip and omnibox both hidden and never | |
| 22 // shown. | |
| 23 }; | |
| 24 } // namespace fullscreen_mac | |
| 25 | |
| 26 // TODO(erikchen): This controller is misnamed. It manages the sliding tab | |
| 27 // strip and omnibox in all fullscreen modes. | |
| 28 | |
| 29 // Provides a controller to manage presentation mode for a single browser | |
| 30 // window. This class handles running animations, showing and hiding the | |
| 31 // floating dropdown bar, and managing the tracking area associated with the | |
| 32 // dropdown. This class does not directly manage any views -- the | |
| 33 // BrowserWindowController is responsible for positioning and z-ordering views. | |
| 34 // | |
| 35 // Tracking areas are disabled while animations are running. If | |
| 36 // |overlayFrameChanged:| is called while an animation is running, the | |
| 37 // controller saves the new frame and installs the appropriate tracking area | |
| 38 // when the animation finishes. This is largely done for ease of | |
| 39 // implementation; it is easier to check the mouse location at each animation | |
| 40 // step than it is to manage a constantly-changing tracking area. | |
| 41 @interface PresentationModeController : NSObject<NSAnimationDelegate> { | |
| 42 @private | |
| 43 // Our parent controller. | |
| 44 BrowserWindowController* browserController_; // weak | |
| 45 | |
| 46 // The content view for the window. This is nil when not in presentation | |
| 47 // mode. | |
| 48 NSView* contentView_; // weak | |
| 49 | |
| 50 // YES while this controller is in the process of entering presentation mode. | |
| 51 BOOL enteringPresentationMode_; | |
| 52 | |
| 53 // Whether or not we are in presentation mode. | |
| 54 BOOL inPresentationMode_; | |
| 55 | |
| 56 // The tracking area associated with the floating dropdown bar. This tracking | |
| 57 // area is attached to |contentView_|, because when the dropdown is completely | |
| 58 // hidden, we still need to keep a 1px tall tracking area visible. Attaching | |
| 59 // to the content view allows us to do this. |trackingArea_| can be nil if | |
| 60 // not in presentation mode or during animations. | |
| 61 base::scoped_nsobject<NSTrackingArea> trackingArea_; | |
| 62 | |
| 63 // Pointer to the currently running animation. Is nil if no animation is | |
| 64 // running. | |
| 65 base::scoped_nsobject<DropdownAnimation> currentAnimation_; | |
| 66 | |
| 67 // Timers for scheduled showing/hiding of the bar (which are always done with | |
| 68 // animation). | |
| 69 base::scoped_nsobject<NSTimer> showTimer_; | |
| 70 base::scoped_nsobject<NSTimer> hideTimer_; | |
| 71 | |
| 72 // Holds the current bounds of |trackingArea_|, even if |trackingArea_| is | |
| 73 // currently nil. Used to restore the tracking area when an animation | |
| 74 // completes. | |
| 75 NSRect trackingAreaBounds_; | |
| 76 | |
| 77 // Tracks the currently requested system fullscreen mode, used to show or hide | |
| 78 // the menubar. This should be |kFullScreenModeNormal| when the window is not | |
| 79 // main or not fullscreen, |kFullScreenModeHideAll| while the overlay is | |
| 80 // hidden, and |kFullScreenModeHideDock| while the overlay is shown. If the | |
| 81 // window is not on the primary screen, this should always be | |
| 82 // |kFullScreenModeNormal|. This value can get out of sync with the correct | |
| 83 // state if we miss a notification (which can happen when a window is closed). | |
| 84 // Used to track the current state and make sure we properly restore the menu | |
| 85 // bar when this controller is destroyed. | |
| 86 base::mac::FullScreenMode systemFullscreenMode_; | |
| 87 | |
| 88 // Whether the omnibox is hidden in fullscreen. | |
| 89 fullscreen_mac::SlidingStyle slidingStyle_; | |
| 90 | |
| 91 // The fraction of the AppKit Menubar that is showing. Ranges from 0 to 1. | |
| 92 // Only used in AppKit Fullscreen. | |
| 93 CGFloat menubarFraction_; | |
| 94 | |
| 95 // The fraction of the omnibox/tabstrip that is showing. Ranges from 0 to 1. | |
| 96 // Used in both AppKit and Immersive Fullscreen. | |
| 97 CGFloat toolbarFraction_; | |
| 98 | |
| 99 // A Carbon event handler that tracks the revealed fraction of the menu bar. | |
| 100 EventHandlerRef menuBarTrackingHandler_; | |
| 101 | |
| 102 // True when the toolbar is dropped to show tabstrip changes. | |
| 103 BOOL revealToolbarForTabStripChanges_; | |
| 104 } | |
| 105 | |
| 106 @property(readonly, nonatomic) BOOL inPresentationMode; | |
| 107 @property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle; | |
| 108 @property(nonatomic, assign) CGFloat toolbarFraction; | |
| 109 | |
| 110 // Designated initializer. | |
| 111 - (id)initWithBrowserController:(BrowserWindowController*)controller | |
| 112 style:(fullscreen_mac::SlidingStyle)style; | |
| 113 | |
| 114 // Informs the controller that the browser has entered or exited presentation | |
| 115 // mode. |-enterPresentationModeForContentView:showDropdown:| should be called | |
| 116 // after the window is setup, just before it is shown. |-exitPresentationMode| | |
| 117 // should be called before any views are moved back to the non-fullscreen | |
| 118 // window. If |-enterPresentationModeForContentView:showDropdown:| is called, | |
| 119 // it must be balanced with a call to |-exitPresentationMode| before the | |
| 120 // controller is released. | |
| 121 - (void)enterPresentationModeForContentView:(NSView*)contentView | |
| 122 showDropdown:(BOOL)showDropdown; | |
| 123 - (void)exitPresentationMode; | |
| 124 | |
| 125 // Returns the amount by which the floating bar should be offset downwards (to | |
| 126 // avoid the menu) and by which the overlay view should be enlarged vertically. | |
| 127 // Generally, this is > 0 when the window is on the primary screen and 0 | |
| 128 // otherwise. | |
| 129 - (CGFloat)floatingBarVerticalOffset; | |
| 130 | |
| 131 // Informs the controller that the overlay's frame has changed. The controller | |
| 132 // uses this information to update its tracking areas. | |
| 133 - (void)overlayFrameChanged:(NSRect)frame; | |
| 134 | |
| 135 // Informs the controller that the overlay should be shown/hidden, possibly with | |
| 136 // animation, possibly after a delay (only applicable for the animated case). | |
| 137 - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay; | |
| 138 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay; | |
| 139 | |
| 140 // Cancels any running animation and timers. | |
| 141 - (void)cancelAnimationAndTimers; | |
| 142 | |
| 143 // Animates the toolbar dropping down to show changes to the tab strip. | |
| 144 - (void)revealToolbarForTabStripChanges; | |
| 145 | |
| 146 // In any fullscreen mode, the y offset to use for the content at the top of | |
| 147 // the screen (tab strip, omnibox, bookmark bar, etc). | |
| 148 // Ranges from 0 to -22. | |
| 149 - (CGFloat)menubarOffset; | |
| 150 | |
| 151 // Returns true if the window is the main window. | |
| 152 - (BOOL)isMainWindow; | |
| 153 | |
| 154 // Returns true if the browser is in the process of entering/exiting | |
| 155 // fullscreen. | |
| 156 - (BOOL)isFullscreenTransitionInProgress; | |
| 157 | |
| 158 @end | |
| 159 | |
| 160 // Private methods exposed for testing. | |
| 161 @interface PresentationModeController (ExposedForTesting) | |
| 162 // Adjusts the AppKit Fullscreen options of the application. | |
| 163 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode; | |
| 164 | |
| 165 // Callback for menu bar animations. | |
| 166 - (void)setMenuBarRevealProgress:(CGFloat)progress; | |
| 167 | |
| 168 // Updates the local state that reflects the fraction of the toolbar area that | |
| 169 // is showing. This function has the side effect of changing the AppKit | |
| 170 // Fullscreen option for whether the menu bar is shown. | |
| 171 - (void)changeToolbarFraction:(CGFloat)fraction; | |
| 172 | |
| 173 @end | |
| 174 | |
| 175 // Notification posted when we're about to enter or leave fullscreen. | |
| 176 extern NSString* const kWillEnterFullscreenNotification; | |
| 177 extern NSString* const kWillLeaveFullscreenNotification; | |
| 178 | |
| 179 #endif // CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_ | |
| OLD | NEW |