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 revealToolbarForTabStripChanges_; |
81 } | 89 } |
82 | 90 |
83 @property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle; | 91 @property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle; |
84 @property(nonatomic, assign) CGFloat toolbarFraction; | |
85 | 92 |
86 // Designated initializer. | 93 // Designated initializer. |
87 - (id)initWithBrowserController:(BrowserWindowController*)controller | 94 - (id)initWithBrowserController:(BrowserWindowController*)controller |
88 style:(fullscreen_mac::SlidingStyle)style; | 95 style:(fullscreen_mac::SlidingStyle)style; |
89 | 96 |
90 // Informs the controller that the browser has entered or exited presentation | 97 // Informs the controller that the browser has entered or exited fullscreen |
91 // mode. |-setupFullscreenToolbarForContentView:showDropdown:| should be called | 98 // mode. |-setupFullscreenToolbarForContentView:showDropdown:| should be called |
92 // after the window is setup, just before it is shown. |-exitFullscreenMode| | 99 // 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 | 100 // should be called before any views are moved back to the non-fullscreen |
94 // window. If |-setupFullscreenToolbarForContentView:showDropdown:| is called, | 101 // window. If |-setupFullscreenToolbarForContentView:showDropdown:| is called, |
95 // it must be balanced with a call to |-exitFullscreenMode| before the | 102 // it must be balanced with a call to |-exitFullscreenMode| before the |
96 // controller is released. | 103 // controller is released. |
97 - (void)setupFullscreenToolbarWithDropdown:(BOOL)showDropdown; | 104 - (void)setupFullscreenToolbarForContentView:(NSView*)contentView; |
98 - (void)exitFullscreenMode; | 105 - (void)exitFullscreenMode; |
99 | 106 |
100 // Returns the amount by which the floating bar should be offset downwards (to | 107 // 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. | 108 // 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 | 109 // Generally, this is > 0 when the window is on the primary screen and 0 |
103 // otherwise. | 110 // otherwise. |
104 - (CGFloat)floatingBarVerticalOffset; | 111 - (CGFloat)floatingBarVerticalOffset; |
105 | 112 |
106 // Informs the controller that the overlay should be shown/hidden, possibly | 113 // Informs the controller that the overlay should be shown/hidden, possibly |
107 // with animation. | 114 // with animation. |
108 - (void)ensureOverlayShownWithAnimation:(BOOL)animate; | 115 - (void)ensureOverlayShownWithAnimation:(BOOL)animate; |
109 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate; | 116 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate; |
110 | 117 |
111 // Cancels any running animation and timers. | 118 // Cancels any running animation and timers. |
112 - (void)cancelAnimationAndTimer; | 119 - (void)cancelAnimationAndTimer; |
113 | 120 |
114 // Animates the toolbar dropping down to show changes to the tab strip. | 121 // Animates the toolbar dropping down to show changes to the tab strip. |
115 - (void)revealToolbarForTabStripChanges; | 122 - (void)revealToolbarForTabStripChanges; |
116 | 123 |
117 // In any fullscreen mode, the y offset to use for the content at the top of | 124 // 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). | 125 // the screen (tab strip, omnibox, bookmark bar, etc). |
119 // Ranges from 0 to -22. | 126 // Ranges from 0 to -22. |
120 - (CGFloat)menubarOffset; | 127 - (CGFloat)menubarOffset; |
121 | 128 |
| 129 // Returns the fraction of the toolbar exposed at the top. |
| 130 // It returns 1.0 if the toolbar is fully shown and 0.0 if the toolbar is |
| 131 // hidden. Otherwise, if the toolbar is in progress of animating, it will |
| 132 // return a float that ranges from (0, 1). |
| 133 - (CGFloat)toolbarFraction; |
| 134 |
122 // Returns YES if the mouse is on the window's screen. This is used to check | 135 // 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 | 136 // if the menubar events belong to window's screen since the menubar would |
124 // only be revealed if the mouse is there. | 137 // only be revealed if the mouse is there. |
125 - (BOOL)isMouseOnScreen; | 138 - (BOOL)isMouseOnScreen; |
126 | 139 |
127 // Returns true if the browser is in the process of entering/exiting | 140 // Sets |trackingAreaFrame_| from the given overlay frame. |
| 141 - (void)setTrackingAreaFromOverlayFrame:(NSRect)frame; |
| 142 |
| 143 // Returns YES if the browser is in the process of entering/exiting |
128 // fullscreen. | 144 // fullscreen. |
129 - (BOOL)isFullscreenTransitionInProgress; | 145 - (BOOL)isFullscreenTransitionInProgress; |
130 | 146 |
| 147 // Returns YES if the browser in in fullscreen. |
| 148 - (BOOL)isInFullscreen; |
| 149 |
| 150 // Updates the toolbar by updating the layout, menubar and dock. |
| 151 - (void)updateToolbar; |
| 152 |
131 @end | 153 @end |
132 | 154 |
133 // Private methods exposed for testing. | 155 // Private methods exposed for testing. |
134 @interface FullscreenToolbarController (ExposedForTesting) | 156 @interface FullscreenToolbarController (ExposedForTesting) |
135 // Adjusts the AppKit Fullscreen options of the application. | 157 // Adjusts the AppKit Fullscreen options of the application. |
136 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode; | 158 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode; |
137 | 159 |
138 // Callback for menu bar animations. | 160 // Callback for menu bar animations. |
139 - (void)setMenuBarRevealProgress:(CGFloat)progress; | 161 - (void)setMenuBarRevealProgress:(CGFloat)progress; |
140 | 162 |
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 | 163 @end |
147 | 164 |
148 #endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ | 165 #endif // CHROME_BROWSER_UI_COCOA_FULLSCREEN_TOOLBAR_CONTROLLER_H_ |
OLD | NEW |