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