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

Side by Side Diff: ui/wm/core/window_animations.cc

Issue 795113002: compositor/layer_animator: handle delegate removal in LayerAnimation::StopAnimating (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed bad test and implemented correct one. Created 6 years 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 | « no previous file | ui/wm/core/window_animations_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "ui/wm/core/window_animations.h" 5 #include "ui/wm/core/window_animations.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 class RotateHidingWindowAnimationObserver 397 class RotateHidingWindowAnimationObserver
398 : public HidingWindowAnimationObserverBase, 398 : public HidingWindowAnimationObserverBase,
399 public ui::LayerAnimationObserver { 399 public ui::LayerAnimationObserver {
400 public: 400 public:
401 explicit RotateHidingWindowAnimationObserver(aura::Window* window) 401 explicit RotateHidingWindowAnimationObserver(aura::Window* window)
402 : HidingWindowAnimationObserverBase(window) {} 402 : HidingWindowAnimationObserverBase(window) {}
403 ~RotateHidingWindowAnimationObserver() override {} 403 ~RotateHidingWindowAnimationObserver() override {}
404 404
405 // Destroys itself after |last_sequence| ends or is aborted. Does not take 405 // Destroys itself after |last_sequence| ends or is aborted. Does not take
406 // ownership of |last_sequence|, which should not be NULL. 406 // ownership of |last_sequence|, which should not be NULL.
407 void SetLastSequence(ui::LayerAnimationSequence* last_sequence) { 407 void AddSequence(ui::LayerAnimationSequence* sequence) {
408 last_sequence->AddObserver(this); 408 sequences_.push_back(sequence);
sky 2014/12/15 17:48:54 I think you're working around the bug. OnLayerAnim
409 sequence->AddObserver(this);
409 } 410 }
410 411
411 // ui::LayerAnimationObserver: 412 // ui::LayerAnimationObserver:
412 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override { 413 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override {
413 OnAnimationCompleted(); 414 RemoveAnimation(sequence);
414 } 415 }
415 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override { 416 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override {
416 OnAnimationCompleted(); 417 RemoveAnimation(sequence);
417 } 418 }
418 void OnLayerAnimationScheduled( 419 void OnLayerAnimationScheduled(
419 ui::LayerAnimationSequence* sequence) override {} 420 ui::LayerAnimationSequence* sequence) override {}
420 421
421 private: 422 private:
423 // Destroys itself after last sequence ends or is aborted.
424 void RemoveAnimation(ui::LayerAnimationSequence *sequence) {
425 auto it = std::remove(sequences_.begin(), sequences_.end(), sequence);
426 if (it != sequences_.end()) {
427 sequences_.erase(it);
428 if (sequences_.empty())
429 OnAnimationCompleted();
430 }
431 }
432
433 std::vector<ui::LayerAnimationSequence *> sequences_;
434
422 DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver); 435 DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver);
423 }; 436 };
424 437
425 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { 438 void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
426 if (show) 439 if (show)
427 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 440 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
428 441
429 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( 442 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
430 kWindowAnimation_Rotate_DurationMS); 443 kWindowAnimation_Rotate_DurationMS);
431 444
432 RotateHidingWindowAnimationObserver* observer = NULL; 445 RotateHidingWindowAnimationObserver* observer = NULL;
433 446
434 if (!show) { 447 if (!show) {
435 observer = new RotateHidingWindowAnimationObserver(window); 448 observer = new RotateHidingWindowAnimationObserver(window);
436 window->layer()->GetAnimator()->SchedulePauseForProperties( 449 window->layer()->GetAnimator()->SchedulePauseForProperties(
437 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, 450 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100,
438 ui::LayerAnimationElement::OPACITY); 451 ui::LayerAnimationElement::OPACITY);
439 } 452 }
440 scoped_ptr<ui::LayerAnimationElement> opacity( 453 scoped_ptr<ui::LayerAnimationElement> opacity(
441 ui::LayerAnimationElement::CreateOpacityElement( 454 ui::LayerAnimationElement::CreateOpacityElement(
442 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, 455 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity,
443 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); 456 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100));
444 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); 457 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT);
445 window->layer()->GetAnimator()->ScheduleAnimation( 458 ui::LayerAnimationSequence *opacity_sequence =
sky 2014/12/15 17:48:54 nit: "ui::LayerAnimationSequence *" -> "ui::LayerA
446 new ui::LayerAnimationSequence(opacity.release())); 459 new ui::LayerAnimationSequence(opacity.release());
460 window->layer()->GetAnimator()->ScheduleAnimation(opacity_sequence);
461 if (observer)
462 observer->AddSequence(opacity_sequence);
447 463
448 float xcenter = window->bounds().width() * 0.5; 464 float xcenter = window->bounds().width() * 0.5;
449 465
450 gfx::Transform transform; 466 gfx::Transform transform;
451 transform.Translate(xcenter, 0); 467 transform.Translate(xcenter, 0);
452 transform.ApplyPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth); 468 transform.ApplyPerspectiveDepth(kWindowAnimation_Rotate_PerspectiveDepth);
453 transform.Translate(-xcenter, 0); 469 transform.Translate(-xcenter, 0);
454 scoped_ptr<ui::InterpolatedTransform> perspective( 470 scoped_ptr<ui::InterpolatedTransform> perspective(
455 new ui::InterpolatedConstantTransform(transform)); 471 new ui::InterpolatedConstantTransform(transform));
456 472
(...skipping 13 matching lines...) Expand all
470 gfx::Vector3dF(1, 0, 0), 0, kWindowAnimation_Rotate_DegreesX)); 486 gfx::Vector3dF(1, 0, 0), 0, kWindowAnimation_Rotate_DegreesX));
471 487
472 scale_about_pivot->SetChild(perspective.release()); 488 scale_about_pivot->SetChild(perspective.release());
473 translation->SetChild(scale_about_pivot.release()); 489 translation->SetChild(scale_about_pivot.release());
474 rotation->SetChild(translation.release()); 490 rotation->SetChild(translation.release());
475 rotation->SetReversed(show); 491 rotation->SetReversed(show);
476 492
477 scoped_ptr<ui::LayerAnimationElement> transition( 493 scoped_ptr<ui::LayerAnimationElement> transition(
478 ui::LayerAnimationElement::CreateInterpolatedTransformElement( 494 ui::LayerAnimationElement::CreateInterpolatedTransformElement(
479 rotation.release(), duration)); 495 rotation.release(), duration));
480 ui::LayerAnimationSequence* last_sequence = 496 ui::LayerAnimationSequence* transition_sequence =
481 new ui::LayerAnimationSequence(transition.release()); 497 new ui::LayerAnimationSequence(transition.release());
482 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); 498 window->layer()->GetAnimator()->ScheduleAnimation(transition_sequence);
483 499
484 if (observer) { 500 if (observer) {
485 observer->SetLastSequence(last_sequence); 501 observer->AddSequence(transition_sequence);
486 observer->DetachAndRecreateLayers(); 502 observer->DetachAndRecreateLayers();
487 } 503 }
488 } 504 }
489 505
490 void AnimateShowWindow_Rotate(aura::Window* window) { 506 void AnimateShowWindow_Rotate(aura::Window* window) {
491 AddLayerAnimationsForRotate(window, true); 507 AddLayerAnimationsForRotate(window, true);
492 } 508 }
493 509
494 void AnimateHideWindow_Rotate(aura::Window* window) { 510 void AnimateHideWindow_Rotate(aura::Window* window) {
495 AddLayerAnimationsForRotate(window, false); 511 AddLayerAnimationsForRotate(window, false);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 // being accessed via Remote Desktop. 677 // being accessed via Remote Desktop.
662 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() == 678 if (ui::ScopedAnimationDurationScaleMode::duration_scale_mode() ==
663 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION) 679 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION)
664 return false; 680 return false;
665 681
666 // Let the user decide whether or not to play the animation. 682 // Let the user decide whether or not to play the animation.
667 return !gfx::Animation::ShouldRenderRichAnimation(); 683 return !gfx::Animation::ShouldRenderRichAnimation();
668 } 684 }
669 685
670 } // namespace wm 686 } // namespace wm
OLDNEW
« no previous file with comments | « no previous file | ui/wm/core/window_animations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698