| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <Carbon/Carbon.h> | 8 #include <Carbon/Carbon.h> |
| 9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
| 10 | 10 |
| 11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
| 12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 13 | 13 |
| 14 @class BrowserWindowController; | 14 @class BrowserWindowController; |
| 15 @class CrTrackingArea; |
| 15 @class DropdownAnimation; | 16 @class DropdownAnimation; |
| 16 | 17 |
| 17 namespace fullscreen_mac { | 18 namespace fullscreen_mac { |
| 18 enum SlidingStyle { | 19 enum SlidingStyle { |
| 19 OMNIBOX_TABS_PRESENT = 0, // Tab strip and omnibox both visible. | 20 OMNIBOX_TABS_PRESENT = 0, // Tab strip and omnibox both visible. |
| 20 OMNIBOX_TABS_HIDDEN, // Tab strip and omnibox both hidden. | 21 OMNIBOX_TABS_HIDDEN, // Tab strip and omnibox both hidden. |
| 21 OMNIBOX_TABS_NONE, // Tab strip and omnibox both hidden and never | 22 OMNIBOX_TABS_NONE, // Tab strip and omnibox both hidden and never |
| 22 // shown. | 23 // shown. |
| 23 }; | 24 }; |
| 24 } // namespace fullscreen_mac | 25 } // namespace fullscreen_mac |
| 25 | 26 |
| 26 // Provides a controller to fullscreen toolbar for a single browser | 27 // Provides a controller to fullscreen toolbar for a single browser |
| 27 // window. This class handles running animations, showing and hiding the | 28 // window. This class handles running animations, showing and hiding the |
| 28 // floating dropdown bar, and managing the tracking area associated with the | 29 // fullscreen toolbar, and managing the tracking area associated with the |
| 29 // dropdown. This class does not directly manage any views -- the | 30 // toolbar. This class does not directly manage any views -- the |
| 30 // BrowserWindowController is responsible for positioning and z-ordering views. | 31 // BrowserWindowController is responsible for positioning and z-ordering views. |
| 31 // | 32 // |
| 32 // Tracking areas are disabled while animations are running. If | 33 |
| 33 // |overlayFrameChanged:| is called while an animation is running, the | 34 // TODO (spqchan): Write tests for this class. See crbug.com/640064. |
| 34 // controller saves the new frame and installs the appropriate tracking area | |
| 35 // when the animation finishes. This is largely done for ease of | |
| 36 // implementation; it is easier to check the mouse location at each animation | |
| 37 // step than it is to manage a constantly-changing tracking area. | |
| 38 @interface FullscreenToolbarController : NSObject<NSAnimationDelegate> { | 35 @interface FullscreenToolbarController : NSObject<NSAnimationDelegate> { |
| 39 @private | 36 @private |
| 40 // Our parent controller. | 37 // Our parent controller. |
| 41 BrowserWindowController* browserController_; // weak | 38 BrowserWindowController* browserController_; // weak |
| 42 | 39 |
| 43 // Whether or not we are in fullscreen mode. | 40 // Whether or not we are in fullscreen mode. |
| 44 BOOL inFullscreenMode_; | 41 BOOL inFullscreenMode_; |
| 45 | 42 |
| 43 // The content view for the window. This is nil when not in fullscreen mode. |
| 44 NSView* contentView_; // weak |
| 45 |
| 46 // The frame for the tracking area. The value is the toolbar overlay's frame |
| 47 // with additional height added at the bottom. |
| 48 NSRect trackingAreaFrame_; |
| 49 |
| 50 // The tracking area associated with the toolbar overlay bar. This tracking |
| 51 // area is used to keep the toolbar active if the menubar had animated out |
| 52 // but the mouse is still on the toolbar. |
| 53 base::scoped_nsobject<CrTrackingArea> trackingArea_; |
| 54 |
| 46 // Pointer to the currently running animation. Is nil if no animation is | 55 // Pointer to the currently running animation. Is nil if no animation is |
| 47 // running. | 56 // running. |
| 48 base::scoped_nsobject<DropdownAnimation> currentAnimation_; | 57 base::scoped_nsobject<DropdownAnimation> currentAnimation_; |
| 49 | 58 |
| 50 // Timer for scheduled hiding of the toolbar when it had been revealed for | 59 // Timer for scheduled hiding of the toolbar when it had been revealed for |
| 51 // tabstrip changes. | 60 // tabstrip changes. |
| 52 base::scoped_nsobject<NSTimer> hideTimer_; | 61 base::scoped_nsobject<NSTimer> hideTimer_; |
| 53 | 62 |
| 54 // Tracks the currently requested system fullscreen mode, used to show or | 63 // Tracks the currently requested system fullscreen mode, used to show or |
| 55 // hide the menubar. This should be |kFullScreenModeNormal| when the window | 64 // hide the menubar. This should be |kFullScreenModeNormal| when the window |
| 56 // is not main or not fullscreen, |kFullScreenModeHideAll| while the overlay | 65 // is not main or not fullscreen, |kFullScreenModeHideAll| while the overlay |
| 57 // is hidden, and |kFullScreenModeHideDock| while the overlay is shown. If | 66 // is hidden, and |kFullScreenModeHideDock| while the overlay is shown. If |
| 58 // the window is not on the primary screen, this should always be | 67 // the window is not on the primary screen, this should always be |
| 59 // |kFullScreenModeNormal|. This value can get out of sync with the correct | 68 // |kFullScreenModeNormal|. This value can get out of sync with the correct |
| 60 // state if we miss a notification (which can happen when a window is closed). | 69 // state if we miss a notification (which can happen when a window is closed). |
| 61 // Used to track the current state and make sure we properly restore the menu | 70 // Used to track the current state and make sure we properly restore the menu |
| 62 // bar when this controller is destroyed. | 71 // bar when this controller is destroyed. |
| 63 base::mac::FullScreenMode systemFullscreenMode_; | 72 base::mac::FullScreenMode systemFullscreenMode_; |
| 64 | 73 |
| 65 // Whether the omnibox is hidden in fullscreen. | 74 // Whether the omnibox is hidden in fullscreen. |
| 66 fullscreen_mac::SlidingStyle slidingStyle_; | 75 fullscreen_mac::SlidingStyle slidingStyle_; |
| 67 | 76 |
| 68 // The fraction of the AppKit Menubar that is showing. Ranges from 0 to 1. | 77 // The fraction of the AppKit Menubar that is showing. Ranges from 0 to 1. |
| 69 // Only used in AppKit Fullscreen. | 78 // Only used in AppKit Fullscreen. |
| 70 CGFloat menubarFraction_; | 79 CGFloat menubarFraction_; |
| 71 | 80 |
| 72 // The fraction of the omnibox/tabstrip that is showing. Ranges from 0 to 1. | 81 // The toolbar fraction set by the menu progress. |
| 73 // Used in both AppKit and Immersive Fullscreen. | 82 CGFloat toolbarFractionFromMenuProgress_; |
| 74 CGFloat toolbarFraction_; | |
| 75 | 83 |
| 76 // A Carbon event handler that tracks the revealed fraction of the menu bar. | 84 // A Carbon event handler that tracks the revealed fraction of the menu bar. |
| 77 EventHandlerRef menuBarTrackingHandler_; | 85 EventHandlerRef menuBarTrackingHandler_; |
| 78 | 86 |
| 79 // True when the toolbar is dropped to show tabstrip changes. | 87 // True when the toolbar is dropped to show tabstrip changes. |
| 80 BOOL revealToolbarForTabStripChanges_; | 88 BOOL isRevealingToolbarForTabStripChanges_; |
| 89 |
| 90 // True when the toolbar should be animated back out via a DropdownAnimation. |
| 91 // This is set and unset in hideTimer:. It's set to YES before it calls |
| 92 // animateToolbarVisibility: and then set to NO after the animation has |
| 93 // started. |
| 94 BOOL shouldAnimateToolbarOut_; |
| 81 } | 95 } |
| 82 | 96 |
| 83 @property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle; | 97 @property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle; |
| 84 @property(nonatomic, assign) CGFloat toolbarFraction; | |
| 85 | 98 |
| 86 // Designated initializer. | 99 // Designated initializer. |
| 87 - (id)initWithBrowserController:(BrowserWindowController*)controller | 100 - (id)initWithBrowserController:(BrowserWindowController*)controller |
| 88 style:(fullscreen_mac::SlidingStyle)style; | 101 style:(fullscreen_mac::SlidingStyle)style; |
| 89 | 102 |
| 90 // Informs the controller that the browser has entered or exited presentation | 103 // Informs the controller that the browser has entered or exited fullscreen |
| 91 // mode. |-setupFullscreenToolbarForContentView:showDropdown:| should be called | 104 // mode. |-setupFullscreenToolbarForContentView:showDropdown:| should be called |
| 92 // after the window is setup, just before it is shown. |-exitFullscreenMode| | 105 // after the window is setup, just before it is shown. |-exitFullscreenMode| |
| 93 // should be called before any views are moved back to the non-fullscreen | 106 // should be called before any views are moved back to the non-fullscreen |
| 94 // window. If |-setupFullscreenToolbarForContentView:showDropdown:| is called, | 107 // window. If |-setupFullscreenToolbarForContentView:showDropdown:| is called, |
| 95 // it must be balanced with a call to |-exitFullscreenMode| before the | 108 // it must be balanced with a call to |-exitFullscreenMode| before the |
| 96 // controller is released. | 109 // controller is released. |
| 97 - (void)setupFullscreenToolbarWithDropdown:(BOOL)showDropdown; | 110 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView; |
| 98 - (void)exitFullscreenMode; | 111 - (void)exitFullscreenMode; |
| 99 | 112 |
| 100 // Returns the amount by which the floating bar should be offset downwards (to | 113 // Returns the amount by which the floating bar should be offset downwards (to |
| 101 // avoid the menu) and by which the overlay view should be enlarged vertically. | 114 // avoid the menu) and by which the overlay view should be enlarged vertically. |
| 102 // Generally, this is > 0 when the window is on the primary screen and 0 | 115 // Generally, this is > 0 when the window is on the primary screen and 0 |
| 103 // otherwise. | 116 // otherwise. |
| 104 - (CGFloat)floatingBarVerticalOffset; | 117 - (CGFloat)floatingBarVerticalOffset; |
| 105 | 118 |
| 106 // Informs the controller that the overlay should be shown/hidden, possibly | 119 // Informs the controller that the overlay should be shown/hidden, possibly |
| 107 // with animation. | 120 // with animation. |
| 108 - (void)ensureOverlayShownWithAnimation:(BOOL)animate; | 121 - (void)ensureOverlayShownWithAnimation:(BOOL)animate; |
| 109 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate; | 122 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate; |
| 110 | 123 |
| 111 // Cancels any running animation and timers. | 124 // Cancels any running animation and timers. |
| 112 - (void)cancelAnimationAndTimer; | 125 - (void)cancelAnimationAndTimer; |
| 113 | 126 |
| 114 // Animates the toolbar dropping down to show changes to the tab strip. | 127 // Animates the toolbar dropping down to show changes to the tab strip. |
| 115 - (void)revealToolbarForTabStripChanges; | 128 - (void)revealToolbarForTabStripChanges; |
| 116 | 129 |
| 117 // In any fullscreen mode, the y offset to use for the content at the top of | 130 // In any fullscreen mode, the y offset to use for the content at the top of |
| 118 // the screen (tab strip, omnibox, bookmark bar, etc). | 131 // the screen (tab strip, omnibox, bookmark bar, etc). |
| 119 // Ranges from 0 to -22. | 132 // Ranges from 0 to -22. |
| 120 - (CGFloat)menubarOffset; | 133 - (CGFloat)menubarOffset; |
| 121 | 134 |
| 135 // Returns the fraction of the toolbar exposed at the top. |
| 136 // It returns 1.0 if the toolbar is fully shown and 0.0 if the toolbar is |
| 137 // hidden. Otherwise, if the toolbar is in progress of animating, it will |
| 138 // return a float that ranges from (0, 1). |
| 139 - (CGFloat)toolbarFraction; |
| 140 |
| 122 // Returns YES if the mouse is on the window's screen. This is used to check | 141 // Returns YES if the mouse is on the window's screen. This is used to check |
| 123 // if the menubar events belong to window's screen since the menubar would | 142 // if the menubar events belong to window's screen since the menubar would |
| 124 // only be revealed if the mouse is there. | 143 // only be revealed if the mouse is there. |
| 125 - (BOOL)isMouseOnScreen; | 144 - (BOOL)isMouseOnScreen; |
| 126 | 145 |
| 127 // Returns true if the browser is in the process of entering/exiting | 146 // Sets |trackingAreaFrame_| from the given overlay frame. |
| 147 - (void)setTrackingAreaFromOverlayFrame:(NSRect)frame; |
| 148 |
| 149 // Returns YES if the browser is in the process of entering/exiting |
| 128 // fullscreen. | 150 // fullscreen. |
| 129 - (BOOL)isFullscreenTransitionInProgress; | 151 - (BOOL)isFullscreenTransitionInProgress; |
| 130 | 152 |
| 153 // Returns YES if the browser in in fullscreen. |
| 154 - (BOOL)isInFullscreen; |
| 155 |
| 156 // Updates the toolbar by updating the layout, menubar and dock. |
| 157 - (void)updateToolbar; |
| 158 |
| 131 @end | 159 @end |
| 132 | 160 |
| 133 // Private methods exposed for testing. | 161 // Private methods exposed for testing. |
| 134 @interface FullscreenToolbarController (ExposedForTesting) | 162 @interface FullscreenToolbarController (ExposedForTesting) |
| 135 // Adjusts the AppKit Fullscreen options of the application. | 163 // Adjusts the AppKit Fullscreen options of the application. |
| 136 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode; | 164 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode; |
| 137 | 165 |
| 138 // Callback for menu bar animations. | 166 // Callback for menu bar animations. |
| 139 - (void)setMenuBarRevealProgress:(CGFloat)progress; | 167 - (void)setMenuBarRevealProgress:(CGFloat)progress; |
| 140 | 168 |
| 141 // Updates the local state that reflects the fraction of the toolbar area that | |
| 142 // is showing. This function has the side effect of changing the AppKit | |
| 143 // Fullscreen option for whether the menu bar is shown. | |
| 144 - (void)changeToolbarFraction:(CGFloat)fraction; | |
| 145 | |
| 146 @end | 169 @end |
| 147 | 170 |
| 148 #endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ | 171 #endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ |
| OLD | NEW |