Index: ash/wm/power_button_controller.cc |
diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc |
index 73c686a403a69604803a88b1728c503c1bbe8d84..93d082b6e1a87a1c23e95478772075285b0ac68e 100644 |
--- a/ash/wm/power_button_controller.cc |
+++ b/ash/wm/power_button_controller.cc |
@@ -8,27 +8,36 @@ |
#include "ash/common/ash_switches.h" |
#include "ash/common/session/session_state_delegate.h" |
#include "ash/common/shell_window_ids.h" |
+#include "ash/common/system/tray/system_tray_notifier.h" |
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
#include "ash/common/wm_shell.h" |
#include "ash/shell.h" |
#include "ash/wm/lock_state_controller.h" |
#include "ash/wm/session_state_animator.h" |
#include "base/command_line.h" |
+#include "base/task_runner.h" |
+#include "base/threading/thread_task_runner_handle.h" |
#include "ui/aura/window_event_dispatcher.h" |
#include "ui/display/types/display_snapshot.h" |
#include "ui/events/event_handler.h" |
#include "ui/wm/core/compound_event_filter.h" |
#if defined(OS_CHROMEOS) |
+#include "chromeos/audio/cras_audio_handler.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#endif |
namespace ash { |
+namespace { |
+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.
|
+} // namespace |
+ |
PowerButtonController::PowerButtonController(LockStateController* controller) |
: power_button_down_(false), |
lock_button_down_(false), |
volume_down_pressed_(false), |
+ saved_volume_percent_(0), |
brightness_is_zero_(false), |
internal_display_off_and_external_display_on_(false), |
has_legacy_power_button_( |
@@ -80,9 +89,24 @@ void PowerButtonController::OnPowerButtonEvent( |
WmShell::Get() |
->maximize_mode_controller() |
->IsMaximizeModeWindowManagerEnabled()) { |
- WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( |
- TAKE_SCREENSHOT); |
+ // Notify that maximize mode screenshot is going to be taken. Receiver does |
+ // preparation work. |
+ WmShell::Get() |
+ ->system_tray_notifier() |
+ ->NotifyWillTakeScreenshotInMaximizeMode(); |
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
+ FROM_HERE, base::Bind(&PowerButtonController::TakingScreenshot, |
+ base::Unretained(this)), |
+ base::TimeDelta::FromMilliseconds(kWaitVolumeSliderHiddenInMs)); |
return; |
+ |
+#if defined(OS_CHROMEOS) |
+ // Restore volume. |
+ chromeos::CrasAudioHandler* audio_handler = |
+ chromeos::CrasAudioHandler::Get(); |
+ 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.
|
+ audio_handler->SetOutputVolumePercent(saved_volume_percent_); |
+#endif |
} |
const SessionStateDelegate* session_state_delegate = |
@@ -151,8 +175,18 @@ void PowerButtonController::OnLockButtonEvent( |
} |
void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
- if (event->key_code() == ui::VKEY_VOLUME_DOWN) |
+ if (event->key_code() == ui::VKEY_VOLUME_DOWN) { |
volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED; |
+#if defined(OS_CHROMEOS) |
+ // 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
|
+ if (!event->is_repeat()) { |
+ chromeos::CrasAudioHandler* audio_handler = |
+ chromeos::CrasAudioHandler::Get(); |
+ DCHECK(audio_handler->IsInitialized()); |
Daniel Erat
2016/07/28 04:45:00
delete this too
|
+ saved_volume_percent_ = audio_handler->GetOutputVolumePercent(); |
+ } |
+#endif |
+ } |
} |
#if defined(OS_CHROMEOS) |
@@ -179,4 +213,9 @@ void PowerButtonController::PowerButtonEventReceived( |
} |
#endif // defined(OS_CHROMEOS) |
+void PowerButtonController::TakingScreenshot() { |
+ WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( |
+ TAKE_SCREENSHOT); |
+} |
+ |
} // namespace ash |