Index: ash/wm/session_state_animator_impl.cc |
diff --git a/ash/wm/session_state_animator.cc b/ash/wm/session_state_animator_impl.cc |
similarity index 80% |
copy from ash/wm/session_state_animator.cc |
copy to ash/wm/session_state_animator_impl.cc |
index 9900275af8a0bf2032bf10661ecf48fdc58c6add..e0c3fe2ad6ae5bcf9504387cda7217b9c06f46d1 100644 |
--- a/ash/wm/session_state_animator.cc |
+++ b/ash/wm/session_state_animator_impl.cc |
@@ -2,7 +2,9 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "ash/wm/session_state_animator.h" |
+#include "ash/wm/session_state_animator_impl.h" |
+ |
+#include <vector> |
#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
@@ -36,7 +38,7 @@ gfx::Transform GetSlowCloseTransform() { |
floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), |
floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); |
transform.Scale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); |
- return transform; |
+ return transform; |
} |
// Returns the transform that should be applied to containers for the fast-close |
@@ -44,6 +46,7 @@ gfx::Transform GetSlowCloseTransform() { |
gfx::Transform GetFastCloseTransform() { |
gfx::Size root_size = Shell::GetPrimaryRootWindow()->bounds().size(); |
gfx::Transform transform; |
+ |
transform.Translate(floor(0.5 * root_size.width() + 0.5), |
floor(0.5 * root_size.height() + 0.5)); |
transform.Scale(kMinimumScale, kMinimumScale); |
@@ -282,7 +285,7 @@ void StartGrayscaleBrightnessAnimationForWindow( |
// finished. It is used in when undoing shutdown animation. |
class CallbackAnimationObserver : public ui::LayerAnimationObserver { |
public: |
- explicit CallbackAnimationObserver(base::Callback<void(void)> &callback) |
+ explicit CallbackAnimationObserver(base::Closure callback) |
: callback_(callback) { |
} |
virtual ~CallbackAnimationObserver() { |
@@ -307,7 +310,7 @@ class CallbackAnimationObserver : public ui::LayerAnimationObserver { |
virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) |
OVERRIDE {} |
- base::Callback<void(void)> callback_; |
+ base::Closure callback_; |
DISALLOW_COPY_AND_ASSIGN(CallbackAnimationObserver); |
}; |
@@ -385,7 +388,102 @@ bool IsLayerAnimated(ui::Layer* layer, |
} // namespace |
-bool SessionStateAnimator::TestApi::ContainersAreAnimated( |
+// This observer is intended to use in cases when some action has to be taken |
+// once some animation successfully completes (i.e. it was not aborted). |
+// Observer will count a number of sequences it is attached to, and a number of |
+// finished sequences (either Ended or Aborted). Once these two numbers are |
+// equal, observer will delete itself, calling callback passed to constructor if |
+// there were no aborted animations. |
+// This way it can be either used to wait for some animation to be finished in |
+// multiple layers, to wait once a sequence of animations is finished in one |
+// layer or the mixture of both. |
+class SessionStateAnimatorImpl::AnimationSequence |
+ : public SessionStateAnimator::AnimationSequence, |
+ public ui::LayerAnimationObserver { |
+ public: |
+ explicit AnimationSequence( |
+ SessionStateAnimatorImpl* animator, |
+ base::Closure callback); |
+ |
+ // SessionStateAnimator::AnimationSequence: |
+ virtual void StartAnimation( |
+ int container_mask, |
+ SessionStateAnimator::AnimationType type, |
+ SessionStateAnimator::AnimationSpeed speed) OVERRIDE; |
+ |
+ private: |
+ virtual ~AnimationSequence(); |
+ |
+ // ui::LayerAnimationObserver: |
+ virtual void OnLayerAnimationEnded( |
+ ui::LayerAnimationSequence* sequence) OVERRIDE; |
+ |
+ virtual void OnLayerAnimationAborted( |
+ ui::LayerAnimationSequence* sequence) OVERRIDE; |
+ |
+ virtual void OnLayerAnimationScheduled( |
+ ui::LayerAnimationSequence* sequence) OVERRIDE; |
+ |
+ virtual void OnAttachedToSequence( |
+ ui::LayerAnimationSequence* sequence) OVERRIDE; |
+ |
+ SessionStateAnimatorImpl* animator_; |
Daniel Erat
2014/09/08 16:16:03
nit: document that the animator isn't owned by thi
bruthig
2014/09/09 17:32:34
Done.
|
+ |
+ // Number of sequences this observer was attached to. |
+ int sequences_attached_; |
+ |
+ // Number of sequences either ended or aborted. |
+ int sequences_completed_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AnimationSequence); |
+}; |
+ |
+SessionStateAnimatorImpl::AnimationSequence::AnimationSequence( |
Daniel Erat
2014/09/08 16:16:03
nit: these are all short; consider inlining them i
bruthig
2014/09/09 17:32:34
Done.
|
+ SessionStateAnimatorImpl* animator, |
+ base::Closure callback) |
+ : SessionStateAnimator::AnimationSequence(callback), |
+ animator_(animator), |
+ sequences_attached_(0), |
+ sequences_completed_(0) { |
+} |
+ |
+SessionStateAnimatorImpl::AnimationSequence:: |
+ ~AnimationSequence() { |
+} |
+ |
+void SessionStateAnimatorImpl::AnimationSequence::StartAnimation( |
+ int container_mask, |
+ SessionStateAnimator::AnimationType type, |
+ SessionStateAnimator::AnimationSpeed speed) { |
+ animator_->StartAnimationInSequence(container_mask, type, speed, this); |
+} |
+ |
+void SessionStateAnimatorImpl::AnimationSequence::OnLayerAnimationEnded( |
+ ui::LayerAnimationSequence* sequence) { |
+ sequences_completed_++; |
+ if (sequences_completed_ == sequences_attached_) { |
+ OnAnimationCompleted(); |
+ } |
+} |
+ |
+void SessionStateAnimatorImpl::AnimationSequence:: |
+ OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) { |
+ sequences_completed_++; |
+ if (sequences_completed_ == sequences_attached_) |
+ OnAnimationAborted(); |
+} |
+ |
+void SessionStateAnimatorImpl::AnimationSequence:: |
+ OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) { |
+} |
+ |
+void SessionStateAnimatorImpl::AnimationSequence::OnAttachedToSequence( |
+ ui::LayerAnimationSequence* sequence) { |
+ LayerAnimationObserver::OnAttachedToSequence(sequence); |
+ sequences_attached_++; |
+} |
+ |
+bool SessionStateAnimatorImpl::TestApi::ContainersAreAnimated( |
int container_mask, AnimationType type) const { |
aura::Window::Windows containers; |
animator_->GetContainers(container_mask, &containers); |
@@ -399,63 +497,29 @@ bool SessionStateAnimator::TestApi::ContainersAreAnimated( |
return true; |
} |
-bool SessionStateAnimator::TestApi::RootWindowIsAnimated(AnimationType type) |
+bool SessionStateAnimatorImpl::TestApi::RootWindowIsAnimated(AnimationType type) |
const { |
aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
ui::Layer* layer = root_window->layer(); |
return IsLayerAnimated(layer, type); |
} |
-const int SessionStateAnimator::kAllLockScreenContainersMask = |
- SessionStateAnimator::LOCK_SCREEN_BACKGROUND | |
- SessionStateAnimator::LOCK_SCREEN_CONTAINERS | |
- SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS; |
- |
-const int SessionStateAnimator::kAllContainersMask = |
- SessionStateAnimator::kAllLockScreenContainersMask | |
- SessionStateAnimator::DESKTOP_BACKGROUND | |
- SessionStateAnimator::LAUNCHER | |
- SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS; |
- |
-SessionStateAnimator::SessionStateAnimator() { |
+SessionStateAnimatorImpl::SessionStateAnimatorImpl() { |
} |
-SessionStateAnimator::~SessionStateAnimator() { |
-} |
- |
-base::TimeDelta SessionStateAnimator::GetDuration(AnimationSpeed speed) { |
- switch (speed) { |
- case ANIMATION_SPEED_IMMEDIATE: |
- return base::TimeDelta(); |
- case ANIMATION_SPEED_UNDOABLE: |
- return base::TimeDelta::FromMilliseconds(400); |
- case ANIMATION_SPEED_REVERT: |
- return base::TimeDelta::FromMilliseconds(150); |
- case ANIMATION_SPEED_FAST: |
- return base::TimeDelta::FromMilliseconds(150); |
- case ANIMATION_SPEED_SHOW_LOCK_SCREEN: |
- return base::TimeDelta::FromMilliseconds(200); |
- case ANIMATION_SPEED_MOVE_WINDOWS: |
- return base::TimeDelta::FromMilliseconds(350); |
- case ANIMATION_SPEED_UNDO_MOVE_WINDOWS: |
- return base::TimeDelta::FromMilliseconds(350); |
- case ANIMATION_SPEED_SHUTDOWN: |
- return base::TimeDelta::FromMilliseconds(1000); |
- case ANIMATION_SPEED_REVERT_SHUTDOWN: |
- return base::TimeDelta::FromMilliseconds(500); |
- } |
- // Satisfy compilers that do not understand that we will return from switch |
- // above anyway. |
- DCHECK(false) << "Unhandled animation speed " << speed; |
- return base::TimeDelta(); |
+SessionStateAnimatorImpl::~SessionStateAnimatorImpl() { |
} |
// Fills |containers| with the containers described by |container_mask|. |
-void SessionStateAnimator::GetContainers(int container_mask, |
- aura::Window::Windows* containers) { |
+void SessionStateAnimatorImpl::GetContainers(int container_mask, |
+ aura::Window::Windows* containers) { |
aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
containers->clear(); |
+ if (container_mask & ROOT_CONTAINER) { |
+ containers->push_back(Shell::GetPrimaryRootWindow()); |
+ } |
+ |
if (container_mask & DESKTOP_BACKGROUND) { |
containers->push_back(Shell::GetContainer( |
root_window, kShellWindowId_DesktopBackgroundContainer)); |
@@ -493,9 +557,9 @@ void SessionStateAnimator::GetContainers(int container_mask, |
} |
} |
-void SessionStateAnimator::StartAnimation(int container_mask, |
- AnimationType type, |
- AnimationSpeed speed) { |
+void SessionStateAnimatorImpl::StartAnimation(int container_mask, |
Daniel Erat
2014/09/08 16:16:03
nit: move "int container_mask" to the next line an
bruthig
2014/09/09 17:32:34
Done.
|
+ SessionStateAnimator::AnimationType type, |
Daniel Erat
2014/09/08 16:16:03
hmm, is the SessionStateAnimator:: needed here eve
bruthig
2014/09/09 17:32:34
Done.
|
+ SessionStateAnimator::AnimationSpeed speed) { |
aura::Window::Windows containers; |
GetContainers(container_mask, &containers); |
for (aura::Window::Windows::const_iterator it = containers.begin(); |
@@ -504,11 +568,11 @@ void SessionStateAnimator::StartAnimation(int container_mask, |
} |
} |
-void SessionStateAnimator::StartAnimationWithCallback( |
+void SessionStateAnimatorImpl::StartAnimationWithCallback( |
int container_mask, |
- AnimationType type, |
- AnimationSpeed speed, |
- base::Callback<void(void)>& callback) { |
+ SessionStateAnimator::AnimationType type, |
+ SessionStateAnimator::AnimationSpeed speed, |
+ base::Closure callback) { |
aura::Window::Windows containers; |
GetContainers(container_mask, &containers); |
for (aura::Window::Windows::const_iterator it = containers.begin(); |
@@ -519,11 +583,16 @@ void SessionStateAnimator::StartAnimationWithCallback( |
} |
} |
-void SessionStateAnimator::StartAnimationWithObserver( |
+SessionStateAnimator::AnimationSequence* |
+ SessionStateAnimatorImpl::BeginAnimationSequence(base::Closure callback) { |
Daniel Erat
2014/09/08 16:16:03
nit: indent four spaces instead of two
bruthig
2014/09/09 17:32:34
Done.
|
+ return new AnimationSequence(this, callback); |
+} |
+ |
+void SessionStateAnimatorImpl::StartAnimationInSequence( |
int container_mask, |
- AnimationType type, |
- AnimationSpeed speed, |
- ui::LayerAnimationObserver* observer) { |
+ SessionStateAnimator::AnimationType type, |
+ SessionStateAnimator::AnimationSpeed speed, |
+ AnimationSequence* observer) { |
aura::Window::Windows containers; |
GetContainers(container_mask, &containers); |
for (aura::Window::Windows::const_iterator it = containers.begin(); |
@@ -532,16 +601,10 @@ void SessionStateAnimator::StartAnimationWithObserver( |
} |
} |
-void SessionStateAnimator::StartGlobalAnimation(AnimationType type, |
- AnimationSpeed speed) { |
- aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
- RunAnimationForWindow(root_window, type, speed, NULL); |
-} |
- |
-void SessionStateAnimator::RunAnimationForWindow( |
+void SessionStateAnimatorImpl::RunAnimationForWindow( |
aura::Window* window, |
- AnimationType type, |
- AnimationSpeed speed, |
+ SessionStateAnimator::AnimationType type, |
+ SessionStateAnimator::AnimationSpeed speed, |
ui::LayerAnimationObserver* observer) { |
base::TimeDelta duration = GetDuration(speed); |