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

Side by Side Diff: ash/wm/power_button_controller.cc

Issue 10382211: chromeos: Ignore power button presses when screen is off. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/power_button_controller.h ('k') | ash/wm/power_button_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 gfx::Rect PowerButtonController::TestApi::GetBackgroundLayerBounds() const { 278 gfx::Rect PowerButtonController::TestApi::GetBackgroundLayerBounds() const {
279 ui::Layer* layer = controller_->background_layer_.get(); 279 ui::Layer* layer = controller_->background_layer_.get();
280 return layer ? layer->bounds() : gfx::Rect(); 280 return layer ? layer->bounds() : gfx::Rect();
281 } 281 }
282 282
283 PowerButtonController::PowerButtonController() 283 PowerButtonController::PowerButtonController()
284 : login_status_(user::LOGGED_IN_NONE), 284 : login_status_(user::LOGGED_IN_NONE),
285 unlocked_login_status_(user::LOGGED_IN_NONE), 285 unlocked_login_status_(user::LOGGED_IN_NONE),
286 power_button_down_(false), 286 power_button_down_(false),
287 lock_button_down_(false), 287 lock_button_down_(false),
288 screen_is_off_(false),
288 shutting_down_(false), 289 shutting_down_(false),
289 has_legacy_power_button_( 290 has_legacy_power_button_(
290 CommandLine::ForCurrentProcess()->HasSwitch( 291 CommandLine::ForCurrentProcess()->HasSwitch(
291 switches::kAuraLegacyPowerButton)) { 292 switches::kAuraLegacyPowerButton)) {
292 Shell::GetInstance()->GetRootWindow()->AddRootWindowObserver(this); 293 Shell::GetInstance()->GetRootWindow()->AddRootWindowObserver(this);
293 } 294 }
294 295
295 PowerButtonController::~PowerButtonController() { 296 PowerButtonController::~PowerButtonController() {
296 Shell::GetInstance()->GetRootWindow()->RemoveRootWindowObserver(this); 297 Shell::GetInstance()->GetRootWindow()->RemoveRootWindowObserver(this);
297 } 298 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs), 339 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs),
339 this, &PowerButtonController::OnLockToShutdownTimeout); 340 this, &PowerButtonController::OnLockToShutdownTimeout);
340 } 341 }
341 } else { 342 } else {
342 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 343 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
343 ANIMATION_RESTORE); 344 ANIMATION_RESTORE);
344 HideBackgroundLayer(); 345 HideBackgroundLayer();
345 } 346 }
346 } 347 }
347 348
349 void PowerButtonController::OnScreenBrightnessChanged(double percent) {
350 screen_is_off_ = percent <= 0.001;
351 }
352
348 void PowerButtonController::OnStartingLock() { 353 void PowerButtonController::OnStartingLock() {
349 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED) 354 if (shutting_down_ || login_status_ == user::LOGGED_IN_LOCKED)
350 return; 355 return;
351 356
352 // Ensure that the background layer is visible -- if the screen was locked via 357 // Ensure that the background layer is visible -- if the screen was locked via
353 // the wrench menu, we won't have already shown the background as part of the 358 // the wrench menu, we won't have already shown the background as part of the
354 // slow-close animation. 359 // slow-close animation.
355 ShowBackgroundLayer(); 360 ShowBackgroundLayer();
356 361
357 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 362 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
358 ANIMATION_FAST_CLOSE); 363 ANIMATION_FAST_CLOSE);
359 364
360 // Hide the screen locker containers so we can make them fade in later. 365 // Hide the screen locker containers so we can make them fade in later.
361 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE); 366 StartAnimation(SCREEN_LOCKER_CONTAINERS, ANIMATION_HIDE);
362 } 367 }
363 368
364 void PowerButtonController::OnPowerButtonEvent( 369 void PowerButtonController::OnPowerButtonEvent(
365 bool down, const base::TimeTicks& timestamp) { 370 bool down, const base::TimeTicks& timestamp) {
366 power_button_down_ = down; 371 power_button_down_ = down;
367 372
368 if (shutting_down_) 373 if (shutting_down_)
369 return; 374 return;
370 375
376 // Avoid starting the lock/shutdown sequence if the power button is pressed
377 // while the screen is off (http://crbug.com/128451).
378 if (screen_is_off_)
379 return;
380
371 if (has_legacy_power_button_) { 381 if (has_legacy_power_button_) {
372 // If power button releases won't get reported correctly because we're not 382 // If power button releases won't get reported correctly because we're not
373 // running on official hardware, just lock the screen or shut down 383 // running on official hardware, just lock the screen or shut down
374 // immediately. 384 // immediately.
375 if (down) { 385 if (down) {
376 ShowBackgroundLayer(); 386 ShowBackgroundLayer();
377 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) { 387 if (LoggedInAsNonGuest() && login_status_ != user::LOGGED_IN_LOCKED) {
378 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 388 StartAnimation(ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
379 ANIMATION_SLOW_CLOSE); 389 ANIMATION_SLOW_CLOSE);
380 OnLockTimeout(); 390 OnLockTimeout();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 root_layer->StackAtBottom(background_layer_.get()); 568 root_layer->StackAtBottom(background_layer_.get());
559 } 569 }
560 background_layer_->SetVisible(true); 570 background_layer_->SetVisible(true);
561 } 571 }
562 572
563 void PowerButtonController::HideBackgroundLayer() { 573 void PowerButtonController::HideBackgroundLayer() {
564 background_layer_.reset(); 574 background_layer_.reset();
565 } 575 }
566 576
567 } // namespace ash 577 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/power_button_controller.h ('k') | ash/wm/power_button_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698