| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 8 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
| 9 | 9 |
| 10 #include "base/timer.h" | 10 #include "base/timer.h" |
| 11 #include "ui/base/events/event_handler.h" | 11 #include "ui/base/events/event_handler.h" |
| 12 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/compositor/layer_animation_observer.h" |
| 13 #include "ui/views/focus/focus_manager.h" | 13 #include "ui/views/focus/focus_manager.h" |
| 14 #include "ui/views/widget/widget_observer.h" | 14 #include "ui/views/widget/widget_observer.h" |
| 15 | 15 |
| 16 class BrowserView; | 16 class BrowserView; |
| 17 | 17 |
| 18 namespace aura { |
| 19 class Window; |
| 20 } |
| 21 |
| 22 namespace gfx { |
| 23 class Transform; |
| 24 } |
| 25 |
| 26 namespace ui { |
| 27 class Layer; |
| 28 } |
| 29 |
| 18 namespace views { | 30 namespace views { |
| 19 class View; | 31 class View; |
| 20 } | 32 } |
| 21 | 33 |
| 22 class ImmersiveModeControllerAsh : public ImmersiveModeController, | 34 class ImmersiveModeControllerAsh : public ImmersiveModeController, |
| 23 public ui::EventHandler, | 35 public ui::EventHandler, |
| 36 public ui::ImplicitAnimationObserver, |
| 24 public views::FocusChangeListener, | 37 public views::FocusChangeListener, |
| 25 public views::WidgetObserver { | 38 public views::WidgetObserver { |
| 26 public: | 39 public: |
| 27 ImmersiveModeControllerAsh(); | 40 ImmersiveModeControllerAsh(); |
| 28 virtual ~ImmersiveModeControllerAsh(); | 41 virtual ~ImmersiveModeControllerAsh(); |
| 29 | 42 |
| 30 // These methods are used to increment and decrement |revealed_lock_count_|. | 43 // These methods are used to increment and decrement |revealed_lock_count_|. |
| 31 // If immersive mode is enabled, a transition from 1 to 0 in | 44 // If immersive mode is enabled, a transition from 1 to 0 in |
| 32 // |revealed_lock_count_| closes the top-of-window views and a transition | 45 // |revealed_lock_count_| closes the top-of-window views and a transition |
| 33 // from 0 to 1 in |revealed_lock_count_| reveals the top-of-window views. | 46 // from 0 to 1 in |revealed_lock_count_| reveals the top-of-window views. |
| 34 void LockRevealedState(); | 47 void LockRevealedState(); |
| 35 void UnlockRevealedState(); | 48 void UnlockRevealedState(); |
| 36 | 49 |
| 50 // Shows the reveal view without any animations if immersive mode is enabled. |
| 51 void MaybeRevealWithoutAnimation(); |
| 52 |
| 37 // ImmersiveModeController overrides: | 53 // ImmersiveModeController overrides: |
| 38 virtual void Init(BrowserView* browser_view) OVERRIDE; | 54 virtual void Init(BrowserView* browser_view) OVERRIDE; |
| 39 virtual void SetEnabled(bool enabled) OVERRIDE; | 55 virtual void SetEnabled(bool enabled) OVERRIDE; |
| 40 virtual bool IsEnabled() const OVERRIDE; | 56 virtual bool IsEnabled() const OVERRIDE; |
| 41 virtual bool ShouldHideTabIndicators() const OVERRIDE; | 57 virtual bool ShouldHideTabIndicators() const OVERRIDE; |
| 42 virtual bool ShouldHideTopViews() const OVERRIDE; | 58 virtual bool ShouldHideTopViews() const OVERRIDE; |
| 43 virtual bool IsRevealed() const OVERRIDE; | 59 virtual bool IsRevealed() const OVERRIDE; |
| 44 virtual void MaybeStackViewAtTop() OVERRIDE; | 60 virtual void MaybeStackViewAtTop() OVERRIDE; |
| 45 virtual ImmersiveModeController::RevealedLock* | 61 virtual ImmersiveModeController::RevealedLock* |
| 46 GetRevealedLock() OVERRIDE WARN_UNUSED_RESULT; | 62 GetRevealedLock() OVERRIDE WARN_UNUSED_RESULT; |
| 63 virtual void AnchorWidgetToTopContainer(views::Widget* widget, |
| 64 int y_offset) OVERRIDE; |
| 65 virtual void UnanchorWidgetFromTopContainer(views::Widget* widget) OVERRIDE; |
| 66 virtual void OnTopContainerBoundsChanged() OVERRIDE; |
| 47 | 67 |
| 48 // ui::EventHandler overrides: | 68 // ui::EventHandler overrides: |
| 49 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 69 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 50 | 70 |
| 51 // views::FocusChangeObserver overrides: | 71 // views::FocusChangeObserver overrides: |
| 52 virtual void OnWillChangeFocus(views::View* focused_before, | 72 virtual void OnWillChangeFocus(views::View* focused_before, |
| 53 views::View* focused_now) OVERRIDE; | 73 views::View* focused_now) OVERRIDE; |
| 54 virtual void OnDidChangeFocus(views::View* focused_before, | 74 virtual void OnDidChangeFocus(views::View* focused_before, |
| 55 views::View* focused_now) OVERRIDE; | 75 views::View* focused_now) OVERRIDE; |
| 56 | 76 |
| 57 // views::WidgetObserver overrides: | 77 // views::WidgetObserver overrides: |
| 58 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; | 78 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; |
| 59 virtual void OnWidgetActivationChanged(views::Widget* widget, | 79 virtual void OnWidgetActivationChanged(views::Widget* widget, |
| 60 bool active) OVERRIDE; | 80 bool active) OVERRIDE; |
| 61 | 81 |
| 82 // ui::ImplicitAnimationObserver override: |
| 83 virtual void OnImplicitAnimationsCompleted() OVERRIDE; |
| 84 |
| 62 // Testing interface. | 85 // Testing interface. |
| 63 void SetHideTabIndicatorsForTest(bool hide); | 86 void SetHideTabIndicatorsForTest(bool hide); |
| 64 void StartRevealForTest(bool hovered); | 87 void StartRevealForTest(bool hovered); |
| 65 void SetMouseHoveredForTest(bool hovered); | 88 void SetMouseHoveredForTest(bool hovered); |
| 66 | 89 |
| 67 private: | 90 private: |
| 68 enum Animate { | 91 enum Animate { |
| 69 ANIMATE_NO, | 92 ANIMATE_NO, |
| 70 ANIMATE_SLOW, | 93 ANIMATE_SLOW, |
| 71 ANIMATE_FAST, | 94 ANIMATE_FAST, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 88 // Acquire the mouse revealed lock if it is not already held. | 111 // Acquire the mouse revealed lock if it is not already held. |
| 89 void AcquireMouseRevealedLock(); | 112 void AcquireMouseRevealedLock(); |
| 90 | 113 |
| 91 // Update |focus_revealed_lock_| based on the currently active view and the | 114 // Update |focus_revealed_lock_| based on the currently active view and the |
| 92 // currently active widget. | 115 // currently active widget. |
| 93 void UpdateFocusRevealedLock(); | 116 void UpdateFocusRevealedLock(); |
| 94 | 117 |
| 95 // Returns the animation duration given |animate|. | 118 // Returns the animation duration given |animate|. |
| 96 int GetAnimationDuration(Animate animate) const; | 119 int GetAnimationDuration(Animate animate) const; |
| 97 | 120 |
| 98 // Reveals the top-of-window views if immersive mode is enabled. | |
| 99 void MaybeStartReveal(); | |
| 100 | |
| 101 // Temporarily reveals the top-of-window views while in immersive mode, | 121 // Temporarily reveals the top-of-window views while in immersive mode, |
| 102 // hiding them when the cursor exits the area of the top views. If |animate| | 122 // hiding them when the cursor exits the area of the top views. If |animate| |
| 103 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately. | 123 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately. |
| 104 void StartReveal(Animate animate); | 124 void MaybeStartReveal(Animate animate); |
| 105 | 125 |
| 106 // Enables or disables layer-based painting to allow smooth animations. | 126 // Enables or disables layer-based painting to allow smooth animations. |
| 107 void EnablePaintToLayer(bool enable); | 127 void EnablePaintToLayer(bool enable); |
| 108 | 128 |
| 109 // Updates layout for |browser_view_| including window caption controls and | 129 // Updates layout for |browser_view_| including window caption controls and |
| 110 // tab strip style |immersive_style|. | 130 // tab strip style |immersive_style|. |
| 111 void LayoutBrowserView(bool immersive_style); | 131 void LayoutBrowserView(bool immersive_style); |
| 112 | 132 |
| 113 // Slides open the reveal view at the top of the screen. | 133 // Called when the animation to slide open the top-of-window views has |
| 114 void AnimateSlideOpen(int duration_ms); | 134 // completed. |
| 115 void OnSlideOpenAnimationCompleted(); | 135 void OnSlideOpenAnimationCompleted(); |
| 116 | 136 |
| 117 // Hides the top-of-window views if immersive mode is enabled and nothing is | 137 // Hides the top-of-window views if immersive mode is enabled and nothing is |
| 118 // keeping them revealed. Optionally animates. | 138 // keeping them revealed. Optionally animates. |
| 119 void MaybeEndReveal(Animate animate); | 139 void MaybeEndReveal(Animate animate); |
| 120 | 140 |
| 121 // Hides the top-of-window views. Optionally animates. | 141 // Called when the animation to slide out the top-of-window views has |
| 122 void EndReveal(Animate animate); | 142 // completed. |
| 143 void OnSlideClosedAnimationCompleted(); |
| 123 | 144 |
| 124 // Slide out the reveal view. | 145 // Starts an animation for the top-of-window views and any anchored widgets |
| 125 void AnimateSlideClosed(int duration_ms); | 146 // of |duration_ms| to |target_transform|. |
| 126 void OnSlideClosedAnimationCompleted(); | 147 void DoAnimation(const gfx::Transform& target_transform, int duration_ms); |
| 148 |
| 149 // Starts an animation for |layer| of |duration_ms| to |target_transform|. |
| 150 // If non-NULL, sets |observer| to be notified when the animation completes. |
| 151 void DoLayerAnimation(ui::Layer* layer, |
| 152 const gfx::Transform& target_transform, |
| 153 int duration_ms, |
| 154 ui::ImplicitAnimationObserver* observer); |
| 127 | 155 |
| 128 // Browser view holding the views to be shown and hidden. Not owned. | 156 // Browser view holding the views to be shown and hidden. Not owned. |
| 129 BrowserView* browser_view_; | 157 BrowserView* browser_view_; |
| 130 | 158 |
| 131 // True when in immersive mode. | 159 // True when in immersive mode. |
| 132 bool enabled_; | 160 bool enabled_; |
| 133 | 161 |
| 134 // State machine for the revealed/closed animations. | 162 // State machine for the revealed/closed animations. |
| 135 RevealState reveal_state_; | 163 RevealState reveal_state_; |
| 136 | 164 |
| 137 int revealed_lock_count_; | 165 int revealed_lock_count_; |
| 138 | 166 |
| 139 // True if the miniature "tab indicators" should be hidden in the main browser | 167 // True if the miniature "tab indicators" should be hidden in the main browser |
| 140 // view when immersive mode is enabled. | 168 // view when immersive mode is enabled. |
| 141 bool hide_tab_indicators_; | 169 bool hide_tab_indicators_; |
| 142 | 170 |
| 143 // Timer to track cursor being held at the top. | 171 // Timer to track cursor being held at the top. |
| 144 base::OneShotTimer<ImmersiveModeController> top_timer_; | 172 base::OneShotTimer<ImmersiveModeController> top_timer_; |
| 145 | 173 |
| 146 // Lock which keeps the top-of-window views revealed based on the current | 174 // Lock which keeps the top-of-window views revealed based on the current |
| 147 // mouse state. | 175 // mouse state. |
| 148 scoped_ptr<RevealedLock> mouse_revealed_lock_; | 176 scoped_ptr<RevealedLock> mouse_revealed_lock_; |
| 149 | 177 |
| 150 // Lock which keeps the top-of-window views revealed based on the focused view | 178 // Lock which keeps the top-of-window views revealed based on the focused view |
| 151 // and the active widget. | 179 // and the active widget. |
| 152 scoped_ptr<RevealedLock> focus_revealed_lock_; | 180 scoped_ptr<RevealedLock> focus_revealed_lock_; |
| 153 | 181 |
| 154 // Native window for the browser, needed to clean up observers. | 182 // Native window for the browser, needed to clean up observers. |
| 155 gfx::NativeWindow native_window_; | 183 aura::Window* native_window_; |
| 156 | 184 |
| 157 #if defined(USE_AURA) | |
| 158 // Observer to disable immersive mode when window leaves the maximized state. | 185 // Observer to disable immersive mode when window leaves the maximized state. |
| 159 class WindowObserver; | 186 class WindowObserver; |
| 160 scoped_ptr<WindowObserver> window_observer_; | 187 scoped_ptr<WindowObserver> window_observer_; |
| 161 #endif | |
| 162 | 188 |
| 163 // Animation observers. They must be separate because animations can be | 189 // Manages widgets which are anchored to the top-of-window views. |
| 164 // aborted and have their observers triggered at any time and the state | 190 class AnchoredWidgetManager; |
| 165 // machine needs to know which animation completed. | 191 scoped_ptr<AnchoredWidgetManager> anchored_widget_manager_; |
| 166 class AnimationObserver; | |
| 167 scoped_ptr<AnimationObserver> slide_open_observer_; | |
| 168 scoped_ptr<AnimationObserver> slide_closed_observer_; | |
| 169 | 192 |
| 170 base::WeakPtrFactory<ImmersiveModeControllerAsh> weak_ptr_factory_; | 193 base::WeakPtrFactory<ImmersiveModeControllerAsh> weak_ptr_factory_; |
| 171 | 194 |
| 172 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh); | 195 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh); |
| 173 }; | 196 }; |
| 174 | 197 |
| 175 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ | 198 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ |
| OLD | NEW |