Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: ash/wm/immersive_fullscreen_controller.h

Issue 48963002: [Refactor] Move the non-browser specific logic of ImmersiveModeControllerAsh into ash part 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ 6 #define ASH_WM_IMMERSIVE_FULLSCREEN_CONTROLLER_H_
7 7
8 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 8 #include <vector>
9 9
10 #include "ash/ash_export.h"
11 #include "ash/wm/immersive_revealed_lock.h"
10 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "ui/aura/window_observer.h" 13 #include "ui/aura/window_observer.h"
14 #include "ui/events/event_handler.h" 14 #include "ui/events/event_handler.h"
15 #include "ui/gfx/animation/animation_delegate.h" 15 #include "ui/gfx/animation/animation_delegate.h"
16 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
17 #include "ui/views/focus/focus_manager.h" 17 #include "ui/views/focus/focus_manager.h"
18 #include "ui/views/widget/widget_observer.h" 18 #include "ui/views/widget/widget_observer.h"
19 19
20 class BrowserView;
21 class BookmarkBarView;
22
23 namespace aura { 20 namespace aura {
24 class Window; 21 class Window;
25 } 22 }
26 23
27 namespace gfx { 24 namespace gfx {
28 class SlideAnimation; 25 class SlideAnimation;
29 class Transform;
30 } 26 }
31 27
32 namespace ui { 28 namespace ui {
33 class Layer;
34 class LocatedEvent; 29 class LocatedEvent;
35 } 30 }
36 31
37 namespace views { 32 namespace views {
38 class View; 33 class View;
34 class Widget;
39 } 35 }
40 36
41 class ImmersiveModeControllerAsh : public ImmersiveModeController, 37 namespace ash {
42 public content::NotificationObserver, 38
43 public gfx::AnimationDelegate, 39 class ASH_EXPORT ImmersiveFullscreenController
44 public ui::EventHandler, 40 : public gfx::AnimationDelegate,
45 public views::FocusChangeListener, 41 public ui::EventHandler,
46 public views::WidgetObserver, 42 public views::FocusChangeListener,
47 public aura::WindowObserver { 43 public views::WidgetObserver,
44 public aura::WindowObserver,
45 public ImmersiveRevealedLock::Delegate {
48 public: 46 public:
49 ImmersiveModeControllerAsh(); 47 class Delegate {
50 virtual ~ImmersiveModeControllerAsh(); 48 public:
49 // Called when a reveal of the top-of-window views starts.
50 virtual void OnImmersiveRevealStarted() = 0;
51 51
52 // These methods are used to increment and decrement |revealed_lock_count_|. 52 // Called when the top-of-window views have finished closing. This call
53 // If immersive mode is enabled, a transition from 1 to 0 in 53 // implies a visibility of 0. SetVisibility(0) may not be called prior to
54 // |revealed_lock_count_| closes the top-of-window views and a transition 54 // OnImmersiveRevealEnded().
55 // from 0 to 1 in |revealed_lock_count_| reveals the top-of-window views. 55 virtual void OnImmersiveRevealEnded() = 0;
56 void LockRevealedState(AnimateReveal animate_reveal);
57 void UnlockRevealedState();
58 56
59 // ImmersiveModeController overrides: 57 // Called as a result of disabling immersive fullscreen via SetEnabled().
60 virtual void Init(Delegate* delegate, 58 virtual void OnImmersiveFullscreenExited() = 0;
61 views::Widget* widget,
62 views::View* top_container) OVERRIDE;
63 virtual void SetEnabled(bool enabled) OVERRIDE;
64 virtual bool IsEnabled() const OVERRIDE;
65 virtual bool ShouldHideTabIndicators() const OVERRIDE;
66 virtual bool ShouldHideTopViews() const OVERRIDE;
67 virtual bool IsRevealed() const OVERRIDE;
68 virtual int GetTopContainerVerticalOffset(
69 const gfx::Size& top_container_size) const OVERRIDE;
70 virtual ImmersiveRevealedLock* GetRevealedLock(
71 AnimateReveal animate_reveal) OVERRIDE WARN_UNUSED_RESULT;
72 virtual void OnFindBarVisibleBoundsChanged(
73 const gfx::Rect& new_visible_bounds_in_screen) OVERRIDE;
74 virtual void SetupForTest() OVERRIDE;
75 59
76 // content::NotificationObserver override: 60 // Called to update the fraction of the top-of-window views height which is
77 virtual void Observe(int type, 61 // visible.
78 const content::NotificationSource& source, 62 virtual void SetVisibility(double visible_fraction) = 0;
James Cook 2013/10/28 18:32:51 I initially thought this was either like SetVisibl
pkotwicz 2013/10/29 04:32:45 Done.
79 const content::NotificationDetails& details) OVERRIDE; 63
64 // Returns a list of rects whose union make up the top-of-window views.
65 // The returned list is used for hittesting when the top-of-window views
66 // are revealed.
67 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() = 0;
68
69 protected:
70 virtual ~Delegate() {}
71 };
72
73 ImmersiveFullscreenController();
74 virtual ~ImmersiveFullscreenController();
75
76 // Initializes the controller. Must be called prior to enabling immersive
77 // fullscreen via SetEnabled(). |top_container| is used to keep the
78 // top-of-window views revealed when a child of |top_container| has focus.
79 // |top_container| has no effect on which mouse and touch events keep the
80 // top-of-window views revealed.
81 void Init(Delegate* delegate,
82 views::Widget* widget,
83 views::View* top_container);
84
85 // Enables or disables immersive fullscreen.
86 void SetEnabled(bool enable);
87
88 // Returns true if |native_window_| is in immersive fullscreen.
89 bool IsEnabled() const;
90
91 // Returns true if |native_window_| is in immersive fullscreen and the
92 // top-of-window views are fully or partially visible.
93 bool IsRevealed() const;
94
95 // Returns a lock which will keep the top-of-window views revealed for its
96 // lifetime. Several locks can be obtained. When all of the locks are
97 // destroyed, if immersive fullscreen is enabled and there is nothing else
98 // keeping the top-of-window views revealed, the top-of-window views will be
99 // closed. This method always returns a valid lock regardless of whether
100 // immersive fullscreen is enabled. The lock's lifetime can span immersive
101 // fullscreen being enabled / disabled. If acquiring the lock causes a reveal,
102 // the top-of-window views will animate according to |animate_reveal|. The
103 // caller takes ownership of the returned lock.
104 ImmersiveRevealedLock* GetRevealedLock(
105 AnimateReveal animate_reveal) WARN_UNUSED_RESULT;
106
107 // Disables animations and moves the mouse so that it is not over the
108 // top-of-window views for the sake of testing.
109 void SetupForTest();
80 110
81 // ui::EventHandler overrides: 111 // ui::EventHandler overrides:
82 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 112 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
83 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 113 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
84 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 114 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
85 115
86 // views::FocusChangeObserver overrides: 116 // views::FocusChangeObserver overrides:
87 virtual void OnWillChangeFocus(views::View* focused_before, 117 virtual void OnWillChangeFocus(views::View* focused_before,
88 views::View* focused_now) OVERRIDE; 118 views::View* focused_now) OVERRIDE;
89 virtual void OnDidChangeFocus(views::View* focused_before, 119 virtual void OnDidChangeFocus(views::View* focused_before,
90 views::View* focused_now) OVERRIDE; 120 views::View* focused_now) OVERRIDE;
91 121
92 // views::WidgetObserver overrides: 122 // views::WidgetObserver overrides:
93 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 123 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
94 virtual void OnWidgetActivationChanged(views::Widget* widget, 124 virtual void OnWidgetActivationChanged(views::Widget* widget,
95 bool active) OVERRIDE; 125 bool active) OVERRIDE;
96 126
97 // gfx::AnimationDelegate overrides: 127 // gfx::AnimationDelegate overrides:
98 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 128 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
99 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 129 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
100 130
101 // aura::WindowObserver overrides: 131 // aura::WindowObserver overrides:
102 virtual void OnWindowPropertyChanged(aura::Window* window,
103 const void* key,
104 intptr_t old) OVERRIDE;
105 virtual void OnAddTransientChild(aura::Window* window, 132 virtual void OnAddTransientChild(aura::Window* window,
106 aura::Window* transient) OVERRIDE; 133 aura::Window* transient) OVERRIDE;
107 virtual void OnRemoveTransientChild(aura::Window* window, 134 virtual void OnRemoveTransientChild(aura::Window* window,
108 aura::Window* transient) OVERRIDE; 135 aura::Window* transient) OVERRIDE;
109 136
137 // ash::ImmersiveRevealedLock::Delegate overrides:
138 virtual void LockRevealedState(AnimateReveal animate_reveal) OVERRIDE;
139 virtual void UnlockRevealedState() OVERRIDE;
140
110 private: 141 private:
111 friend class ImmersiveModeControllerAshTest; 142 friend class ImmersiveFullscreenControllerTest;
112 143
113 enum AllowRevealWhileClosing { 144 enum AllowRevealWhileClosing {
114 ALLOW_REVEAL_WHILE_CLOSING_YES, 145 ALLOW_REVEAL_WHILE_CLOSING_YES,
115 ALLOW_REVEAL_WHILE_CLOSING_NO 146 ALLOW_REVEAL_WHILE_CLOSING_NO
116 }; 147 };
117 enum Animate { 148 enum Animate {
118 ANIMATE_NO, 149 ANIMATE_NO,
119 ANIMATE_SLOW, 150 ANIMATE_SLOW,
120 ANIMATE_FAST, 151 ANIMATE_FAST,
121 }; 152 };
122 enum Layout {
123 LAYOUT_YES,
124 LAYOUT_NO
125 };
126 enum RevealState { 153 enum RevealState {
127 CLOSED, // Top container only showing tabstrip, y = 0. 154 CLOSED,
James Cook 2013/10/28 18:32:51 Are the old comments no longer accurate? What hap
pkotwicz 2013/10/29 04:32:45 The y position is actually an implementation detai
128 SLIDING_OPEN, // All views showing, y animating from -height to 0. 155 SLIDING_OPEN,
129 REVEALED, // All views showing, y = 0. 156 REVEALED,
130 SLIDING_CLOSED, // All views showing, y animating from 0 to -height. 157 SLIDING_CLOSED,
131 };
132 enum TabIndicatorVisibility {
133 TAB_INDICATORS_FORCE_HIDE,
134 TAB_INDICATORS_HIDE,
135 TAB_INDICATORS_SHOW
136 }; 158 };
137 enum SwipeType { 159 enum SwipeType {
138 SWIPE_OPEN, 160 SWIPE_OPEN,
139 SWIPE_CLOSE, 161 SWIPE_CLOSE,
140 SWIPE_NONE 162 SWIPE_NONE
141 }; 163 };
142 164
143 // Enables or disables observers for mouse move, focus, and window restore. 165 // Enables or disables observers for mouse, touch, focus, and activation.
144 void EnableWindowObservers(bool enable); 166 void EnableWindowObservers(bool enable);
145 167
146 // Updates |top_edge_hover_timer_| based on a mouse |event|. If the mouse is 168 // Updates |top_edge_hover_timer_| based on a mouse |event|. If the mouse is
147 // hovered at the top of the screen the timer is started. If the mouse moves 169 // hovered at the top of the screen the timer is started. If the mouse moves
148 // away from the top edge, or moves too much in the x direction, the timer is 170 // away from the top edge, or moves too much in the x direction, the timer is
149 // stopped. 171 // stopped.
150 void UpdateTopEdgeHoverTimer(ui::MouseEvent* event); 172 void UpdateTopEdgeHoverTimer(ui::MouseEvent* event);
151 173
152 // Updates |located_event_revealed_lock_| based on the current mouse state and 174 // Updates |located_event_revealed_lock_| based on the current mouse state and
153 // the current touch state. 175 // the current touch state.
(...skipping 10 matching lines...) Expand all
164 186
165 // Updates |focus_revealed_lock_| based on the currently active view and the 187 // Updates |focus_revealed_lock_| based on the currently active view and the
166 // currently active widget. 188 // currently active widget.
167 void UpdateFocusRevealedLock(); 189 void UpdateFocusRevealedLock();
168 190
169 // Update |located_event_revealed_lock_| and |focus_revealed_lock_| as a 191 // Update |located_event_revealed_lock_| and |focus_revealed_lock_| as a
170 // result of a gesture of |swipe_type|. Returns true if any locks were 192 // result of a gesture of |swipe_type|. Returns true if any locks were
171 // acquired or released. 193 // acquired or released.
172 bool UpdateRevealedLocksForSwipe(SwipeType swipe_type); 194 bool UpdateRevealedLocksForSwipe(SwipeType swipe_type);
173 195
174 // Updates whether fullscreen uses any chrome at all. When using minimal
175 // chrome, a 'light bar' is permanently visible for the launcher and possibly
176 // for the tabstrip.
177 void UpdateUseMinimalChrome(Layout layout);
178
179 // Returns the animation duration given |animate|. 196 // Returns the animation duration given |animate|.
180 int GetAnimationDuration(Animate animate) const; 197 int GetAnimationDuration(Animate animate) const;
181 198
182 // Temporarily reveals the top-of-window views while in immersive mode, 199 // Temporarily reveals the top-of-window views while in immersive mode,
183 // hiding them when the cursor exits the area of the top views. If |animate| 200 // hiding them when the cursor exits the area of the top views. If |animate|
184 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately. 201 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately.
185 void MaybeStartReveal(Animate animate); 202 void MaybeStartReveal(Animate animate);
186 203
187 // Updates the browser root view's layout including window caption controls.
188 void LayoutBrowserRootView();
189
190 // Called when the animation to slide open the top-of-window views has 204 // Called when the animation to slide open the top-of-window views has
191 // completed. 205 // completed.
192 void OnSlideOpenAnimationCompleted(Layout layout); 206 void OnSlideOpenAnimationCompleted();
193 207
194 // Hides the top-of-window views if immersive mode is enabled and nothing is 208 // Hides the top-of-window views if immersive mode is enabled and nothing is
195 // keeping them revealed. Optionally animates. 209 // keeping them revealed. Optionally animates.
196 void MaybeEndReveal(Animate animate); 210 void MaybeEndReveal(Animate animate);
197 211
198 // Called when the animation to slide out the top-of-window views has 212 // Called when the animation to slide out the top-of-window views has
199 // completed. 213 // completed.
200 void OnSlideClosedAnimationCompleted(); 214 void OnSlideClosedAnimationCompleted();
201 215
202 // Returns the type of swipe given |event|. 216 // Returns the type of swipe given |event|.
(...skipping 10 matching lines...) Expand all
213 // the top container is closed "near" means either within the displayed 227 // the top container is closed "near" means either within the displayed
214 // bounds, above it, or within a few pixels below it. This allow the container 228 // bounds, above it, or within a few pixels below it. This allow the container
215 // to steal enough pixels to detect a swipe in and handles the case that there 229 // to steal enough pixels to detect a swipe in and handles the case that there
216 // is a bezel sensor above the top container. 230 // is a bezel sensor above the top container.
217 bool ShouldHandleGestureEvent(const gfx::Point& location) const; 231 bool ShouldHandleGestureEvent(const gfx::Point& location) const;
218 232
219 // Recreate |bubble_manager_| and start observing any bubbles anchored to a 233 // Recreate |bubble_manager_| and start observing any bubbles anchored to a
220 // child of |top_container_|. 234 // child of |top_container_|.
221 void RecreateBubbleManager(); 235 void RecreateBubbleManager();
222 236
223 // Shrinks or expands the touch hit test by updating insets for the render 237 // Not owned.
224 // window depending on if top_inset is positive or negative respectively. 238 Delegate* delegate_;
225 // Used to ensure that touch events at the top of the screen go to the top 239 views::View* top_container_;
226 // container so a slide gesture can be generated when the content window is 240 views::Widget* widget_;
227 // consuming all touch events sent to it. 241 aura::Window* native_window_;
228 void SetRenderWindowTopInsetsForTouch(int top_inset);
229 242
230 // Injected dependencies. Not owned. 243 // True if the observers have been enabled.
231 Delegate* delegate_;
232 views::Widget* widget_;
233 views::View* top_container_;
234
235 // True if the window observers are enabled.
236 bool observers_enabled_; 244 bool observers_enabled_;
237 245
238 // True when in immersive mode. 246 // True when in immersive fullscreen.
239 bool enabled_; 247 bool enabled_;
240 248
241 // State machine for the revealed/closed animations. 249 // State machine for the revealed/closed animations.
242 RevealState reveal_state_; 250 RevealState reveal_state_;
243 251
244 int revealed_lock_count_; 252 int revealed_lock_count_;
245 253
246 // The visibility of the miniature "tab indicators" in the main browser view
247 // when immersive mode is enabled and the top-of-window views are closed.
248 TabIndicatorVisibility tab_indicator_visibility_;
249
250 // Timer to track cursor being held at the top edge of the screen. 254 // Timer to track cursor being held at the top edge of the screen.
251 base::OneShotTimer<ImmersiveModeController> top_edge_hover_timer_; 255 base::OneShotTimer<ImmersiveFullscreenController> top_edge_hover_timer_;
252 256
253 // The cursor x position in screen coordinates when the cursor first hit the 257 // The cursor x position in screen coordinates when the cursor first hit the
254 // top edge of the screen. 258 // top edge of the screen.
255 int mouse_x_when_hit_top_in_screen_; 259 int mouse_x_when_hit_top_in_screen_;
256 260
257 // Tracks if the controller has seen a ET_GESTURE_SCROLL_BEGIN, without the 261 // Tracks if the controller has seen a ET_GESTURE_SCROLL_BEGIN, without the
258 // following events. 262 // following events.
259 bool gesture_begun_; 263 bool gesture_begun_;
260 264
261 // The current visible bounds of the find bar, in screen coordinates. This is
262 // an empty rect if the find bar is not visible.
263 gfx::Rect find_bar_visible_bounds_in_screen_;
264
265 // Lock which keeps the top-of-window views revealed based on the current 265 // Lock which keeps the top-of-window views revealed based on the current
266 // mouse state and the current touch state. Acquiring the lock is used to 266 // mouse state and the current touch state. Acquiring the lock is used to
267 // trigger a reveal when the user moves the mouse to the top of the screen 267 // trigger a reveal when the user moves the mouse to the top of the screen
268 // and when the user does a SWIPE_OPEN edge gesture. 268 // and when the user does a SWIPE_OPEN edge gesture.
269 scoped_ptr<ImmersiveRevealedLock> located_event_revealed_lock_; 269 scoped_ptr<ImmersiveRevealedLock> located_event_revealed_lock_;
270 270
271 // Lock which keeps the top-of-window views revealed based on the focused view 271 // Lock which keeps the top-of-window views revealed based on the focused view
272 // and the active widget. Acquiring the lock never triggers a reveal because 272 // and the active widget. Acquiring the lock never triggers a reveal because
273 // a view is not focusable till a reveal has made it visible. 273 // a view is not focusable till a reveal has made it visible.
274 scoped_ptr<ImmersiveRevealedLock> focus_revealed_lock_; 274 scoped_ptr<ImmersiveRevealedLock> focus_revealed_lock_;
275 275
276 // Native window for the browser.
277 aura::Window* native_window_;
278
279 // The animation which controls sliding the top-of-window views in and out. 276 // The animation which controls sliding the top-of-window views in and out.
280 scoped_ptr<gfx::SlideAnimation> animation_; 277 scoped_ptr<gfx::SlideAnimation> animation_;
281 278
282 // Whether the animations are disabled for testing. 279 // Whether the animations are disabled for testing.
283 bool animations_disabled_for_test_; 280 bool animations_disabled_for_test_;
284 281
285 // Manages bubbles which are anchored to a child of |top_container_|. 282 // Manages bubbles which are anchored to a child of |top_container_|.
286 class BubbleManager; 283 class BubbleManager;
287 scoped_ptr<BubbleManager> bubble_manager_; 284 scoped_ptr<BubbleManager> bubble_manager_;
288 285
289 content::NotificationRegistrar registrar_; 286 base::WeakPtrFactory<ImmersiveFullscreenController> weak_ptr_factory_;
290 287
291 base::WeakPtrFactory<ImmersiveModeControllerAsh> weak_ptr_factory_; 288 DISALLOW_COPY_AND_ASSIGN(ImmersiveFullscreenController);
292
293 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh);
294 }; 289 };
295 290
296 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ 291 } // namespace ash
292
293 #endif // ASH_WM_IMMERSIVE_FULLSREEN_CONTROLLER_H_
James Cook 2013/10/28 18:32:51 FULLSREEN -> FULLSCREEN
pkotwicz 2013/10/29 04:32:45 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698