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/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
13 #include "ash/public/cpp/shell_window_ids.h" | 13 #include "ash/public/cpp/shell_window_ids.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/wm/lock_state_controller.h" | 15 #include "ash/wm/lock_state_controller.h" |
16 #include "ash/wm/session_state_animator.h" | 16 #include "ash/wm/session_state_animator.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
19 #include "ui/display/types/display_snapshot.h" | 19 #include "ui/display/types/display_snapshot.h" |
| 20 #include "ui/events/event_handler.h" |
20 #include "ui/wm/core/compound_event_filter.h" | 21 #include "ui/wm/core/compound_event_filter.h" |
21 | 22 |
22 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
23 #include "ash/common/system/chromeos/audio/tray_audio.h" | 24 #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" | 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 lock_state_controller_(controller) { | 43 #if defined(OS_CHROMEOS) |
| 44 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 45 switches::kAshEnableTouchView)), |
| 46 #else |
| 47 enable_quick_lock_(false), |
| 48 #endif |
| 49 controller_(controller) { |
44 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
45 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 51 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
46 this); | 52 this); |
47 tablet_controller_.reset( | |
48 new TabletPowerButtonController(lock_state_controller_)); | |
49 Shell::GetInstance()->display_configurator()->AddObserver(this); | 53 Shell::GetInstance()->display_configurator()->AddObserver(this); |
50 #endif | 54 #endif |
51 Shell::GetInstance()->PrependPreTargetHandler(this); | 55 Shell::GetInstance()->PrependPreTargetHandler(this); |
52 } | 56 } |
53 | 57 |
54 PowerButtonController::~PowerButtonController() { | 58 PowerButtonController::~PowerButtonController() { |
55 Shell::GetInstance()->RemovePreTargetHandler(this); | 59 Shell::GetInstance()->RemovePreTargetHandler(this); |
56 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
57 Shell::GetInstance()->display_configurator()->RemoveObserver(this); | 61 Shell::GetInstance()->display_configurator()->RemoveObserver(this); |
58 tablet_controller_.reset(); | |
59 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 62 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
60 this); | 63 this); |
61 #endif | 64 #endif |
62 } | 65 } |
63 | 66 |
64 void PowerButtonController::OnScreenBrightnessChanged(double percent) { | 67 void PowerButtonController::OnScreenBrightnessChanged(double percent) { |
65 brightness_is_zero_ = percent <= 0.001; | 68 brightness_is_zero_ = percent <= 0.001; |
66 } | 69 } |
67 | 70 |
68 void PowerButtonController::OnPowerButtonEvent( | 71 void PowerButtonController::OnPowerButtonEvent( |
69 bool down, | 72 bool down, |
70 const base::TimeTicks& timestamp) { | 73 const base::TimeTicks& timestamp) { |
71 power_button_down_ = down; | 74 power_button_down_ = down; |
72 | 75 |
73 if (lock_state_controller_->ShutdownRequested()) | 76 if (controller_->ShutdownRequested()) |
74 return; | 77 return; |
75 | 78 |
76 #if defined(OS_CHROMEOS) | |
77 bool should_take_screenshot = down && volume_down_pressed_ && | |
78 WmShell::Get() | |
79 ->maximize_mode_controller() | |
80 ->IsMaximizeModeWindowManagerEnabled(); | |
81 | |
82 if (!has_legacy_power_button_ && !should_take_screenshot && | |
83 tablet_controller_->ShouldHandlePowerButtonEvents()) { | |
84 tablet_controller_->OnPowerButtonEvent(down, timestamp); | |
85 return; | |
86 } | |
87 #endif | |
88 | |
89 // Avoid starting the lock/shutdown sequence if the power button is pressed | 79 // Avoid starting the lock/shutdown sequence if the power button is pressed |
90 // while the screen is off (http://crbug.com/128451), unless an external | 80 // while the screen is off (http://crbug.com/128451), unless an external |
91 // display is still on (http://crosbug.com/p/24912). | 81 // display is still on (http://crosbug.com/p/24912). |
92 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 82 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
93 return; | 83 return; |
94 | 84 |
95 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
96 // Take screenshot on power button down plus volume down when in touch view. | 86 // Take screenshot on power button down plus volume down when in touch view. |
97 if (should_take_screenshot) { | 87 if (volume_down_pressed_ && down && |
| 88 WmShell::Get() |
| 89 ->maximize_mode_controller() |
| 90 ->IsMaximizeModeWindowManagerEnabled()) { |
98 SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray(); | 91 SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray(); |
99 if (system_tray && system_tray->GetTrayAudio()) | 92 if (system_tray && system_tray->GetTrayAudio()) |
100 system_tray->GetTrayAudio()->HideDetailedView(false); | 93 system_tray->GetTrayAudio()->HideDetailedView(false); |
101 | 94 |
102 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | 95 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( |
103 TAKE_SCREENSHOT); | 96 TAKE_SCREENSHOT); |
104 | 97 |
105 // Restore volume. | 98 // Restore volume. |
106 chromeos::CrasAudioHandler* audio_handler = | 99 chromeos::CrasAudioHandler* audio_handler = |
107 chromeos::CrasAudioHandler::Get(); | 100 chromeos::CrasAudioHandler::Get(); |
108 audio_handler->SetOutputVolumePercentWithoutNotifyingObservers( | 101 audio_handler->SetOutputVolumePercentWithoutNotifyingObservers( |
109 volume_percent_before_screenshot_, | 102 volume_percent_before_screenshot_, |
110 chromeos::CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); | 103 chromeos::CrasAudioHandler::VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT); |
111 return; | 104 return; |
112 } | 105 } |
113 #endif // defined(OS_CHROMEOS) | 106 #endif // defined(OS_CHROMEOS) |
114 | 107 |
115 const SessionStateDelegate* session_state_delegate = | 108 const SessionStateDelegate* session_state_delegate = |
116 WmShell::Get()->GetSessionStateDelegate(); | 109 WmShell::Get()->GetSessionStateDelegate(); |
117 if (has_legacy_power_button_) { | 110 if (has_legacy_power_button_) { |
118 // 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 |
119 // running on official hardware, just lock the screen or shut down | 112 // running on official hardware, just lock the screen or shut down |
120 // immediately. | 113 // immediately. |
121 if (down) { | 114 if (down) { |
122 if (session_state_delegate->CanLockScreen() && | 115 if (session_state_delegate->CanLockScreen() && |
123 !session_state_delegate->IsUserSessionBlocked() && | 116 !session_state_delegate->IsUserSessionBlocked() && |
124 !lock_state_controller_->LockRequested()) { | 117 !controller_->LockRequested()) { |
125 lock_state_controller_->StartLockAnimationAndLockImmediately(false); | 118 controller_->StartLockAnimationAndLockImmediately(false); |
126 } else { | 119 } else { |
127 lock_state_controller_->RequestShutdown(); | 120 controller_->RequestShutdown(); |
128 } | 121 } |
129 } | 122 } |
130 } else { // !has_legacy_power_button_ | 123 } else { // !has_legacy_power_button_ |
131 if (down) { | 124 if (down) { |
132 // If we already have a pending request to lock the screen, wait. | 125 // If we already have a pending request to lock the screen, wait. |
133 if (lock_state_controller_->LockRequested()) | 126 if (controller_->LockRequested()) |
134 return; | 127 return; |
135 | 128 |
136 if (session_state_delegate->CanLockScreen() && | 129 if (session_state_delegate->CanLockScreen() && |
137 !session_state_delegate->IsUserSessionBlocked()) { | 130 !session_state_delegate->IsUserSessionBlocked()) { |
138 lock_state_controller_->StartLockAnimation(true); | 131 if (WmShell::Get() |
| 132 ->maximize_mode_controller() |
| 133 ->IsMaximizeModeWindowManagerEnabled() && |
| 134 enable_quick_lock_) |
| 135 controller_->StartLockAnimationAndLockImmediately(true); |
| 136 else |
| 137 controller_->StartLockAnimation(true); |
139 } else { | 138 } else { |
140 lock_state_controller_->StartShutdownAnimation(); | 139 controller_->StartShutdownAnimation(); |
141 } | 140 } |
142 } else { // Button is up. | 141 } else { // Button is up. |
143 if (lock_state_controller_->CanCancelLockAnimation()) | 142 if (controller_->CanCancelLockAnimation()) |
144 lock_state_controller_->CancelLockAnimation(); | 143 controller_->CancelLockAnimation(); |
145 else if (lock_state_controller_->CanCancelShutdownAnimation()) | 144 else if (controller_->CanCancelShutdownAnimation()) |
146 lock_state_controller_->CancelShutdownAnimation(); | 145 controller_->CancelShutdownAnimation(); |
147 } | 146 } |
148 } | 147 } |
149 } | 148 } |
150 | 149 |
151 void PowerButtonController::OnLockButtonEvent( | 150 void PowerButtonController::OnLockButtonEvent( |
152 bool down, | 151 bool down, |
153 const base::TimeTicks& timestamp) { | 152 const base::TimeTicks& timestamp) { |
154 lock_button_down_ = down; | 153 lock_button_down_ = down; |
155 | 154 |
156 const SessionStateDelegate* session_state_delegate = | 155 const SessionStateDelegate* session_state_delegate = |
157 WmShell::Get()->GetSessionStateDelegate(); | 156 WmShell::Get()->GetSessionStateDelegate(); |
158 if (!session_state_delegate->CanLockScreen() || | 157 if (!session_state_delegate->CanLockScreen() || |
159 session_state_delegate->IsScreenLocked() || | 158 session_state_delegate->IsScreenLocked() || |
160 lock_state_controller_->LockRequested() || | 159 controller_->LockRequested() || controller_->ShutdownRequested()) { |
161 lock_state_controller_->ShutdownRequested()) { | |
162 return; | 160 return; |
163 } | 161 } |
164 | 162 |
165 // Give the power button precedence over the lock button. | 163 // Give the power button precedence over the lock button. |
166 if (power_button_down_) | 164 if (power_button_down_) |
167 return; | 165 return; |
168 | 166 |
169 if (down) | 167 if (down) |
170 lock_state_controller_->StartLockAnimation(false); | 168 controller_->StartLockAnimation(false); |
171 else | 169 else |
172 lock_state_controller_->CancelLockAnimation(); | 170 controller_->CancelLockAnimation(); |
173 } | 171 } |
174 | 172 |
175 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 173 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
176 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { | 174 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
177 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; | 175 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; |
178 #if defined(OS_CHROMEOS) | 176 #if defined(OS_CHROMEOS) |
179 if (!event->is_repeat()) { | 177 if (!event->is_repeat()) { |
180 chromeos::CrasAudioHandler* audio_handler = | 178 chromeos::CrasAudioHandler* audio_handler = |
181 chromeos::CrasAudioHandler::Get(); | 179 chromeos::CrasAudioHandler::Get(); |
182 volume_percent_before_screenshot_ = | 180 volume_percent_before_screenshot_ = |
(...skipping 21 matching lines...) Expand all Loading... |
204 } | 202 } |
205 | 203 |
206 void PowerButtonController::PowerButtonEventReceived( | 204 void PowerButtonController::PowerButtonEventReceived( |
207 bool down, | 205 bool down, |
208 const base::TimeTicks& timestamp) { | 206 const base::TimeTicks& timestamp) { |
209 OnPowerButtonEvent(down, timestamp); | 207 OnPowerButtonEvent(down, timestamp); |
210 } | 208 } |
211 #endif // defined(OS_CHROMEOS) | 209 #endif // defined(OS_CHROMEOS) |
212 | 210 |
213 } // namespace ash | 211 } // namespace ash |
OLD | NEW |