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/session/session_state_delegate.h" | 8 #include "ash/session/session_state_delegate.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/wm/lock_state_controller.h" | 11 #include "ash/wm/lock_state_controller.h" |
| 12 #include "ash/wm/session_state_animator.h" | 12 #include "ash/wm/session_state_animator.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/display/types/chromeos/display_snapshot.h" | 15 #include "ui/display/types/chromeos/display_snapshot.h" |
| 16 #include "ui/events/event_handler.h" | |
| 16 #include "ui/wm/core/compound_event_filter.h" | 17 #include "ui/wm/core/compound_event_filter.h" |
| 17 | 18 |
| 18 namespace ash { | 19 namespace ash { |
| 19 | 20 |
| 20 PowerButtonController::PowerButtonController( | 21 PowerButtonController::PowerButtonController( |
| 21 LockStateController* controller) | 22 LockStateController* controller) |
| 22 : power_button_down_(false), | 23 : power_button_down_(false), |
| 23 lock_button_down_(false), | 24 lock_button_down_(false), |
| 25 volume_down_pressed_(false), | |
| 24 brightness_is_zero_(false), | 26 brightness_is_zero_(false), |
| 25 internal_display_off_and_external_display_on_(false), | 27 internal_display_off_and_external_display_on_(false), |
| 26 has_legacy_power_button_( | 28 has_legacy_power_button_( |
| 27 CommandLine::ForCurrentProcess()->HasSwitch( | 29 CommandLine::ForCurrentProcess()->HasSwitch( |
| 28 switches::kAuraLegacyPowerButton)), | 30 switches::kAuraLegacyPowerButton)), |
| 29 controller_(controller) { | 31 controller_(controller) { |
| 30 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
| 31 Shell::GetInstance()->display_configurator()->AddObserver(this); | 33 Shell::GetInstance()->display_configurator()->AddObserver(this); |
| 34 Shell::GetInstance()->PrependPreTargetHandler(this); | |
| 32 #endif | 35 #endif |
| 33 } | 36 } |
| 34 | 37 |
| 35 PowerButtonController::~PowerButtonController() { | 38 PowerButtonController::~PowerButtonController() { |
| 36 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 37 Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 40 Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
| 41 Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 38 #endif | 42 #endif |
| 39 } | 43 } |
| 40 | 44 |
| 41 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 45 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
| 42 brightness_is_zero_ = percent <= 0.001; | 46 brightness_is_zero_ = percent <= 0.001; |
| 43 } | 47 } |
| 44 | 48 |
| 45 void PowerButtonController::OnPowerButtonEvent( | 49 void PowerButtonController::OnPowerButtonEvent( |
| 46 bool down, const base::TimeTicks& timestamp) { | 50 bool down, const base::TimeTicks& timestamp) { |
| 47 power_button_down_ = down; | 51 power_button_down_ = down; |
| 48 | 52 |
| 49 if (controller_->ShutdownRequested()) | 53 if (controller_->ShutdownRequested()) |
| 50 return; | 54 return; |
| 51 | 55 |
| 52 // Avoid starting the lock/shutdown sequence if the power button is pressed | 56 // Avoid starting the lock/shutdown sequence if the power button is pressed |
| 53 // while the screen is off (http://crbug.com/128451), unless an external | 57 // while the screen is off (http://crbug.com/128451), unless an external |
| 54 // display is still on (http://crosbug.com/p/24912). | 58 // display is still on (http://crosbug.com/p/24912). |
| 55 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 59 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
| 56 return; | 60 return; |
| 57 | 61 |
| 62 if (volume_down_pressed_ && down) { | |
| 63 Shell::GetInstance()->accelerator_controller()->PerformAction( | |
| 64 ash::TAKE_SCREENSHOT, ui::Accelerator()); | |
| 65 return; | |
| 66 } | |
| 67 | |
| 58 const SessionStateDelegate* session_state_delegate = | 68 const SessionStateDelegate* session_state_delegate = |
| 59 Shell::GetInstance()->session_state_delegate(); | 69 Shell::GetInstance()->session_state_delegate(); |
| 60 if (has_legacy_power_button_) { | 70 if (has_legacy_power_button_) { |
| 61 // If power button releases won't get reported correctly because we're not | 71 // If power button releases won't get reported correctly because we're not |
| 62 // running on official hardware, just lock the screen or shut down | 72 // running on official hardware, just lock the screen or shut down |
| 63 // immediately. | 73 // immediately. |
| 64 if (down) { | 74 if (down) { |
| 65 if (session_state_delegate->CanLockScreen() && | 75 if (session_state_delegate->CanLockScreen() && |
| 66 !session_state_delegate->IsScreenLocked() && | 76 !session_state_delegate->IsScreenLocked() && |
| 67 !controller_->LockRequested()) { | 77 !controller_->LockRequested()) { |
| 68 controller_->StartLockAnimationAndLockImmediately(); | 78 controller_->StartLockAnimationAndLockImmediately(); |
| 69 } else { | 79 } else { |
| 70 controller_->RequestShutdown(); | 80 controller_->RequestShutdown(); |
| 71 } | 81 } |
| 72 } | 82 } |
| 73 } else { // !has_legacy_power_button_ | 83 } else { // !has_legacy_power_button_ |
| 74 if (down) { | 84 if (down) { |
| 75 // If we already have a pending request to lock the screen, wait. | 85 // If we already have a pending request to lock the screen, wait. |
| 76 if (controller_->LockRequested()) | 86 if (controller_->LockRequested()) |
| 77 return; | 87 return; |
| 78 | 88 |
| 79 if (session_state_delegate->CanLockScreen() && | 89 if (session_state_delegate->CanLockScreen() && |
| 80 !session_state_delegate->IsScreenLocked()) { | 90 !session_state_delegate->IsScreenLocked()) { |
| 81 controller_->StartLockAnimation(true); | 91 controller_->StartLockAnimationAndLockImmediately(); |
|
flackr
2014/06/10 17:34:42
Won't this affect the regular power button on a ch
| |
| 82 } else { | 92 } else { |
| 83 controller_->StartShutdownAnimation(); | 93 controller_->StartShutdownAnimation(); |
| 84 } | 94 } |
| 85 } else { // Button is up. | 95 } else { // Button is up. |
| 86 if (controller_->CanCancelLockAnimation()) | 96 if (controller_->CanCancelLockAnimation()) |
| 87 controller_->CancelLockAnimation(); | 97 controller_->CancelLockAnimation(); |
| 88 else if (controller_->CanCancelShutdownAnimation()) | 98 else if (controller_->CanCancelShutdownAnimation()) |
| 89 controller_->CancelShutdownAnimation(); | 99 controller_->CancelShutdownAnimation(); |
| 90 } | 100 } |
| 91 } | 101 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 109 // something completely stupid if that assumption changes later). | 119 // something completely stupid if that assumption changes later). |
| 110 if (power_button_down_) | 120 if (power_button_down_) |
| 111 return; | 121 return; |
| 112 | 122 |
| 113 if (down) | 123 if (down) |
| 114 controller_->StartLockAnimation(false); | 124 controller_->StartLockAnimation(false); |
| 115 else | 125 else |
| 116 controller_->CancelLockAnimation(); | 126 controller_->CancelLockAnimation(); |
| 117 } | 127 } |
| 118 | 128 |
| 129 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | |
| 130 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { | |
| 131 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED || | |
| 132 event->type() == ui::ET_TRANSLATED_KEY_PRESS; | |
| 133 } | |
| 134 } | |
| 135 | |
| 119 #if defined(OS_CHROMEOS) | 136 #if defined(OS_CHROMEOS) |
| 120 void PowerButtonController::OnDisplayModeChanged( | 137 void PowerButtonController::OnDisplayModeChanged( |
| 121 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 138 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
| 122 bool internal_display_off = false; | 139 bool internal_display_off = false; |
| 123 bool external_display_on = false; | 140 bool external_display_on = false; |
| 124 for (size_t i = 0; i < display_states.size(); ++i) { | 141 for (size_t i = 0; i < display_states.size(); ++i) { |
| 125 const ui::DisplayConfigurator::DisplayState& state = display_states[i]; | 142 const ui::DisplayConfigurator::DisplayState& state = display_states[i]; |
| 126 if (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 143 if (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
| 127 if (!state.display->current_mode()) | 144 if (!state.display->current_mode()) |
| 128 internal_display_off = true; | 145 internal_display_off = true; |
| 129 } else if (state.display->current_mode()) { | 146 } else if (state.display->current_mode()) { |
| 130 external_display_on = true; | 147 external_display_on = true; |
| 131 } | 148 } |
| 132 } | 149 } |
| 133 internal_display_off_and_external_display_on_ = | 150 internal_display_off_and_external_display_on_ = |
| 134 internal_display_off && external_display_on; | 151 internal_display_off && external_display_on; |
| 135 } | 152 } |
| 136 #endif | 153 #endif |
| 137 | 154 |
| 138 } // namespace ash | 155 } // namespace ash |
| OLD | NEW |