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_delegate.h" | 9 #include "ash/shell_delegate.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 window->layer()->SetOpacity(0.0); | 152 window->layer()->SetOpacity(0.0); |
153 } | 153 } |
154 | 154 |
155 // Restores |window| to its original position and scale and full opacity | 155 // Restores |window| to its original position and scale and full opacity |
156 // instantaneously. | 156 // instantaneously. |
157 void RestoreWindow(aura::Window* window) { | 157 void RestoreWindow(aura::Window* window) { |
158 window->layer()->SetTransform(ui::Transform()); | 158 window->layer()->SetTransform(ui::Transform()); |
159 window->layer()->SetOpacity(1.0); | 159 window->layer()->SetOpacity(1.0); |
160 } | 160 } |
161 | 161 |
162 // Fills |containers| with the containers described by |group|. | 162 // Fills |containers| with the containers described by |container_mask|. |
163 void GetContainers(PowerButtonController::ContainerGroup group, | 163 void GetContainers(int container_mask, aura::Window::Windows* containers) { |
164 aura::Window::Windows* containers) { | |
165 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 164 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 165 containers->clear(); |
166 | 166 |
167 aura::Window* non_lock_screen_containers = Shell::GetContainer( | 167 if (container_mask & PowerButtonController::DESKTOP_BACKGROUND) { |
168 root_window, | 168 containers->push_back(Shell::GetContainer( |
169 internal::kShellWindowId_NonLockScreenContainersContainer); | 169 root_window, |
170 aura::Window* lock_screen_containers = Shell::GetContainer( | 170 internal::kShellWindowId_DesktopBackgroundContainer)); |
171 root_window, | 171 } |
172 internal::kShellWindowId_LockScreenContainersContainer); | 172 if (container_mask & PowerButtonController::NON_LOCK_SCREEN_CONTAINERS) { |
173 aura::Window* lock_screen_related_containers = Shell::GetContainer( | 173 containers->push_back(Shell::GetContainer( |
174 root_window, | 174 root_window, |
175 internal::kShellWindowId_LockScreenRelatedContainersContainer); | 175 internal::kShellWindowId_NonLockScreenContainersContainer)); |
176 | 176 } |
177 containers->clear(); | 177 if (container_mask & PowerButtonController::LOCK_SCREEN_BACKGROUND) { |
178 switch (group) { | 178 containers->push_back(Shell::GetContainer( |
179 case PowerButtonController::ALL_CONTAINERS: | 179 root_window, |
180 containers->push_back(non_lock_screen_containers); | 180 internal::kShellWindowId_LockScreenBackgroundContainer)); |
181 containers->push_back(lock_screen_containers); | 181 } |
182 containers->push_back(lock_screen_related_containers); | 182 if (container_mask & PowerButtonController::LOCK_SCREEN_CONTAINERS) { |
183 break; | 183 containers->push_back(Shell::GetContainer( |
184 case PowerButtonController::SCREEN_LOCKER_CONTAINERS: | 184 root_window, |
185 containers->push_back(lock_screen_containers); | 185 internal::kShellWindowId_LockScreenContainersContainer)); |
186 break; | 186 } |
187 case PowerButtonController::SCREEN_LOCKER_AND_RELATED_CONTAINERS: | 187 if (container_mask & PowerButtonController::LOCK_SCREEN_RELATED_CONTAINERS) { |
188 containers->push_back(lock_screen_containers); | 188 containers->push_back(Shell::GetContainer( |
189 containers->push_back(lock_screen_related_containers); | 189 root_window, |
190 break; | 190 internal::kShellWindowId_LockScreenRelatedContainersContainer)); |
191 case PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS: | |
192 containers->push_back(non_lock_screen_containers); | |
193 break; | |
194 default: | |
195 NOTREACHED() << "Unhandled container group " << group; | |
196 } | 191 } |
197 } | 192 } |
198 | 193 |
199 // Apply animation |type| to all containers described by |group|. | 194 // Apply animation |type| to all containers described by |container_mask|. |
200 void StartAnimation(PowerButtonController::ContainerGroup group, | 195 void StartAnimation(int container_mask, |
201 PowerButtonController::AnimationType type) { | 196 PowerButtonController::AnimationType type) { |
202 aura::Window::Windows containers; | 197 aura::Window::Windows containers; |
203 GetContainers(group, &containers); | 198 GetContainers(container_mask, &containers); |
204 | 199 |
205 for (aura::Window::Windows::const_iterator it = containers.begin(); | 200 for (aura::Window::Windows::const_iterator it = containers.begin(); |
206 it != containers.end(); ++it) { | 201 it != containers.end(); ++it) { |
207 aura::Window* window = *it; | 202 aura::Window* window = *it; |
208 switch (type) { | 203 switch (type) { |
209 case PowerButtonController::ANIMATION_SLOW_CLOSE: | 204 case PowerButtonController::ANIMATION_SLOW_CLOSE: |
210 StartSlowCloseAnimationForWindow(window); | 205 StartSlowCloseAnimationForWindow(window); |
211 break; | 206 break; |
212 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: | 207 case PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE: |
213 StartUndoSlowCloseAnimationForWindow(window); | 208 StartUndoSlowCloseAnimationForWindow(window); |
(...skipping 11 matching lines...) Expand all Loading... |
225 RestoreWindow(window); | 220 RestoreWindow(window); |
226 break; | 221 break; |
227 default: | 222 default: |
228 NOTREACHED() << "Unhandled animation type " << type; | 223 NOTREACHED() << "Unhandled animation type " << type; |
229 } | 224 } |
230 } | 225 } |
231 } | 226 } |
232 | 227 |
233 } // namespace | 228 } // namespace |
234 | 229 |
235 bool PowerButtonController::TestApi::ContainerGroupIsAnimated( | 230 bool PowerButtonController::TestApi::ContainersAreAnimated( |
236 ContainerGroup group, AnimationType type) const { | 231 int container_mask, AnimationType type) const { |
237 aura::Window::Windows containers; | 232 aura::Window::Windows containers; |
238 GetContainers(group, &containers); | 233 GetContainers(container_mask, &containers); |
239 for (aura::Window::Windows::const_iterator it = containers.begin(); | 234 for (aura::Window::Windows::const_iterator it = containers.begin(); |
240 it != containers.end(); ++it) { | 235 it != containers.end(); ++it) { |
241 aura::Window* window = *it; | 236 aura::Window* window = *it; |
242 ui::Layer* layer = window->layer(); | 237 ui::Layer* layer = window->layer(); |
243 | 238 |
244 switch (type) { | 239 switch (type) { |
245 case PowerButtonController::ANIMATION_SLOW_CLOSE: | 240 case PowerButtonController::ANIMATION_SLOW_CLOSE: |
246 if (layer->GetTargetTransform() != GetSlowCloseTransform()) | 241 if (layer->GetTargetTransform() != GetSlowCloseTransform()) |
247 return false; | 242 return false; |
248 break; | 243 break; |
(...skipping 19 matching lines...) Expand all Loading... |
268 return false; | 263 return false; |
269 break; | 264 break; |
270 default: | 265 default: |
271 NOTREACHED() << "Unhandled animation type " << type; | 266 NOTREACHED() << "Unhandled animation type " << type; |
272 return false; | 267 return false; |
273 } | 268 } |
274 } | 269 } |
275 return true; | 270 return true; |
276 } | 271 } |
277 | 272 |
278 bool PowerButtonController::TestApi::BackgroundLayerIsVisible() const { | 273 bool PowerButtonController::TestApi::BlackLayerIsVisible() const { |
279 return controller_->background_layer_.get() && | 274 return controller_->black_layer_.get() && |
280 controller_->background_layer_->visible(); | 275 controller_->black_layer_->visible(); |
281 } | 276 } |
282 | 277 |
283 gfx::Rect PowerButtonController::TestApi::GetBackgroundLayerBounds() const { | 278 gfx::Rect PowerButtonController::TestApi::GetBlackLayerBounds() const { |
284 ui::Layer* layer = controller_->background_layer_.get(); | 279 ui::Layer* layer = controller_->black_layer_.get(); |
285 return layer ? layer->bounds() : gfx::Rect(); | 280 return layer ? layer->bounds() : gfx::Rect(); |
286 } | 281 } |
287 | 282 |
| 283 // static |
| 284 int PowerButtonController::GetAllContainersMask() { |
| 285 return PowerButtonController::DESKTOP_BACKGROUND | |
| 286 PowerButtonController::NON_LOCK_SCREEN_CONTAINERS | |
| 287 GetAllLockScreenContainersMask(); |
| 288 } |
| 289 |
| 290 // static |
| 291 int PowerButtonController::GetAllLockScreenContainersMask() { |
| 292 return PowerButtonController::LOCK_SCREEN_BACKGROUND | |
| 293 PowerButtonController::LOCK_SCREEN_CONTAINERS | |
| 294 PowerButtonController::LOCK_SCREEN_RELATED_CONTAINERS; |
| 295 } |
| 296 |
288 PowerButtonController::PowerButtonController() | 297 PowerButtonController::PowerButtonController() |
289 : login_status_(user::LOGGED_IN_NONE), | 298 : login_status_(user::LOGGED_IN_NONE), |
290 unlocked_login_status_(user::LOGGED_IN_NONE), | 299 unlocked_login_status_(user::LOGGED_IN_NONE), |
291 power_button_down_(false), | 300 power_button_down_(false), |
292 lock_button_down_(false), | 301 lock_button_down_(false), |
293 screen_is_off_(false), | 302 screen_is_off_(false), |
294 shutting_down_(false), | 303 shutting_down_(false), |
295 has_legacy_power_button_( | 304 has_legacy_power_button_( |
296 CommandLine::ForCurrentProcess()->HasSwitch( | 305 CommandLine::ForCurrentProcess()->HasSwitch( |
297 switches::kAuraLegacyPowerButton)) { | 306 switches::kAuraLegacyPowerButton)) { |
(...skipping 10 matching lines...) Expand all Loading... |
308 } | 317 } |
309 | 318 |
310 void PowerButtonController::OnAppTerminating() { | 319 void PowerButtonController::OnAppTerminating() { |
311 // If we hear that Chrome is exiting but didn't request it ourselves, all we | 320 // If we hear that Chrome is exiting but didn't request it ourselves, all we |
312 // can really hope for is that we'll have time to clear the screen. | 321 // can really hope for is that we'll have time to clear the screen. |
313 if (!shutting_down_) { | 322 if (!shutting_down_) { |
314 shutting_down_ = true; | 323 shutting_down_ = true; |
315 Shell* shell = ash::Shell::GetInstance(); | 324 Shell* shell = ash::Shell::GetInstance(); |
316 shell->env_filter()->set_update_cursor_visibility(false); | 325 shell->env_filter()->set_update_cursor_visibility(false); |
317 shell->cursor_manager()->ShowCursor(false); | 326 shell->cursor_manager()->ShowCursor(false); |
318 ShowBackgroundLayer(); | 327 ShowBlackLayer(); |
319 StartAnimation(ALL_CONTAINERS, ANIMATION_HIDE); | 328 StartAnimation(GetAllContainersMask(), ANIMATION_HIDE); |
320 } | 329 } |
321 } | 330 } |
322 | 331 |
323 void PowerButtonController::OnLockStateChanged(bool locked) { | 332 void PowerButtonController::OnLockStateChanged(bool locked) { |
324 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked) | 333 if (shutting_down_ || (login_status_ == user::LOGGED_IN_LOCKED) == locked) |
325 return; | 334 return; |
326 | 335 |
327 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) { | 336 if (!locked && login_status_ == user::LOGGED_IN_LOCKED) { |
328 login_status_ = unlocked_login_status_; | 337 login_status_ = unlocked_login_status_; |
329 unlocked_login_status_ = user::LOGGED_IN_NONE; | 338 unlocked_login_status_ = user::LOGGED_IN_NONE; |
330 } else { | 339 } else { |
331 unlocked_login_status_ = login_status_; | 340 unlocked_login_status_ = login_status_; |
332 login_status_ = user::LOGGED_IN_LOCKED; | 341 login_status_ = user::LOGGED_IN_LOCKED; |
333 } | 342 } |
334 | 343 |
335 if (locked) { | 344 if (locked) { |
336 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_FADE_IN); | 345 StartAnimation(LOCK_SCREEN_CONTAINERS, ANIMATION_FADE_IN); |
337 lock_timer_.Stop(); | 346 lock_timer_.Stop(); |
338 lock_fail_timer_.Stop(); | 347 lock_fail_timer_.Stop(); |
339 | 348 |
340 if (!has_legacy_power_button_ && power_button_down_) { | 349 if (!has_legacy_power_button_ && power_button_down_) { |
341 lock_to_shutdown_timer_.Stop(); | 350 lock_to_shutdown_timer_.Stop(); |
342 lock_to_shutdown_timer_.Start( | 351 lock_to_shutdown_timer_.Start( |
343 FROM_HERE, | 352 FROM_HERE, |
344 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), | 353 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), |
345 this, &PowerButtonController::OnLockToShutdownTimeout); | 354 this, &PowerButtonController::OnLockToShutdownTimeout); |
346 } | 355 } |
347 } else { | 356 } else { |
348 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 357 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_RESTORE); |
349 ANIMATION_RESTORE); | 358 HideBlackLayer(); |
350 HideBackgroundLayer(); | |
351 } | 359 } |
352 } | 360 } |
353 | 361 |
354 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 362 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
355 screen_is_off_ = percent <= 0.001; | 363 screen_is_off_ = percent <= 0.001; |
356 } | 364 } |
357 | 365 |
358 void PowerButtonController::OnStartingLock() { | 366 void PowerButtonController::OnStartingLock() { |
359 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) | 367 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) |
360 return; | 368 return; |
361 | 369 |
362 // Ensure that the background layer is visible -- if the screen was locked via | 370 // Ensure that the black layer is visible -- if the screen was locked via |
363 // the wrench menu, we won't have already shown the background as part of the | 371 // the wrench menu, we won't have already shown the black background |
364 // slow-close animation. | 372 // as part of the slow-close animation. |
365 ShowBackgroundLayer(); | 373 ShowBlackLayer(); |
366 | 374 |
367 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 375 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_FAST_CLOSE); |
368 ANIMATION_FAST_CLOSE); | |
369 | 376 |
370 // Hide the screen locker containers so we can make them fade in later. | 377 // Hide the screen locker containers so we can make them fade in later. |
371 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); | 378 StartAnimation(LOCK_SCREEN_CONTAINERS, ANIMATION_HIDE); |
372 } | 379 } |
373 | 380 |
374 void PowerButtonController::OnPowerButtonEvent( | 381 void PowerButtonController::OnPowerButtonEvent( |
375 bool down, const base::TimeTicks& timestamp) { | 382 bool down, const base::TimeTicks& timestamp) { |
376 power_button_down_ = down; | 383 power_button_down_ = down; |
377 | 384 |
378 if (shutting_down_) | 385 if (shutting_down_) |
379 return; | 386 return; |
380 | 387 |
381 // Avoid starting the lock/shutdown sequence if the power button is pressed | 388 // Avoid starting the lock/shutdown sequence if the power button is pressed |
382 // while the screen is off (http://crbug.com/128451). | 389 // while the screen is off (http://crbug.com/128451). |
383 if (screen_is_off_) | 390 if (screen_is_off_) |
384 return; | 391 return; |
385 | 392 |
386 if (has_legacy_power_button_) { | 393 if (has_legacy_power_button_) { |
387 // If power button releases won't get reported correctly because we're not | 394 // If power button releases won't get reported correctly because we're not |
388 // running on official hardware, just lock the screen or shut down | 395 // running on official hardware, just lock the screen or shut down |
389 // immediately. | 396 // immediately. |
390 if (down) { | 397 if (down) { |
391 ShowBackgroundLayer(); | 398 ShowBlackLayer(); |
392 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) { | 399 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) { |
393 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 400 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_SLOW_CLOSE); |
394 ANIMATION_SLOW_CLOSE); | |
395 OnLockTimeout(); | 401 OnLockTimeout(); |
396 } else { | 402 } else { |
397 OnShutdownTimeout(); | 403 OnShutdownTimeout(); |
398 } | 404 } |
399 } | 405 } |
400 } else { // !has_legacy_power_button_ | 406 } else { // !has_legacy_power_button_ |
401 if (down) { | 407 if (down) { |
402 // If we already have a pending request to lock the screen, wait. | 408 // If we already have a pending request to lock the screen, wait. |
403 if (lock_fail_timer_.IsRunning()) | 409 if (lock_fail_timer_.IsRunning()) |
404 return; | 410 return; |
405 | 411 |
406 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) | 412 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) |
407 StartLockTimer(); | 413 StartLockTimer(); |
408 else | 414 else |
409 StartShutdownTimer(); | 415 StartShutdownTimer(); |
410 } else { // Button is up. | 416 } else { // Button is up. |
411 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) | 417 if (lock_timer_.IsRunning() || shutdown_timer_.IsRunning()) |
412 StartAnimation( | 418 StartAnimation( |
413 (login_status_ == user::LOGGED_IN_LOCKED) ? | 419 (login_status_ == user::LOGGED_IN_LOCKED) ? |
414 SCREEN_LOCKER_AND_RELATED_CONTAINERS : ALL_CONTAINERS, | 420 GetAllLockScreenContainersMask() : GetAllContainersMask(), |
415 ANIMATION_UNDO_SLOW_CLOSE); | 421 ANIMATION_UNDO_SLOW_CLOSE); |
416 | 422 |
417 // Drop the background layer after the undo animation finishes. | 423 // Drop the black layer after the undo animation finishes. |
418 if (lock_timer_.IsRunning() || | 424 if (lock_timer_.IsRunning() || |
419 (shutdown_timer_.IsRunning() && !LoggedInAsNonGuest())) { | 425 (shutdown_timer_.IsRunning() && !LoggedInAsNonGuest())) { |
420 hide_background_layer_timer_.Stop(); | 426 hide_black_layer_timer_.Stop(); |
421 hide_background_layer_timer_.Start( | 427 hide_black_layer_timer_.Start( |
422 FROM_HERE, | 428 FROM_HERE, |
423 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | 429 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
424 this, &PowerButtonController::HideBackgroundLayer); | 430 this, &PowerButtonController::HideBlackLayer); |
425 } | 431 } |
426 | 432 |
427 lock_timer_.Stop(); | 433 lock_timer_.Stop(); |
428 shutdown_timer_.Stop(); | 434 shutdown_timer_.Stop(); |
429 lock_to_shutdown_timer_.Stop(); | 435 lock_to_shutdown_timer_.Stop(); |
430 } | 436 } |
431 } | 437 } |
432 } | 438 } |
433 | 439 |
434 void PowerButtonController::OnLockButtonEvent( | 440 void PowerButtonController::OnLockButtonEvent( |
435 bool down, const base::TimeTicks& timestamp) { | 441 bool down, const base::TimeTicks& timestamp) { |
436 lock_button_down_ = down; | 442 lock_button_down_ = down; |
437 | 443 |
438 if (shutting_down_ || !LoggedInAsNonGuest()) | 444 if (shutting_down_ || !LoggedInAsNonGuest()) |
439 return; | 445 return; |
440 | 446 |
441 // Bail if we're already locked or are in the process of locking. Also give | 447 // Bail if we're already locked or are in the process of locking. Also give |
442 // the power button precedence over the lock button (we don't expect both | 448 // the power button precedence over the lock button (we don't expect both |
443 // buttons to be present, so this is just making sure that we don't do | 449 // buttons to be present, so this is just making sure that we don't do |
444 // something completely stupid if that assumption changes later). | 450 // something completely stupid if that assumption changes later). |
445 if (login_status_ == user::LOGGED_IN_LOCKED || | 451 if (login_status_ == user::LOGGED_IN_LOCKED || |
446 lock_fail_timer_.IsRunning() || power_button_down_) | 452 lock_fail_timer_.IsRunning() || power_button_down_) |
447 return; | 453 return; |
448 | 454 |
449 if (down) { | 455 if (down) { |
450 StartLockTimer(); | 456 StartLockTimer(); |
451 } else { | 457 } else { |
452 if (lock_timer_.IsRunning()) { | 458 if (lock_timer_.IsRunning()) { |
453 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 459 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_UNDO_SLOW_CLOSE); |
454 ANIMATION_UNDO_SLOW_CLOSE); | 460 hide_black_layer_timer_.Stop(); |
455 hide_background_layer_timer_.Stop(); | 461 hide_black_layer_timer_.Start( |
456 hide_background_layer_timer_.Start( | |
457 FROM_HERE, | 462 FROM_HERE, |
458 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), | 463 base::TimeDelta::FromMilliseconds(kUndoSlowCloseAnimMs), |
459 this, &PowerButtonController::HideBackgroundLayer); | 464 this, &PowerButtonController::HideBlackLayer); |
460 lock_timer_.Stop(); | 465 lock_timer_.Stop(); |
461 } | 466 } |
462 } | 467 } |
463 } | 468 } |
464 | 469 |
465 void PowerButtonController::RequestShutdown() { | 470 void PowerButtonController::RequestShutdown() { |
466 if (!shutting_down_) | 471 if (!shutting_down_) |
467 StartShutdownAnimationAndRequestShutdown(); | 472 StartShutdownAnimationAndRequestShutdown(); |
468 } | 473 } |
469 | 474 |
470 void PowerButtonController::OnRootWindowResized(const aura::RootWindow* root, | 475 void PowerButtonController::OnRootWindowResized(const aura::RootWindow* root, |
471 const gfx::Size& new_size) { | 476 const gfx::Size& new_size) { |
472 if (background_layer_.get()) | 477 if (black_layer_.get()) |
473 background_layer_->SetBounds(gfx::Rect(root->bounds().size())); | 478 black_layer_->SetBounds(gfx::Rect(root->bounds().size())); |
474 } | 479 } |
475 | 480 |
476 void PowerButtonController::OnRootWindowHostCloseRequested( | 481 void PowerButtonController::OnRootWindowHostCloseRequested( |
477 const aura::RootWindow*) { | 482 const aura::RootWindow*) { |
478 if(Shell::GetInstance() && Shell::GetInstance()->delegate()) | 483 if(Shell::GetInstance() && Shell::GetInstance()->delegate()) |
479 Shell::GetInstance()->delegate()->Exit(); | 484 Shell::GetInstance()->delegate()->Exit(); |
480 } | 485 } |
481 | 486 |
482 bool PowerButtonController::LoggedInAsNonGuest() const { | 487 bool PowerButtonController::LoggedInAsNonGuest() const { |
483 if (login_status_ == user::LOGGED_IN_NONE) | 488 if (login_status_ == user::LOGGED_IN_NONE) |
484 return false; | 489 return false; |
485 if (login_status_ == user::LOGGED_IN_GUEST) | 490 if (login_status_ == user::LOGGED_IN_GUEST) |
486 return false; | 491 return false; |
487 // TODO(mukai): think about kiosk mode. | 492 // TODO(mukai): think about kiosk mode. |
488 return true; | 493 return true; |
489 } | 494 } |
490 | 495 |
491 void PowerButtonController::OnLockTimeout() { | 496 void PowerButtonController::OnLockTimeout() { |
492 delegate_->RequestLockScreen(); | 497 delegate_->RequestLockScreen(); |
493 lock_fail_timer_.Start( | 498 lock_fail_timer_.Start( |
494 FROM_HERE, | 499 FROM_HERE, |
495 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), | 500 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs), |
496 this, &PowerButtonController::OnLockFailTimeout); | 501 this, &PowerButtonController::OnLockFailTimeout); |
497 } | 502 } |
498 | 503 |
499 void PowerButtonController::OnLockFailTimeout() { | 504 void PowerButtonController::OnLockFailTimeout() { |
500 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED); | 505 DCHECK_NE(login_status_, user::LOGGED_IN_LOCKED); |
501 LOG(ERROR) << "Screen lock request timed out"; | 506 LOG(ERROR) << "Screen lock request timed out"; |
502 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 507 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_RESTORE); |
503 ANIMATION_RESTORE); | 508 HideBlackLayer(); |
504 HideBackgroundLayer(); | |
505 } | 509 } |
506 | 510 |
507 void PowerButtonController::OnLockToShutdownTimeout() { | 511 void PowerButtonController::OnLockToShutdownTimeout() { |
508 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED); | 512 DCHECK_EQ(login_status_, user::LOGGED_IN_LOCKED); |
509 StartShutdownTimer(); | 513 StartShutdownTimer(); |
510 } | 514 } |
511 | 515 |
512 void PowerButtonController::OnShutdownTimeout() { | 516 void PowerButtonController::OnShutdownTimeout() { |
513 if (!shutting_down_) | 517 if (!shutting_down_) |
514 StartShutdownAnimationAndRequestShutdown(); | 518 StartShutdownAnimationAndRequestShutdown(); |
515 } | 519 } |
516 | 520 |
517 void PowerButtonController::OnRealShutdownTimeout() { | 521 void PowerButtonController::OnRealShutdownTimeout() { |
518 DCHECK(shutting_down_); | 522 DCHECK(shutting_down_); |
519 delegate_->RequestShutdown(); | 523 delegate_->RequestShutdown(); |
520 } | 524 } |
521 | 525 |
522 void PowerButtonController::StartLockTimer() { | 526 void PowerButtonController::StartLockTimer() { |
523 ShowBackgroundLayer(); | 527 ShowBlackLayer(); |
524 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 528 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_SLOW_CLOSE); |
525 ANIMATION_SLOW_CLOSE); | |
526 lock_timer_.Stop(); | 529 lock_timer_.Stop(); |
527 lock_timer_.Start(FROM_HERE, | 530 lock_timer_.Start(FROM_HERE, |
528 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs), | 531 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs), |
529 this, &PowerButtonController::OnLockTimeout); | 532 this, &PowerButtonController::OnLockTimeout); |
530 } | 533 } |
531 | 534 |
532 void PowerButtonController::StartShutdownTimer() { | 535 void PowerButtonController::StartShutdownTimer() { |
533 ShowBackgroundLayer(); | 536 ShowBlackLayer(); |
534 StartAnimation(ALL_CONTAINERS, ANIMATION_SLOW_CLOSE); | 537 StartAnimation(GetAllContainersMask(), ANIMATION_SLOW_CLOSE); |
535 shutdown_timer_.Stop(); | 538 shutdown_timer_.Stop(); |
536 shutdown_timer_.Start( | 539 shutdown_timer_.Start( |
537 FROM_HERE, | 540 FROM_HERE, |
538 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), | 541 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), |
539 this, &PowerButtonController::OnShutdownTimeout); | 542 this, &PowerButtonController::OnShutdownTimeout); |
540 } | 543 } |
541 | 544 |
542 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { | 545 void PowerButtonController::StartShutdownAnimationAndRequestShutdown() { |
543 DCHECK(!shutting_down_); | 546 DCHECK(!shutting_down_); |
544 shutting_down_ = true; | 547 shutting_down_ = true; |
545 | 548 |
546 Shell* shell = ash::Shell::GetInstance(); | 549 Shell* shell = ash::Shell::GetInstance(); |
547 shell->env_filter()->set_update_cursor_visibility(false); | 550 shell->env_filter()->set_update_cursor_visibility(false); |
548 shell->cursor_manager()->ShowCursor(false); | 551 shell->cursor_manager()->ShowCursor(false); |
549 | 552 |
550 ShowBackgroundLayer(); | 553 ShowBlackLayer(); |
551 if (login_status_ != user::LOGGED_IN_NONE) { | 554 if (login_status_ != user::LOGGED_IN_NONE) { |
552 // Hide the other containers before starting the animation. | 555 // Hide the other containers before starting the animation. |
553 // ANIMATION_FAST_CLOSE will make the screen locker windows partially | 556 // ANIMATION_FAST_CLOSE will make the screen locker windows partially |
554 // transparent, and we don't want the other windows to show through. | 557 // transparent, and we don't want the other windows to show through. |
555 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 558 StartAnimation(NON_LOCK_SCREEN_CONTAINERS, ANIMATION_HIDE); |
556 ANIMATION_HIDE); | 559 StartAnimation(GetAllLockScreenContainersMask(), ANIMATION_FAST_CLOSE); |
557 StartAnimation(SCREEN_LOCKER_AND_RELATED_CONTAINERS, ANIMATION_FAST_CLOSE); | |
558 } else { | 560 } else { |
559 StartAnimation(ALL_CONTAINERS, ANIMATION_FAST_CLOSE); | 561 StartAnimation(GetAllContainersMask(), ANIMATION_FAST_CLOSE); |
560 } | 562 } |
561 | 563 |
562 real_shutdown_timer_.Start( | 564 real_shutdown_timer_.Start( |
563 FROM_HERE, | 565 FROM_HERE, |
564 base::TimeDelta::FromMilliseconds( | 566 base::TimeDelta::FromMilliseconds( |
565 kFastCloseAnimMs + kShutdownRequestDelayMs), | 567 kFastCloseAnimMs + kShutdownRequestDelayMs), |
566 this, &PowerButtonController::OnRealShutdownTimeout); | 568 this, &PowerButtonController::OnRealShutdownTimeout); |
567 } | 569 } |
568 | 570 |
569 void PowerButtonController::ShowBackgroundLayer() { | 571 void PowerButtonController::ShowBlackLayer() { |
570 if (hide_background_layer_timer_.IsRunning()) | 572 if (hide_black_layer_timer_.IsRunning()) |
571 hide_background_layer_timer_.Stop(); | 573 hide_black_layer_timer_.Stop(); |
572 | 574 |
573 if (!background_layer_.get()) { | 575 if (!black_layer_.get()) { |
574 background_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 576 black_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
575 background_layer_->SetColor(SK_ColorBLACK); | 577 black_layer_->SetColor(SK_ColorBLACK); |
576 | 578 |
577 ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer(); | 579 ui::Layer* root_layer = Shell::GetPrimaryRootWindow()->layer(); |
578 background_layer_->SetBounds(root_layer->bounds()); | 580 black_layer_->SetBounds(root_layer->bounds()); |
579 root_layer->Add(background_layer_.get()); | 581 root_layer->Add(black_layer_.get()); |
580 root_layer->StackAtBottom(background_layer_.get()); | 582 root_layer->StackAtBottom(black_layer_.get()); |
581 } | 583 } |
582 background_layer_->SetVisible(true); | 584 black_layer_->SetVisible(true); |
583 } | 585 } |
584 | 586 |
585 void PowerButtonController::HideBackgroundLayer() { | 587 void PowerButtonController::HideBlackLayer() { |
586 background_layer_.reset(); | 588 black_layer_.reset(); |
587 } | 589 } |
588 | 590 |
589 } // namespace ash | 591 } // namespace ash |
OLD | NEW |