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/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/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/system/tray/system_tray_notifier.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/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "ash/wm/lock_state_controller.h" | 15 #include "ash/wm/lock_state_controller.h" |
| 15 #include "ash/wm/session_state_animator.h" | 16 #include "ash/wm/session_state_animator.h" |
| 16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/task_runner.h" | |
| 19 #include "base/threading/thread_task_runner_handle.h" | |
| 17 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/display/types/display_snapshot.h" | 21 #include "ui/display/types/display_snapshot.h" |
| 19 #include "ui/events/event_handler.h" | 22 #include "ui/events/event_handler.h" |
| 20 #include "ui/wm/core/compound_event_filter.h" | 23 #include "ui/wm/core/compound_event_filter.h" |
| 21 | 24 |
| 22 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
| 26 #include "chromeos/audio/cras_audio_handler.h" | |
| 23 #include "chromeos/dbus/dbus_thread_manager.h" | 27 #include "chromeos/dbus/dbus_thread_manager.h" |
| 24 #endif | 28 #endif |
| 25 | 29 |
| 26 namespace ash { | 30 namespace ash { |
| 27 | 31 |
| 32 namespace { | |
| 33 const int kWaitVolumeSliderHiddenInMs = 200; | |
| 34 } // namespace | |
| 35 | |
| 28 PowerButtonController::PowerButtonController(LockStateController* controller) | 36 PowerButtonController::PowerButtonController(LockStateController* controller) |
| 29 : power_button_down_(false), | 37 : power_button_down_(false), |
| 30 lock_button_down_(false), | 38 lock_button_down_(false), |
| 31 volume_down_pressed_(false), | 39 volume_down_pressed_(false), |
| 40 first_pressed_volume_percent_(0), | |
| 41 volume_down_first_(false), | |
| 32 brightness_is_zero_(false), | 42 brightness_is_zero_(false), |
| 33 internal_display_off_and_external_display_on_(false), | 43 internal_display_off_and_external_display_on_(false), |
| 34 has_legacy_power_button_( | 44 has_legacy_power_button_( |
| 35 base::CommandLine::ForCurrentProcess()->HasSwitch( | 45 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 36 switches::kAuraLegacyPowerButton)), | 46 switches::kAuraLegacyPowerButton)), |
| 37 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 38 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 48 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 39 switches::kAshEnableTouchView)), | 49 switches::kAshEnableTouchView)), |
| 40 #else | 50 #else |
| 41 enable_quick_lock_(false), | 51 enable_quick_lock_(false), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 // Avoid starting the lock/shutdown sequence if the power button is pressed | 83 // Avoid starting the lock/shutdown sequence if the power button is pressed |
| 74 // while the screen is off (http://crbug.com/128451), unless an external | 84 // while the screen is off (http://crbug.com/128451), unless an external |
| 75 // display is still on (http://crosbug.com/p/24912). | 85 // display is still on (http://crosbug.com/p/24912). |
| 76 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 86 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
| 77 return; | 87 return; |
| 78 | 88 |
| 79 if (volume_down_pressed_ && down && | 89 if (volume_down_pressed_ && down && |
| 80 WmShell::Get() | 90 WmShell::Get() |
| 81 ->maximize_mode_controller() | 91 ->maximize_mode_controller() |
| 82 ->IsMaximizeModeWindowManagerEnabled()) { | 92 ->IsMaximizeModeWindowManagerEnabled()) { |
| 83 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | 93 WmShell::Get()->system_tray_notifier()->NotifyWillTakeScreenshot( |
| 84 TAKE_SCREENSHOT); | 94 first_pressed_volume_percent_); |
| 95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 96 FROM_HERE, base::Bind(&PowerButtonController::TakingScreenshot, | |
| 97 base::Unretained(this)), | |
| 98 base::TimeDelta::FromMilliseconds(kWaitVolumeSliderHiddenInMs)); | |
| 85 return; | 99 return; |
| 86 } | 100 } |
| 87 | 101 |
| 88 const SessionStateDelegate* session_state_delegate = | 102 const SessionStateDelegate* session_state_delegate = |
| 89 WmShell::Get()->GetSessionStateDelegate(); | 103 WmShell::Get()->GetSessionStateDelegate(); |
| 90 if (has_legacy_power_button_) { | 104 if (has_legacy_power_button_) { |
| 91 // If power button releases won't get reported correctly because we're not | 105 // If power button releases won't get reported correctly because we're not |
| 92 // running on official hardware, just lock the screen or shut down | 106 // running on official hardware, just lock the screen or shut down |
| 93 // immediately. | 107 // immediately. |
| 94 if (down) { | 108 if (down) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 if (power_button_down_) | 158 if (power_button_down_) |
| 145 return; | 159 return; |
| 146 | 160 |
| 147 if (down) | 161 if (down) |
| 148 controller_->StartLockAnimation(false); | 162 controller_->StartLockAnimation(false); |
| 149 else | 163 else |
| 150 controller_->CancelLockAnimation(); | 164 controller_->CancelLockAnimation(); |
| 151 } | 165 } |
| 152 | 166 |
| 153 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 167 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
| 154 if (event->key_code() == ui::VKEY_VOLUME_DOWN) | 168 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
| 155 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; | 169 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; |
| 170 #if defined(OS_CHROMEOS) | |
| 171 if (event->type() == ui::ET_KEY_RELEASED) { | |
| 172 volume_down_first_ = false; | |
| 173 return; | |
| 174 } | |
| 175 // We should avoid saving volume to |first_pressed_volume_percent_| if that | |
| 176 // is continuous press. | |
| 177 if (!volume_down_first_) { | |
|
Daniel Erat
2016/07/27 23:51:31
can't you use event->is_repeat() to determine if t
Qiang(Joe) Xu
2016/07/28 00:15:39
Yes. Just find it. I will update it later.
| |
| 178 chromeos::CrasAudioHandler* audio_handler = | |
| 179 chromeos::CrasAudioHandler::Get(); | |
| 180 DCHECK(audio_handler->IsInitialized()); | |
| 181 first_pressed_volume_percent_ = audio_handler->GetOutputVolumePercent(); | |
| 182 volume_down_first_ = true; | |
| 183 } | |
| 184 #endif | |
| 185 } | |
| 156 } | 186 } |
| 157 | 187 |
| 158 #if defined(OS_CHROMEOS) | 188 #if defined(OS_CHROMEOS) |
| 159 void PowerButtonController::OnDisplayModeChanged( | 189 void PowerButtonController::OnDisplayModeChanged( |
| 160 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 190 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
| 161 bool internal_display_off = false; | 191 bool internal_display_off = false; |
| 162 bool external_display_on = false; | 192 bool external_display_on = false; |
| 163 for (const ui::DisplaySnapshot* display : display_states) { | 193 for (const ui::DisplaySnapshot* display : display_states) { |
| 164 if (display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 194 if (display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
| 165 if (!display->current_mode()) | 195 if (!display->current_mode()) |
| 166 internal_display_off = true; | 196 internal_display_off = true; |
| 167 } else if (display->current_mode()) { | 197 } else if (display->current_mode()) { |
| 168 external_display_on = true; | 198 external_display_on = true; |
| 169 } | 199 } |
| 170 } | 200 } |
| 171 internal_display_off_and_external_display_on_ = | 201 internal_display_off_and_external_display_on_ = |
| 172 internal_display_off && external_display_on; | 202 internal_display_off && external_display_on; |
| 173 } | 203 } |
| 174 | 204 |
| 175 void PowerButtonController::PowerButtonEventReceived( | 205 void PowerButtonController::PowerButtonEventReceived( |
| 176 bool down, | 206 bool down, |
| 177 const base::TimeTicks& timestamp) { | 207 const base::TimeTicks& timestamp) { |
| 178 OnPowerButtonEvent(down, timestamp); | 208 OnPowerButtonEvent(down, timestamp); |
| 179 } | 209 } |
| 180 #endif // defined(OS_CHROMEOS) | 210 #endif // defined(OS_CHROMEOS) |
| 181 | 211 |
| 212 void PowerButtonController::TakingScreenshot() { | |
| 213 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | |
| 214 TAKE_SCREENSHOT); | |
| 215 } | |
| 216 | |
| 182 } // namespace ash | 217 } // namespace ash |
| OLD | NEW |