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

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: The test and the fix. 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
« 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 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 sequence->AddElement(CreateGrowShrinkElement(window, false)); 390 sequence->AddElement(CreateGrowShrinkElement(window, false));
390 window->layer()->GetAnimator()->StartAnimation(sequence.release()); 391 window->layer()->GetAnimator()->StartAnimation(sequence.release());
391 } 392 }
392 393
393 // A HidingWindowAnimationObserver that deletes observer and detached 394 // A HidingWindowAnimationObserver that deletes observer and detached
394 // layers when the last_sequence has been completed or aborted. 395 // layers when the last_sequence has been completed or aborted.
395 class RotateHidingWindowAnimationObserver 396 class RotateHidingWindowAnimationObserver
396 : public HidingWindowAnimationObserverBase, 397 : public HidingWindowAnimationObserverBase,
397 public ui::LayerAnimationObserver { 398 public ui::LayerAnimationObserver {
398 public: 399 public:
399 RotateHidingWindowAnimationObserver(aura::Window* window) 400 explicit RotateHidingWindowAnimationObserver(aura::Window* window)
400 : HidingWindowAnimationObserverBase(window), last_sequence_(NULL) {} 401 : HidingWindowAnimationObserverBase(window) {}
401 virtual ~RotateHidingWindowAnimationObserver() {} 402 virtual ~RotateHidingWindowAnimationObserver() {}
402 403
403 void set_last_sequence(ui::LayerAnimationSequence* last_sequence) { 404 void SetLastSequence(ui::LayerAnimationSequence* sequence) {
404 last_sequence_ = last_sequence; 405 DCHECK(sequence);
406 sequence->AddObserver(this);
407 DetachAndRecreateLayers();
405 } 408 }
406 409
407 // ui::LayerAnimationObserver: 410 // ui::LayerAnimationObserver:
408 virtual void OnLayerAnimationEnded( 411 virtual void OnLayerAnimationEnded(
409 ui::LayerAnimationSequence* sequence) OVERRIDE { 412 ui::LayerAnimationSequence* sequence) OVERRIDE {
410 if (last_sequence_ == sequence) 413 OnAnimationCompleted();
411 OnAnimationCompleted();
412 } 414 }
413 virtual void OnLayerAnimationAborted( 415 virtual void OnLayerAnimationAborted(
414 ui::LayerAnimationSequence* sequence) OVERRIDE { 416 ui::LayerAnimationSequence* sequence) OVERRIDE {
415 if (last_sequence_ == sequence) 417 OnAnimationCompleted();
416 OnAnimationCompleted();
417 } 418 }
418 virtual void OnLayerAnimationScheduled( 419 virtual void OnLayerAnimationScheduled(
419 ui::LayerAnimationSequence* sequence) OVERRIDE {} 420 ui::LayerAnimationSequence* sequence) OVERRIDE {}
420 421
421 private: 422 private:
422 ui::LayerAnimationSequence* last_sequence_;
423
424 DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver); 423 DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver);
425 }; 424 };
426 425
427 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { 426 void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
428 if (show) 427 if (show)
429 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 428 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
430 429
431 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( 430 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
432 kWindowAnimation_Rotate_DurationMS); 431 kWindowAnimation_Rotate_DurationMS);
433 432
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 scale_about_pivot->SetChild(perspective.release()); 473 scale_about_pivot->SetChild(perspective.release());
475 translation->SetChild(scale_about_pivot.release()); 474 translation->SetChild(scale_about_pivot.release());
476 rotation->SetChild(translation.release()); 475 rotation->SetChild(translation.release());
477 rotation->SetReversed(show); 476 rotation->SetReversed(show);
478 477
479 scoped_ptr<ui::LayerAnimationElement> transition( 478 scoped_ptr<ui::LayerAnimationElement> transition(
480 ui::LayerAnimationElement::CreateInterpolatedTransformElement( 479 ui::LayerAnimationElement::CreateInterpolatedTransformElement(
481 rotation.release(), duration)); 480 rotation.release(), duration));
482 ui::LayerAnimationSequence* last_sequence = 481 ui::LayerAnimationSequence* last_sequence =
483 new ui::LayerAnimationSequence(transition.release()); 482 new ui::LayerAnimationSequence(transition.release());
483
484 if (observer)
485 observer->SetLastSequence(last_sequence);
sky 2014/07/09 20:32:12 If you do this here, doesn't that mean the animati
please use gerrit instead 2014/07/09 20:53:55 Hm, I think you're right. The problem I'm encounte
486
484 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); 487 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence);
485 if (observer) {
486 observer->set_last_sequence(last_sequence);
487 observer->DetachAndRecreateLayers();
488 }
489 } 488 }
490 489
491 void AnimateShowWindow_Rotate(aura::Window* window) { 490 void AnimateShowWindow_Rotate(aura::Window* window) {
492 AddLayerAnimationsForRotate(window, true); 491 AddLayerAnimationsForRotate(window, true);
493 } 492 }
494 493
495 void AnimateHideWindow_Rotate(aura::Window* window) { 494 void AnimateHideWindow_Rotate(aura::Window* window) {
496 AddLayerAnimationsForRotate(window, false); 495 AddLayerAnimationsForRotate(window, false);
497 } 496 }
498 497
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 648 }
650 649
651 bool WindowAnimationsDisabled(aura::Window* window) { 650 bool WindowAnimationsDisabled(aura::Window* window) {
652 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && 651 return (!gfx::Animation::ShouldRenderRichAnimation() || (window &&
653 window->GetProperty(aura::client::kAnimationsDisabledKey)) || 652 window->GetProperty(aura::client::kAnimationsDisabledKey)) ||
654 CommandLine::ForCurrentProcess()->HasSwitch( 653 CommandLine::ForCurrentProcess()->HasSwitch(
655 switches::kWindowAnimationsDisabled)); 654 switches::kWindowAnimationsDisabled));
656 } 655 }
657 656
658 } // namespace wm 657 } // 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