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

Unified Diff: ash/wm/power_button_controller.cc

Issue 9348089: Make power button controller restore to original transformation on the layer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: udpate. Created 8 years, 10 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
Index: ash/wm/power_button_controller.cc
diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc
index f41d9c4cea8b4d39b627153b314dcd82bac83678..8d0739062a0d8b38e600632eb02af35aa9ca80e1 100644
--- a/ash/wm/power_button_controller.cc
+++ b/ash/wm/power_button_controller.cc
@@ -95,24 +95,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 that should be applied to containers in addition to the
+// base transformation containers for slow-close animation.
Daniel Erat 2012/02/15 05:50:03 this comment doesn't make sense to me. something
alicet1 2012/02/15 20:48:53 much better.
+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 that should be applied to containers in addition to the
Daniel Erat 2012/02/15 05:50:03 ditto here
alicet1 2012/02/15 20:48:53 Done.
+// base transformation 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;
@@ -126,19 +126,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& base_transform) {
Daniel Erat 2012/02/15 05:50:03 |base_transform| doesn't seem right here. |orig_t
alicet1 2012/02/15 20:48:53 Done.
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(),
+ base_transform,
base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs))));
}
@@ -151,7 +152,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(
@@ -177,8 +178,8 @@ 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& transform) {
Daniel Erat 2012/02/15 05:50:03 s/transform/orig_transform/
alicet1 2012/02/15 20:48:53 Done.
+ window->layer()->SetTransform(transform);
window->layer()->SetOpacity(1.0);
}
@@ -218,21 +219,48 @@ void GetContainers(PowerButtonController::ContainerGroup group,
}
}
+void StoreOriginalTransform(PowerButtonController::AnimationType type,
+ aura::Window* window,
+ ash::WindowTransformsMap* window_transforms) {
Daniel Erat 2012/02/15 05:50:03 you don't need "ash::" here; this is already in th
alicet1 2012/02/15 20:48:53 removed.
+ if (window_transforms != NULL &&
+ type != PowerButtonController::ANIMATION_RESTORE &&
Daniel Erat 2012/02/15 05:50:03 hoist these checks out to StartAnimation(), so you
alicet1 2012/02/15 20:48:53 removed.
+ type != PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE) {
+ (*window_transforms)[window] = window->layer()->GetTargetTransform();
+ }
+}
+
+ui::Transform RetrieveOriginalTransform(
+ aura::Window* window,
+ ash::WindowTransformsMap* window_transforms) {
Daniel Erat 2012/02/15 05:50:03 make this method take a const ash::WindowTransform
alicet1 2012/02/15 20:48:53 ah yes.
+ if (window_transforms != NULL) {
+ WindowTransformsConstIter it = window_transforms->find(window);
+ if (it != window_transforms->end())
+ return it->second;
+ }
+ return ui::Transform();
+}
+
// Apply animation |type| to all containers described by |group|.
void StartAnimation(PowerButtonController::ContainerGroup group,
Daniel Erat 2012/02/15 06:07:51 actually, a better approach would probably be to m
alicet1 2012/02/15 20:48:53 done. left RetrieveOriginalTransform in default na
- PowerButtonController::AnimationType type) {
+ PowerButtonController::AnimationType type,
+ ash::WindowTransformsMap* window_transforms) {
aura::Window::Windows containers;
GetContainers(group, &containers);
-
+ ui::Transform transform;
Daniel Erat 2012/02/15 05:50:03 this doesn't look like it gets used anywhere... ?
alicet1 2012/02/15 20:48:53 removed.
for (aura::Window::Windows::const_iterator it = containers.begin();
it != containers.end(); ++it) {
aura::Window* window = *it;
+ // Store this away so we can restore.
+ StoreOriginalTransform(type, window, window_transforms);
+
switch (type) {
case PowerButtonController::ANIMATION_SLOW_CLOSE:
StartSlowCloseAnimationForWindow(window);
break;
case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE:
- StartUndoSlowCloseAnimationForWindow(window);
+ StartUndoSlowCloseAnimationForWindow(
+ window,
+ RetrieveOriginalTransform(window, window_transforms));
break;
case PowerButtonController::ANIMATION_FAST_CLOSE:
StartFastCloseAnimationForWindow(window);
@@ -244,7 +272,9 @@ void StartAnimation(PowerButtonController::ContainerGroup group,
HideWindow(window);
break;
case PowerButtonController::ANIMATION_RESTORE:
- RestoreWindow(window);
+ RestoreWindow(
+ window,
+ RetrieveOriginalTransform(window, window_transforms));
break;
default:
NOTREACHED() << "Unhandled animation type " << type;
@@ -265,15 +295,21 @@ bool PowerButtonController::TestApi::ContainerGroupIsAnimated(
switch (type) {
case PowerButtonController::ANIMATION_SLOW_CLOSE:
- if (layer->GetTargetTransform() != GetSlowCloseTransform())
+ if (layer->GetTargetTransform() !=
+ GetSlowCloseTransform(
+ RetrieveOriginalTransform(
+ window, &controller_->window_transforms_)))
return false;
break;
case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE:
- if (layer->GetTargetTransform() != ui::Transform())
- return false;
+ if (layer->GetTargetTransform() !=
+ RetrieveOriginalTransform(
+ window, &controller_->window_transforms_))
+ return false;
break;
case PowerButtonController::ANIMATION_FAST_CLOSE:
- if (layer->GetTargetTransform() != GetFastCloseTransform() ||
+ if (layer->GetTargetTransform() != GetFastCloseTransform(
Daniel Erat 2012/02/15 05:50:03 improve the indenting here: if (layer->Get... !
alicet1 2012/02/15 20:48:53 Done.
+ layer->GetTargetTransform()) ||
layer->GetTargetOpacity() > 0.0001)
return false;
break;
@@ -286,7 +322,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() != RetrieveOriginalTransform(
Daniel Erat 2012/02/15 05:50:03 ditto
alicet1 2012/02/15 20:48:53 Done.
+ window, &controller_->window_transforms_))
return false;
break;
default:
@@ -302,6 +340,12 @@ bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const {
controller_->background_layer_->visible();
}
+void PowerButtonController::TestApi::GetContainerWindows(
+ ContainerGroup group,
+ aura::Window::Windows* containers) {
+ GetContainers(group, containers);
+}
+
PowerButtonController::PowerButtonController()
: logged_in_as_non_guest_(false),
locked_(false),
@@ -326,7 +370,7 @@ void PowerButtonController::OnLockStateChange(bool locked) {
locked_ = locked;
if (locked) {
- StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN);
+ StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN, NULL);
lock_timer_.Stop();
lock_fail_timer_.Stop();
@@ -339,7 +383,7 @@ void PowerButtonController::OnLockStateChange(bool locked) {
}
} else {
StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
- ANIMATION_RESTORE);
+ ANIMATION_RESTORE, &window_transforms_);
Daniel Erat 2012/02/15 05:50:03 nit: one param per line unless they all fit on a s
alicet1 2012/02/15 20:48:53 removed. altho, style guide said when calling a f
HideBackgroundLayer();
}
}
@@ -354,10 +398,10 @@ void PowerButtonController::OnStartingLock() {
ShowBackgroundLayer();
StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
- ANIMATION_FAST_CLOSE);
+ ANIMATION_FAST_CLOSE, &window_transforms_);
// Hide the screen locker containers so we can make them fade in later.
- StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE);
+ StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE, NULL);
Daniel Erat 2012/02/15 05:50:03 it'd be simpler to always pass &window_transforms_
alicet1 2012/02/15 20:48:53 removed. since startanimation is now part of the c
}
void PowerButtonController::OnPowerButtonEvent(
@@ -375,7 +419,7 @@ void PowerButtonController::OnPowerButtonEvent(
ShowBackgroundLayer();
if (logged_in_as_non_guest_ && !locked_) {
StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
- ANIMATION_SLOW_CLOSE);
+ ANIMATION_SLOW_CLOSE, &window_transforms_);
OnLockTimeout();
} else {
OnShutdownTimeout();
@@ -395,7 +439,7 @@ void PowerButtonController::OnPowerButtonEvent(
if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning())
StartAnimation(
locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS,
- ANIMATION_UNDO_SLOW_CLOSE);
+ ANIMATION_UNDO_SLOW_CLOSE, &window_transforms_);
// Drop the background layer after the undo animation finishes.
if (lock_timer_.IsRunning() ||
@@ -433,7 +477,8 @@ void PowerButtonController::OnLockButtonEvent(
} else {
if (lock_timer_.IsRunning()) {
StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
- ANIMATION_UNDO_SLOW_CLOSE);
+ ANIMATION_UNDO_SLOW_CLOSE,
+ &window_transforms_);
hide_background_layer_timer_.Stop();
hide_background_layer_timer_.Start(
FROM_HERE,
@@ -459,9 +504,8 @@ void PowerButtonController::OnLockTimeout() {
void PowerButtonController::OnLockFailTimeout() {
DCHECK(!locked_);
- LOG(ERROR) << "Screen lock request timed out";
StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
- ANIMATION_RESTORE);
+ ANIMATION_RESTORE, &window_transforms_);
HideBackgroundLayer();
}
@@ -474,7 +518,7 @@ void PowerButtonController::OnShutdownTimeout() {
DCHECK(!shutting_down_);
shutting_down_ = true;
aura::RootWindow::GetInstance()->ShowCursor(false);
- StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE);
+ StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE, &window_transforms_);
real_shutdown_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kFastCloseAnimMs),
@@ -489,7 +533,7 @@ void PowerButtonController::OnRealShutdownTimeout() {
void PowerButtonController::StartLockTimer() {
ShowBackgroundLayer();
StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
- ANIMATION_SLOW_CLOSE);
+ ANIMATION_SLOW_CLOSE, &window_transforms_);
lock_timer_.Stop();
lock_timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs),
@@ -498,7 +542,7 @@ void PowerButtonController::StartLockTimer() {
void PowerButtonController::StartShutdownTimer() {
ShowBackgroundLayer();
- StartAnimation(ALL_CONTAINERS, ANIMATION_SLOW_CLOSE);
+ StartAnimation(ALL_CONTAINERS, ANIMATION_SLOW_CLOSE, &window_transforms_);
shutdown_timer_.Stop();
shutdown_timer_.Start(
FROM_HERE,

Powered by Google App Engine
This is Rietveld 408576698