Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: ash/wm/power_button_controller.cc

Issue 2474913004: Tablet-like power button behavior on Convertible/Tablet ChromeOS devices (Closed)
Patch Set: based on comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wm/power_button_controller.cc
diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc
index 92ca9c12aabcd64eeb6996e10f6ab273b57e803c..fd382726fca95caf1b30d518724c2cfe9fdce159 100644
--- a/ash/wm/power_button_controller.cc
+++ b/ash/wm/power_button_controller.cc
@@ -18,10 +18,10 @@
#include "base/command_line.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 "ash/system/chromeos/power/tablet_power_button_controller.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#endif
@@ -40,13 +40,7 @@ PowerButtonController::PowerButtonController(LockStateController* controller)
has_legacy_power_button_(
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAuraLegacyPowerButton)),
-#if defined(OS_CHROMEOS)
- enable_quick_lock_(base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kAshEnableTouchView)),
-#else
- enable_quick_lock_(false),
-#endif
- controller_(controller) {
+ lock_state_controller_(controller) {
#if defined(OS_CHROMEOS)
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
@@ -73,8 +67,23 @@ void PowerButtonController::OnPowerButtonEvent(
const base::TimeTicks& timestamp) {
power_button_down_ = down;
- if (controller_->ShutdownRequested())
+ if (lock_state_controller_->ShutdownRequested())
+ return;
+
+ bool should_take_screenshot = down && volume_down_pressed_ &&
+ WmShell::Get()
+ ->maximize_mode_controller()
+ ->IsMaximizeModeWindowManagerEnabled();
+
+#if defined(OS_CHROMEOS)
+ TabletPowerButtonController* tablet_controller =
+ Shell::GetInstance()->tablet_power_button_controller();
+ if (!has_legacy_power_button_ && !should_take_screenshot &&
+ tablet_controller->ShouldHandlePowerButtonEvents()) {
+ tablet_controller->OnPowerButtonEvent(down, timestamp);
return;
+ }
+#endif
// Avoid starting the lock/shutdown sequence if the power button is pressed
// while the screen is off (http://crbug.com/128451), unless an external
@@ -82,10 +91,7 @@ void PowerButtonController::OnPowerButtonEvent(
if (brightness_is_zero_ && !internal_display_off_and_external_display_on_)
return;
- if (volume_down_pressed_ && down &&
- WmShell::Get()
- ->maximize_mode_controller()
- ->IsMaximizeModeWindowManagerEnabled()) {
+ if (should_take_screenshot) {
SystemTray* system_tray = Shell::GetInstance()->GetPrimarySystemTray();
if (system_tray && system_tray->GetTrayAudio())
system_tray->GetTrayAudio()->HideDetailedView(false);
@@ -113,35 +119,29 @@ void PowerButtonController::OnPowerButtonEvent(
if (down) {
if (session_state_delegate->CanLockScreen() &&
!session_state_delegate->IsUserSessionBlocked() &&
- !controller_->LockRequested()) {
- controller_->StartLockAnimationAndLockImmediately(false);
+ !lock_state_controller_->LockRequested()) {
+ lock_state_controller_->StartLockAnimationAndLockImmediately(false);
} else {
- controller_->RequestShutdown();
+ lock_state_controller_->RequestShutdown();
}
}
} else { // !has_legacy_power_button_
if (down) {
// If we already have a pending request to lock the screen, wait.
- if (controller_->LockRequested())
+ if (lock_state_controller_->LockRequested())
return;
if (session_state_delegate->CanLockScreen() &&
!session_state_delegate->IsUserSessionBlocked()) {
- if (WmShell::Get()
- ->maximize_mode_controller()
- ->IsMaximizeModeWindowManagerEnabled() &&
- enable_quick_lock_)
- controller_->StartLockAnimationAndLockImmediately(true);
- else
- controller_->StartLockAnimation(true);
+ lock_state_controller_->StartLockAnimation(true);
} else {
- controller_->StartShutdownAnimation();
+ lock_state_controller_->StartShutdownAnimation();
}
} else { // Button is up.
- if (controller_->CanCancelLockAnimation())
- controller_->CancelLockAnimation();
- else if (controller_->CanCancelShutdownAnimation())
- controller_->CancelShutdownAnimation();
+ if (lock_state_controller_->CanCancelLockAnimation())
+ lock_state_controller_->CancelLockAnimation();
+ else if (lock_state_controller_->CanCancelShutdownAnimation())
+ lock_state_controller_->CancelShutdownAnimation();
}
}
}
@@ -155,7 +155,8 @@ void PowerButtonController::OnLockButtonEvent(
WmShell::Get()->GetSessionStateDelegate();
if (!session_state_delegate->CanLockScreen() ||
session_state_delegate->IsScreenLocked() ||
- controller_->LockRequested() || controller_->ShutdownRequested()) {
+ lock_state_controller_->LockRequested() ||
+ lock_state_controller_->ShutdownRequested()) {
return;
}
@@ -164,9 +165,9 @@ void PowerButtonController::OnLockButtonEvent(
return;
if (down)
- controller_->StartLockAnimation(false);
+ lock_state_controller_->StartLockAnimation(false);
else
- controller_->CancelLockAnimation();
+ lock_state_controller_->CancelLockAnimation();
}
void PowerButtonController::OnKeyEvent(ui::KeyEvent* event) {

Powered by Google App Engine
This is Rietveld 408576698