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

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

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: Make ScreenRotationAnimator handle its own internal states. 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
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
(...skipping 16 matching lines...) Expand all
27 #include "ui/gfx/animation/tween.h" 27 #include "ui/gfx/animation/tween.h"
28 #include "ui/gfx/geometry/point.h" 28 #include "ui/gfx/geometry/point.h"
29 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
30 #include "ui/gfx/geometry/rect_f.h" 30 #include "ui/gfx/geometry/rect_f.h"
31 #include "ui/gfx/transform.h" 31 #include "ui/gfx/transform.h"
32 #include "ui/gfx/transform_util.h" 32 #include "ui/gfx/transform_util.h"
33 #include "ui/wm/core/window_util.h" 33 #include "ui/wm/core/window_util.h"
34 34
35 namespace ash { 35 namespace ash {
36 36
37 ScreenRotationAnimator::ScreenRotationAnimatorObserver::
38 ScreenRotationAnimatorObserver() {}
39
40 ScreenRotationAnimator::ScreenRotationAnimatorObserver::
41 ~ScreenRotationAnimatorObserver() {}
42
43 void ScreenRotationAnimator::ScreenRotationAnimatorObserver::
44 OnEndedOrAbortedScreenRotationAnimation(ScreenRotationAnimator* animator) {}
45
37 namespace { 46 namespace {
38 47
39 // The number of degrees that the rotation animations animate through. 48 // The number of degrees that the rotation animations animate through.
40 const int kRotationDegrees = 20; 49 const int kRotationDegrees = 20;
41 50
42 // The time it takes for the rotation animations to run. 51 // The time it takes for the rotation animations to run.
43 const int kRotationDurationInMs = 250; 52 const int kRotationDurationInMs = 250;
44 53
45 // Gets the current display rotation for the display with the specified 54 // The rotation directions
46 // |display_id|. 55 const int kCounterClockWiseRotation = 1;
47 display::Display::Rotation GetCurrentRotation(int64_t display_id) { 56 const int kClockWiseRotation = -1;
48 return Shell::GetInstance() 57
49 ->display_manager() 58 int GetRotationFactor(display::Display::Rotation initial_rotation,
50 ->GetDisplayInfo(display_id) 59 display::Display::Rotation new_rotation) {
51 .GetActiveRotation(); 60 return (initial_rotation + 3) % 4 == new_rotation ? kCounterClockWiseRotation
61 : kClockWiseRotation;
52 } 62 }
53 63
54 // Returns true if the rotation between |initial_rotation| and |new_rotation| is 64 // Returns true if the rotation between |initial_rotation| and |new_rotation| is
55 // 180 degrees. 65 // 180 degrees.
56 bool Is180DegreeFlip(display::Display::Rotation initial_rotation, 66 bool Is180DegreeFlip(display::Display::Rotation initial_rotation,
57 display::Display::Rotation new_rotation) { 67 display::Display::Rotation new_rotation) {
58 return (initial_rotation + 2) % 4 == new_rotation; 68 return (initial_rotation + 2) % 4 == new_rotation;
59 } 69 }
60 70
61 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when 71 // Returns the initial degrees the old layer animation to begin with.
62 // notified that a layer animation has ended or was aborted. 72 int GetInitialDegrees(display::Display::Rotation initial_rotation,
73 display::Display::Rotation new_rotation) {
74 return (Is180DegreeFlip(initial_rotation, new_rotation) ? 180 : 90);
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
83 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner
84 // when notified that a layer animation has ended or was aborted.
63 class LayerCleanupObserver : public ui::LayerAnimationObserver { 85 class LayerCleanupObserver : public ui::LayerAnimationObserver {
64 public: 86 public:
65 explicit LayerCleanupObserver( 87 explicit LayerCleanupObserver(base::WeakPtr<ScreenRotationAnimator> animator);
66 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner);
67 ~LayerCleanupObserver() override; 88 ~LayerCleanupObserver() override;
68 89
69 // Get the root layer of the owned layer tree.
70 ui::Layer* GetRootLayer();
71
72 // ui::LayerAnimationObserver: 90 // ui::LayerAnimationObserver:
73 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override; 91 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
74 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override; 92 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
75 void OnLayerAnimationScheduled( 93 void OnLayerAnimationScheduled(
76 ui::LayerAnimationSequence* sequence) override {} 94 ui::LayerAnimationSequence* sequence) override {}
77 95
78 protected: 96 protected:
79 // ui::LayerAnimationObserver: 97 // ui::LayerAnimationObserver:
80 bool RequiresNotificationWhenAnimatorDestroyed() const override { 98 bool RequiresNotificationWhenAnimatorDestroyed() const override {
81 return true; 99 return true;
82 } 100 }
83 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override; 101 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override;
84 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override; 102 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override;
85 103
86 private: 104 private:
87 // Aborts the active animations of the layer, and recurses upon its child 105 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 106
94 // The LayerAnimationSequence that |this| has been attached to. Defaults to 107 // The LayerAnimationSequence that |this| has been attached to. Defaults to
95 // nullptr. 108 // nullptr.
96 ui::LayerAnimationSequence* sequence_; 109 ui::LayerAnimationSequence* sequence_;
97 110
98 DISALLOW_COPY_AND_ASSIGN(LayerCleanupObserver); 111 DISALLOW_COPY_AND_ASSIGN(LayerCleanupObserver);
99 }; 112 };
100 113
101 LayerCleanupObserver::LayerCleanupObserver( 114 LayerCleanupObserver::LayerCleanupObserver(
102 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner) 115 base::WeakPtr<ScreenRotationAnimator> animator)
103 : layer_tree_owner_(std::move(layer_tree_owner)), sequence_(nullptr) {} 116 : animator_(animator), sequence_(nullptr) {}
104 117
105 LayerCleanupObserver::~LayerCleanupObserver() { 118 LayerCleanupObserver::~LayerCleanupObserver() {
106 // We must eplicitly detach from |sequence_| because we return true from 119 // We must eplicitly detach from |sequence_| because we return true from
107 // RequiresNotificationWhenAnimatorDestroyed. 120 // RequiresNotificationWhenAnimatorDestroyed.
108 if (sequence_) 121 if (sequence_)
109 sequence_->RemoveObserver(this); 122 sequence_->RemoveObserver(this);
110 AbortAnimations(layer_tree_owner_->root());
111 }
112
113 ui::Layer* LayerCleanupObserver::GetRootLayer() {
114 return layer_tree_owner_->root();
115 } 123 }
116 124
117 void LayerCleanupObserver::OnLayerAnimationEnded( 125 void LayerCleanupObserver::OnLayerAnimationEnded(
118 ui::LayerAnimationSequence* sequence) { 126 ui::LayerAnimationSequence* sequence) {
127 if (animator_) {
bruthig 2017/03/10 22:34:08 nit: No need for the '{}' if the 'if' and 'body' o
wutao 2017/03/14 16:46:37 Done.
128 animator_->OnLayerAnimationEnded();
129 }
130
119 delete this; 131 delete this;
120 } 132 }
121 133
122 void LayerCleanupObserver::OnLayerAnimationAborted( 134 void LayerCleanupObserver::OnLayerAnimationAborted(
123 ui::LayerAnimationSequence* sequence) { 135 ui::LayerAnimationSequence* sequence) {
136 if (animator_) {
137 animator_->OnLayerAnimationAborted();
138 }
139
124 delete this; 140 delete this;
125 } 141 }
126 142
127 void LayerCleanupObserver::OnAttachedToSequence( 143 void LayerCleanupObserver::OnAttachedToSequence(
128 ui::LayerAnimationSequence* sequence) { 144 ui::LayerAnimationSequence* sequence) {
129 sequence_ = sequence; 145 sequence_ = sequence;
130 } 146 }
131 147
132 void LayerCleanupObserver::OnDetachedFromSequence( 148 void LayerCleanupObserver::OnDetachedFromSequence(
133 ui::LayerAnimationSequence* sequence) { 149 ui::LayerAnimationSequence* sequence) {
134 DCHECK_EQ(sequence, sequence_); 150 DCHECK_EQ(sequence, sequence_);
135 sequence_ = nullptr; 151 sequence_ = nullptr;
136 } 152 }
137 153
138 void LayerCleanupObserver::AbortAnimations(ui::Layer* layer) {
139 for (ui::Layer* child_layer : layer->children())
140 AbortAnimations(child_layer);
141 layer->GetAnimator()->AbortAllAnimations();
142 }
143
144 // Set the screen orientation for the given |display_id| to |new_rotation| and 154 // Set the screen orientation for the given |display_id| to |new_rotation| and
145 // animate the change. The animation will rotate the initial orientation's 155 // animate the change. The animation will rotate the initial orientation's
146 // layer towards the new orientation through |rotation_degrees| while fading 156 // layer towards the new orientation through |rotation_degrees| while fading
147 // out, and the new orientation's layer will be rotated in to the 157 // out, and the new orientation's layer will be rotated in to the
148 // |new_orientation| through |rotation_degrees| arc. 158 // |new_orientation| through |rotation_degrees| arc.
149 void RotateScreen(int64_t display_id, 159 void RotateScreen(
150 display::Display::Rotation new_rotation, 160 const ScreenRotationAnimator::ScreenRotationRequest& rotation_request) {
151 display::Display::RotationSource source) { 161 aura::Window* root_window = GetRootWindow(rotation_request.display_id);
152 aura::Window* root_window = Shell::GetInstance()
153 ->window_tree_host_manager()
154 ->GetRootWindowForDisplayId(display_id);
155
156 const display::Display::Rotation initial_orientation =
157 GetCurrentRotation(display_id);
158 162
159 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); 163 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds();
160 // 180 degree rotations should animate clock-wise. 164 // 180 degree rotations should animate clock-wise.
161 const int rotation_factor = 165 const int rotation_factor = GetRotationFactor(
162 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1; 166 rotation_request.initial_rotation, rotation_request.new_rotation);
163 167
164 const int old_layer_initial_rotation_degrees = 168 const int old_layer_initial_rotation_degrees = GetInitialDegrees(
165 (Is180DegreeFlip(initial_orientation, new_rotation) ? 180 : 90); 169 rotation_request.initial_rotation, rotation_request.new_rotation);
166 170
167 const base::TimeDelta duration = 171 const base::TimeDelta duration =
168 base::TimeDelta::FromMilliseconds(kRotationDurationInMs); 172 base::TimeDelta::FromMilliseconds(kRotationDurationInMs);
169 173
170 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN; 174 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN;
171 175
172 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree = 176 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree =
173 ::wm::RecreateLayers(root_window); 177 ::wm::RecreateLayers(root_window);
178 old_layer_tree->root()->set_name("ScreenRotationAnimator:old_layer_tree");
174 179
175 // Add the cloned layer tree in to the root, so it will be rendered. 180 // Add the cloned layer tree in to the root, so it will be rendered.
176 root_window->layer()->Add(old_layer_tree->root()); 181 root_window->layer()->Add(old_layer_tree->root());
177 root_window->layer()->StackAtTop(old_layer_tree->root()); 182 root_window->layer()->StackAtTop(old_layer_tree->root());
178 183
179 std::unique_ptr<LayerCleanupObserver> layer_cleanup_observer( 184 ScreenRotationAnimator* screen_rotation_animator = rotation_request.animator;
180 new LayerCleanupObserver(std::move(old_layer_tree))); 185 screen_rotation_animator->set_old_layer_tree_owner(old_layer_tree.release());
186 std::unique_ptr<LayerCleanupObserver> old_layer_cleanup_observer(
187 new LayerCleanupObserver(screen_rotation_animator->WeakPtr()));
181 188
182 Shell::GetInstance()->display_manager()->SetDisplayRotation( 189 Shell::GetInstance()->display_manager()->SetDisplayRotation(
183 display_id, new_rotation, source); 190 rotation_request.display_id, rotation_request.new_rotation,
191 rotation_request.source);
184 192
185 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds(); 193 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds();
186 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, 194 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2,
187 rotated_screen_bounds.height() / 2); 195 rotated_screen_bounds.height() / 2);
188 196
189 // We must animate each non-cloned child layer individually because the cloned 197 // 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 198 // layer was added as a child to |root_window|'s layer so that it will be
191 // rendered. 199 // rendered.
192 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and 200 // 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 201 // its current children so that we only need to initiate two
194 // LayerAnimationSequences. One for the new layers and one for the old layer. 202 // LayerAnimationSequences. One for the new layers and one for the old layer.
195 for (ui::Layer* child_layer : root_window->layer()->children()) { 203 for (ui::Layer* child_layer : root_window->layer()->children()) {
196 // Skip the cloned layer because it has a different animation. 204 // Skip the cloned layer because it has a different animation.
197 if (child_layer == layer_cleanup_observer->GetRootLayer()) 205 if (child_layer == screen_rotation_animator->GetOldLayerTreeRootLayer())
198 continue; 206 continue;
199 207
200 std::unique_ptr<ScreenRotationAnimation> screen_rotation = 208 std::unique_ptr<ScreenRotationAnimation> screen_rotation =
201 base::MakeUnique<ScreenRotationAnimation>( 209 base::MakeUnique<ScreenRotationAnimation>(
202 child_layer, kRotationDegrees * rotation_factor, 210 child_layer, kRotationDegrees * rotation_factor,
203 0 /* end_degrees */, child_layer->opacity(), 211 0 /* end_degrees */, child_layer->opacity(),
204 1.0f /* target_opacity */, pivot, duration, tween_type); 212 1.0f /* target_opacity */, pivot, duration, tween_type);
205 213
206 ui::LayerAnimator* animator = child_layer->GetAnimator(); 214 ui::LayerAnimator* animator = child_layer->GetAnimator();
207 animator->set_preemption_strategy( 215 animator->set_preemption_strategy(
208 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 216 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
209 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 217 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
210 base::MakeUnique<ui::LayerAnimationSequence>( 218 base::MakeUnique<ui::LayerAnimationSequence>(
211 std::move(screen_rotation)); 219 std::move(screen_rotation));
212 animator->StartAnimation(animation_sequence.release()); 220 animator->StartAnimation(animation_sequence.release());
213 } 221 }
214 222
215 // The old layer will also be transformed into the new orientation. We will 223 // 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 224 // 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 225 // orientation's center point and use that center point as the pivot for the
218 // rotation animation. 226 // rotation animation.
219 gfx::Transform translate_transform; 227 gfx::Transform translate_transform;
220 translate_transform.Translate( 228 translate_transform.Translate(
221 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2, 229 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2,
222 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2); 230 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2);
223 layer_cleanup_observer->GetRootLayer()->SetTransform(translate_transform); 231 screen_rotation_animator->GetOldLayerTreeRootLayer()->SetTransform(
232 translate_transform);
224 233
225 std::unique_ptr<ScreenRotationAnimation> screen_rotation = 234 std::unique_ptr<ScreenRotationAnimation> screen_rotation =
226 base::MakeUnique<ScreenRotationAnimation>( 235 base::MakeUnique<ScreenRotationAnimation>(
227 layer_cleanup_observer->GetRootLayer(), 236 screen_rotation_animator->GetOldLayerTreeRootLayer(),
228 old_layer_initial_rotation_degrees * rotation_factor, 237 old_layer_initial_rotation_degrees * rotation_factor,
229 (old_layer_initial_rotation_degrees - kRotationDegrees) * 238 (old_layer_initial_rotation_degrees - kRotationDegrees) *
230 rotation_factor, 239 rotation_factor,
231 layer_cleanup_observer->GetRootLayer()->opacity(), 240 screen_rotation_animator->GetOldLayerTreeRootLayer()->opacity(),
232 0.0f /* target_opacity */, pivot, duration, tween_type); 241 0.0f /* target_opacity */, pivot, duration, tween_type);
233 242
234 ui::LayerAnimator* animator = 243 ui::LayerAnimator* animator =
235 layer_cleanup_observer->GetRootLayer()->GetAnimator(); 244 screen_rotation_animator->GetOldLayerTreeRootLayer()->GetAnimator();
236 animator->set_preemption_strategy( 245 animator->set_preemption_strategy(
237 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 246 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
238 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 247 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
239 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); 248 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation));
240 // Add an observer so that the cloned layers can be cleaned up with the 249 // Add an observer so that the cloned layers can be cleaned up with the
241 // animation completes/aborts. 250 // animation completes/aborts.
242 animation_sequence->AddObserver(layer_cleanup_observer.release()); 251 animation_sequence->AddObserver(old_layer_cleanup_observer.release());
243 animator->StartAnimation(animation_sequence.release()); 252 animator->StartAnimation(animation_sequence.release());
244 } 253 }
245 254
255 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) {
256 return Shell::GetInstance()
257 ->display_manager()
258 ->GetDisplayInfo(display_id)
259 .GetActiveRotation();
260 }
261
246 } // namespace 262 } // namespace
247 263
248 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) 264 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
249 : display_id_(display_id) {} 265 : display_id_(display_id),
266 is_rotating_(false),
267 screen_rotation_animator_observer_(nullptr),
268 weak_factory_(this) {}
250 269
251 ScreenRotationAnimator::~ScreenRotationAnimator() {} 270 ScreenRotationAnimator::~ScreenRotationAnimator() {}
252 271
253 bool ScreenRotationAnimator::CanAnimate() const { 272 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation,
254 return Shell::GetInstance() 273 display::Display::RotationSource source) {
255 ->display_manager() 274 const display::Display::Rotation initial_rotation =
256 ->GetDisplayForId(display_id_) 275 GetCurrentScreenRotation(display_id_);
257 .is_valid(); 276
277 if (initial_rotation == new_rotation)
278 return;
279
280 std::unique_ptr<ScreenRotationRequest> rotation_request =
281 base::MakeUnique<ScreenRotationRequest>();
282 rotation_request->animator = this;
283 rotation_request->display_id = display_id_;
284 rotation_request->initial_rotation = initial_rotation;
285 rotation_request->new_rotation = new_rotation;
286 rotation_request->source = source;
287
288 if (is_rotating_) {
289 last_pending_request_.reset(rotation_request.release());
290 StopAnimating();
291 } else {
292 last_pending_request_.reset();
293 is_rotating_ = true;
294 RotateScreen(*rotation_request);
295 rotation_request.reset();
296 }
258 } 297 }
259 298
260 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, 299 ui::Layer* ScreenRotationAnimator::GetOldLayerTreeRootLayer() {
261 display::Display::RotationSource source) { 300 if (old_layer_tree_owner_) {
262 const display::Display::Rotation current_rotation = 301 return old_layer_tree_owner_->root();
263 GetCurrentRotation(display_id_); 302 } else {
bruthig 2017/03/10 22:34:08 nit: The 'else' is not really necessary since the
wutao 2017/03/14 16:46:37 What if old_layer_tree_owner_ is not assigned yet?
bruthig 2017/03/15 23:12:37 I'm not suggesting to remove the body of the 'else
wutao 2017/03/16 07:37:58 Done.
303 NOTREACHED();
304 return nullptr;
305 }
306 }
264 307
265 if (current_rotation == new_rotation) 308 void ScreenRotationAnimator::OnLayerAnimationEnded() {
266 return; 309 ContinueOrCleanUp();
310 }
267 311
268 RotateScreen(display_id_, new_rotation, source); 312 void ScreenRotationAnimator::OnLayerAnimationAborted() {
313 AbortAnimations(old_layer_tree_owner_->root());
314 ContinueOrCleanUp();
315 }
316
317 void ScreenRotationAnimator::ContinueOrCleanUp() {
318 is_rotating_ = false;
319 old_layer_tree_owner_.reset();
320 if (last_pending_request_) {
321 const ScreenRotationAnimator::ScreenRotationRequest pending_request =
bruthig 2017/03/10 22:34:08 nit: Instead of creating a copy of the |last_pendi
wutao 2017/03/14 16:46:37 lol. Right. Forget this when I moved the code to h
322 *last_pending_request_;
323 const display::Display::Rotation new_rotation =
324 pending_request.new_rotation;
325 if (GetCurrentScreenRotation(display_id_) != new_rotation) {
bruthig 2017/03/10 22:34:08 nit: I don't think duplicating this early return i
wutao 2017/03/14 16:46:37 Done.
326 Rotate(new_rotation, pending_request.source);
327 return;
328 }
329 }
330
331 if (screen_rotation_animator_observer_)
332 screen_rotation_animator_observer_->OnEndedOrAbortedScreenRotationAnimation(
333 this);
bruthig 2017/03/10 22:34:07 If the body wraps onto more than one line the '{}'
wutao 2017/03/14 16:46:37 Done.
334 }
335
336 void ScreenRotationAnimator::AbortAnimations(ui::Layer* layer) {
bruthig 2017/03/10 22:34:08 nit: It might make sense to make this a non-member
wutao 2017/03/14 16:46:37 Done.
337 for (ui::Layer* child_layer : layer->children())
338 AbortAnimations(child_layer);
339 layer->GetAnimator()->AbortAllAnimations();
340 }
341
342 void ScreenRotationAnimator::StopAnimating() {
343 aura::Window* root_window = GetRootWindow(display_id_);
344 for (ui::Layer* child_layer : root_window->layer()->children()) {
345 if (old_layer_tree_owner_ && child_layer == old_layer_tree_owner_->root())
bruthig 2017/03/10 22:34:08 Adding a quick return if (!old_layer_tree_owner_)
wutao 2017/03/14 16:46:37 Do we assume if (!old_layer_tree_owner_), then the
346 continue;
347
348 child_layer->GetAnimator()->StopAnimating();
349 }
350
351 if (old_layer_tree_owner_) {
352 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating();
353 }
269 } 354 }
270 355
271 } // namespace ash 356 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698