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

Side by Side Diff: chrome/browser/ui/views/frame/immersive_mode_controller_ash.h

Issue 13866026: Adds functionality to anchor widgets to the top-of-window views in immersive mode (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 months 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
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 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 // / MaybeEndReveal().
James Cook 2013/04/09 22:22:03 nit: "// /" looks weird, maybe just say "or"
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 void MaybeStartReveal() OVERRIDE; 75 virtual void MaybeStartReveal() OVERRIDE;
46 virtual void CancelReveal() OVERRIDE; 76 virtual void CancelReveal() OVERRIDE;
47 virtual ImmersiveModeController::RevealedLock* 77 virtual ImmersiveModeController::RevealedLock*
48 GetRevealedLock() OVERRIDE WARN_UNUSED_RESULT; 78 GetRevealedLock() OVERRIDE WARN_UNUSED_RESULT;
79 virtual void AnchorWidgetToTopContainer(views::Widget* widget,
80 int y_offset) OVERRIDE;
81 virtual void UnanchorWidgetFromTopContainer(views::Widget* widget) OVERRIDE;
82 virtual void OnTopContainerBoundsChanged() OVERRIDE;
49 83
50 // ui::EventHandler overrides: 84 // ui::EventHandler overrides:
51 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 85 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
52 86
53 // views::FocusChangeObserver overrides: 87 // views::FocusChangeObserver overrides:
54 virtual void OnWillChangeFocus(views::View* focused_before, 88 virtual void OnWillChangeFocus(views::View* focused_before,
55 views::View* focused_now) OVERRIDE; 89 views::View* focused_now) OVERRIDE;
56 virtual void OnDidChangeFocus(views::View* focused_before, 90 virtual void OnDidChangeFocus(views::View* focused_before,
57 views::View* focused_now) OVERRIDE; 91 views::View* focused_now) OVERRIDE;
58 92
59 // views::WidgetObserver overrides: 93 // views::WidgetObserver overrides:
60 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 94 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
61 virtual void OnWidgetActivationChanged(views::Widget* widget, 95 virtual void OnWidgetActivationChanged(views::Widget* widget,
62 bool active) OVERRIDE; 96 bool active) OVERRIDE;
63 97
98 // ui::ImplicitAnimationObserver override:
99 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
100
64 // Testing interface. 101 // Testing interface.
65 void SetHideTabIndicatorsForTest(bool hide); 102 void SetHideTabIndicatorsForTest(bool hide);
66 void StartRevealForTest(bool hovered); 103 void StartRevealForTest(bool hovered);
67 void SetMouseHoveredForTest(bool hovered); 104 void SetMouseHoveredForTest(bool hovered);
68 105
69 private: 106 private:
70 enum Animate { 107 enum Animate {
71 ANIMATE_NO, 108 ANIMATE_NO,
72 ANIMATE_SLOW, 109 ANIMATE_SLOW,
73 ANIMATE_FAST, 110 ANIMATE_FAST,
(...skipping 19 matching lines...) Expand all
93 // Update |focus_revealed_lock_| based on the currently active view and the 130 // Update |focus_revealed_lock_| based on the currently active view and the
94 // currently active widget. 131 // currently active widget.
95 void UpdateFocusRevealedLock(); 132 void UpdateFocusRevealedLock();
96 133
97 // Returns the animation duration given |animate|. 134 // Returns the animation duration given |animate|.
98 int GetAnimationDuration(Animate animate) const; 135 int GetAnimationDuration(Animate animate) const;
99 136
100 // Temporarily reveals the top-of-window views while in immersive mode, 137 // Temporarily reveals the top-of-window views while in immersive mode,
101 // hiding them when the cursor exits the area of the top views. If |animate| 138 // hiding them when the cursor exits the area of the top views. If |animate|
102 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately. 139 // is not ANIMATE_NO, slides in the view, otherwise shows it immediately.
103 void StartReveal(Animate animate); 140 void MaybeStartReveal(Animate animate);
104 141
105 // Enables or disables layer-based painting to allow smooth animations. 142 // Enables or disables layer-based painting to allow smooth animations.
106 void EnablePaintToLayer(bool enable); 143 void EnablePaintToLayer(bool enable);
107 144
108 // Updates layout for |browser_view_| including window caption controls and 145 // Updates layout for |browser_view_| including window caption controls and
109 // tab strip style |immersive_style|. 146 // tab strip style |immersive_style|.
110 void LayoutBrowserView(bool immersive_style); 147 void LayoutBrowserView(bool immersive_style);
111 148
112 // Slides open the reveal view at the top of the screen. 149 // Called when the animation to slide open the top-of-window views has
113 void AnimateSlideOpen(int duration_ms); 150 // completed.
114 void OnSlideOpenAnimationCompleted(); 151 void OnSlideOpenAnimationCompleted();
115 152
116 // Hides the top-of-window views if immersive mode is enabled and nothing is 153 // Hides the top-of-window views if immersive mode is enabled and nothing is
117 // keeping them revealed. Optionally animates. 154 // keeping them revealed. Optionally animates.
118 void MaybeEndReveal(Animate animate); 155 void MaybeEndReveal(Animate animate);
119 156
120 // Hides the top-of-window views. Optionally animates. 157 // Called when the animation to slide out the top-of-window views has
121 void EndReveal(Animate animate); 158 // completed.
159 void OnSlideClosedAnimationCompleted();
122 160
123 // Slide out the reveal view. 161 // Starts an animation for the top-of-window views and any anchored widgets
124 void AnimateSlideClosed(int duration_ms); 162 // of |duration_ms| to |target_transform|.
125 void OnSlideClosedAnimationCompleted(); 163 void DoAnimation(const gfx::Transform& target_transform, int duration_ms);
164
165 // Starts an animation for |layer| of |duration_ms| to |target_transform|.
166 // If non-NULL, sets |observer| to be notified when the animation completes.
167 void DoAnimation(ui::Layer* layer,
James Cook 2013/04/09 22:22:03 Consider calling this DoLayerAnimation or some oth
168 const gfx::Transform& target_transform,
169 int duration_ms,
170 ui::ImplicitAnimationObserver* observer);
126 171
127 // Browser view holding the views to be shown and hidden. Not owned. 172 // Browser view holding the views to be shown and hidden. Not owned.
128 BrowserView* browser_view_; 173 BrowserView* browser_view_;
129 174
130 // True when in immersive mode. 175 // True when in immersive mode.
131 bool enabled_; 176 bool enabled_;
132 177
133 // State machine for the revealed/closed animations. 178 // State machine for the revealed/closed animations.
134 RevealState reveal_state_; 179 RevealState reveal_state_;
135 180
181 bool is_animating_;
182
136 int revealed_lock_count_; 183 int revealed_lock_count_;
137 184
138 // True if the miniature "tab indicators" should be hidden in the main browser 185 // True if the miniature "tab indicators" should be hidden in the main browser
139 // view when immersive mode is enabled. 186 // view when immersive mode is enabled.
140 bool hide_tab_indicators_; 187 bool hide_tab_indicators_;
141 188
142 // Timer to track cursor being held at the top. 189 // Timer to track cursor being held at the top.
143 base::OneShotTimer<ImmersiveModeController> top_timer_; 190 base::OneShotTimer<ImmersiveModeController> top_timer_;
144 191
145 // Lock which keeps the top-of-window views revealed based on the current 192 // Lock which keeps the top-of-window views revealed based on the current
146 // mouse state. 193 // mouse state.
147 scoped_ptr<RevealedLock> mouse_revealed_lock_; 194 scoped_ptr<RevealedLock> mouse_revealed_lock_;
148 195
149 // Lock which keeps the top-of-window views revealed based on the focused view 196 // Lock which keeps the top-of-window views revealed based on the focused view
150 // and the active widget. 197 // and the active widget.
151 scoped_ptr<RevealedLock> focus_revealed_lock_; 198 scoped_ptr<RevealedLock> focus_revealed_lock_;
152 199
153 // Native window for the browser, needed to clean up observers. 200 // Native window for the browser, needed to clean up observers.
154 gfx::NativeWindow native_window_; 201 aura::Window* native_window_;
James Cook 2013/04/09 22:22:03 Thanks for cleaning these up.
155 202
156 #if defined(USE_AURA)
157 // Observer to disable immersive mode when window leaves the maximized state. 203 // Observer to disable immersive mode when window leaves the maximized state.
158 class WindowObserver; 204 class WindowObserver;
159 scoped_ptr<WindowObserver> window_observer_; 205 scoped_ptr<WindowObserver> window_observer_;
160 #endif
161 206
162 // Animation observers. They must be separate because animations can be 207 // Manages widgets which are anchored to the top-of-window views.
163 // aborted and have their observers triggered at any time and the state 208 scoped_ptr<AnchoredWidgetManager> anchored_widget_manager_;
164 // machine needs to know which animation completed.
165 class AnimationObserver;
166 scoped_ptr<AnimationObserver> slide_open_observer_;
167 scoped_ptr<AnimationObserver> slide_closed_observer_;
168 209
169 base::WeakPtrFactory<ImmersiveModeControllerAsh> weak_ptr_factory_; 210 base::WeakPtrFactory<ImmersiveModeControllerAsh> weak_ptr_factory_;
170 211
171 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh); 212 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAsh);
172 }; 213 };
173 214
174 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_ 215 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_IMMERSIVE_MODE_CONTROLLER_ASH_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698