| 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/common/accelerators/accelerator_controller.h" | 7 #include "ash/common/accelerators/accelerator_controller.h" |
| 8 #include "ash/common/ash_switches.h" | 8 #include "ash/common/ash_switches.h" |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/system/chromeos/audio/tray_audio.h" |
| 10 #include "ash/common/system/tray/system_tray.h" | 11 #include "ash/common/system/tray/system_tray.h" |
| 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 13 #include "ash/public/cpp/shell_window_ids.h" | 14 #include "ash/public/cpp/shell_window_ids.h" |
| 14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/system/chromeos/power/tablet_power_button_controller.h" |
| 15 #include "ash/wm/lock_state_controller.h" | 17 #include "ash/wm/lock_state_controller.h" |
| 16 #include "ash/wm/session_state_animator.h" | 18 #include "ash/wm/session_state_animator.h" |
| 17 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "chromeos/audio/cras_audio_handler.h" |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 18 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
| 19 #include "ui/display/types/display_snapshot.h" | 23 #include "ui/display/types/display_snapshot.h" |
| 20 #include "ui/wm/core/compound_event_filter.h" | 24 #include "ui/wm/core/compound_event_filter.h" |
| 21 | 25 |
| 22 #if defined(OS_CHROMEOS) | |
| 23 #include "ash/common/system/chromeos/audio/tray_audio.h" | |
| 24 #include "ash/system/chromeos/power/tablet_power_button_controller.h" | |
| 25 #include "chromeos/audio/cras_audio_handler.h" | |
| 26 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 27 #endif | |
| 28 | |
| 29 namespace ash { | 26 namespace ash { |
| 30 | 27 |
| 31 PowerButtonController::PowerButtonController(LockStateController* controller) | 28 PowerButtonController::PowerButtonController(LockStateController* controller) |
| 32 : power_button_down_(false), | 29 : power_button_down_(false), |
| 33 lock_button_down_(false), | 30 lock_button_down_(false), |
| 34 volume_down_pressed_(false), | 31 volume_down_pressed_(false), |
| 35 #if defined(OS_CHROMEOS) | |
| 36 volume_percent_before_screenshot_(0), | 32 volume_percent_before_screenshot_(0), |
| 37 #endif | |
| 38 brightness_is_zero_(false), | 33 brightness_is_zero_(false), |
| 39 internal_display_off_and_external_display_on_(false), | 34 internal_display_off_and_external_display_on_(false), |
| 40 has_legacy_power_button_( | 35 has_legacy_power_button_( |
| 41 base::CommandLine::ForCurrentProcess()->HasSwitch( | 36 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 42 switches::kAuraLegacyPowerButton)), | 37 switches::kAuraLegacyPowerButton)), |
| 43 lock_state_controller_(controller) { | 38 lock_state_controller_(controller) { |
| 44 #if defined(OS_CHROMEOS) | |
| 45 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 39 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 46 this); | 40 this); |
| 47 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 41 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 48 switches::kAshEnableTouchView) || | 42 switches::kAshEnableTouchView) || |
| 49 base::CommandLine::ForCurrentProcess()->HasSwitch( | 43 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 50 switches::kAshEnableTouchViewTesting)) { | 44 switches::kAshEnableTouchViewTesting)) { |
| 51 tablet_controller_.reset( | 45 tablet_controller_.reset( |
| 52 new TabletPowerButtonController(lock_state_controller_)); | 46 new TabletPowerButtonController(lock_state_controller_)); |
| 53 } | 47 } |
| 54 Shell::GetInstance()->display_configurator()->AddObserver(this); | 48 Shell::GetInstance()->display_configurator()->AddObserver(this); |
| 55 #endif | |
| 56 Shell::GetInstance()->PrependPreTargetHandler(this); | 49 Shell::GetInstance()->PrependPreTargetHandler(this); |
| 57 } | 50 } |
| 58 | 51 |
| 59 PowerButtonController::~PowerButtonController() { | 52 PowerButtonController::~PowerButtonController() { |
| 60 Shell::GetInstance()->RemovePreTargetHandler(this); | 53 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 61 #if defined(OS_CHROMEOS) | |
| 62 Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 54 Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
| 63 tablet_controller_.reset(); | 55 tablet_controller_.reset(); |
| 64 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| 65 this); | 57 this); |
| 66 #endif | |
| 67 } | 58 } |
| 68 | 59 |
| 69 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 60 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
| 70 brightness_is_zero_ = percent <= 0.001; | 61 brightness_is_zero_ = percent <= 0.001; |
| 71 } | 62 } |
| 72 | 63 |
| 73 void PowerButtonController::OnPowerButtonEvent( | 64 void PowerButtonController::OnPowerButtonEvent( |
| 74 bool down, | 65 bool down, |
| 75 const base::TimeTicks& timestamp) { | 66 const base::TimeTicks& timestamp) { |
| 76 power_button_down_ = down; | 67 power_button_down_ = down; |
| 77 | 68 |
| 78 if (lock_state_controller_->ShutdownRequested()) | 69 if (lock_state_controller_->ShutdownRequested()) |
| 79 return; | 70 return; |
| 80 | 71 |
| 81 #if defined(OS_CHROMEOS) | |
| 82 bool should_take_screenshot = down && volume_down_pressed_ && | 72 bool should_take_screenshot = down && volume_down_pressed_ && |
| 83 WmShell::Get() | 73 WmShell::Get() |
| 84 ->maximize_mode_controller() | 74 ->maximize_mode_controller() |
| 85 ->IsMaximizeModeWindowManagerEnabled(); | 75 ->IsMaximizeModeWindowManagerEnabled(); |
| 86 | 76 |
| 87 if (!has_legacy_power_button_ && !should_take_screenshot && | 77 if (!has_legacy_power_button_ && !should_take_screenshot && |
| 88 tablet_controller_ && | 78 tablet_controller_ && |
| 89 tablet_controller_->ShouldHandlePowerButtonEvents()) { | 79 tablet_controller_->ShouldHandlePowerButtonEvents()) { |
| 90 tablet_controller_->OnPowerButtonEvent(down, timestamp); | 80 tablet_controller_->OnPowerButtonEvent(down, timestamp); |
| 91 return; | 81 return; |
| 92 } | 82 } |
| 93 #endif | |
| 94 | 83 |
| 95 // Avoid starting the lock/shutdown sequence if the power button is pressed | 84 // Avoid starting the lock/shutdown sequence if the power button is pressed |
| 96 // while the screen is off (http://crbug.com/128451), unless an external | 85 // while the screen is off (http://crbug.com/128451), unless an external |
| 97 // display is still on (http://crosbug.com/p/24912). | 86 // display is still on (http://crosbug.com/p/24912). |
| 98 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 87 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
| 99 return; | 88 return; |
| 100 | 89 |
| 101 #if defined(OS_CHROMEOS) | |
| 102 // Take screenshot on power button down plus volume down when in touch view. | 90 // Take screenshot on power button down plus volume down when in touch view. |
| 103 if (should_take_screenshot) { | 91 if (should_take_screenshot) { |
| 104 SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray(); | 92 SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray(); |
| 105 if (system_tray && system_tray->GetTrayAudio()) | 93 if (system_tray && system_tray->GetTrayAudio()) |
| 106 system_tray->GetTrayAudio()->HideDetailedView(false); | 94 system_tray->GetTrayAudio()->HideDetailedView(false); |
| 107 | 95 |
| 108 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | 96 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( |
| 109 TAKE_SCREENSHOT); | 97 TAKE_SCREENSHOT); |
| 110 | 98 |
| 111 // Restore volume. | 99 // Restore volume. |
| 112 chromeos::CrasAudioHandler* audio_handler = | 100 chromeos::CrasAudioHandler* audio_handler = |
| 113 chromeos::CrasAudioHandler::Get(); | 101 chromeos::CrasAudioHandler::Get(); |
| 114 audio_handler->SetOutputVolumePercentWithoutNotifyingObservers( | 102 audio_handler->SetOutputVolumePercentWithoutNotifyingObservers( |
| 115 volume_percent_before_screenshot_, | 103 volume_percent_before_screenshot_, |
| 116 chromeos::CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); | 104 chromeos::CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); |
| 117 return; | 105 return; |
| 118 } | 106 } |
| 119 #endif // defined(OS_CHROMEOS) | |
| 120 | 107 |
| 121 const SessionStateDelegate* session_state_delegate = | 108 const SessionStateDelegate* session_state_delegate = |
| 122 WmShell::Get()->GetSessionStateDelegate(); | 109 WmShell::Get()->GetSessionStateDelegate(); |
| 123 if (has_legacy_power_button_) { | 110 if (has_legacy_power_button_) { |
| 124 // If power button releases won't get reported correctly because we're not | 111 // If power button releases won't get reported correctly because we're not |
| 125 // running on official hardware, just lock the screen or shut down | 112 // running on official hardware, just lock the screen or shut down |
| 126 // immediately. | 113 // immediately. |
| 127 if (down) { | 114 if (down) { |
| 128 if (session_state_delegate->CanLockScreen() && | 115 if (session_state_delegate->CanLockScreen() && |
| 129 !session_state_delegate->IsUserSessionBlocked() && | 116 !session_state_delegate->IsUserSessionBlocked() && |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 161 |
| 175 if (down) | 162 if (down) |
| 176 lock_state_controller_->StartLockAnimation(false); | 163 lock_state_controller_->StartLockAnimation(false); |
| 177 else | 164 else |
| 178 lock_state_controller_->CancelLockAnimation(); | 165 lock_state_controller_->CancelLockAnimation(); |
| 179 } | 166 } |
| 180 | 167 |
| 181 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 168 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
| 182 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { | 169 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
| 183 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; | 170 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; |
| 184 #if defined(OS_CHROMEOS) | |
| 185 if (!event->is_repeat()) { | 171 if (!event->is_repeat()) { |
| 186 chromeos::CrasAudioHandler* audio_handler = | 172 chromeos::CrasAudioHandler* audio_handler = |
| 187 chromeos::CrasAudioHandler::Get(); | 173 chromeos::CrasAudioHandler::Get(); |
| 188 volume_percent_before_screenshot_ = | 174 volume_percent_before_screenshot_ = |
| 189 audio_handler->GetOutputVolumePercent(); | 175 audio_handler->GetOutputVolumePercent(); |
| 190 } | 176 } |
| 191 #endif | |
| 192 } | 177 } |
| 193 } | 178 } |
| 194 | 179 |
| 195 #if defined(OS_CHROMEOS) | |
| 196 void PowerButtonController::OnDisplayModeChanged( | 180 void PowerButtonController::OnDisplayModeChanged( |
| 197 const display::DisplayConfigurator::DisplayStateList& display_states) { | 181 const display::DisplayConfigurator::DisplayStateList& display_states) { |
| 198 bool internal_display_off = false; | 182 bool internal_display_off = false; |
| 199 bool external_display_on = false; | 183 bool external_display_on = false; |
| 200 for (const display::DisplaySnapshot* display : display_states) { | 184 for (const display::DisplaySnapshot* display : display_states) { |
| 201 if (display->type() == display::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 185 if (display->type() == display::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
| 202 if (!display->current_mode()) | 186 if (!display->current_mode()) |
| 203 internal_display_off = true; | 187 internal_display_off = true; |
| 204 } else if (display->current_mode()) { | 188 } else if (display->current_mode()) { |
| 205 external_display_on = true; | 189 external_display_on = true; |
| 206 } | 190 } |
| 207 } | 191 } |
| 208 internal_display_off_and_external_display_on_ = | 192 internal_display_off_and_external_display_on_ = |
| 209 internal_display_off && external_display_on; | 193 internal_display_off && external_display_on; |
| 210 } | 194 } |
| 211 | 195 |
| 212 void PowerButtonController::PowerButtonEventReceived( | 196 void PowerButtonController::PowerButtonEventReceived( |
| 213 bool down, | 197 bool down, |
| 214 const base::TimeTicks& timestamp) { | 198 const base::TimeTicks& timestamp) { |
| 215 OnPowerButtonEvent(down, timestamp); | 199 OnPowerButtonEvent(down, timestamp); |
| 216 } | 200 } |
| 217 #endif // defined(OS_CHROMEOS) | |
| 218 | 201 |
| 219 } // namespace ash | 202 } // namespace ash |
| OLD | NEW |