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; | |
Daniel Erat
2016/07/28 04:45:00
this isn't good; it means there's a delay between
Qiang(Joe) Xu
2016/07/28 20:25:02
done by disable hiding animation.
| |
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 saved_volume_percent_(0), | |
32 brightness_is_zero_(false), | 41 brightness_is_zero_(false), |
33 internal_display_off_and_external_display_on_(false), | 42 internal_display_off_and_external_display_on_(false), |
34 has_legacy_power_button_( | 43 has_legacy_power_button_( |
35 base::CommandLine::ForCurrentProcess()->HasSwitch( | 44 base::CommandLine::ForCurrentProcess()->HasSwitch( |
36 switches::kAuraLegacyPowerButton)), | 45 switches::kAuraLegacyPowerButton)), |
37 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
38 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 47 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
39 switches::kAshEnableTouchView)), | 48 switches::kAshEnableTouchView)), |
40 #else | 49 #else |
41 enable_quick_lock_(false), | 50 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 | 82 // 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 | 83 // while the screen is off (http://crbug.com/128451), unless an external |
75 // display is still on (http://crosbug.com/p/24912). | 84 // display is still on (http://crosbug.com/p/24912). |
76 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 85 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
77 return; | 86 return; |
78 | 87 |
79 if (volume_down_pressed_ && down && | 88 if (volume_down_pressed_ && down && |
80 WmShell::Get() | 89 WmShell::Get() |
81 ->maximize_mode_controller() | 90 ->maximize_mode_controller() |
82 ->IsMaximizeModeWindowManagerEnabled()) { | 91 ->IsMaximizeModeWindowManagerEnabled()) { |
83 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | 92 // Notify that maximize mode screenshot is going to be taken. Receiver does |
84 TAKE_SCREENSHOT); | 93 // preparation work. |
94 WmShell::Get() | |
95 ->system_tray_notifier() | |
96 ->NotifyWillTakeScreenshotInMaximizeMode(); | |
97 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
98 FROM_HERE, base::Bind(&PowerButtonController::TakingScreenshot, | |
99 base::Unretained(this)), | |
100 base::TimeDelta::FromMilliseconds(kWaitVolumeSliderHiddenInMs)); | |
85 return; | 101 return; |
102 | |
103 #if defined(OS_CHROMEOS) | |
104 // Restore volume. | |
105 chromeos::CrasAudioHandler* audio_handler = | |
106 chromeos::CrasAudioHandler::Get(); | |
107 DCHECK(audio_handler->IsInitialized()); | |
Daniel Erat
2016/07/28 04:45:00
you don't need this; Get() on the previous line al
Qiang(Joe) Xu
2016/07/28 20:25:02
Done.
| |
108 audio_handler->SetOutputVolumePercent(saved_volume_percent_); | |
109 #endif | |
86 } | 110 } |
87 | 111 |
88 const SessionStateDelegate* session_state_delegate = | 112 const SessionStateDelegate* session_state_delegate = |
89 WmShell::Get()->GetSessionStateDelegate(); | 113 WmShell::Get()->GetSessionStateDelegate(); |
90 if (has_legacy_power_button_) { | 114 if (has_legacy_power_button_) { |
91 // If power button releases won't get reported correctly because we're not | 115 // 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 | 116 // running on official hardware, just lock the screen or shut down |
93 // immediately. | 117 // immediately. |
94 if (down) { | 118 if (down) { |
95 if (session_state_delegate->CanLockScreen() && | 119 if (session_state_delegate->CanLockScreen() && |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 if (power_button_down_) | 168 if (power_button_down_) |
145 return; | 169 return; |
146 | 170 |
147 if (down) | 171 if (down) |
148 controller_->StartLockAnimation(false); | 172 controller_->StartLockAnimation(false); |
149 else | 173 else |
150 controller_->CancelLockAnimation(); | 174 controller_->CancelLockAnimation(); |
151 } | 175 } |
152 | 176 |
153 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 177 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
154 if (event->key_code() == ui::VKEY_VOLUME_DOWN) | 178 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
155 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; | 179 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; |
180 #if defined(OS_CHROMEOS) | |
181 // Avoid saving to |saved_volume_percent_| if that is repeated pressing. | |
Daniel Erat
2016/07/28 04:45:00
nit: delete this comment; the code is self-explana
| |
182 if (!event->is_repeat()) { | |
183 chromeos::CrasAudioHandler* audio_handler = | |
184 chromeos::CrasAudioHandler::Get(); | |
185 DCHECK(audio_handler->IsInitialized()); | |
Daniel Erat
2016/07/28 04:45:00
delete this too
| |
186 saved_volume_percent_ = audio_handler->GetOutputVolumePercent(); | |
187 } | |
188 #endif | |
189 } | |
156 } | 190 } |
157 | 191 |
158 #if defined(OS_CHROMEOS) | 192 #if defined(OS_CHROMEOS) |
159 void PowerButtonController::OnDisplayModeChanged( | 193 void PowerButtonController::OnDisplayModeChanged( |
160 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 194 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
161 bool internal_display_off = false; | 195 bool internal_display_off = false; |
162 bool external_display_on = false; | 196 bool external_display_on = false; |
163 for (const ui::DisplaySnapshot* display : display_states) { | 197 for (const ui::DisplaySnapshot* display : display_states) { |
164 if (display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 198 if (display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
165 if (!display->current_mode()) | 199 if (!display->current_mode()) |
166 internal_display_off = true; | 200 internal_display_off = true; |
167 } else if (display->current_mode()) { | 201 } else if (display->current_mode()) { |
168 external_display_on = true; | 202 external_display_on = true; |
169 } | 203 } |
170 } | 204 } |
171 internal_display_off_and_external_display_on_ = | 205 internal_display_off_and_external_display_on_ = |
172 internal_display_off && external_display_on; | 206 internal_display_off && external_display_on; |
173 } | 207 } |
174 | 208 |
175 void PowerButtonController::PowerButtonEventReceived( | 209 void PowerButtonController::PowerButtonEventReceived( |
176 bool down, | 210 bool down, |
177 const base::TimeTicks& timestamp) { | 211 const base::TimeTicks& timestamp) { |
178 OnPowerButtonEvent(down, timestamp); | 212 OnPowerButtonEvent(down, timestamp); |
179 } | 213 } |
180 #endif // defined(OS_CHROMEOS) | 214 #endif // defined(OS_CHROMEOS) |
181 | 215 |
216 void PowerButtonController::TakingScreenshot() { | |
217 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | |
218 TAKE_SCREENSHOT); | |
219 } | |
220 | |
182 } // namespace ash | 221 } // namespace ash |
OLD | NEW |