| Index: ash/wm/power_button_controller.cc
|
| diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc
|
| index c057b20acf5b61708ffc9f9afc7e39c996e5060c..b095a4e10a2e9d6e5b9937072c95aa2a2466fd81 100644
|
| --- a/ash/wm/power_button_controller.cc
|
| +++ b/ash/wm/power_button_controller.cc
|
| @@ -96,24 +96,24 @@ bool IsRelatedContainer(aura::Window* window) {
|
| return false;
|
| }
|
|
|
| -// Returns the transform that should be applied to containers for the slow-close
|
| -// animation.
|
| -ui::Transform GetSlowCloseTransform() {
|
| +// Returns the transform, based on |base_transform|, that should be applied
|
| +// to containers for slow-close animation.
|
| +ui::Transform GetSlowCloseTransform(const ui::Transform& base_transform) {
|
| gfx::Size root_size = aura::RootWindow::GetInstance()->bounds().size();
|
| - ui::Transform transform;
|
| - transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio);
|
| + ui::Transform transform(base_transform);
|
| + transform.ConcatScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio);
|
| transform.ConcatTranslate(
|
| floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5),
|
| floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5));
|
| return transform;
|
| }
|
|
|
| -// Returns the transform that should be applied to containers for the fast-close
|
| -// animation.
|
| -ui::Transform GetFastCloseTransform() {
|
| +// Returns the transform, based on |base_transform|, that should be applied
|
| +// to containers for fast-close animation.
|
| +ui::Transform GetFastCloseTransform(const ui::Transform& base_transform) {
|
| gfx::Size root_size = aura::RootWindow::GetInstance()->bounds().size();
|
| - ui::Transform transform;
|
| - transform.SetScale(0.0, 0.0);
|
| + ui::Transform transform(base_transform);
|
| + transform.ConcatScale(0.0, 0.0);
|
| transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5),
|
| floor(0.5 * root_size.height() + 0.5));
|
| return transform;
|
| @@ -127,19 +127,20 @@ void StartSlowCloseAnimationForWindow(aura::Window* window) {
|
| animator->StartAnimation(
|
| new ui::LayerAnimationSequence(
|
| ui::LayerAnimationElement::CreateTransformElement(
|
| - GetSlowCloseTransform(),
|
| + GetSlowCloseTransform(window->layer()->GetTargetTransform()),
|
| base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs))));
|
| }
|
|
|
| // Quickly undoes the effects of the slow-close animation on |window|.
|
| -void StartUndoSlowCloseAnimationForWindow(aura::Window* window) {
|
| +void StartUndoSlowCloseAnimationForWindow(aura::Window* window,
|
| + const ui::Transform& orig_transform) {
|
| ui::LayerAnimator* animator = window->layer()->GetAnimator();
|
| animator->set_preemption_strategy(
|
| ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
|
| animator->StartAnimation(
|
| new ui::LayerAnimationSequence(
|
| ui::LayerAnimationElement::CreateTransformElement(
|
| - ui::Transform(),
|
| + orig_transform,
|
| base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs))));
|
| }
|
|
|
| @@ -152,7 +153,7 @@ void StartFastCloseAnimationForWindow(aura::Window* window) {
|
| animator->StartAnimation(
|
| new ui::LayerAnimationSequence(
|
| ui::LayerAnimationElement::CreateTransformElement(
|
| - GetFastCloseTransform(),
|
| + GetFastCloseTransform(window->layer()->GetTargetTransform()),
|
| base::TimeDelta::FromMilliseconds(kFastCloseAnimMs))));
|
| animator->StartAnimation(
|
| new ui::LayerAnimationSequence(
|
| @@ -178,87 +179,18 @@ void HideWindow(aura::Window* window) {
|
|
|
| // Restores |window| to its original position and scale and full opacity
|
| // instantaneously.
|
| -void RestoreWindow(aura::Window* window) {
|
| - window->layer()->SetTransform(ui::Transform());
|
| +void RestoreWindow(aura::Window* window,
|
| + const ui::Transform& orig_transform) {
|
| + window->layer()->SetTransform(orig_transform);
|
| window->layer()->SetOpacity(1.0);
|
| }
|
|
|
| -// Fills |containers| with the containers described by |group|.
|
| -void GetContainers(PowerButtonController::ContainerGroup group,
|
| - aura::Window::Windows* containers) {
|
| - containers->clear();
|
| -
|
| - aura::Window* root = aura::RootWindow::GetInstance();
|
| - for (aura::Window::Windows::const_iterator it = root->children().begin();
|
| - it != root->children().end(); ++it) {
|
| - aura::Window* window = *it;
|
| -
|
| - bool matched = true;
|
| - if (group != PowerButtonController::ALL_CONTAINERS) {
|
| - bool is_screen_locker = IsScreenLockerContainer(window);
|
| - bool is_related = IsRelatedContainer(window);
|
| -
|
| - switch (group) {
|
| - case PowerButtonController::SCREEN_LOCKER_CONTAINERS:
|
| - matched = is_screen_locker;
|
| - break;
|
| - case PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS:
|
| - matched = is_screen_locker || is_related;
|
| - break;
|
| - case PowerButtonController::
|
| - ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS:
|
| - matched = !is_screen_locker && !is_related;
|
| - break;
|
| - default:
|
| - NOTREACHED() << "Unhandled container group " << group;
|
| - }
|
| - }
|
| -
|
| - if (matched)
|
| - containers->push_back(window);
|
| - }
|
| -}
|
| -
|
| -// Apply animation |type| to all containers described by |group|.
|
| -void StartAnimation(PowerButtonController::ContainerGroup group,
|
| - PowerButtonController::AnimationType type) {
|
| - aura::Window::Windows containers;
|
| - GetContainers(group, &containers);
|
| -
|
| - for (aura::Window::Windows::const_iterator it = containers.begin();
|
| - it != containers.end(); ++it) {
|
| - aura::Window* window = *it;
|
| - switch (type) {
|
| - case PowerButtonController::ANIMATION_SLOW_CLOSE:
|
| - StartSlowCloseAnimationForWindow(window);
|
| - break;
|
| - case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE:
|
| - StartUndoSlowCloseAnimationForWindow(window);
|
| - break;
|
| - case PowerButtonController::ANIMATION_FAST_CLOSE:
|
| - StartFastCloseAnimationForWindow(window);
|
| - break;
|
| - case PowerButtonController::ANIMATION_FADE_IN:
|
| - FadeInWindow(window);
|
| - break;
|
| - case PowerButtonController::ANIMATION_HIDE:
|
| - HideWindow(window);
|
| - break;
|
| - case PowerButtonController::ANIMATION_RESTORE:
|
| - RestoreWindow(window);
|
| - break;
|
| - default:
|
| - NOTREACHED() << "Unhandled animation type " << type;
|
| - }
|
| - }
|
| -}
|
| -
|
| } // namespace
|
|
|
| bool PowerButtonController::TestApi::ContainerGroupIsAnimated(
|
| ContainerGroup group, AnimationType type) const {
|
| aura::Window::Windows containers;
|
| - GetContainers(group, &containers);
|
| + controller_->GetContainers(group, &containers);
|
| for (aura::Window::Windows::const_iterator it = containers.begin();
|
| it != containers.end(); ++it) {
|
| aura::Window* window = *it;
|
| @@ -266,15 +198,19 @@ bool PowerButtonController::TestApi::ContainerGroupIsAnimated(
|
|
|
| switch (type) {
|
| case PowerButtonController::ANIMATION_SLOW_CLOSE:
|
| - if (layer->GetTargetTransform() != GetSlowCloseTransform())
|
| + if (layer->GetTargetTransform() !=
|
| + GetSlowCloseTransform(
|
| + controller_->RetrieveOriginalTransform(window)))
|
| return false;
|
| break;
|
| case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE:
|
| - if (layer->GetTargetTransform() != ui::Transform())
|
| - return false;
|
| + if (layer->GetTargetTransform() !=
|
| + controller_->RetrieveOriginalTransform(window))
|
| + return false;
|
| break;
|
| case PowerButtonController::ANIMATION_FAST_CLOSE:
|
| - if (layer->GetTargetTransform() != GetFastCloseTransform() ||
|
| + if (layer->GetTargetTransform() !=
|
| + GetFastCloseTransform(layer->GetTargetTransform()) ||
|
| layer->GetTargetOpacity() > 0.0001)
|
| return false;
|
| break;
|
| @@ -287,7 +223,9 @@ bool PowerButtonController::TestApi::ContainerGroupIsAnimated(
|
| return false;
|
| break;
|
| case PowerButtonController::ANIMATION_RESTORE:
|
| - if (layer->opacity() < 0.9999 || layer->transform() != ui::Transform())
|
| + if (layer->opacity() < 0.9999 ||
|
| + layer->transform() !=
|
| + controller_->RetrieveOriginalTransform(window))
|
| return false;
|
| break;
|
| default:
|
| @@ -450,6 +388,41 @@ void PowerButtonController::OnRootWindowResized(const gfx::Size& new_size) {
|
| background_layer_->SetBounds(gfx::Rect(new_size));
|
| }
|
|
|
| +// Fills |containers| with the containers described by |group|.
|
| +void PowerButtonController::GetContainers(ContainerGroup group,
|
| + aura::Window::Windows* containers) {
|
| + containers->clear();
|
| +
|
| + aura::Window* root = aura::RootWindow::GetInstance();
|
| + for (aura::Window::Windows::const_iterator it = root->children().begin();
|
| + it != root->children().end(); ++it) {
|
| + aura::Window* window = *it;
|
| +
|
| + bool matched = true;
|
| + if (group != ALL_CONTAINERS) {
|
| + bool is_screen_locker = IsScreenLockerContainer(window);
|
| + bool is_related = IsRelatedContainer(window);
|
| +
|
| + switch (group) {
|
| + case SCREEN_LOCKER_CONTAINERS:
|
| + matched = is_screen_locker;
|
| + break;
|
| + case SCREEN_LOCKER_AND_RELATED_CONTAINERS:
|
| + matched = is_screen_locker || is_related;
|
| + break;
|
| + case ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS:
|
| + matched = !is_screen_locker && !is_related;
|
| + break;
|
| + default:
|
| + NOTREACHED() << "Unhandled container group " << group;
|
| + }
|
| + }
|
| +
|
| + if (matched)
|
| + containers->push_back(window);
|
| + }
|
| +}
|
| +
|
| void PowerButtonController::OnLockTimeout() {
|
| delegate_->RequestLockScreen();
|
| lock_fail_timer_.Start(
|
| @@ -528,4 +501,52 @@ void PowerButtonController::HideBackgroundLayer() {
|
| background_layer_.reset();
|
| }
|
|
|
| +// Apply animation |type| to all containers described by |group|.
|
| +void PowerButtonController::StartAnimation(ContainerGroup group,
|
| + AnimationType type) {
|
| + aura::Window::Windows containers;
|
| + GetContainers(group, &containers);
|
| + for (aura::Window::Windows::const_iterator it = containers.begin();
|
| + it != containers.end(); ++it) {
|
| + aura::Window* window = *it;
|
| +
|
| + // Store this away so we can restore.
|
| + if (type != ANIMATION_RESTORE && type != ANIMATION_UNDO_SLOW_CLOSE)
|
| + container_transforms_[window] = window->layer()->GetTargetTransform();
|
| +
|
| + switch (type) {
|
| + case ANIMATION_SLOW_CLOSE:
|
| + StartSlowCloseAnimationForWindow(window);
|
| + break;
|
| + case ANIMATION_UNDO_SLOW_CLOSE:
|
| + StartUndoSlowCloseAnimationForWindow(
|
| + window,
|
| + RetrieveOriginalTransform(window));
|
| + break;
|
| + case ANIMATION_FAST_CLOSE:
|
| + StartFastCloseAnimationForWindow(window);
|
| + break;
|
| + case ANIMATION_FADE_IN:
|
| + FadeInWindow(window);
|
| + break;
|
| + case ANIMATION_HIDE:
|
| + HideWindow(window);
|
| + break;
|
| + case ANIMATION_RESTORE:
|
| + RestoreWindow(window, RetrieveOriginalTransform(window));
|
| + break;
|
| + default:
|
| + NOTREACHED() << "Unhandled animation type " << type;
|
| + }
|
| + }
|
| +}
|
| +
|
| +ui::Transform PowerButtonController::RetrieveOriginalTransform(
|
| + aura::Window* window) {
|
| + WindowTransformsMap::const_iterator it = container_transforms_.find(window);
|
| + if (it != container_transforms_.end())
|
| + return it->second;
|
| + return ui::Transform();
|
| +}
|
| +
|
| } // namespace ash
|
|
|