| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 // Destroys itself after |last_sequence| ends or is aborted. Does not take |
| 404 last_sequence_ = last_sequence; | 405 // ownership of |last_sequence|, which should not be NULL. |
| 406 void SetLastSequence(ui::LayerAnimationSequence* last_sequence) { |
| 407 last_sequence->AddObserver(this); |
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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()); |
| 484 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); | 483 window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); |
| 484 |
| 485 if (observer) { | 485 if (observer) { |
| 486 observer->set_last_sequence(last_sequence); | 486 observer->SetLastSequence(last_sequence); |
| 487 observer->DetachAndRecreateLayers(); | 487 observer->DetachAndRecreateLayers(); |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 | 490 |
| 491 void AnimateShowWindow_Rotate(aura::Window* window) { | 491 void AnimateShowWindow_Rotate(aura::Window* window) { |
| 492 AddLayerAnimationsForRotate(window, true); | 492 AddLayerAnimationsForRotate(window, true); |
| 493 } | 493 } |
| 494 | 494 |
| 495 void AnimateHideWindow_Rotate(aura::Window* window) { | 495 void AnimateHideWindow_Rotate(aura::Window* window) { |
| 496 AddLayerAnimationsForRotate(window, false); | 496 AddLayerAnimationsForRotate(window, false); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 649 } |
| 650 | 650 |
| 651 bool WindowAnimationsDisabled(aura::Window* window) { | 651 bool WindowAnimationsDisabled(aura::Window* window) { |
| 652 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && | 652 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && |
| 653 window->GetProperty(aura::client::kAnimationsDisabledKey)) || | 653 window->GetProperty(aura::client::kAnimationsDisabledKey)) || |
| 654 CommandLine::ForCurrentProcess()->HasSwitch( | 654 CommandLine::ForCurrentProcess()->HasSwitch( |
| 655 switches::kWindowAnimationsDisabled)); | 655 switches::kWindowAnimationsDisabled)); |
| 656 } | 656 } |
| 657 | 657 |
| 658 } // namespace wm | 658 } // namespace wm |
| OLD | NEW |