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

Side by Side Diff: ash/rotator/screen_rotation_animator.cc

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: Rebased to commit. Created 3 years, 9 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
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | ash/rotator/screen_rotation_animator_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "ash/rotator/screen_rotation_animator.h" 5 #include "ash/rotator/screen_rotation_animator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/display/window_tree_host_manager.h" 11 #include "ash/display/window_tree_host_manager.h"
12 #include "ash/rotator/screen_rotation_animation.h" 12 #include "ash/rotator/screen_rotation_animation.h"
13 #include "ash/rotator/screen_rotation_animator_observer.h"
13 #include "ash/shell.h" 14 #include "ash/shell.h"
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
18 #include "ui/compositor/layer.h" 19 #include "ui/compositor/layer.h"
19 #include "ui/compositor/layer_animation_observer.h" 20 #include "ui/compositor/layer_animation_observer.h"
20 #include "ui/compositor/layer_animation_sequence.h" 21 #include "ui/compositor/layer_animation_sequence.h"
21 #include "ui/compositor/layer_animator.h" 22 #include "ui/compositor/layer_animator.h"
22 #include "ui/compositor/layer_owner.h" 23 #include "ui/compositor/layer_owner.h"
(...skipping 12 matching lines...) Expand all
35 namespace ash { 36 namespace ash {
36 37
37 namespace { 38 namespace {
38 39
39 // The number of degrees that the rotation animations animate through. 40 // The number of degrees that the rotation animations animate through.
40 const int kRotationDegrees = 20; 41 const int kRotationDegrees = 20;
41 42
42 // The time it takes for the rotation animations to run. 43 // The time it takes for the rotation animations to run.
43 const int kRotationDurationInMs = 250; 44 const int kRotationDurationInMs = 250;
44 45
45 // Gets the current display rotation for the display with the specified 46 // The rotation factors.
46 // |display_id|. 47 const int kCounterClockWiseRotationFactor = 1;
47 display::Display::Rotation GetCurrentRotation(int64_t display_id) { 48 const int kClockWiseRotationFactor = -1;
49
50 // Aborts the active animations of the layer, and recurses upon its child
51 // layers.
52 void AbortAnimations(ui::Layer* layer) {
53 for (ui::Layer* child_layer : layer->children())
54 AbortAnimations(child_layer);
55 layer->GetAnimator()->AbortAllAnimations();
56 }
57
58 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) {
48 return Shell::GetInstance() 59 return Shell::GetInstance()
49 ->display_manager() 60 ->display_manager()
50 ->GetDisplayInfo(display_id) 61 ->GetDisplayInfo(display_id)
51 .GetActiveRotation(); 62 .GetActiveRotation();
52 } 63 }
53 64
65 bool IsDisplayIdValid(int64_t display_id) {
66 return Shell::GetInstance()->display_manager()->IsDisplayIdValid(display_id);
67 }
68
69 // 180 degree rotations should animate clock-wise.
70 int GetRotationFactor(display::Display::Rotation initial_rotation,
71 display::Display::Rotation new_rotation) {
72 return (initial_rotation + 3) % 4 == new_rotation
73 ? kCounterClockWiseRotationFactor
74 : kClockWiseRotationFactor;
75 }
76
77 aura::Window* GetRootWindow(int64_t display_id) {
78 return Shell::GetInstance()
79 ->window_tree_host_manager()
80 ->GetRootWindowForDisplayId(display_id);
81 }
82
54 // Returns true if the rotation between |initial_rotation| and |new_rotation| is 83 // Returns true if the rotation between |initial_rotation| and |new_rotation| is
55 // 180 degrees. 84 // 180 degrees.
56 bool Is180DegreeFlip(display::Display::Rotation initial_rotation, 85 bool Is180DegreeFlip(display::Display::Rotation initial_rotation,
57 display::Display::Rotation new_rotation) { 86 display::Display::Rotation new_rotation) {
58 return (initial_rotation + 2) % 4 == new_rotation; 87 return (initial_rotation + 2) % 4 == new_rotation;
59 } 88 }
60 89
61 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when 90 // Returns the initial degrees the old layer animation to begin with.
62 // notified that a layer animation has ended or was aborted. 91 int GetInitialDegrees(display::Display::Rotation initial_rotation,
92 display::Display::Rotation new_rotation) {
93 return (Is180DegreeFlip(initial_rotation, new_rotation) ? 180 : 90);
94 }
95
96 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner
97 // when notified that a layer animation has ended or was aborted.
63 class LayerCleanupObserver : public ui::LayerAnimationObserver { 98 class LayerCleanupObserver : public ui::LayerAnimationObserver {
64 public: 99 public:
65 explicit LayerCleanupObserver( 100 // Takes WeakPtr of ScreenRotationAnimator. |this| may outlive the |animator_|
66 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner); 101 // instance and the |animator_| isn't detaching itself as an observer when
102 // being destroyed. However, ideally, when |animator_| is destroying,
103 // deleting |old_layer_tree_owner_| will trigger OnLayerAnimationAborted and
104 // delete |this| before |animator_| deleted.
105 explicit LayerCleanupObserver(base::WeakPtr<ScreenRotationAnimator> animator);
67 ~LayerCleanupObserver() override; 106 ~LayerCleanupObserver() override;
68 107
69 // Get the root layer of the owned layer tree.
70 ui::Layer* GetRootLayer();
71
72 // ui::LayerAnimationObserver: 108 // ui::LayerAnimationObserver:
73 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override; 109 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
74 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override; 110 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
75 void OnLayerAnimationScheduled( 111 void OnLayerAnimationScheduled(
76 ui::LayerAnimationSequence* sequence) override {} 112 ui::LayerAnimationSequence* sequence) override {}
77 113
78 protected: 114 protected:
79 // ui::LayerAnimationObserver: 115 // ui::LayerAnimationObserver:
80 bool RequiresNotificationWhenAnimatorDestroyed() const override { 116 bool RequiresNotificationWhenAnimatorDestroyed() const override {
81 return true; 117 return true;
82 } 118 }
83 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override; 119 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override;
84 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override; 120 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override;
85 121
86 private: 122 private:
87 // Aborts the active animations of the layer, and recurses upon its child 123 base::WeakPtr<ScreenRotationAnimator> animator_;
88 // layers.
89 void AbortAnimations(ui::Layer* layer);
90
91 // The owned layer tree.
92 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner_;
93 124
94 // The LayerAnimationSequence that |this| has been attached to. Defaults to 125 // The LayerAnimationSequence that |this| has been attached to. Defaults to
95 // nullptr. 126 // nullptr.
96 ui::LayerAnimationSequence* sequence_; 127 ui::LayerAnimationSequence* sequence_;
97 128
98 DISALLOW_COPY_AND_ASSIGN(LayerCleanupObserver); 129 DISALLOW_COPY_AND_ASSIGN(LayerCleanupObserver);
99 }; 130 };
100 131
101 LayerCleanupObserver::LayerCleanupObserver( 132 LayerCleanupObserver::LayerCleanupObserver(
102 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner) 133 base::WeakPtr<ScreenRotationAnimator> animator)
103 : layer_tree_owner_(std::move(layer_tree_owner)), sequence_(nullptr) {} 134 : animator_(animator), sequence_(nullptr) {}
104 135
105 LayerCleanupObserver::~LayerCleanupObserver() { 136 LayerCleanupObserver::~LayerCleanupObserver() {
106 // We must eplicitly detach from |sequence_| because we return true from 137 // We must eplicitly detach from |sequence_| because we return true from
107 // RequiresNotificationWhenAnimatorDestroyed. 138 // RequiresNotificationWhenAnimatorDestroyed.
108 if (sequence_) 139 if (sequence_)
109 sequence_->RemoveObserver(this); 140 sequence_->RemoveObserver(this);
110 AbortAnimations(layer_tree_owner_->root());
111 }
112
113 ui::Layer* LayerCleanupObserver::GetRootLayer() {
114 return layer_tree_owner_->root();
115 } 141 }
116 142
117 void LayerCleanupObserver::OnLayerAnimationEnded( 143 void LayerCleanupObserver::OnLayerAnimationEnded(
118 ui::LayerAnimationSequence* sequence) { 144 ui::LayerAnimationSequence* sequence) {
145 if (animator_)
146 animator_->OnLayerAnimationEnded();
147
119 delete this; 148 delete this;
120 } 149 }
121 150
122 void LayerCleanupObserver::OnLayerAnimationAborted( 151 void LayerCleanupObserver::OnLayerAnimationAborted(
123 ui::LayerAnimationSequence* sequence) { 152 ui::LayerAnimationSequence* sequence) {
153 if (animator_)
154 animator_->OnLayerAnimationAborted();
155
124 delete this; 156 delete this;
125 } 157 }
126 158
127 void LayerCleanupObserver::OnAttachedToSequence( 159 void LayerCleanupObserver::OnAttachedToSequence(
128 ui::LayerAnimationSequence* sequence) { 160 ui::LayerAnimationSequence* sequence) {
129 sequence_ = sequence; 161 sequence_ = sequence;
130 } 162 }
131 163
132 void LayerCleanupObserver::OnDetachedFromSequence( 164 void LayerCleanupObserver::OnDetachedFromSequence(
133 ui::LayerAnimationSequence* sequence) { 165 ui::LayerAnimationSequence* sequence) {
134 DCHECK_EQ(sequence, sequence_); 166 DCHECK_EQ(sequence, sequence_);
135 sequence_ = nullptr; 167 sequence_ = nullptr;
136 } 168 }
137 169
138 void LayerCleanupObserver::AbortAnimations(ui::Layer* layer) { 170 } // namespace
139 for (ui::Layer* child_layer : layer->children())
140 AbortAnimations(child_layer);
141 layer->GetAnimator()->AbortAllAnimations();
142 }
143 171
144 // Set the screen orientation for the given |display_id| to |new_rotation| and 172 struct ScreenRotationAnimator::ScreenRotationRequest {
145 // animate the change. The animation will rotate the initial orientation's 173 ScreenRotationRequest(display::Display::Rotation to_rotation,
146 // layer towards the new orientation through |rotation_degrees| while fading 174 display::Display::RotationSource from_source)
147 // out, and the new orientation's layer will be rotated in to the 175 : new_rotation(to_rotation), source(from_source) {}
148 // |new_orientation| through |rotation_degrees| arc. 176 display::Display::Rotation new_rotation;
149 void RotateScreen(int64_t display_id, 177 display::Display::RotationSource source;
150 display::Display::Rotation new_rotation, 178 };
151 display::Display::RotationSource source) {
152 aura::Window* root_window = Shell::GetInstance()
153 ->window_tree_host_manager()
154 ->GetRootWindowForDisplayId(display_id);
155 179
156 const display::Display::Rotation initial_orientation = 180 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
157 GetCurrentRotation(display_id); 181 : display_id_(display_id),
182 is_rotating_(false),
183 disable_animation_timers_for_test_(false),
184 weak_factory_(this) {}
185
186 ScreenRotationAnimator::~ScreenRotationAnimator() {}
187
188 void ScreenRotationAnimator::AnimateRotation(
189 std::unique_ptr<ScreenRotationRequest> rotation_request) {
190 aura::Window* root_window = GetRootWindow(display_id_);
158 191
159 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); 192 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds();
160 // 180 degree rotations should animate clock-wise.
161 const int rotation_factor =
162 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1;
163 193
164 const int old_layer_initial_rotation_degrees = 194 const int rotation_factor = GetRotationFactor(
165 (Is180DegreeFlip(initial_orientation, new_rotation) ? 180 : 90); 195 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation);
196
197 const int old_layer_initial_rotation_degrees = GetInitialDegrees(
198 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation);
166 199
167 const base::TimeDelta duration = 200 const base::TimeDelta duration =
168 base::TimeDelta::FromMilliseconds(kRotationDurationInMs); 201 base::TimeDelta::FromMilliseconds(kRotationDurationInMs);
169 202
170 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN; 203 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN;
171 204
172 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree = 205 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree =
173 ::wm::RecreateLayers(root_window); 206 ::wm::RecreateLayers(root_window);
207 old_layer_tree->root()->set_name("ScreenRotationAnimator:old_layer_tree");
174 208
175 // Add the cloned layer tree in to the root, so it will be rendered. 209 // Add the cloned layer tree in to the root, so it will be rendered.
176 root_window->layer()->Add(old_layer_tree->root()); 210 root_window->layer()->Add(old_layer_tree->root());
177 root_window->layer()->StackAtTop(old_layer_tree->root()); 211 root_window->layer()->StackAtTop(old_layer_tree->root());
178 212
179 std::unique_ptr<LayerCleanupObserver> layer_cleanup_observer( 213 old_layer_tree_owner_ = std::move(old_layer_tree);
180 new LayerCleanupObserver(std::move(old_layer_tree))); 214 std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer(
215 new LayerCleanupObserver(weak_factory_.GetWeakPtr()));
181 216
182 Shell::GetInstance()->display_manager()->SetDisplayRotation( 217 Shell::GetInstance()->display_manager()->SetDisplayRotation(
183 display_id, new_rotation, source); 218 display_id_, rotation_request->new_rotation, rotation_request->source);
184 219
185 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds(); 220 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds();
186 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, 221 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2,
187 rotated_screen_bounds.height() / 2); 222 rotated_screen_bounds.height() / 2);
188 223
224 ui::Layer* old_root_layer = old_layer_tree_owner_->root();
189 // We must animate each non-cloned child layer individually because the cloned 225 // We must animate each non-cloned child layer individually because the cloned
190 // layer was added as a child to |root_window|'s layer so that it will be 226 // layer was added as a child to |root_window|'s layer so that it will be
191 // rendered. 227 // rendered.
192 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and 228 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and
193 // its current children so that we only need to initiate two 229 // its current children so that we only need to initiate two
194 // LayerAnimationSequences. One for the new layers and one for the old layer. 230 // LayerAnimationSequences. One for the new layers and one for the old layer.
195 for (ui::Layer* child_layer : root_window->layer()->children()) { 231 for (ui::Layer* child_layer : root_window->layer()->children()) {
196 // Skip the cloned layer because it has a different animation. 232 // Skip the cloned layer because it has a different animation.
197 if (child_layer == layer_cleanup_observer->GetRootLayer()) 233 if (child_layer == old_root_layer)
198 continue; 234 continue;
199 235
200 std::unique_ptr<ScreenRotationAnimation> screen_rotation = 236 std::unique_ptr<ScreenRotationAnimation> screen_rotation =
201 base::MakeUnique<ScreenRotationAnimation>( 237 base::MakeUnique<ScreenRotationAnimation>(
202 child_layer, kRotationDegrees * rotation_factor, 238 child_layer, kRotationDegrees * rotation_factor,
203 0 /* end_degrees */, child_layer->opacity(), 239 0 /* end_degrees */, child_layer->opacity(),
204 1.0f /* target_opacity */, pivot, duration, tween_type); 240 1.0f /* target_opacity */, pivot, duration, tween_type);
205 241
206 ui::LayerAnimator* animator = child_layer->GetAnimator(); 242 ui::LayerAnimator* animator = child_layer->GetAnimator();
207 animator->set_preemption_strategy( 243 animator->set_preemption_strategy(
208 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 244 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
209 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 245 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
210 base::MakeUnique<ui::LayerAnimationSequence>( 246 base::MakeUnique<ui::LayerAnimationSequence>(
211 std::move(screen_rotation)); 247 std::move(screen_rotation));
212 animator->StartAnimation(animation_sequence.release()); 248 animator->StartAnimation(animation_sequence.release());
213 } 249 }
214 250
215 // The old layer will also be transformed into the new orientation. We will 251 // The old layer will also be transformed into the new orientation. We will
216 // translate it so that the old layer's center point aligns with the new 252 // translate it so that the old layer's center point aligns with the new
217 // orientation's center point and use that center point as the pivot for the 253 // orientation's center point and use that center point as the pivot for the
218 // rotation animation. 254 // rotation animation.
219 gfx::Transform translate_transform; 255 gfx::Transform translate_transform;
220 translate_transform.Translate( 256 translate_transform.Translate(
221 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2, 257 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2,
222 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2); 258 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2);
223 layer_cleanup_observer->GetRootLayer()->SetTransform(translate_transform); 259 old_root_layer->SetTransform(translate_transform);
224 260
225 std::unique_ptr<ScreenRotationAnimation> screen_rotation = 261 std::unique_ptr<ScreenRotationAnimation> screen_rotation =
226 base::MakeUnique<ScreenRotationAnimation>( 262 base::MakeUnique<ScreenRotationAnimation>(
227 layer_cleanup_observer->GetRootLayer(), 263 old_root_layer, old_layer_initial_rotation_degrees * rotation_factor,
228 old_layer_initial_rotation_degrees * rotation_factor,
229 (old_layer_initial_rotation_degrees - kRotationDegrees) * 264 (old_layer_initial_rotation_degrees - kRotationDegrees) *
230 rotation_factor, 265 rotation_factor,
231 layer_cleanup_observer->GetRootLayer()->opacity(), 266 old_root_layer->opacity(), 0.0f /* target_opacity */, pivot, duration,
232 0.0f /* target_opacity */, pivot, duration, tween_type); 267 tween_type);
233 268
234 ui::LayerAnimator* animator = 269 ui::LayerAnimator* animator = old_root_layer->GetAnimator();
235 layer_cleanup_observer->GetRootLayer()->GetAnimator();
236 animator->set_preemption_strategy( 270 animator->set_preemption_strategy(
237 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 271 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
238 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 272 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
239 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); 273 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation));
240 // Add an observer so that the cloned layers can be cleaned up with the 274 // Add an observer so that the cloned layers can be cleaned up with the
241 // animation completes/aborts. 275 // animation completes/aborts.
242 animation_sequence->AddObserver(layer_cleanup_observer.release()); 276 animation_sequence->AddObserver(old_layer_cleanup_observer.release());
277 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to
278 // control the animation.
279 if (disable_animation_timers_for_test_)
280 animator->set_disable_timer_for_test(true);
243 animator->StartAnimation(animation_sequence.release()); 281 animator->StartAnimation(animation_sequence.release());
244 }
245 282
246 } // namespace 283 rotation_request.reset();
247
248 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
249 : display_id_(display_id) {}
250
251 ScreenRotationAnimator::~ScreenRotationAnimator() {}
252
253 bool ScreenRotationAnimator::CanAnimate() const {
254 return Shell::GetInstance()
255 ->display_manager()
256 ->GetDisplayForId(display_id_)
257 .is_valid();
258 } 284 }
259 285
260 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, 286 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation,
261 display::Display::RotationSource source) { 287 display::Display::RotationSource source) {
262 const display::Display::Rotation current_rotation = 288 if (GetCurrentScreenRotation(display_id_) == new_rotation)
263 GetCurrentRotation(display_id_);
264
265 if (current_rotation == new_rotation)
266 return; 289 return;
267 290
268 RotateScreen(display_id_, new_rotation, source); 291 std::unique_ptr<ScreenRotationRequest> rotation_request =
292 base::MakeUnique<ScreenRotationRequest>(new_rotation, source);
293
294 if (is_rotating_) {
295 last_pending_request_ = std::move(rotation_request);
296 // The pending request will be processed when the
297 // OnLayerAnimation(Ended|Aborted) methods should be called after
298 // StopAnimating().
299 StopAnimating();
300 } else {
301 is_rotating_ = true;
302 AnimateRotation(std::move(rotation_request));
303 }
304 }
305
306 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver(
307 ScreenRotationAnimatorObserver* observer) {
308 screen_rotation_animator_observers_.AddObserver(observer);
309 }
310
311 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver(
312 ScreenRotationAnimatorObserver* observer) {
313 screen_rotation_animator_observers_.RemoveObserver(observer);
314 }
315
316 void ScreenRotationAnimator::OnLayerAnimationEnded() {
317 ProcessAnimationQueue();
318 }
319
320 void ScreenRotationAnimator::OnLayerAnimationAborted() {
321 AbortAnimations(old_layer_tree_owner_->root());
322 ProcessAnimationQueue();
323 }
324
325 void ScreenRotationAnimator::ProcessAnimationQueue() {
326 is_rotating_ = false;
327 old_layer_tree_owner_.reset();
328 if (last_pending_request_ && IsDisplayIdValid(display_id_)) {
329 std::unique_ptr<ScreenRotationRequest> rotation_request =
330 std::move(last_pending_request_);
331 Rotate(rotation_request->new_rotation, rotation_request->source);
332 rotation_request.reset();
333 return;
334 }
335
336 for (auto& observer : screen_rotation_animator_observers_)
337 observer.OnScreenRotationAnimationFinished(this);
338 }
339
340 void ScreenRotationAnimator::set_disable_animation_timers_for_test(
341 bool disable_timers) {
342 disable_animation_timers_for_test_ = disable_timers;
343 }
344
345 void ScreenRotationAnimator::StopAnimating() {
346 aura::Window* root_window = GetRootWindow(display_id_);
347 for (ui::Layer* child_layer : root_window->layer()->children()) {
348 if (child_layer == old_layer_tree_owner_->root())
349 continue;
350
351 child_layer->GetAnimator()->StopAnimating();
352 }
353
354 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating();
269 } 355 }
270 356
271 } // namespace ash 357 } // namespace ash
OLDNEW
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | ash/rotator/screen_rotation_animator_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698