Chromium Code Reviews| 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 "ash/wm/power_button_controller.h" | 5 #include "ash/wm/power_button_controller.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 | 88 |
| 89 // Is |window| a container that holds other windows that should be shown while | 89 // Is |window| a container that holds other windows that should be shown while |
| 90 // the screen is locked? | 90 // the screen is locked? |
| 91 bool IsRelatedContainer(aura::Window* window) { | 91 bool IsRelatedContainer(aura::Window* window) { |
| 92 for (size_t i = 0; i < arraysize(kRelatedContainerIds); ++i) | 92 for (size_t i = 0; i < arraysize(kRelatedContainerIds); ++i) |
| 93 if (window->id() == kRelatedContainerIds[i]) | 93 if (window->id() == kRelatedContainerIds[i]) |
| 94 return true; | 94 return true; |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Returns the transform that should be applied to containers for the slow-close | 98 // Returns the transform that should be applied to containers in addition to the |
| 99 // animation. | 99 // 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.
| |
| 100 ui::Transform GetSlowCloseTransform() { | 100 ui::Transform GetSlowCloseTransform(const ui::Transform& base_transform) { |
| 101 gfx::Size root_size = aura::RootWindow::GetInstance()->bounds().size(); | 101 gfx::Size root_size = aura::RootWindow::GetInstance()->bounds().size(); |
| 102 ui::Transform transform; | 102 ui::Transform transform(base_transform); |
| 103 transform.SetScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); | 103 transform.ConcatScale(kSlowCloseSizeRatio, kSlowCloseSizeRatio); |
| 104 transform.ConcatTranslate( | 104 transform.ConcatTranslate( |
| 105 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), | 105 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.width() + 0.5), |
| 106 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); | 106 floor(0.5 * (1.0 - kSlowCloseSizeRatio) * root_size.height() + 0.5)); |
| 107 return transform; | 107 return transform; |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Returns the transform that should be applied to containers for the fast-close | 110 // 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.
| |
| 111 // animation. | 111 // base transformation for fast-close animation. |
| 112 ui::Transform GetFastCloseTransform() { | 112 ui::Transform GetFastCloseTransform(const ui::Transform& base_transform) { |
| 113 gfx::Size root_size = aura::RootWindow::GetInstance()->bounds().size(); | 113 gfx::Size root_size = aura::RootWindow::GetInstance()->bounds().size(); |
| 114 ui::Transform transform; | 114 ui::Transform transform(base_transform); |
| 115 transform.SetScale(0.0, 0.0); | 115 transform.ConcatScale(0.0, 0.0); |
| 116 transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5), | 116 transform.ConcatTranslate(floor(0.5 * root_size.width() + 0.5), |
| 117 floor(0.5 * root_size.height() + 0.5)); | 117 floor(0.5 * root_size.height() + 0.5)); |
| 118 return transform; | 118 return transform; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Slowly shrinks |window| to a slightly-smaller size. | 121 // Slowly shrinks |window| to a slightly-smaller size. |
| 122 void StartSlowCloseAnimationForWindow(aura::Window* window) { | 122 void StartSlowCloseAnimationForWindow(aura::Window* window) { |
| 123 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 123 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| 124 animator->set_preemption_strategy( | 124 animator->set_preemption_strategy( |
| 125 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 125 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 126 animator->StartAnimation( | 126 animator->StartAnimation( |
| 127 new ui::LayerAnimationSequence( | 127 new ui::LayerAnimationSequence( |
| 128 ui::LayerAnimationElement::CreateTransformElement( | 128 ui::LayerAnimationElement::CreateTransformElement( |
| 129 GetSlowCloseTransform(), | 129 GetSlowCloseTransform(window->layer()->GetTargetTransform()), |
| 130 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs)))); | 130 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs)))); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Quickly undoes the effects of the slow-close animation on |window|. | 133 // Quickly undoes the effects of the slow-close animation on |window|. |
| 134 void StartUndoSlowCloseAnimationForWindow(aura::Window* window) { | 134 void StartUndoSlowCloseAnimationForWindow(aura::Window* window, |
| 135 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.
| |
| 135 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 136 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| 136 animator->set_preemption_strategy( | 137 animator->set_preemption_strategy( |
| 137 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 138 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 138 animator->StartAnimation( | 139 animator->StartAnimation( |
| 139 new ui::LayerAnimationSequence( | 140 new ui::LayerAnimationSequence( |
| 140 ui::LayerAnimationElement::CreateTransformElement( | 141 ui::LayerAnimationElement::CreateTransformElement( |
| 141 ui::Transform(), | 142 base_transform, |
| 142 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs)))); | 143 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs)))); |
| 143 } | 144 } |
| 144 | 145 |
| 145 // Quickly shrinks |window| down to a point in the center of the screen and | 146 // Quickly shrinks |window| down to a point in the center of the screen and |
| 146 // fades it out to 0 opacity. | 147 // fades it out to 0 opacity. |
| 147 void StartFastCloseAnimationForWindow(aura::Window* window) { | 148 void StartFastCloseAnimationForWindow(aura::Window* window) { |
| 148 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 149 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| 149 animator->set_preemption_strategy( | 150 animator->set_preemption_strategy( |
| 150 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 151 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 151 animator->StartAnimation( | 152 animator->StartAnimation( |
| 152 new ui::LayerAnimationSequence( | 153 new ui::LayerAnimationSequence( |
| 153 ui::LayerAnimationElement::CreateTransformElement( | 154 ui::LayerAnimationElement::CreateTransformElement( |
| 154 GetFastCloseTransform(), | 155 GetFastCloseTransform(window->layer()->GetTargetTransform()), |
| 155 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); | 156 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); |
| 156 animator->StartAnimation( | 157 animator->StartAnimation( |
| 157 new ui::LayerAnimationSequence( | 158 new ui::LayerAnimationSequence( |
| 158 ui::LayerAnimationElement::CreateOpacityElement( | 159 ui::LayerAnimationElement::CreateOpacityElement( |
| 159 0.0, base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); | 160 0.0, base::TimeDelta::FromMilliseconds(kFastCloseAnimMs)))); |
| 160 } | 161 } |
| 161 | 162 |
| 162 // Fades |window| in to full opacity. | 163 // Fades |window| in to full opacity. |
| 163 void FadeInWindow(aura::Window* window) { | 164 void FadeInWindow(aura::Window* window) { |
| 164 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 165 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| 165 animator->set_preemption_strategy( | 166 animator->set_preemption_strategy( |
| 166 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 167 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 167 animator->StartAnimation( | 168 animator->StartAnimation( |
| 168 new ui::LayerAnimationSequence( | 169 new ui::LayerAnimationSequence( |
| 169 ui::LayerAnimationElement::CreateOpacityElement( | 170 ui::LayerAnimationElement::CreateOpacityElement( |
| 170 1.0, base::TimeDelta::FromMilliseconds(kLockFadeInAnimMs)))); | 171 1.0, base::TimeDelta::FromMilliseconds(kLockFadeInAnimMs)))); |
| 171 } | 172 } |
| 172 | 173 |
| 173 // Makes |window| fully transparent instantaneously. | 174 // Makes |window| fully transparent instantaneously. |
| 174 void HideWindow(aura::Window* window) { | 175 void HideWindow(aura::Window* window) { |
| 175 window->layer()->SetOpacity(0.0); | 176 window->layer()->SetOpacity(0.0); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Restores |window| to its original position and scale and full opacity | 179 // Restores |window| to its original position and scale and full opacity |
| 179 // instantaneously. | 180 // instantaneously. |
| 180 void RestoreWindow(aura::Window* window) { | 181 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.
| |
| 181 window->layer()->SetTransform(ui::Transform()); | 182 window->layer()->SetTransform(transform); |
| 182 window->layer()->SetOpacity(1.0); | 183 window->layer()->SetOpacity(1.0); |
| 183 } | 184 } |
| 184 | 185 |
| 185 // Fills |containers| with the containers described by |group|. | 186 // Fills |containers| with the containers described by |group|. |
| 186 void GetContainers(PowerButtonController::ContainerGroup group, | 187 void GetContainers(PowerButtonController::ContainerGroup group, |
| 187 aura::Window::Windows* containers) { | 188 aura::Window::Windows* containers) { |
| 188 containers->clear(); | 189 containers->clear(); |
| 189 | 190 |
| 190 aura::Window* root = aura::RootWindow::GetInstance(); | 191 aura::Window* root = aura::RootWindow::GetInstance(); |
| 191 for (aura::Window::Windows::const_iterator it = root->children().begin(); | 192 for (aura::Window::Windows::const_iterator it = root->children().begin(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 211 default: | 212 default: |
| 212 NOTREACHED() << "Unhandled container group " << group; | 213 NOTREACHED() << "Unhandled container group " << group; |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 if (matched) | 217 if (matched) |
| 217 containers->push_back(window); | 218 containers->push_back(window); |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 | 221 |
| 222 void StoreOriginalTransform(PowerButtonController::AnimationType type, | |
| 223 aura::Window* window, | |
| 224 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.
| |
| 225 if (window_transforms != NULL && | |
| 226 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.
| |
| 227 type != PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE) { | |
| 228 (*window_transforms)[window] = window->layer()->GetTargetTransform(); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 ui::Transform RetrieveOriginalTransform( | |
| 233 aura::Window* window, | |
| 234 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.
| |
| 235 if (window_transforms != NULL) { | |
| 236 WindowTransformsConstIter it = window_transforms->find(window); | |
| 237 if (it != window_transforms->end()) | |
| 238 return it->second; | |
| 239 } | |
| 240 return ui::Transform(); | |
| 241 } | |
| 242 | |
| 221 // Apply animation |type| to all containers described by |group|. | 243 // Apply animation |type| to all containers described by |group|. |
| 222 void StartAnimation(PowerButtonController::ContainerGroup group, | 244 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
| |
| 223 PowerButtonController::AnimationType type) { | 245 PowerButtonController::AnimationType type, |
| 246 ash::WindowTransformsMap* window_transforms) { | |
| 224 aura::Window::Windows containers; | 247 aura::Window::Windows containers; |
| 225 GetContainers(group, &containers); | 248 GetContainers(group, &containers); |
| 226 | 249 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.
| |
| 227 for (aura::Window::Windows::const_iterator it = containers.begin(); | 250 for (aura::Window::Windows::const_iterator it = containers.begin(); |
| 228 it != containers.end(); ++it) { | 251 it != containers.end(); ++it) { |
| 229 aura::Window* window = *it; | 252 aura::Window* window = *it; |
| 253 // Store this away so we can restore. | |
| 254 StoreOriginalTransform(type, window, window_transforms); | |
| 255 | |
| 230 switch (type) { | 256 switch (type) { |
| 231 case PowerButtonController::ANIMATION_SLOW_CLOSE: | 257 case PowerButtonController::ANIMATION_SLOW_CLOSE: |
| 232 StartSlowCloseAnimationForWindow(window); | 258 StartSlowCloseAnimationForWindow(window); |
| 233 break; | 259 break; |
| 234 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: | 260 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: |
| 235 StartUndoSlowCloseAnimationForWindow(window); | 261 StartUndoSlowCloseAnimationForWindow( |
| 262 window, | |
| 263 RetrieveOriginalTransform(window, window_transforms)); | |
| 236 break; | 264 break; |
| 237 case PowerButtonController::ANIMATION_FAST_CLOSE: | 265 case PowerButtonController::ANIMATION_FAST_CLOSE: |
| 238 StartFastCloseAnimationForWindow(window); | 266 StartFastCloseAnimationForWindow(window); |
| 239 break; | 267 break; |
| 240 case PowerButtonController::ANIMATION_FADE_IN: | 268 case PowerButtonController::ANIMATION_FADE_IN: |
| 241 FadeInWindow(window); | 269 FadeInWindow(window); |
| 242 break; | 270 break; |
| 243 case PowerButtonController::ANIMATION_HIDE: | 271 case PowerButtonController::ANIMATION_HIDE: |
| 244 HideWindow(window); | 272 HideWindow(window); |
| 245 break; | 273 break; |
| 246 case PowerButtonController::ANIMATION_RESTORE: | 274 case PowerButtonController::ANIMATION_RESTORE: |
| 247 RestoreWindow(window); | 275 RestoreWindow( |
| 276 window, | |
| 277 RetrieveOriginalTransform(window, window_transforms)); | |
| 248 break; | 278 break; |
| 249 default: | 279 default: |
| 250 NOTREACHED() << "Unhandled animation type " << type; | 280 NOTREACHED() << "Unhandled animation type " << type; |
| 251 } | 281 } |
| 252 } | 282 } |
| 253 } | 283 } |
| 254 | 284 |
| 255 } // namespace | 285 } // namespace |
| 256 | 286 |
| 257 bool PowerButtonController::TestApi::ContainerGroupIsAnimated( | 287 bool PowerButtonController::TestApi::ContainerGroupIsAnimated( |
| 258 ContainerGroup group, AnimationType type) const { | 288 ContainerGroup group, AnimationType type) const { |
| 259 aura::Window::Windows containers; | 289 aura::Window::Windows containers; |
| 260 GetContainers(group, &containers); | 290 GetContainers(group, &containers); |
| 261 for (aura::Window::Windows::const_iterator it = containers.begin(); | 291 for (aura::Window::Windows::const_iterator it = containers.begin(); |
| 262 it != containers.end(); ++it) { | 292 it != containers.end(); ++it) { |
| 263 aura::Window* window = *it; | 293 aura::Window* window = *it; |
| 264 ui::Layer* layer = window->layer(); | 294 ui::Layer* layer = window->layer(); |
| 265 | 295 |
| 266 switch (type) { | 296 switch (type) { |
| 267 case PowerButtonController::ANIMATION_SLOW_CLOSE: | 297 case PowerButtonController::ANIMATION_SLOW_CLOSE: |
| 268 if (layer->GetTargetTransform() != GetSlowCloseTransform()) | 298 if (layer->GetTargetTransform() != |
| 299 GetSlowCloseTransform( | |
| 300 RetrieveOriginalTransform( | |
| 301 window, &controller_->window_transforms_))) | |
| 269 return false; | 302 return false; |
| 270 break; | 303 break; |
| 271 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: | 304 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: |
| 272 if (layer->GetTargetTransform() != ui::Transform()) | 305 if (layer->GetTargetTransform() != |
| 273 return false; | 306 RetrieveOriginalTransform( |
| 307 window, &controller_->window_transforms_)) | |
| 308 return false; | |
| 274 break; | 309 break; |
| 275 case PowerButtonController::ANIMATION_FAST_CLOSE: | 310 case PowerButtonController::ANIMATION_FAST_CLOSE: |
| 276 if (layer->GetTargetTransform() != GetFastCloseTransform() || | 311 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.
| |
| 312 layer->GetTargetTransform()) || | |
| 277 layer->GetTargetOpacity() > 0.0001) | 313 layer->GetTargetOpacity() > 0.0001) |
| 278 return false; | 314 return false; |
| 279 break; | 315 break; |
| 280 case PowerButtonController::ANIMATION_FADE_IN: | 316 case PowerButtonController::ANIMATION_FADE_IN: |
| 281 if (layer->GetTargetOpacity() < 0.9999) | 317 if (layer->GetTargetOpacity() < 0.9999) |
| 282 return false; | 318 return false; |
| 283 break; | 319 break; |
| 284 case PowerButtonController::ANIMATION_HIDE: | 320 case PowerButtonController::ANIMATION_HIDE: |
| 285 if (layer->GetTargetOpacity() > 0.0001) | 321 if (layer->GetTargetOpacity() > 0.0001) |
| 286 return false; | 322 return false; |
| 287 break; | 323 break; |
| 288 case PowerButtonController::ANIMATION_RESTORE: | 324 case PowerButtonController::ANIMATION_RESTORE: |
| 289 if (layer->opacity() < 0.9999 || layer->transform() != ui::Transform()) | 325 if (layer->opacity() < 0.9999 || |
| 326 layer->transform() != RetrieveOriginalTransform( | |
|
Daniel Erat
2012/02/15 05:50:03
ditto
alicet1
2012/02/15 20:48:53
Done.
| |
| 327 window, &controller_->window_transforms_)) | |
| 290 return false; | 328 return false; |
| 291 break; | 329 break; |
| 292 default: | 330 default: |
| 293 NOTREACHED() << "Unhandled animation type " << type; | 331 NOTREACHED() << "Unhandled animation type " << type; |
| 294 return false; | 332 return false; |
| 295 } | 333 } |
| 296 } | 334 } |
| 297 return true; | 335 return true; |
| 298 } | 336 } |
| 299 | 337 |
| 300 bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const { | 338 bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const { |
| 301 return controller_->background_layer_.get() && | 339 return controller_->background_layer_.get() && |
| 302 controller_->background_layer_->visible(); | 340 controller_->background_layer_->visible(); |
| 303 } | 341 } |
| 304 | 342 |
| 343 void PowerButtonController::TestApi::GetContainerWindows( | |
| 344 ContainerGroup group, | |
| 345 aura::Window::Windows* containers) { | |
| 346 GetContainers(group, containers); | |
| 347 } | |
| 348 | |
| 305 PowerButtonController::PowerButtonController() | 349 PowerButtonController::PowerButtonController() |
| 306 : logged_in_as_non_guest_(false), | 350 : logged_in_as_non_guest_(false), |
| 307 locked_(false), | 351 locked_(false), |
| 308 power_button_down_(false), | 352 power_button_down_(false), |
| 309 lock_button_down_(false), | 353 lock_button_down_(false), |
| 310 shutting_down_(false), | 354 shutting_down_(false), |
| 311 has_legacy_power_button_( | 355 has_legacy_power_button_( |
| 312 CommandLine::ForCurrentProcess()->HasSwitch( | 356 CommandLine::ForCurrentProcess()->HasSwitch( |
| 313 switches::kAuraLegacyPowerButton)) { | 357 switches::kAuraLegacyPowerButton)) { |
| 314 } | 358 } |
| 315 | 359 |
| 316 PowerButtonController::~PowerButtonController() { | 360 PowerButtonController::~PowerButtonController() { |
| 317 } | 361 } |
| 318 | 362 |
| 319 void PowerButtonController::OnLoginStateChange(bool logged_in, bool is_guest) { | 363 void PowerButtonController::OnLoginStateChange(bool logged_in, bool is_guest) { |
| 320 logged_in_as_non_guest_ = logged_in && !is_guest; | 364 logged_in_as_non_guest_ = logged_in && !is_guest; |
| 321 } | 365 } |
| 322 | 366 |
| 323 void PowerButtonController::OnLockStateChange(bool locked) { | 367 void PowerButtonController::OnLockStateChange(bool locked) { |
| 324 if (shutting_down_ || locked_ == locked) | 368 if (shutting_down_ || locked_ == locked) |
| 325 return; | 369 return; |
| 326 | 370 |
| 327 locked_ = locked; | 371 locked_ = locked; |
| 328 if (locked) { | 372 if (locked) { |
| 329 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); | 373 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN, NULL); |
| 330 lock_timer_.Stop(); | 374 lock_timer_.Stop(); |
| 331 lock_fail_timer_.Stop(); | 375 lock_fail_timer_.Stop(); |
| 332 | 376 |
| 333 if (!has_legacy_power_button_ && power_button_down_) { | 377 if (!has_legacy_power_button_ && power_button_down_) { |
| 334 lock_to_shutdown_timer_.Stop(); | 378 lock_to_shutdown_timer_.Stop(); |
| 335 lock_to_shutdown_timer_.Start( | 379 lock_to_shutdown_timer_.Start( |
| 336 FROM_HERE, | 380 FROM_HERE, |
| 337 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | 381 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), |
| 338 this, &PowerButtonController::OnLockToShutdownTimeout); | 382 this, &PowerButtonController::OnLockToShutdownTimeout); |
| 339 } | 383 } |
| 340 } else { | 384 } else { |
| 341 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 385 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 342 ANIMATION_RESTORE); | 386 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
| |
| 343 HideBackgroundLayer(); | 387 HideBackgroundLayer(); |
| 344 } | 388 } |
| 345 } | 389 } |
| 346 | 390 |
| 347 void PowerButtonController::OnStartingLock() { | 391 void PowerButtonController::OnStartingLock() { |
| 348 if (shutting_down_ || locked_) | 392 if (shutting_down_ || locked_) |
| 349 return; | 393 return; |
| 350 | 394 |
| 351 // Ensure that the background layer is visible -- if the screen was locked via | 395 // Ensure that the background layer is visible -- if the screen was locked via |
| 352 // the wrench menu, we won't have already shown the background as part of the | 396 // the wrench menu, we won't have already shown the background as part of the |
| 353 // slow-close animation. | 397 // slow-close animation. |
| 354 ShowBackgroundLayer(); | 398 ShowBackgroundLayer(); |
| 355 | 399 |
| 356 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 400 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 357 ANIMATION_FAST_CLOSE); | 401 ANIMATION_FAST_CLOSE, &window_transforms_); |
| 358 | 402 |
| 359 // Hide the screen locker containers so we can make them fade in later. | 403 // Hide the screen locker containers so we can make them fade in later. |
| 360 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); | 404 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
| |
| 361 } | 405 } |
| 362 | 406 |
| 363 void PowerButtonController::OnPowerButtonEvent( | 407 void PowerButtonController::OnPowerButtonEvent( |
| 364 bool down, const base::TimeTicks& timestamp) { | 408 bool down, const base::TimeTicks& timestamp) { |
| 365 power_button_down_ = down; | 409 power_button_down_ = down; |
| 366 | 410 |
| 367 if (shutting_down_) | 411 if (shutting_down_) |
| 368 return; | 412 return; |
| 369 | 413 |
| 370 if (has_legacy_power_button_) { | 414 if (has_legacy_power_button_) { |
| 371 // If power button releases won't get reported correctly because we're not | 415 // If power button releases won't get reported correctly because we're not |
| 372 // running on official hardware, just lock the screen or shut down | 416 // running on official hardware, just lock the screen or shut down |
| 373 // immediately. | 417 // immediately. |
| 374 if (down) { | 418 if (down) { |
| 375 ShowBackgroundLayer(); | 419 ShowBackgroundLayer(); |
| 376 if (logged_in_as_non_guest_ && !locked_) { | 420 if (logged_in_as_non_guest_ && !locked_) { |
| 377 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 421 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 378 ANIMATION_SLOW_CLOSE); | 422 ANIMATION_SLOW_CLOSE, &window_transforms_); |
| 379 OnLockTimeout(); | 423 OnLockTimeout(); |
| 380 } else { | 424 } else { |
| 381 OnShutdownTimeout(); | 425 OnShutdownTimeout(); |
| 382 } | 426 } |
| 383 } | 427 } |
| 384 } else { // !has_legacy_power_button_ | 428 } else { // !has_legacy_power_button_ |
| 385 if (down) { | 429 if (down) { |
| 386 // If we already have a pending request to lock the screen, wait. | 430 // If we already have a pending request to lock the screen, wait. |
| 387 if (lock_fail_timer_.IsRunning()) | 431 if (lock_fail_timer_.IsRunning()) |
| 388 return; | 432 return; |
| 389 | 433 |
| 390 if (logged_in_as_non_guest_ && !locked_) | 434 if (logged_in_as_non_guest_ && !locked_) |
| 391 StartLockTimer(); | 435 StartLockTimer(); |
| 392 else | 436 else |
| 393 StartShutdownTimer(); | 437 StartShutdownTimer(); |
| 394 } else { // Button is up. | 438 } else { // Button is up. |
| 395 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) | 439 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) |
| 396 StartAnimation( | 440 StartAnimation( |
| 397 locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, | 441 locked_ ? SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, |
| 398 ANIMATION_UNDO_SLOW_CLOSE); | 442 ANIMATION_UNDO_SLOW_CLOSE, &window_transforms_); |
| 399 | 443 |
| 400 // Drop the background layer after the undo animation finishes. | 444 // Drop the background layer after the undo animation finishes. |
| 401 if (lock_timer_.IsRunning() || | 445 if (lock_timer_.IsRunning() || |
| 402 (shutdown_timer_.IsRunning() && !logged_in_as_non_guest_)) { | 446 (shutdown_timer_.IsRunning() && !logged_in_as_non_guest_)) { |
| 403 hide_background_layer_timer_.Stop(); | 447 hide_background_layer_timer_.Stop(); |
| 404 hide_background_layer_timer_.Start( | 448 hide_background_layer_timer_.Start( |
| 405 FROM_HERE, | 449 FROM_HERE, |
| 406 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | 450 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
| 407 this, &PowerButtonController::HideBackgroundLayer); | 451 this, &PowerButtonController::HideBackgroundLayer); |
| 408 } | 452 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 426 // buttons to be present, so this is just making sure that we don't do | 470 // buttons to be present, so this is just making sure that we don't do |
| 427 // something completely stupid if that assumption changes later). | 471 // something completely stupid if that assumption changes later). |
| 428 if (locked_ || lock_fail_timer_.IsRunning() || power_button_down_) | 472 if (locked_ || lock_fail_timer_.IsRunning() || power_button_down_) |
| 429 return; | 473 return; |
| 430 | 474 |
| 431 if (down) { | 475 if (down) { |
| 432 StartLockTimer(); | 476 StartLockTimer(); |
| 433 } else { | 477 } else { |
| 434 if (lock_timer_.IsRunning()) { | 478 if (lock_timer_.IsRunning()) { |
| 435 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 479 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 436 ANIMATION_UNDO_SLOW_CLOSE); | 480 ANIMATION_UNDO_SLOW_CLOSE, |
| 481 &window_transforms_); | |
| 437 hide_background_layer_timer_.Stop(); | 482 hide_background_layer_timer_.Stop(); |
| 438 hide_background_layer_timer_.Start( | 483 hide_background_layer_timer_.Start( |
| 439 FROM_HERE, | 484 FROM_HERE, |
| 440 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | 485 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
| 441 this, &PowerButtonController::HideBackgroundLayer); | 486 this, &PowerButtonController::HideBackgroundLayer); |
| 442 lock_timer_.Stop(); | 487 lock_timer_.Stop(); |
| 443 } | 488 } |
| 444 } | 489 } |
| 445 } | 490 } |
| 446 | 491 |
| 447 void PowerButtonController::OnRootWindowResized(const gfx::Size& new_size) { | 492 void PowerButtonController::OnRootWindowResized(const gfx::Size& new_size) { |
| 448 if (background_layer_.get()) | 493 if (background_layer_.get()) |
| 449 background_layer_->SetBounds(gfx::Rect(new_size)); | 494 background_layer_->SetBounds(gfx::Rect(new_size)); |
| 450 } | 495 } |
| 451 | 496 |
| 452 void PowerButtonController::OnLockTimeout() { | 497 void PowerButtonController::OnLockTimeout() { |
| 453 delegate_->RequestLockScreen(); | 498 delegate_->RequestLockScreen(); |
| 454 lock_fail_timer_.Start( | 499 lock_fail_timer_.Start( |
| 455 FROM_HERE, | 500 FROM_HERE, |
| 456 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), | 501 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), |
| 457 this, &PowerButtonController::OnLockFailTimeout); | 502 this, &PowerButtonController::OnLockFailTimeout); |
| 458 } | 503 } |
| 459 | 504 |
| 460 void PowerButtonController::OnLockFailTimeout() { | 505 void PowerButtonController::OnLockFailTimeout() { |
| 461 DCHECK(!locked_); | 506 DCHECK(!locked_); |
| 462 LOG(ERROR) << "Screen lock request timed out"; | |
| 463 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 507 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 464 ANIMATION_RESTORE); | 508 ANIMATION_RESTORE, &window_transforms_); |
| 465 HideBackgroundLayer(); | 509 HideBackgroundLayer(); |
| 466 } | 510 } |
| 467 | 511 |
| 468 void PowerButtonController::OnLockToShutdownTimeout() { | 512 void PowerButtonController::OnLockToShutdownTimeout() { |
| 469 DCHECK(locked_); | 513 DCHECK(locked_); |
| 470 StartShutdownTimer(); | 514 StartShutdownTimer(); |
| 471 } | 515 } |
| 472 | 516 |
| 473 void PowerButtonController::OnShutdownTimeout() { | 517 void PowerButtonController::OnShutdownTimeout() { |
| 474 DCHECK(!shutting_down_); | 518 DCHECK(!shutting_down_); |
| 475 shutting_down_ = true; | 519 shutting_down_ = true; |
| 476 aura::RootWindow::GetInstance()->ShowCursor(false); | 520 aura::RootWindow::GetInstance()->ShowCursor(false); |
| 477 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE); | 521 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE, &window_transforms_); |
| 478 real_shutdown_timer_.Start( | 522 real_shutdown_timer_.Start( |
| 479 FROM_HERE, | 523 FROM_HERE, |
| 480 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs), | 524 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs), |
| 481 this, &PowerButtonController::OnRealShutdownTimeout); | 525 this, &PowerButtonController::OnRealShutdownTimeout); |
| 482 } | 526 } |
| 483 | 527 |
| 484 void PowerButtonController::OnRealShutdownTimeout() { | 528 void PowerButtonController::OnRealShutdownTimeout() { |
| 485 DCHECK(shutting_down_); | 529 DCHECK(shutting_down_); |
| 486 delegate_->RequestShutdown(); | 530 delegate_->RequestShutdown(); |
| 487 } | 531 } |
| 488 | 532 |
| 489 void PowerButtonController::StartLockTimer() { | 533 void PowerButtonController::StartLockTimer() { |
| 490 ShowBackgroundLayer(); | 534 ShowBackgroundLayer(); |
| 491 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 535 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 492 ANIMATION_SLOW_CLOSE); | 536 ANIMATION_SLOW_CLOSE, &window_transforms_); |
| 493 lock_timer_.Stop(); | 537 lock_timer_.Stop(); |
| 494 lock_timer_.Start(FROM_HERE, | 538 lock_timer_.Start(FROM_HERE, |
| 495 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs), | 539 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs), |
| 496 this, &PowerButtonController::OnLockTimeout); | 540 this, &PowerButtonController::OnLockTimeout); |
| 497 } | 541 } |
| 498 | 542 |
| 499 void PowerButtonController::StartShutdownTimer() { | 543 void PowerButtonController::StartShutdownTimer() { |
| 500 ShowBackgroundLayer(); | 544 ShowBackgroundLayer(); |
| 501 StartAnimation(ALL_CONTAINERS, ANIMATION_SLOW_CLOSE); | 545 StartAnimation(ALL_CONTAINERS, ANIMATION_SLOW_CLOSE, &window_transforms_); |
| 502 shutdown_timer_.Stop(); | 546 shutdown_timer_.Stop(); |
| 503 shutdown_timer_.Start( | 547 shutdown_timer_.Start( |
| 504 FROM_HERE, | 548 FROM_HERE, |
| 505 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), | 549 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), |
| 506 this, &PowerButtonController::OnShutdownTimeout); | 550 this, &PowerButtonController::OnShutdownTimeout); |
| 507 } | 551 } |
| 508 | 552 |
| 509 void PowerButtonController::ShowBackgroundLayer() { | 553 void PowerButtonController::ShowBackgroundLayer() { |
| 510 if (hide_background_layer_timer_.IsRunning()) | 554 if (hide_background_layer_timer_.IsRunning()) |
| 511 hide_background_layer_timer_.Stop(); | 555 hide_background_layer_timer_.Stop(); |
| 512 | 556 |
| 513 if (!background_layer_.get()) { | 557 if (!background_layer_.get()) { |
| 514 background_layer_.reset(new ui::Layer(ui::Layer::LAYER_SOLID_COLOR)); | 558 background_layer_.reset(new ui::Layer(ui::Layer::LAYER_SOLID_COLOR)); |
| 515 background_layer_->SetColor(SK_ColorBLACK); | 559 background_layer_->SetColor(SK_ColorBLACK); |
| 516 | 560 |
| 517 ui::Layer* root_layer = aura::RootWindow::GetInstance()->layer(); | 561 ui::Layer* root_layer = aura::RootWindow::GetInstance()->layer(); |
| 518 background_layer_->SetBounds(root_layer->bounds()); | 562 background_layer_->SetBounds(root_layer->bounds()); |
| 519 root_layer->Add(background_layer_.get()); | 563 root_layer->Add(background_layer_.get()); |
| 520 root_layer->StackAtBottom(background_layer_.get()); | 564 root_layer->StackAtBottom(background_layer_.get()); |
| 521 } | 565 } |
| 522 background_layer_->SetVisible(true); | 566 background_layer_->SetVisible(true); |
| 523 } | 567 } |
| 524 | 568 |
| 525 void PowerButtonController::HideBackgroundLayer() { | 569 void PowerButtonController::HideBackgroundLayer() { |
| 526 background_layer_.reset(); | 570 background_layer_.reset(); |
| 527 } | 571 } |
| 528 | 572 |
| 529 } // namespace ash | 573 } // namespace ash |
| OLD | NEW |