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

Unified Diff: ash/wm/session_state_animator_impl.cc

Issue 326813004: Added quick lock mechanism while in Touchview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added ASH_EXPORT to SessionStateAnimator Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/wm/session_state_animator_impl.h ('k') | chrome/browser/chromeos/power/power_button_observer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 82%
copy from ash/wm/session_state_animator.cc
copy to ash/wm/session_state_animator_impl.cc
index 9900275af8a0bf2032bf10661ecf48fdc58c6add..4fb0d7b4f9d3bc4dea8966dc1154dbc670deb122 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"
@@ -27,6 +29,13 @@ const float kPartialFadeRatio = 0.3f;
// Minimum size. Not zero as it causes numeric issues.
const float kMinimumScale = 1e-4f;
+// Returns the primary root window's container.
+aura::Window* GetBackground() {
+ aura::Window* root_window = Shell::GetPrimaryRootWindow();
+ return Shell::GetContainer(root_window,
+ kShellWindowId_DesktopBackgroundContainer);
+}
+
// Returns the transform that should be applied to containers for the slow-close
// animation.
gfx::Transform GetSlowCloseTransform() {
@@ -36,7 +45,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 +53,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 +292,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 +317,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 +395,75 @@ 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(callback),
+ animator_(animator),
+ sequences_attached_(0),
+ sequences_completed_(0) {
+ }
+
+ // SessionStateAnimator::AnimationSequence:
+ virtual void StartAnimation(
+ int container_mask,
+ SessionStateAnimator::AnimationType type,
+ SessionStateAnimator::AnimationSpeed speed) OVERRIDE {
+ animator_->StartAnimationInSequence(container_mask, type, speed, this);
+ }
+
+ private:
+ virtual ~AnimationSequence() {}
+
+ // ui::LayerAnimationObserver:
+ virtual void OnLayerAnimationEnded(
+ ui::LayerAnimationSequence* sequence) OVERRIDE {
+ sequences_completed_++;
+ if (sequences_completed_ == sequences_attached_)
+ OnAnimationCompleted();
+ }
+
+ virtual void OnLayerAnimationAborted(
+ ui::LayerAnimationSequence* sequence) OVERRIDE {
+ sequences_completed_++;
+ if (sequences_completed_ == sequences_attached_)
+ OnAnimationAborted();
+ }
+
+ virtual void OnLayerAnimationScheduled(
+ ui::LayerAnimationSequence* sequence) OVERRIDE {}
+
+ virtual void OnAttachedToSequence(
+ ui::LayerAnimationSequence* sequence) OVERRIDE {
+ LayerAnimationObserver::OnAttachedToSequence(sequence);
+ sequences_attached_++;
+ }
+
+ SessionStateAnimatorImpl* animator_; // not owned
+
+ // 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);
+};
+
+bool SessionStateAnimatorImpl::TestApi::ContainersAreAnimated(
int container_mask, AnimationType type) const {
aura::Window::Windows containers;
animator_->GetContainers(container_mask, &containers);
@@ -399,63 +477,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() {
-}
-
-SessionStateAnimator::~SessionStateAnimator() {
+SessionStateAnimatorImpl::SessionStateAnimatorImpl() {
}
-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 +537,9 @@ void SessionStateAnimator::GetContainers(int container_mask,
}
}
-void SessionStateAnimator::StartAnimation(int container_mask,
- AnimationType type,
- AnimationSpeed speed) {
+void SessionStateAnimatorImpl::StartAnimation(int container_mask,
+ AnimationType type,
+ AnimationSpeed speed) {
aura::Window::Windows containers;
GetContainers(container_mask, &containers);
for (aura::Window::Windows::const_iterator it = containers.begin();
@@ -504,11 +548,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) {
+ base::Closure callback) {
aura::Window::Windows containers;
GetContainers(container_mask, &containers);
for (aura::Window::Windows::const_iterator it = containers.begin();
@@ -519,11 +563,34 @@ void SessionStateAnimator::StartAnimationWithCallback(
}
}
-void SessionStateAnimator::StartAnimationWithObserver(
+SessionStateAnimator::AnimationSequence*
+ SessionStateAnimatorImpl::BeginAnimationSequence(base::Closure callback) {
+ return new AnimationSequence(this, callback);
+}
+
+bool SessionStateAnimatorImpl::IsBackgroundHidden() const {
+ return !GetBackground()->IsVisible();
+}
+
+void SessionStateAnimatorImpl::ShowBackground() {
+ ui::ScopedLayerAnimationSettings settings(
+ GetBackground()->layer()->GetAnimator());
+ settings.SetTransitionDuration(base::TimeDelta());
+ GetBackground()->Show();
+}
+
+void SessionStateAnimatorImpl::HideBackground() {
+ ui::ScopedLayerAnimationSettings settings(
+ GetBackground()->layer()->GetAnimator());
+ settings.SetTransitionDuration(base::TimeDelta());
+ GetBackground()->Hide();
+}
+
+void SessionStateAnimatorImpl::StartAnimationInSequence(
int container_mask,
AnimationType type,
AnimationSpeed speed,
- ui::LayerAnimationObserver* observer) {
+ AnimationSequence* observer) {
aura::Window::Windows containers;
GetContainers(container_mask, &containers);
for (aura::Window::Windows::const_iterator it = containers.begin();
@@ -532,13 +599,7 @@ 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,
« no previous file with comments | « ash/wm/session_state_animator_impl.h ('k') | chrome/browser/chromeos/power/power_button_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698