Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / ash / wm / immersive_fullscreen_controller.h
blobbee6642f97c18e9a74ccdf3d6c00804becabe789
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.
5 #ifndef ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_
6 #define ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_
8 #include <vector>
10 #include "ash/ash_export.h"
11 #include "ash/wm/immersive_revealed_lock.h"
12 #include "base/timer/timer.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/events/event_handler.h"
15 #include "ui/gfx/animation/animation_delegate.h"
16 #include "ui/views/corewm/transient_window_observer.h"
17 #include "ui/views/focus/focus_manager.h"
18 #include "ui/views/widget/widget_observer.h"
20 namespace aura {
21 class Window;
24 namespace gfx {
25 class Point;
26 class Rect;
27 class SlideAnimation;
30 namespace ui {
31 class LocatedEvent;
34 namespace views {
35 class View;
36 class Widget;
39 namespace ash {
41 class ASH_EXPORT ImmersiveFullscreenController
42 : public gfx::AnimationDelegate,
43 public ui::EventHandler,
44 public views::corewm::TransientWindowObserver,
45 public views::FocusChangeListener,
46 public views::WidgetObserver,
47 public ImmersiveRevealedLock::Delegate {
48 public:
49 // The enum is used for an enumerated histogram. New items should be only
50 // added to the end.
51 enum WindowType {
52 WINDOW_TYPE_OTHER,
53 WINDOW_TYPE_BROWSER,
54 WINDOW_TYPE_HOSTED_APP,
55 WINDOW_TYPE_PACKAGED_APP,
56 WINDOW_TYPE_COUNT
59 class Delegate {
60 public:
61 // Called when a reveal of the top-of-window views starts.
62 virtual void OnImmersiveRevealStarted() = 0;
64 // Called when the top-of-window views have finished closing. This call
65 // implies a visible fraction of 0. SetVisibleFraction(0) may not be called
66 // prior to OnImmersiveRevealEnded().
67 virtual void OnImmersiveRevealEnded() = 0;
69 // Called as a result of disabling immersive fullscreen via SetEnabled().
70 virtual void OnImmersiveFullscreenExited() = 0;
72 // Called to update the fraction of the top-of-window views height which is
73 // visible.
74 virtual void SetVisibleFraction(double visible_fraction) = 0;
76 // Returns a list of rects whose union makes up the top-of-window views.
77 // The returned list is used for hittesting when the top-of-window views
78 // are revealed. GetVisibleBoundsInScreen() must return a valid value when
79 // not in immersive fullscreen for the sake of SetupForTest().
80 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const = 0;
82 protected:
83 virtual ~Delegate() {}
86 ImmersiveFullscreenController();
87 virtual ~ImmersiveFullscreenController();
89 // Initializes the controller. Must be called prior to enabling immersive
90 // fullscreen via SetEnabled(). |top_container| is used to keep the
91 // top-of-window views revealed when a child of |top_container| has focus.
92 // |top_container| does not affect which mouse and touch events keep the
93 // top-of-window views revealed.
94 void Init(Delegate* delegate,
95 views::Widget* widget,
96 views::View* top_container);
98 // Enables or disables immersive fullscreen.
99 // |window_type| is the type of window which is put in immersive fullscreen.
100 // It is only used for histogramming.
101 void SetEnabled(WindowType window_type, bool enable);
103 // Returns true if |native_window_| is in immersive fullscreen.
104 bool IsEnabled() const;
106 // Returns true if |native_window_| is in immersive fullscreen and the
107 // top-of-window views are fully or partially visible.
108 bool IsRevealed() const;
110 // Returns a lock which will keep the top-of-window views revealed for its
111 // lifetime. Several locks can be obtained. When all of the locks are
112 // destroyed, if immersive fullscreen is enabled and there is nothing else
113 // keeping the top-of-window views revealed, the top-of-window views will be
114 // closed. This method always returns a valid lock regardless of whether
115 // immersive fullscreen is enabled. The lock's lifetime can span immersive
116 // fullscreen being enabled / disabled. If acquiring the lock causes a reveal,
117 // the top-of-window views will animate according to |animate_reveal|. The
118 // caller takes ownership of the returned lock.
119 ImmersiveRevealedLock* GetRevealedLock(
120 AnimateReveal animate_reveal) WARN_UNUSED_RESULT;
122 // Disables animations and moves the mouse so that it is not over the
123 // top-of-window views for the sake of testing.
124 void SetupForTest();
126 // ui::EventHandler overrides:
127 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
128 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
129 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
131 // views::FocusChangeObserver overrides:
132 virtual void OnWillChangeFocus(views::View* focused_before,
133 views::View* focused_now) OVERRIDE;
134 virtual void OnDidChangeFocus(views::View* focused_before,
135 views::View* focused_now) OVERRIDE;
137 // views::WidgetObserver overrides:
138 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
139 virtual void OnWidgetActivationChanged(views::Widget* widget,
140 bool active) OVERRIDE;
142 // gfx::AnimationDelegate overrides:
143 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
144 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
146 // views::corewm::TransientWindowObserver overrides:
147 virtual void OnTransientChildAdded(aura::Window* window,
148 aura::Window* transient) OVERRIDE;
149 virtual void OnTransientChildRemoved(aura::Window* window,
150 aura::Window* transient) OVERRIDE;
152 // ash::ImmersiveRevealedLock::Delegate overrides:
153 virtual void LockRevealedState(AnimateReveal animate_reveal) OVERRIDE;
154 virtual void UnlockRevealedState() OVERRIDE;
156 private:
157 friend class ImmersiveFullscreenControllerTest;
159 enum Animate {
160 ANIMATE_NO,
161 ANIMATE_SLOW,
162 ANIMATE_FAST,
164 enum RevealState {
165 CLOSED,
166 SLIDING_OPEN,
167 REVEALED,
168 SLIDING_CLOSED,
170 enum SwipeType {
171 SWIPE_OPEN,
172 SWIPE_CLOSE,
173 SWIPE_NONE
176 // Enables or disables observers for mouse, touch, focus, and activation.
177 void EnableWindowObservers(bool enable);
179 // Updates |top_edge_hover_timer_| based on a mouse |event|. If the mouse is
180 // hovered at the top of the screen the timer is started. If the mouse moves
181 // away from the top edge, or moves too much in the x direction, the timer is
182 // stopped.
183 void UpdateTopEdgeHoverTimer(ui::MouseEvent* event);
185 // Updates |located_event_revealed_lock_| based on the current mouse state and
186 // the current touch state.
187 // |event| is NULL if the source event is not known.
188 void UpdateLocatedEventRevealedLock(ui::LocatedEvent* event);
190 // Acquires |located_event_revealed_lock_| if it is not already held.
191 void AcquireLocatedEventRevealedLock();
193 // Updates |focus_revealed_lock_| based on the currently active view and the
194 // currently active widget.
195 void UpdateFocusRevealedLock();
197 // Update |located_event_revealed_lock_| and |focus_revealed_lock_| as a
198 // result of a gesture of |swipe_type|. Returns true if any locks were
199 // acquired or released.
200 bool UpdateRevealedLocksForSwipe(SwipeType swipe_type);
202 // Returns the animation duration given |animate|.
203 int GetAnimationDuration(Animate animate) const;
205 // Temporarily reveals the top-of-window views while in immersive mode,
206 // hiding them when the cursor exits the area of the top views. If |animate|
207 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately.
208 void MaybeStartReveal(Animate animate);
210 // Called when the animation to slide open the top-of-window views has
211 // completed.
212 void OnSlideOpenAnimationCompleted();
214 // Hides the top-of-window views if immersive mode is enabled and nothing is
215 // keeping them revealed. Optionally animates.
216 void MaybeEndReveal(Animate animate);
218 // Called when the animation to slide out the top-of-window views has
219 // completed.
220 void OnSlideClosedAnimationCompleted();
222 // Returns the type of swipe given |event|.
223 SwipeType GetSwipeType(ui::GestureEvent* event) const;
225 // Returns true if a mouse event at |location_in_screen| should be ignored.
226 // Ignored mouse events should not contribute to revealing or unrevealing the
227 // top-of-window views.
228 bool ShouldIgnoreMouseEventAtLocation(
229 const gfx::Point& location_in_screen) const;
231 // True when |location| is "near" to the top container. When the top container
232 // is not closed "near" means within the displayed bounds or above it. When
233 // the top container is closed "near" means either within the displayed
234 // bounds, above it, or within a few pixels below it. This allow the container
235 // to steal enough pixels to detect a swipe in and handles the case that there
236 // is a bezel sensor above the top container.
237 bool ShouldHandleGestureEvent(const gfx::Point& location) const;
239 // Recreate |bubble_manager_| and start observing any bubbles anchored to a
240 // child of |top_container_|.
241 void RecreateBubbleManager();
243 // Not owned.
244 Delegate* delegate_;
245 views::View* top_container_;
246 views::Widget* widget_;
247 aura::Window* native_window_;
249 // True if the observers have been enabled.
250 bool observers_enabled_;
252 // True when in immersive fullscreen.
253 bool enabled_;
255 // State machine for the revealed/closed animations.
256 RevealState reveal_state_;
258 int revealed_lock_count_;
260 // Timer to track cursor being held at the top edge of the screen.
261 base::OneShotTimer<ImmersiveFullscreenController> top_edge_hover_timer_;
263 // The cursor x position in screen coordinates when the cursor first hit the
264 // top edge of the screen.
265 int mouse_x_when_hit_top_in_screen_;
267 // Tracks if the controller has seen a ET_GESTURE_SCROLL_BEGIN, without the
268 // following events.
269 bool gesture_begun_;
271 // Lock which keeps the top-of-window views revealed based on the current
272 // mouse state and the current touch state. Acquiring the lock is used to
273 // trigger a reveal when the user moves the mouse to the top of the screen
274 // and when the user does a SWIPE_OPEN edge gesture.
275 scoped_ptr<ImmersiveRevealedLock> located_event_revealed_lock_;
277 // Lock which keeps the top-of-window views revealed based on the focused view
278 // and the active widget. Acquiring the lock never triggers a reveal because
279 // a view is not focusable till a reveal has made it visible.
280 scoped_ptr<ImmersiveRevealedLock> focus_revealed_lock_;
282 // The animation which controls sliding the top-of-window views in and out.
283 scoped_ptr<gfx::SlideAnimation> animation_;
285 // Whether the animations are disabled for testing.
286 bool animations_disabled_for_test_;
288 // Manages bubbles which are anchored to a child of |top_container_|.
289 class BubbleManager;
290 scoped_ptr<BubbleManager> bubble_manager_;
292 base::WeakPtrFactory<ImmersiveFullscreenController> weak_ptr_factory_;
294 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenController);
297 } // namespace ash
299 #endif // ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_