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

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

Issue 343753007: Fix a leak in wm::AnimateOnChildWindowVisibilityChanged(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Apply the animation to the correct layer. Created 6 years, 5 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 | Annotate | Revision Log
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // 1) Notifies AnimationHost at the end of hiding animation. 51 // 1) Notifies AnimationHost at the end of hiding animation.
52 // 2) Detaches the window's layers for hiding animation and deletes 52 // 2) Detaches the window's layers for hiding animation and deletes
53 // them upon completion of the animation. This is necessary to a) 53 // them upon completion of the animation. This is necessary to a)
54 // ensure that the animation continues in the event of the window being 54 // ensure that the animation continues in the event of the window being
55 // deleted, and b) to ensure that the animation is visible even if the 55 // deleted, and b) to ensure that the animation is visible even if the
56 // window gets restacked below other windows when focus or activation 56 // window gets restacked below other windows when focus or activation
57 // changes. 57 // changes.
58 // The subclass will determine when the animation is completed. 58 // The subclass will determine when the animation is completed.
59 class HidingWindowAnimationObserverBase : public aura::WindowObserver { 59 class HidingWindowAnimationObserverBase : public aura::WindowObserver {
60 public: 60 public:
61 HidingWindowAnimationObserverBase(aura::Window* window) : window_(window) { 61 explicit HidingWindowAnimationObserverBase(aura::Window* window)
62 : window_(window) {
62 window_->AddObserver(this); 63 window_->AddObserver(this);
63 } 64 }
64 virtual ~HidingWindowAnimationObserverBase() { 65 virtual ~HidingWindowAnimationObserverBase() {
65 if (window_) 66 if (window_)
66 window_->RemoveObserver(this); 67 window_->RemoveObserver(this);
67 } 68 }
68 69
69 // aura::WindowObserver: 70 // aura::WindowObserver:
70 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 71 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
71 DCHECK_EQ(window, window_); 72 DCHECK_EQ(window, window_);
(...skipping 29 matching lines...) Expand all
101 topmost_transient_child = *iter; 102 topmost_transient_child = *iter;
102 } 103 }
103 } 104 }
104 if (topmost_transient_child) { 105 if (topmost_transient_child) {
105 window_->parent()->layer()->StackAbove( 106 window_->parent()->layer()->StackAbove(
106 layer_owner_->root(), topmost_transient_child->layer()); 107 layer_owner_->root(), topmost_transient_child->layer());
107 } 108 }
108 } 109 }
109 } 110 }
110 111
112 // Returns the root of the detached layer tree. Should be called only after
113 // DetachAndRecreateLayers(). The caller does not own the result.
114 ui::Layer* detached_layer_tree_root() { return layer_owner_->root(); }
115
111 protected: 116 protected:
112 // Invoked when the hiding animation is completed. It will delete 117 // Invoked when the hiding animation is completed. It will delete
113 // 'this', and no operation should be made on this object after this 118 // 'this', and no operation should be made on this object after this
114 // point. 119 // point.
115 void OnAnimationCompleted() { 120 void OnAnimationCompleted() {
116 // Window may have been destroyed by this point. 121 // Window may have been destroyed by this point.
117 if (window_) { 122 if (window_) {
118 aura::client::AnimationHost* animation_host = 123 aura::client::AnimationHost* animation_host =
119 aura::client::GetAnimationHost(window_); 124 aura::client::GetAnimationHost(window_);
120 if (animation_host) 125 if (animation_host)
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 sequence->AddElement(CreateGrowShrinkElement(window, false)); 394 sequence->AddElement(CreateGrowShrinkElement(window, false));
390 window->layer()->GetAnimator()->StartAnimation(sequence.release()); 395 window->layer()->GetAnimator()->StartAnimation(sequence.release());
391 } 396 }
392 397
393 // A HidingWindowAnimationObserver that deletes observer and detached 398 // A HidingWindowAnimationObserver that deletes observer and detached
394 // layers when the last_sequence has been completed or aborted. 399 // layers when the last_sequence has been completed or aborted.
395 class RotateHidingWindowAnimationObserver 400 class RotateHidingWindowAnimationObserver
396 : public HidingWindowAnimationObserverBase, 401 : public HidingWindowAnimationObserverBase,
397 public ui::LayerAnimationObserver { 402 public ui::LayerAnimationObserver {
398 public: 403 public:
399 RotateHidingWindowAnimationObserver(aura::Window* window) 404 explicit RotateHidingWindowAnimationObserver(aura::Window* window)
400 : HidingWindowAnimationObserverBase(window), last_sequence_(NULL) {} 405 : HidingWindowAnimationObserverBase(window) {}
401 virtual ~RotateHidingWindowAnimationObserver() {} 406 virtual ~RotateHidingWindowAnimationObserver() {}
402 407
403 void set_last_sequence(ui::LayerAnimationSequence* last_sequence) { 408 // The observer destroys itself after the |last_sequence| ends or is aborted.
404 last_sequence_ = last_sequence; 409 // Does not take ownership of the |last_sequence| parameter, which should not
410 // be NULL.
411 void SetLastSequence(ui::LayerAnimationSequence* last_sequence) {
412 last_sequence->AddObserver(this);
405 } 413 }
406 414
407 // ui::LayerAnimationObserver: 415 // ui::LayerAnimationObserver:
408 virtual void OnLayerAnimationEnded( 416 virtual void OnLayerAnimationEnded(
409 ui::LayerAnimationSequence* sequence) OVERRIDE { 417 ui::LayerAnimationSequence* sequence) OVERRIDE {
410 if (last_sequence_ == sequence) 418 OnAnimationCompleted();
411 OnAnimationCompleted();
412 } 419 }
413 virtual void OnLayerAnimationAborted( 420 virtual void OnLayerAnimationAborted(
414 ui::LayerAnimationSequence* sequence) OVERRIDE { 421 ui::LayerAnimationSequence* sequence) OVERRIDE {
415 if (last_sequence_ == sequence) 422 OnAnimationCompleted();
416 OnAnimationCompleted();
417 } 423 }
418 virtual void OnLayerAnimationScheduled( 424 virtual void OnLayerAnimationScheduled(
419 ui::LayerAnimationSequence* sequence) OVERRIDE {} 425 ui::LayerAnimationSequence* sequence) OVERRIDE {}
420 426
421 private: 427 private:
422 ui::LayerAnimationSequence* last_sequence_;
423
424 DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver); 428 DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver);
425 }; 429 };
426 430
427 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { 431 void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
428 if (show) 432 if (show)
429 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 433 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
430 434
431 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( 435 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
432 kWindowAnimation_Rotate_DurationMS); 436 kWindowAnimation_Rotate_DurationMS);
433 437
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 scale_about_pivot->SetChild(perspective.release()); 478 scale_about_pivot->SetChild(perspective.release());
475 translation->SetChild(scale_about_pivot.release()); 479 translation->SetChild(scale_about_pivot.release());
476 rotation->SetChild(translation.release()); 480 rotation->SetChild(translation.release());
477 rotation->SetReversed(show); 481 rotation->SetReversed(show);
478 482
479 scoped_ptr<ui::LayerAnimationElement> transition( 483 scoped_ptr<ui::LayerAnimationElement> transition(
480 ui::LayerAnimationElement::CreateInterpolatedTransformElement( 484 ui::LayerAnimationElement::CreateInterpolatedTransformElement(
481 rotation.release(), duration)); 485 rotation.release(), duration));
482 ui::LayerAnimationSequence* last_sequence = 486 ui::LayerAnimationSequence* last_sequence =
483 new ui::LayerAnimationSequence(transition.release()); 487 new ui::LayerAnimationSequence(transition.release());
484 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); 488
485 if (observer) { 489 if (observer) {
486 observer->set_last_sequence(last_sequence); 490 observer->SetLastSequence(last_sequence);
487 observer->DetachAndRecreateLayers(); 491 observer->DetachAndRecreateLayers();
492 observer->detached_layer_tree_root()->GetAnimator()->ScheduleAnimation(
sky 2014/07/14 19:18:18 Isn't the important part here your changes to SetL
please use gerrit instead 2014/07/14 20:12:17 Yes.
please use gerrit instead 2014/07/17 03:14:00 Done.
493 last_sequence);
494 } else {
495 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence);
488 } 496 }
489 } 497 }
490 498
491 void AnimateShowWindow_Rotate(aura::Window* window) { 499 void AnimateShowWindow_Rotate(aura::Window* window) {
492 AddLayerAnimationsForRotate(window, true); 500 AddLayerAnimationsForRotate(window, true);
493 } 501 }
494 502
495 void AnimateHideWindow_Rotate(aura::Window* window) { 503 void AnimateHideWindow_Rotate(aura::Window* window) {
496 AddLayerAnimationsForRotate(window, false); 504 AddLayerAnimationsForRotate(window, false);
497 } 505 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 657 }
650 658
651 bool WindowAnimationsDisabled(aura::Window* window) { 659 bool WindowAnimationsDisabled(aura::Window* window) {
652 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && 660 return (!gfx::Animation::ShouldRenderRichAnimation() || (window &&
653 window->GetProperty(aura::client::kAnimationsDisabledKey)) || 661 window->GetProperty(aura::client::kAnimationsDisabledKey)) ||
654 CommandLine::ForCurrentProcess()->HasSwitch( 662 CommandLine::ForCurrentProcess()->HasSwitch(
655 switches::kWindowAnimationsDisabled)); 663 switches::kWindowAnimationsDisabled));
656 } 664 }
657 665
658 } // namespace wm 666 } // namespace wm
OLDNEW
« no previous file with comments | « no previous file | ui/wm/core/window_animations_unittest.cc » ('j') | ui/wm/core/window_animations_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698