| OLD | NEW |
| (Empty) |
| 1 // Copyright 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_VIEWS_IMMERSIVE_MODE_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_IMMERSIVE_MODE_CONTROLLER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/timer.h" | |
| 11 #include "ui/base/events/event_handler.h" | |
| 12 #include "ui/gfx/native_widget_types.h" | |
| 13 | |
| 14 class BrowserView; | |
| 15 class RevealView; | |
| 16 | |
| 17 namespace views { | |
| 18 class MouseWatcher; | |
| 19 class View; | |
| 20 } | |
| 21 | |
| 22 // Controller for an "immersive mode" similar to MacOS presentation mode where | |
| 23 // the top-of-window views are hidden until the mouse hits the top of the | |
| 24 // screen. The tab strip is optionally painted with miniature "tab indicator" | |
| 25 // rectangles. | |
| 26 class ImmersiveModeController : public ui::EventHandler { | |
| 27 public: | |
| 28 ImmersiveModeController(); | |
| 29 virtual ~ImmersiveModeController(); | |
| 30 | |
| 31 // Must initialize after browser view has a Widget and native window. | |
| 32 void Init(BrowserView* browser_view); | |
| 33 | |
| 34 // Returns true if immersive mode should be used for fullscreen based on | |
| 35 // command line flags. | |
| 36 static bool UseImmersiveFullscreen(); | |
| 37 | |
| 38 // Enables or disables immersive mode. | |
| 39 void SetEnabled(bool enabled); | |
| 40 bool enabled() const { return enabled_; } | |
| 41 | |
| 42 // See member comment below. | |
| 43 bool hide_tab_indicators() const { return hide_tab_indicators_; } | |
| 44 | |
| 45 // True when the top views are hidden due to immersive mode. | |
| 46 bool ShouldHideTopViews() const { | |
| 47 return enabled_ && reveal_state_ == CLOSED; | |
| 48 } | |
| 49 | |
| 50 // True when the top views are fully or partially visible. | |
| 51 bool IsRevealed() const { return enabled_ && reveal_state_ != CLOSED; } | |
| 52 | |
| 53 // If the controller is temporarily revealing the top views ensures that | |
| 54 // the reveal view's layer is on top and hence visible over web contents. | |
| 55 void MaybeStackViewAtTop(); | |
| 56 | |
| 57 // Shows the reveal view if immersive mode is enabled. Used when focus is | |
| 58 // placed in the location bar, tools menu, etc. | |
| 59 void MaybeStartReveal(); | |
| 60 | |
| 61 // Immediately hides the reveal view, without animating. | |
| 62 void CancelReveal(); | |
| 63 | |
| 64 // If |reveal| performs a reveal and holds the view open until called again | |
| 65 // with |reveal| false. Immersive mode must be enabled. | |
| 66 void RevealAndLock(bool reveal); | |
| 67 | |
| 68 // Called when the reveal view's children lose focus, may end the reveal. | |
| 69 void OnRevealViewLostFocus(); | |
| 70 | |
| 71 // ui::EventHandler overrides: | |
| 72 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | |
| 73 | |
| 74 // Testing interface. | |
| 75 void SetHideTabIndicatorsForTest(bool hide); | |
| 76 void StartRevealForTest(); | |
| 77 void OnRevealViewLostMouseForTest(); | |
| 78 | |
| 79 private: | |
| 80 enum Animate { | |
| 81 ANIMATE_NO, | |
| 82 ANIMATE_SLOW, | |
| 83 ANIMATE_FAST, | |
| 84 }; | |
| 85 enum RevealState { | |
| 86 CLOSED, // Top container only showing tabstrip, y = 0. | |
| 87 SLIDING_OPEN, // All views showing, y animating from -height to 0. | |
| 88 REVEALED, // All views showing, y = 0. | |
| 89 SLIDING_CLOSED, // All views showing, y animating from 0 to -height. | |
| 90 }; | |
| 91 | |
| 92 // Enables or disables observers for mouse move and window restore. | |
| 93 void EnableWindowObservers(bool enable); | |
| 94 | |
| 95 // Temporarily reveals the top-of-window views while in immersive mode, | |
| 96 // hiding them when the cursor exits the area of the top views. If |animate| | |
| 97 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately. | |
| 98 void StartReveal(Animate animate); | |
| 99 | |
| 100 // Updates layout for |browser_view_| including window caption controls and | |
| 101 // tab strip style |immersive_style|. | |
| 102 void LayoutBrowserView(bool immersive_style); | |
| 103 | |
| 104 // Slides open the reveal view at the top of the screen. | |
| 105 void AnimateSlideOpen(); | |
| 106 void OnSlideOpenAnimationCompleted(); | |
| 107 | |
| 108 // Called when the mouse exits the reveal view area, may end the reveal. | |
| 109 void OnRevealViewLostMouse(); | |
| 110 | |
| 111 // Hides the top-of-window views. Optionally animates. | |
| 112 void EndReveal(Animate animate); | |
| 113 | |
| 114 // Slide out the reveal view. | |
| 115 void AnimateSlideClosed(int duration_ms); | |
| 116 void OnSlideClosedAnimationCompleted(); | |
| 117 | |
| 118 // Browser view holding the views to be shown and hidden. Not owned. | |
| 119 BrowserView* browser_view_; | |
| 120 | |
| 121 // True when in immersive mode. | |
| 122 bool enabled_; | |
| 123 | |
| 124 // State machine for the revealed/closed animations. | |
| 125 RevealState reveal_state_; | |
| 126 | |
| 127 // If true, reveal will not be canceled when the mouse moves outside the | |
| 128 // top view. | |
| 129 bool reveal_locked_; | |
| 130 | |
| 131 // True if the miniature "tab indicators" should be hidden in the main browser | |
| 132 // view when immersive mode is enabled. | |
| 133 bool hide_tab_indicators_; | |
| 134 | |
| 135 // Timer to track cursor being held at the top. | |
| 136 base::OneShotTimer<ImmersiveModeController> top_timer_; | |
| 137 | |
| 138 // Mouse is hovering over the revealed view. | |
| 139 bool reveal_hovered_; | |
| 140 | |
| 141 // Native window for the browser, needed to clean up observers. | |
| 142 gfx::NativeWindow native_window_; | |
| 143 | |
| 144 #if defined(USE_AURA) | |
| 145 // Observer to disable immersive mode when window leaves the maximized state. | |
| 146 class WindowObserver; | |
| 147 scoped_ptr<WindowObserver> window_observer_; | |
| 148 #endif | |
| 149 | |
| 150 // Animation observers. They must be separate because animations can be | |
| 151 // aborted and have their observers triggered at any time and the state | |
| 152 // machine needs to know which animation completed. | |
| 153 class AnimationObserver; | |
| 154 scoped_ptr<AnimationObserver> slide_open_observer_; | |
| 155 scoped_ptr<AnimationObserver> slide_closed_observer_; | |
| 156 | |
| 157 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeController); | |
| 158 }; | |
| 159 | |
| 160 #endif // CHROME_BROWSER_UI_VIEWS_IMMERSIVE_MODE_CONTROLLER_H_ | |
| OLD | NEW |