BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / presentation_mode_controller.h
blobf98251255e491032fd8871e8db6ccc1989bad4f4
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.
5 #ifndef CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_
8 #include <Carbon/Carbon.h>
9 #import <Cocoa/Cocoa.h>
11 #include "base/mac/mac_util.h"
12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
14 @class BrowserWindowController;
15 @class DropdownAnimation;
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.
24 } // namespace fullscreen_mac
26 // TODO(erikchen): This controller is misnamed. It manages the sliding tab
27 // strip and omnibox in all fullscreen modes.
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.
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
46 // The content view for the window. This is nil when not in presentation
47 // mode.
48 NSView* contentView_; // weak
50 // YES while this controller is in the process of entering presentation mode.
51 BOOL enteringPresentationMode_;
53 // Whether or not we are in presentation mode.
54 BOOL inPresentationMode_;
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_;
63 // Pointer to the currently running animation. Is nil if no animation is
64 // running.
65 base::scoped_nsobject<DropdownAnimation> currentAnimation_;
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_;
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_;
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_;
88 // Whether the omnibox is hidden in fullscreen.
89 fullscreen_mac::SlidingStyle slidingStyle_;
91 // The fraction of the AppKit Menubar that is showing. Ranges from 0 to 1.
92 // Only used in AppKit Fullscreen.
93 CGFloat menubarFraction_;
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_;
99 // A Carbon event handler that tracks the revealed fraction of the menu bar.
100 EventHandlerRef menuBarTrackingHandler_;
103 @property(readonly, nonatomic) BOOL inPresentationMode;
104 @property(nonatomic, assign) fullscreen_mac::SlidingStyle slidingStyle;
105 @property(nonatomic, assign) CGFloat toolbarFraction;
107 // Designated initializer.
108 - (id)initWithBrowserController:(BrowserWindowController*)controller
109 style:(fullscreen_mac::SlidingStyle)style;
111 // Informs the controller that the browser has entered or exited presentation
112 // mode. |-enterPresentationModeForContentView:showDropdown:| should be called
113 // after the window is setup, just before it is shown. |-exitPresentationMode|
114 // should be called before any views are moved back to the non-fullscreen
115 // window. If |-enterPresentationModeForContentView:showDropdown:| is called,
116 // it must be balanced with a call to |-exitPresentationMode| before the
117 // controller is released.
118 - (void)enterPresentationModeForContentView:(NSView*)contentView
119 showDropdown:(BOOL)showDropdown;
120 - (void)exitPresentationMode;
122 // Returns the amount by which the floating bar should be offset downwards (to
123 // avoid the menu) and by which the overlay view should be enlarged vertically.
124 // Generally, this is > 0 when the window is on the primary screen and 0
125 // otherwise.
126 - (CGFloat)floatingBarVerticalOffset;
128 // Informs the controller that the overlay's frame has changed. The controller
129 // uses this information to update its tracking areas.
130 - (void)overlayFrameChanged:(NSRect)frame;
132 // Informs the controller that the overlay should be shown/hidden, possibly with
133 // animation, possibly after a delay (only applicable for the animated case).
134 - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay;
135 - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay;
137 // Cancels any running animation and timers.
138 - (void)cancelAnimationAndTimers;
140 // In any fullscreen mode, the y offset to use for the content at the top of
141 // the screen (tab strip, omnibox, bookmark bar, etc).
142 // Ranges from 0 to -22.
143 - (CGFloat)menubarOffset;
145 @end
147 // Private methods exposed for testing.
148 @interface PresentationModeController (ExposedForTesting)
149 // Adjusts the AppKit Fullscreen options of the application.
150 - (void)setSystemFullscreenModeTo:(base::mac::FullScreenMode)mode;
152 // Callback for menu bar animations.
153 - (void)setMenuBarRevealProgress:(CGFloat)progress;
155 // Updates the local state that reflects the fraction of the toolbar area that
156 // is showing. This function has the side effect of changing the AppKit
157 // Fullscreen option for whether the menu bar is shown.
158 - (void)changeToolbarFraction:(CGFloat)fraction;
159 @end
161 // Notification posted when we're about to enter or leave fullscreen.
162 extern NSString* const kWillEnterFullscreenNotification;
163 extern NSString* const kWillLeaveFullscreenNotification;
165 #endif // CHROME_BROWSER_UI_COCOA_PRESENTATION_MODE_CONTROLLER_H_