OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_ | |
6 #define ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_ | |
7 | |
8 #include <memory> | |
9 #include <vector> | |
10 | |
11 #include "ash/ash_export.h" | |
12 #include "ash/common/wm/immersive/wm_immersive_fullscreen_controller.h" | |
13 #include "ash/common/wm/immersive_revealed_lock.h" | |
14 #include "base/macros.h" | |
15 #include "base/timer/timer.h" | |
16 #include "ui/gfx/animation/animation_delegate.h" | |
17 #include "ui/views/pointer_watcher.h" | |
18 #include "ui/views/widget/widget_observer.h" | |
19 | |
20 namespace gfx { | |
21 class Point; | |
22 class SlideAnimation; | |
23 } | |
24 | |
25 namespace ui { | |
26 class GestureEvent; | |
27 class LocatedEvent; | |
28 class MouseEvent; | |
29 class TouchEvent; | |
30 } | |
31 | |
32 namespace views { | |
33 class View; | |
34 class Widget; | |
35 } | |
36 | |
37 namespace ash { | |
38 | |
39 class ImmersiveFocusWatcher; | |
40 class ImmersiveFullscreenControllerTestApi; | |
41 class ImmersiveGestureHandler; | |
42 class WmWindow; | |
43 | |
44 class ASH_EXPORT ImmersiveFullscreenController | |
45 : public WmImmersiveFullscreenController, | |
46 public gfx::AnimationDelegate, | |
47 public views::PointerWatcher, | |
48 public views::WidgetObserver, | |
49 public ImmersiveRevealedLock::Delegate { | |
50 public: | |
51 static const int kMouseRevealBoundsHeight; | |
52 | |
53 ImmersiveFullscreenController(); | |
54 ~ImmersiveFullscreenController() override; | |
55 | |
56 // WmImmersiveFullscreenController overrides: | |
57 void Init(WmImmersiveFullscreenControllerDelegate* delegate, | |
58 views::Widget* widget, | |
59 views::View* top_container) override; | |
60 void SetEnabled(WindowType window_type, bool enable) override; | |
61 bool IsEnabled() const override; | |
62 bool IsRevealed() const override; | |
63 | |
64 // Returns a lock which will keep the top-of-window views revealed for its | |
65 // lifetime. Several locks can be obtained. When all of the locks are | |
66 // destroyed, if immersive fullscreen is enabled and there is nothing else | |
67 // keeping the top-of-window views revealed, the top-of-window views will be | |
68 // closed. This method always returns a valid lock regardless of whether | |
69 // immersive fullscreen is enabled. The lock's lifetime can span immersive | |
70 // fullscreen being enabled / disabled. If acquiring the lock causes a reveal, | |
71 // the top-of-window views will animate according to |animate_reveal|. The | |
72 // caller takes ownership of the returned lock. | |
73 ImmersiveRevealedLock* GetRevealedLock(AnimateReveal animate_reveal) | |
74 WARN_UNUSED_RESULT; | |
75 | |
76 views::Widget* widget() { return widget_; } | |
77 views::View* top_container() { return top_container_; } | |
78 | |
79 // TODO(sky): move OnMouseEvent/OnTouchEvent to private section. | |
80 void OnMouseEvent(const ui::MouseEvent& event, | |
81 const gfx::Point& location_in_screen, | |
82 views::Widget* target); | |
83 void OnTouchEvent(const ui::TouchEvent& event, | |
84 const gfx::Point& location_in_screen); | |
85 // Processes a GestureEvent. This may call SetHandled() on the supplied event. | |
86 void OnGestureEvent(ui::GestureEvent* event, | |
87 const gfx::Point& location_in_screen); | |
88 | |
89 // views::PointerWatcher: | |
90 void OnPointerEventObserved(const ui::PointerEvent& event, | |
91 const gfx::Point& location_in_screen, | |
92 views::Widget* target) override; | |
93 void OnMouseCaptureChanged() override; | |
94 | |
95 // views::WidgetObserver overrides: | |
96 void OnWidgetDestroying(views::Widget* widget) override; | |
97 | |
98 // gfx::AnimationDelegate overrides: | |
99 void AnimationEnded(const gfx::Animation* animation) override; | |
100 void AnimationProgressed(const gfx::Animation* animation) override; | |
101 | |
102 // ash::ImmersiveRevealedLock::Delegate overrides: | |
103 void LockRevealedState(AnimateReveal animate_reveal) override; | |
104 void UnlockRevealedState() override; | |
105 | |
106 private: | |
107 friend class ImmersiveFullscreenControllerTest; | |
108 friend class ImmersiveFullscreenControllerTestApi; | |
109 | |
110 enum Animate { | |
111 ANIMATE_NO, | |
112 ANIMATE_SLOW, | |
113 ANIMATE_FAST, | |
114 }; | |
115 enum RevealState { | |
116 CLOSED, | |
117 SLIDING_OPEN, | |
118 REVEALED, | |
119 SLIDING_CLOSED, | |
120 }; | |
121 enum SwipeType { SWIPE_OPEN, SWIPE_CLOSE, SWIPE_NONE }; | |
122 | |
123 // Enables or disables observers for mouse, touch, focus, and activation. | |
124 void EnableWindowObservers(bool enable); | |
125 | |
126 // Updates |top_edge_hover_timer_| based on a mouse |event|. If the mouse is | |
127 // hovered at the top of the screen the timer is started. If the mouse moves | |
128 // away from the top edge, or moves too much in the x direction, the timer is | |
129 // stopped. | |
130 void UpdateTopEdgeHoverTimer(const ui::MouseEvent& event, | |
131 const gfx::Point& location_in_screen, | |
132 views::Widget* target); | |
133 | |
134 // Updates |located_event_revealed_lock_| based on the current mouse state and | |
135 // the current touch state. | |
136 // |event| is NULL if the source event is not known. | |
137 void UpdateLocatedEventRevealedLock(const ui::LocatedEvent* event, | |
138 const gfx::Point& location_in_screen); | |
139 | |
140 // Convenience for calling two argument version with a null event and looking | |
141 // up the location from the last mouse location. | |
142 void UpdateLocatedEventRevealedLock(); | |
143 | |
144 // Acquires |located_event_revealed_lock_| if it is not already held. | |
145 void AcquireLocatedEventRevealedLock(); | |
146 | |
147 // Updates |focus_revealed_lock_| based on the currently active view and the | |
148 // currently active widget. | |
149 void UpdateFocusRevealedLock(); | |
150 | |
151 // Update |located_event_revealed_lock_| and |focus_revealed_lock_| as a | |
152 // result of a gesture of |swipe_type|. Returns true if any locks were | |
153 // acquired or released. | |
154 bool UpdateRevealedLocksForSwipe(SwipeType swipe_type); | |
155 | |
156 // Returns the animation duration given |animate|. | |
157 int GetAnimationDuration(Animate animate) const; | |
158 | |
159 // Temporarily reveals the top-of-window views while in immersive mode, | |
160 // hiding them when the cursor exits the area of the top views. If |animate| | |
161 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately. | |
162 void MaybeStartReveal(Animate animate); | |
163 | |
164 // Called when the animation to slide open the top-of-window views has | |
165 // completed. | |
166 void OnSlideOpenAnimationCompleted(); | |
167 | |
168 // Hides the top-of-window views if immersive mode is enabled and nothing is | |
169 // keeping them revealed. Optionally animates. | |
170 void MaybeEndReveal(Animate animate); | |
171 | |
172 // Called when the animation to slide out the top-of-window views has | |
173 // completed. | |
174 void OnSlideClosedAnimationCompleted(); | |
175 | |
176 // Returns the type of swipe given |event|. | |
177 SwipeType GetSwipeType(const ui::GestureEvent& event) const; | |
178 | |
179 // Returns true if a mouse event at |location_in_screen| should be ignored. | |
180 // Ignored mouse events should not contribute to revealing or unrevealing the | |
181 // top-of-window views. | |
182 bool ShouldIgnoreMouseEventAtLocation( | |
183 const gfx::Point& location_in_screen) const; | |
184 | |
185 // True when |location| is "near" to the top container. When the top container | |
186 // is not closed "near" means within the displayed bounds or above it. When | |
187 // the top container is closed "near" means either within the displayed | |
188 // bounds, above it, or within a few pixels below it. This allow the container | |
189 // to steal enough pixels to detect a swipe in and handles the case that there | |
190 // is a bezel sensor above the top container. | |
191 bool ShouldHandleGestureEvent(const gfx::Point& location) const; | |
192 | |
193 // Returns the display bounds of the screen |widget_| is on. | |
194 gfx::Rect GetDisplayBoundsInScreen() const; | |
195 | |
196 // Not owned. | |
197 WmImmersiveFullscreenControllerDelegate* delegate_; | |
198 views::View* top_container_; | |
199 views::Widget* widget_; | |
200 // The WmWindow for |widget_|. | |
201 WmWindow* widget_window_ = nullptr; | |
202 | |
203 // True if the observers have been enabled. | |
204 bool observers_enabled_; | |
205 | |
206 // True when in immersive fullscreen. | |
207 bool enabled_; | |
208 | |
209 // State machine for the revealed/closed animations. | |
210 RevealState reveal_state_; | |
211 | |
212 int revealed_lock_count_; | |
213 | |
214 // Timer to track cursor being held at the top edge of the screen. | |
215 base::OneShotTimer top_edge_hover_timer_; | |
216 | |
217 // The cursor x position in screen coordinates when the cursor first hit the | |
218 // top edge of the screen. | |
219 int mouse_x_when_hit_top_in_screen_; | |
220 | |
221 // Tracks if the controller has seen a ET_GESTURE_SCROLL_BEGIN, without the | |
222 // following events. | |
223 bool gesture_begun_; | |
224 | |
225 // Lock which keeps the top-of-window views revealed based on the current | |
226 // mouse state and the current touch state. Acquiring the lock is used to | |
227 // trigger a reveal when the user moves the mouse to the top of the screen | |
228 // and when the user does a SWIPE_OPEN edge gesture. | |
229 std::unique_ptr<ImmersiveRevealedLock> located_event_revealed_lock_; | |
230 | |
231 // The animation which controls sliding the top-of-window views in and out. | |
232 std::unique_ptr<gfx::SlideAnimation> animation_; | |
233 | |
234 // Whether the animations are disabled for testing. | |
235 bool animations_disabled_for_test_; | |
236 | |
237 std::unique_ptr<ImmersiveFocusWatcher> immersive_focus_watcher_; | |
238 std::unique_ptr<ImmersiveGestureHandler> immersive_gesture_handler_; | |
239 | |
240 base::WeakPtrFactory<ImmersiveFullscreenController> weak_ptr_factory_; | |
241 | |
242 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenController); | |
243 }; | |
244 | |
245 } // namespace ash | |
246 | |
247 #endif // ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_ | |
OLD | NEW |