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" |
17 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
18 #include "ui/display/types/display_snapshot.h" | 19 #include "ui/display/types/display_snapshot.h" |
19 #include "ui/events/event_handler.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) |
24 #include "chromeos/audio/cras_audio_handler.h" | |
23 #include "chromeos/dbus/dbus_thread_manager.h" | 25 #include "chromeos/dbus/dbus_thread_manager.h" |
24 #endif | 26 #endif |
25 | 27 |
26 namespace ash { | 28 namespace ash { |
27 | 29 |
28 PowerButtonController::PowerButtonController(LockStateController* controller) | 30 PowerButtonController::PowerButtonController(LockStateController* controller) |
29 : power_button_down_(false), | 31 : power_button_down_(false), |
30 lock_button_down_(false), | 32 lock_button_down_(false), |
31 volume_down_pressed_(false), | 33 volume_down_pressed_(false), |
34 #if defined(OS_CHROMEOS) | |
35 volume_percent_before_screenshot_(0), | |
36 #endif | |
32 brightness_is_zero_(false), | 37 brightness_is_zero_(false), |
33 internal_display_off_and_external_display_on_(false), | 38 internal_display_off_and_external_display_on_(false), |
34 has_legacy_power_button_( | 39 has_legacy_power_button_( |
35 base::CommandLine::ForCurrentProcess()->HasSwitch( | 40 base::CommandLine::ForCurrentProcess()->HasSwitch( |
36 switches::kAuraLegacyPowerButton)), | 41 switches::kAuraLegacyPowerButton)), |
37 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
38 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 43 enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
39 switches::kAshEnableTouchView)), | 44 switches::kAshEnableTouchView)), |
40 #else | 45 #else |
41 enable_quick_lock_(false), | 46 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 | 78 // 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 | 79 // while the screen is off (http://crbug.com/128451), unless an external |
75 // display is still on (http://crosbug.com/p/24912). | 80 // display is still on (http://crosbug.com/p/24912). |
76 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) | 81 if (brightness_is_zero_ && !internal_display_off_and_external_display_on_) |
77 return; | 82 return; |
78 | 83 |
79 if (volume_down_pressed_ && down && | 84 if (volume_down_pressed_ && down && |
80 WmShell::Get() | 85 WmShell::Get() |
81 ->maximize_mode_controller() | 86 ->maximize_mode_controller() |
82 ->IsMaximizeModeWindowManagerEnabled()) { | 87 ->IsMaximizeModeWindowManagerEnabled()) { |
83 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( | 88 // Notify that maximize mode screenshot is going to be taken. Receiver does |
84 TAKE_SCREENSHOT); | 89 // preparation work. |
90 WmShell* wm_shell = WmShell::Get(); | |
91 wm_shell->system_tray_notifier()->NotifyTakingScreenshotInMaximizeMode(); | |
James Cook
2016/08/01 16:51:46
This is fine.
| |
92 wm_shell->accelerator_controller()->PerformActionIfEnabled(TAKE_SCREENSHOT); | |
93 | |
94 #if defined(OS_CHROMEOS) | |
95 // Restore volume. | |
96 chromeos::CrasAudioHandler* audio_handler = | |
97 chromeos::CrasAudioHandler::Get(); | |
98 audio_handler->SetOutputVolumePercentWithoutNotifyingObservers( | |
99 volume_percent_before_screenshot_); | |
100 #endif | |
85 return; | 101 return; |
86 } | 102 } |
87 | 103 |
88 const SessionStateDelegate* session_state_delegate = | 104 const SessionStateDelegate* session_state_delegate = |
89 WmShell::Get()->GetSessionStateDelegate(); | 105 WmShell::Get()->GetSessionStateDelegate(); |
90 if (has_legacy_power_button_) { | 106 if (has_legacy_power_button_) { |
91 // If power button releases won't get reported correctly because we're not | 107 // 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 | 108 // running on official hardware, just lock the screen or shut down |
93 // immediately. | 109 // immediately. |
94 if (down) { | 110 if (down) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 if (power_button_down_) | 160 if (power_button_down_) |
145 return; | 161 return; |
146 | 162 |
147 if (down) | 163 if (down) |
148 controller_->StartLockAnimation(false); | 164 controller_->StartLockAnimation(false); |
149 else | 165 else |
150 controller_->CancelLockAnimation(); | 166 controller_->CancelLockAnimation(); |
151 } | 167 } |
152 | 168 |
153 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 169 void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
154 if (event->key_code() == ui::VKEY_VOLUME_DOWN) | 170 if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
155 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; | 171 volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; |
172 #if defined(OS_CHROMEOS) | |
173 if (!event->is_repeat()) { | |
174 chromeos::CrasAudioHandler* audio_handler = | |
175 chromeos::CrasAudioHandler::Get(); | |
176 volume_percent_before_screenshot_ = | |
177 audio_handler->GetOutputVolumePercent(); | |
178 } | |
179 #endif | |
180 } | |
156 } | 181 } |
157 | 182 |
158 #if defined(OS_CHROMEOS) | 183 #if defined(OS_CHROMEOS) |
159 void PowerButtonController::OnDisplayModeChanged( | 184 void PowerButtonController::OnDisplayModeChanged( |
160 const ui::DisplayConfigurator::DisplayStateList& display_states) { | 185 const ui::DisplayConfigurator::DisplayStateList& display_states) { |
161 bool internal_display_off = false; | 186 bool internal_display_off = false; |
162 bool external_display_on = false; | 187 bool external_display_on = false; |
163 for (const ui::DisplaySnapshot* display : display_states) { | 188 for (const ui::DisplaySnapshot* display : display_states) { |
164 if (display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { | 189 if (display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) { |
165 if (!display->current_mode()) | 190 if (!display->current_mode()) |
166 internal_display_off = true; | 191 internal_display_off = true; |
167 } else if (display->current_mode()) { | 192 } else if (display->current_mode()) { |
168 external_display_on = true; | 193 external_display_on = true; |
169 } | 194 } |
170 } | 195 } |
171 internal_display_off_and_external_display_on_ = | 196 internal_display_off_and_external_display_on_ = |
172 internal_display_off && external_display_on; | 197 internal_display_off && external_display_on; |
173 } | 198 } |
174 | 199 |
175 void PowerButtonController::PowerButtonEventReceived( | 200 void PowerButtonController::PowerButtonEventReceived( |
176 bool down, | 201 bool down, |
177 const base::TimeTicks& timestamp) { | 202 const base::TimeTicks& timestamp) { |
178 OnPowerButtonEvent(down, timestamp); | 203 OnPowerButtonEvent(down, timestamp); |
179 } | 204 } |
180 #endif // defined(OS_CHROMEOS) | 205 #endif // defined(OS_CHROMEOS) |
181 | 206 |
182 } // namespace ash | 207 } // namespace ash |
OLD | NEW |