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/system/audio/tray_audio.h" | 10 #include "ash/common/system/audio/tray_audio.h" |
| 11 #include "ash/common/system/tray/system_tray.h" | 11 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 13 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 14 #include "ash/public/cpp/shell_window_ids.h" | 14 #include "ash/public/cpp/shell_window_ids.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/wm/lock_state_controller.h" | 16 #include "ash/wm/lock_state_controller.h" |
| 17 #include "ash/wm/session_state_animator.h" | 17 #include "ash/wm/session_state_animator.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
| 20 #include "ui/display/types/display_snapshot.h" | 20 #include "ui/display/types/display_snapshot.h" |
| 21 #include "ui/events/event_handler.h" | |
| 22 #include "ui/wm/core/compound_event_filter.h" | 21 #include "ui/wm/core/compound_event_filter.h" |
| 23 | 22 |
| 24 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 24 #include "ash/wm/tablet_power_button_controller.h" | |
| 25 #include "chromeos/audio/cras_audio_handler.h" | 25 #include "chromeos/audio/cras_audio_handler.h" |
| 26 #include "chromeos/dbus/dbus_thread_manager.h" | 26 #include "chromeos/dbus/dbus_thread_manager.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace ash { | 29 namespace ash { |
| 30 | 30 |
| 31 PowerButtonController::PowerButtonController(LockStateController* controller) | 31 PowerButtonController::PowerButtonController(LockStateController* controller) |
| 32 : power_button_down_(false), | 32 : power_button_down_(false), |
| 33 lock_button_down_(false), | 33 lock_button_down_(false), |
| 34 volume_down_pressed_(false), | 34 volume_down_pressed_(false), |
| 35 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 36 volume_percent_before_screenshot_(0), | 36 volume_percent_before_screenshot_(0), |
| 37 #endif | 37 #endif |
| 38 brightness_is_zero_(false), | 38 brightness_is_zero_(false), |
| 39 internal_display_off_and_external_display_on_(false), | 39 internal_display_off_and_external_display_on_(false), |
| 40 has_legacy_power_button_( | 40 has_legacy_power_button_( |
| 41 base::CommandLine::ForCurrentProcess()->HasSwitch( | 41 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 42 switches::kAuraLegacyPowerButton)), | 42 switches::kAuraLegacyPowerButton)), |
| 43 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 44 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 44 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 45 switches::kAshEnableTouchView)), | 45 switches::kAshEnableTouchView)), |
| 46 #else | 46 #else |
| 47 enable_quick_lock_(false), | 47 enable_quick_lock_(false), |
| 48 #endif | 48 #endif |
| 49 controller_(controller) { | 49 controller_(controller) { |
| 50 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
| 51 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 51 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 52 this); | 52 this); |
| 53 tablet_controller_.reset(new TabletPowerButtonController(controller_)); | |
|
Daniel Erat
2016/11/07 20:54:41
do you mind renaming the "controller_" member to "
Qiang(Joe) Xu
2016/11/10 22:18:44
Done.
| |
| 53 Shell::GetInstance()->display_configurator()->AddObserver(this); | 54 Shell::GetInstance()->display_configurator()->AddObserver(this); |
| 54 #endif | 55 #endif |
| 55 Shell::GetInstance()->PrependPreTargetHandler(this); | 56 Shell::GetInstance()->PrependPreTargetHandler(this); |
| 56 } | 57 } |
| 57 | 58 |
| 58 PowerButtonController::~PowerButtonController() { | 59 PowerButtonController::~PowerButtonController() { |
| 59 Shell::GetInstance()->RemovePreTargetHandler(this); | 60 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 60 #if defined(OS_CHROMEOS) | 61 #if defined(OS_CHROMEOS) |
| 61 Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 62 Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
| 63 tablet_controller_.reset(); | |
| 62 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 64 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| 63 this); | 65 this); |
| 64 #endif | 66 #endif |
| 65 } | 67 } |
| 66 | 68 |
| 67 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 69 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
| 68 brightness_is_zero_ = percent <= 0.001; | 70 brightness_is_zero_ = percent <= 0.001; |
| 69 } | 71 } |
| 70 | 72 |
| 71 void PowerButtonController::OnPowerButtonEvent( | 73 void PowerButtonController::OnPowerButtonEvent( |
| 72 bool down, | 74 bool down, |
| 73 const base::TimeTicks& timestamp) { | 75 const base::TimeTicks& timestamp) { |
| 74 power_button_down_ = down; | 76 power_button_down_ = down; |
| 75 | 77 |
| 76 if (controller_->ShutdownRequested()) | 78 if (controller_->ShutdownRequested()) |
| 77 return; | 79 return; |
| 78 | 80 |
| 81 bool should_take_screenshot = down && volume_down_pressed_ && | |
| 82 WmShell::Get() | |
| 83 ->maximize_mode_controller() | |
| 84 ->IsMaximizeModeWindowManagerEnabled(); | |
| 85 | |
| 86 #if defined(OS_CHROMEOS) | |
| 87 if (!has_legacy_power_button_ && !should_take_screenshot && | |
| 88 tablet_controller_->ShouldHandlePowerButtonEvents()) { | |
| 89 tablet_controller_->OnPowerButtonEvent(down, timestamp, | |
| 90 brightness_is_zero_); | |
| 91 return; | |
| 92 } | |
| 93 #endif | |
| 94 | |
| 79 // Avoid starting the lock/shutdown sequence if the power button is pressed | 95 // Avoid starting the lock/shutdown sequence if the power button is pressed |
| 80 // while the screen is off (http://crbug.com/128451), unless an external | 96 // while the screen is off (http://crbug.com/128451), unless an external |
| 81 // display is still on (http://crosbug.com/p/24912). | 97 // display is still on (http://crosbug.com/p/24912). |
| 82 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 98 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
| 83 return; | 99 return; |
| 84 | 100 |
| 85 if (volume_down_pressed_ && down && | 101 if (should_take_screenshot) { |
| 86 WmShell::Get() | |
| 87 ->maximize_mode_controller() | |
| 88 ->IsMaximizeModeWindowManagerEnabled()) { | |
| 89 SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray(); | 102 SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray(); |
| 90 if (system_tray && system_tray->GetTrayAudio()) | 103 if (system_tray && system_tray->GetTrayAudio()) |
| 91 system_tray->GetTrayAudio()->HideDetailedView(false); | 104 system_tray->GetTrayAudio()->HideDetailedView(false); |
| 92 | 105 |
| 93 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | 106 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( |
| 94 TAKE_SCREENSHOT); | 107 TAKE_SCREENSHOT); |
| 95 | 108 |
| 96 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
| 97 // Restore volume. | 110 // Restore volume. |
| 98 chromeos::CrasAudioHandler* audio_handler = | 111 chromeos::CrasAudioHandler* audio_handler = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 } | 214 } |
| 202 | 215 |
| 203 void PowerButtonController::PowerButtonEventReceived( | 216 void PowerButtonController::PowerButtonEventReceived( |
| 204 bool down, | 217 bool down, |
| 205 const base::TimeTicks& timestamp) { | 218 const base::TimeTicks& timestamp) { |
| 206 OnPowerButtonEvent(down, timestamp); | 219 OnPowerButtonEvent(down, timestamp); |
| 207 } | 220 } |
| 208 #endif // defined(OS_CHROMEOS) | 221 #endif // defined(OS_CHROMEOS) |
| 209 | 222 |
| 210 } // namespace ash | 223 } // namespace ash |
| OLD | NEW |