| 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/timer.h" | 10 #include "ash/wm/immersive_fullscreen_controller.h" |
| 11 #include "ash/wm/window_state_observer.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.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/gfx/rect.h" | |
| 17 #include "ui/views/focus/focus_manager.h" | |
| 18 #include "ui/views/widget/widget_observer.h" | |
| 19 | |
| 20 class BrowserView; | |
| 21 class BookmarkBarView; | |
| 22 | 15 |
| 23 namespace aura { | 16 namespace aura { |
| 24 class Window; | 17 class Window; |
| 25 } | 18 } |
| 26 | 19 |
| 27 namespace gfx { | 20 namespace gfx { |
| 28 class SlideAnimation; | 21 class Rect; |
| 29 class Transform; | |
| 30 } | 22 } |
| 31 | 23 |
| 32 namespace ui { | 24 class ImmersiveModeControllerAsh |
| 33 class Layer; | 25 : public ImmersiveModeController, |
| 34 class LocatedEvent; | 26 public ash::ImmersiveFullscreenController::Delegate, |
| 35 } | 27 public ash::wm::WindowStateObserver, |
| 36 | 28 public content::NotificationObserver { |
| 37 namespace views { | |
| 38 class View; | |
| 39 } | |
| 40 | |
| 41 class ImmersiveModeControllerAsh : public ImmersiveModeController, | |
| 42 public content::NotificationObserver, | |
| 43 public gfx::AnimationDelegate, | |
| 44 public ui::EventHandler, | |
| 45 public views::FocusChangeListener, | |
| 46 public views::WidgetObserver, | |
| 47 public aura::WindowObserver { | |
| 48 public: | 29 public: |
| 49 ImmersiveModeControllerAsh(); | 30 ImmersiveModeControllerAsh(); |
| 50 virtual ~ImmersiveModeControllerAsh(); | 31 virtual ~ImmersiveModeControllerAsh(); |
| 51 | 32 |
| 52 // These methods are used to increment and decrement |revealed_lock_count_|. | |
| 53 // If immersive mode is enabled, a transition from 1 to 0 in | |
| 54 // |revealed_lock_count_| closes the top-of-window views and a transition | |
| 55 // from 0 to 1 in |revealed_lock_count_| reveals the top-of-window views. | |
| 56 void LockRevealedState(AnimateReveal animate_reveal); | |
| 57 void UnlockRevealedState(); | |
| 58 | |
| 59 // ImmersiveModeController overrides: | 33 // ImmersiveModeController overrides: |
| 60 virtual void Init(Delegate* delegate, | 34 virtual void Init(BrowserView* browser_view) OVERRIDE; |
| 61 views::Widget* widget, | |
| 62 views::View* top_container) OVERRIDE; | |
| 63 virtual void SetEnabled(bool enabled) OVERRIDE; | 35 virtual void SetEnabled(bool enabled) OVERRIDE; |
| 64 virtual bool IsEnabled() const OVERRIDE; | 36 virtual bool IsEnabled() const OVERRIDE; |
| 65 virtual bool ShouldHideTabIndicators() const OVERRIDE; | 37 virtual bool ShouldHideTabIndicators() const OVERRIDE; |
| 66 virtual bool ShouldHideTopViews() const OVERRIDE; | 38 virtual bool ShouldHideTopViews() const OVERRIDE; |
| 67 virtual bool IsRevealed() const OVERRIDE; | 39 virtual bool IsRevealed() const OVERRIDE; |
| 68 virtual int GetTopContainerVerticalOffset( | 40 virtual int GetTopContainerVerticalOffset( |
| 69 const gfx::Size& top_container_size) const OVERRIDE; | 41 const gfx::Size& top_container_size) const OVERRIDE; |
| 70 virtual ImmersiveRevealedLock* GetRevealedLock( | 42 virtual ImmersiveRevealedLock* GetRevealedLock( |
| 71 AnimateReveal animate_reveal) OVERRIDE WARN_UNUSED_RESULT; | 43 AnimateReveal animate_reveal) OVERRIDE WARN_UNUSED_RESULT; |
| 72 virtual void OnFindBarVisibleBoundsChanged( | 44 virtual void OnFindBarVisibleBoundsChanged( |
| 73 const gfx::Rect& new_visible_bounds_in_screen) OVERRIDE; | 45 const gfx::Rect& new_visible_bounds_in_screen) OVERRIDE; |
| 74 virtual void SetupForTest() OVERRIDE; | 46 virtual void SetupForTest() OVERRIDE; |
| 75 | 47 |
| 76 // content::NotificationObserver override: | |
| 77 virtual void Observe(int type, | |
| 78 const content::NotificationSource& source, | |
| 79 const content::NotificationDetails& details) OVERRIDE; | |
| 80 | |
| 81 // ui::EventHandler overrides: | |
| 82 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | |
| 83 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | |
| 84 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | |
| 85 | |
| 86 // views::FocusChangeObserver overrides: | |
| 87 virtual void OnWillChangeFocus(views::View* focused_before, | |
| 88 views::View* focused_now) OVERRIDE; | |
| 89 virtual void OnDidChangeFocus(views::View* focused_before, | |
| 90 views::View* focused_now) OVERRIDE; | |
| 91 | |
| 92 // views::WidgetObserver overrides: | |
| 93 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; | |
| 94 virtual void OnWidgetActivationChanged(views::Widget* widget, | |
| 95 bool active) OVERRIDE; | |
| 96 | |
| 97 // gfx::AnimationDelegate overrides: | |
| 98 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; | |
| 99 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | |
| 100 | |
| 101 // 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, | |
| 106 aura::Window* transient) OVERRIDE; | |
| 107 virtual void OnRemoveTransientChild(aura::Window* window, | |
| 108 aura::Window* transient) OVERRIDE; | |
| 109 | |
| 110 private: | 48 private: |
| 111 friend class ImmersiveModeControllerAshTest; | 49 // Enables or disables observers for window restore and entering / exiting |
| 112 | 50 // tab fullscreen. |
| 113 enum AllowRevealWhileClosing { | |
| 114 ALLOW_REVEAL_WHILE_CLOSING_YES, | |
| 115 ALLOW_REVEAL_WHILE_CLOSING_NO | |
| 116 }; | |
| 117 enum Animate { | |
| 118 ANIMATE_NO, | |
| 119 ANIMATE_SLOW, | |
| 120 ANIMATE_FAST, | |
| 121 }; | |
| 122 enum Layout { | |
| 123 LAYOUT_YES, | |
| 124 LAYOUT_NO | |
| 125 }; | |
| 126 enum RevealState { | |
| 127 CLOSED, // Top container only showing tabstrip, y = 0. | |
| 128 SLIDING_OPEN, // All views showing, y animating from -height to 0. | |
| 129 REVEALED, // All views showing, y = 0. | |
| 130 SLIDING_CLOSED, // All views showing, y animating from 0 to -height. | |
| 131 }; | |
| 132 enum TabIndicatorVisibility { | |
| 133 TAB_INDICATORS_FORCE_HIDE, | |
| 134 TAB_INDICATORS_HIDE, | |
| 135 TAB_INDICATORS_SHOW | |
| 136 }; | |
| 137 enum SwipeType { | |
| 138 SWIPE_OPEN, | |
| 139 SWIPE_CLOSE, | |
| 140 SWIPE_NONE | |
| 141 }; | |
| 142 | |
| 143 // Enables or disables observers for mouse move, focus, and window restore. | |
| 144 void EnableWindowObservers(bool enable); | 51 void EnableWindowObservers(bool enable); |
| 145 | 52 |
| 146 // 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 | |
| 148 // away from the top edge, or moves too much in the x direction, the timer is | |
| 149 // stopped. | |
| 150 void UpdateTopEdgeHoverTimer(ui::MouseEvent* event); | |
| 151 | |
| 152 // Updates |located_event_revealed_lock_| based on the current mouse state and | |
| 153 // the current touch state. | |
| 154 // |event| is NULL if the source event is not known. | |
| 155 // |allow_reveal_while_closing| indicates whether the mouse and touch | |
| 156 // are allowed to initiate a reveal while the top-of-window views are sliding | |
| 157 // closed. | |
| 158 void UpdateLocatedEventRevealedLock( | |
| 159 ui::LocatedEvent* event, | |
| 160 AllowRevealWhileClosing allow_reveal_while_closing); | |
| 161 | |
| 162 // Acquires |located_event_revealed_lock_| if it is not already held. | |
| 163 void AcquireLocatedEventRevealedLock(); | |
| 164 | |
| 165 // Updates |focus_revealed_lock_| based on the currently active view and the | |
| 166 // currently active widget. | |
| 167 void UpdateFocusRevealedLock(); | |
| 168 | |
| 169 // 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 | |
| 171 // acquired or released. | |
| 172 bool UpdateRevealedLocksForSwipe(SwipeType swipe_type); | |
| 173 | |
| 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|. | |
| 180 int GetAnimationDuration(Animate animate) const; | |
| 181 | |
| 182 // 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| | |
| 184 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately. | |
| 185 void MaybeStartReveal(Animate animate); | |
| 186 | |
| 187 // Updates the browser root view's layout including window caption controls. | 53 // Updates the browser root view's layout including window caption controls. |
| 188 void LayoutBrowserRootView(); | 54 void LayoutBrowserRootView(); |
| 189 | 55 |
| 190 // Called when the animation to slide open the top-of-window views has | |
| 191 // completed. | |
| 192 void OnSlideOpenAnimationCompleted(Layout layout); | |
| 193 | |
| 194 // Hides the top-of-window views if immersive mode is enabled and nothing is | |
| 195 // keeping them revealed. Optionally animates. | |
| 196 void MaybeEndReveal(Animate animate); | |
| 197 | |
| 198 // Called when the animation to slide out the top-of-window views has | |
| 199 // completed. | |
| 200 void OnSlideClosedAnimationCompleted(); | |
| 201 | |
| 202 // Returns the type of swipe given |event|. | |
| 203 SwipeType GetSwipeType(ui::GestureEvent* event) const; | |
| 204 | |
| 205 // Returns true if a mouse event at |location_in_screen| should be ignored. | |
| 206 // Ignored mouse events should not contribute to revealing or unrevealing the | |
| 207 // top-of-window views. | |
| 208 bool ShouldIgnoreMouseEventAtLocation( | |
| 209 const gfx::Point& location_in_screen) const; | |
| 210 | |
| 211 // True when |location| is "near" to the top container. When the top container | |
| 212 // is not closed "near" means within the displayed bounds or above it. When | |
| 213 // 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 | |
| 215 // to steal enough pixels to detect a swipe in and handles the case that there | |
| 216 // is a bezel sensor above the top container. | |
| 217 bool ShouldHandleGestureEvent(const gfx::Point& location) const; | |
| 218 | |
| 219 // Recreate |bubble_manager_| and start observing any bubbles anchored to a | |
| 220 // child of |top_container_|. | |
| 221 void RecreateBubbleManager(); | |
| 222 | |
| 223 // Shrinks or expands the touch hit test by updating insets for the render | 56 // Shrinks or expands the touch hit test by updating insets for the render |
| 224 // window depending on if top_inset is positive or negative respectively. | 57 // window depending on if top_inset is positive or negative respectively. |
| 225 // Used to ensure that touch events at the top of the screen go to the top | 58 // Used to ensure that touch events at the top of the screen go to the top |
| 226 // container so a slide gesture can be generated when the content window is | 59 // container so a slide gesture can be generated when the content window is |
| 227 // consuming all touch events sent to it. | 60 // consuming all touch events sent to it. |
| 228 void SetRenderWindowTopInsetsForTouch(int top_inset); | 61 void SetRenderWindowTopInsetsForTouch(int top_inset); |
| 229 | 62 |
| 230 // Injected dependencies. Not owned. | 63 // Sets whether the tab strip is painted in a short "light bar" style. |
| 231 Delegate* delegate_; | 64 void SetTabIndicatorsVisible(bool visible); |
| 232 views::Widget* widget_; | |
| 233 views::View* top_container_; | |
| 234 | 65 |
| 235 // True if the window observers are enabled. | 66 // ImmersiveFullscreenController::Delegate overrides: |
| 236 bool observers_enabled_; | 67 virtual void OnImmersiveRevealStarted() OVERRIDE; |
| 68 virtual void OnImmersiveRevealEnded() OVERRIDE; |
| 69 virtual void OnImmersiveFullscreenExited() OVERRIDE; |
| 70 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; |
| 71 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() OVERRIDE; |
| 237 | 72 |
| 238 // True when in immersive mode. | 73 // ash::wm::WindowStateObserver override: |
| 239 bool enabled_; | 74 virtual void OnWindowShowTypeChanged( |
| 75 ash::wm::WindowState* window_state, |
| 76 ash::wm::WindowShowType old_type) OVERRIDE; |
| 240 | 77 |
| 241 // State machine for the revealed/closed animations. | 78 // content::NotificationObserver override: |
| 242 RevealState reveal_state_; | 79 virtual void Observe(int type, |
| 80 const content::NotificationSource& source, |
| 81 const content::NotificationDetails& details) OVERRIDE; |
| 243 | 82 |
| 244 int revealed_lock_count_; | 83 scoped_ptr<ash::ImmersiveFullscreenController> controller_; |
| 245 | 84 |
| 246 // The visibility of the miniature "tab indicators" in the main browser view | 85 // Not owned. |
| 247 // when immersive mode is enabled and the top-of-window views are closed. | 86 BrowserView* browser_view_; |
| 248 TabIndicatorVisibility tab_indicator_visibility_; | 87 aura::Window* native_window_; |
| 249 | 88 |
| 250 // Timer to track cursor being held at the top edge of the screen. | 89 // Whether a short "light bar" version of the tab strip should be painted when |
| 251 base::OneShotTimer<ImmersiveModeController> top_edge_hover_timer_; | 90 // the top-of-window views are closed. If |use_indicators_| is false, the tab |
| 252 | 91 // strip is not painted at all when the top-of-window views are closed. |
| 253 // The cursor x position in screen coordinates when the cursor first hit the | 92 bool use_tab_indicators_; |
| 254 // top edge of the screen. | |
| 255 int mouse_x_when_hit_top_in_screen_; | |
| 256 | |
| 257 // Tracks if the controller has seen a ET_GESTURE_SCROLL_BEGIN, without the | |
| 258 // following events. | |
| 259 bool gesture_begun_; | |
| 260 | 93 |
| 261 // The current visible bounds of the find bar, in screen coordinates. This is | 94 // The current visible bounds of the find bar, in screen coordinates. This is |
| 262 // an empty rect if the find bar is not visible. | 95 // an empty rect if the find bar is not visible. |
| 263 gfx::Rect find_bar_visible_bounds_in_screen_; | 96 gfx::Rect find_bar_visible_bounds_in_screen_; |
| 264 | 97 |
| 265 // Lock which keeps the top-of-window views revealed based on the current | 98 // The fraction of the TopContainerView's height which is visible. Zero when |
| 266 // mouse state and the current touch state. Acquiring the lock is used to | 99 // the top-of-window views are not revealed regardless of |
| 267 // trigger a reveal when the user moves the mouse to the top of the screen | 100 // |use_tab_indicators_|. |
| 268 // and when the user does a SWIPE_OPEN edge gesture. | 101 double visible_fraction_; |
| 269 scoped_ptr<ImmersiveRevealedLock> located_event_revealed_lock_; | |
| 270 | 102 |
| 271 // Lock which keeps the top-of-window views revealed based on the focused view | 103 // True if the observers for window restore and entering / exiting tab |
| 272 // and the active widget. Acquiring the lock never triggers a reveal because | 104 // fullscreen are enabled. |
| 273 // a view is not focusable till a reveal has made it visible. | 105 bool observers_enabled_; |
| 274 scoped_ptr<ImmersiveRevealedLock> focus_revealed_lock_; | |
| 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. | |
| 280 scoped_ptr<gfx::SlideAnimation> animation_; | |
| 281 | |
| 282 // Whether the animations are disabled for testing. | |
| 283 bool animations_disabled_for_test_; | |
| 284 | |
| 285 // Manages bubbles which are anchored to a child of |top_container_|. | |
| 286 class BubbleManager; | |
| 287 scoped_ptr<BubbleManager> bubble_manager_; | |
| 288 | 106 |
| 289 content::NotificationRegistrar registrar_; | 107 content::NotificationRegistrar registrar_; |
| 290 | 108 |
| 291 base::WeakPtrFactory<ImmersiveModeControllerAsh> weak_ptr_factory_; | |
| 292 | |
| 293 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh); | 109 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh); |
| 294 }; | 110 }; |
| 295 | 111 |
| 296 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ | 112 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ |
| OLD | NEW |