| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/chromeos/power/tablet_power_button_controller.h" | 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h" |
| 6 | 6 |
| 7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shell_delegate.h" | 9 #include "ash/common/shell_delegate.h" |
| 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 10 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/wm/lock_state_controller.h" | 13 #include "ash/wm/lock_state_controller.h" |
| 13 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 15 #include "ui/events/devices/input_device_manager.h" | 16 #include "ui/events/devices/input_device_manager.h" |
| 16 #include "ui/events/devices/stylus_state.h" | 17 #include "ui/events/devices/stylus_state.h" |
| 17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 18 | 19 |
| 19 namespace ash { | 20 namespace ash { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 66 |
| 66 TabletPowerButtonController::TabletPowerButtonController( | 67 TabletPowerButtonController::TabletPowerButtonController( |
| 67 LockStateController* controller) | 68 LockStateController* controller) |
| 68 : tick_clock_(new base::DefaultTickClock()), | 69 : tick_clock_(new base::DefaultTickClock()), |
| 69 last_resume_time_(base::TimeTicks()), | 70 last_resume_time_(base::TimeTicks()), |
| 70 force_off_on_button_up_(true), | 71 force_off_on_button_up_(true), |
| 71 controller_(controller), | 72 controller_(controller), |
| 72 weak_ptr_factory_(this) { | 73 weak_ptr_factory_(this) { |
| 73 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 74 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 74 this); | 75 this); |
| 75 if (WmShell::Get()->maximize_mode_controller()) | 76 WmShell::Get()->AddShellObserver(this); |
| 76 WmShell::Get()->maximize_mode_controller()->AddObserver(this); | |
| 77 ui::InputDeviceManager::GetInstance()->AddObserver(this); | 77 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
| 78 Shell::GetInstance()->PrependPreTargetHandler(this); | 78 Shell::GetInstance()->PrependPreTargetHandler(this); |
| 79 | 79 |
| 80 GetInitialBacklightsForcedOff(); | 80 GetInitialBacklightsForcedOff(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TabletPowerButtonController::~TabletPowerButtonController() { | 83 TabletPowerButtonController::~TabletPowerButtonController() { |
| 84 Shell::GetInstance()->RemovePreTargetHandler(this); | 84 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 85 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | 85 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
| 86 if (WmShell::Get()->maximize_mode_controller()) | 86 WmShell::Get()->RemoveShellObserver(this); |
| 87 WmShell::Get()->maximize_mode_controller()->RemoveObserver(this); | |
| 88 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 87 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| 89 this); | 88 this); |
| 90 } | 89 } |
| 91 | 90 |
| 92 bool TabletPowerButtonController::ShouldHandlePowerButtonEvents() const { | 91 bool TabletPowerButtonController::ShouldHandlePowerButtonEvents() const { |
| 93 return IsTabletModeSupported(); | 92 return IsTabletModeSupported(); |
| 94 } | 93 } |
| 95 | 94 |
| 96 void TabletPowerButtonController::OnPowerButtonEvent( | 95 void TabletPowerButtonController::OnPowerButtonEvent( |
| 97 bool down, | 96 bool down, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 void TabletPowerButtonController::BrightnessChanged(int level, | 134 void TabletPowerButtonController::BrightnessChanged(int level, |
| 136 bool user_initiated) { | 135 bool user_initiated) { |
| 137 brightness_level_is_zero_ = level == 0; | 136 brightness_level_is_zero_ = level == 0; |
| 138 } | 137 } |
| 139 | 138 |
| 140 void TabletPowerButtonController::SuspendDone( | 139 void TabletPowerButtonController::SuspendDone( |
| 141 const base::TimeDelta& sleep_duration) { | 140 const base::TimeDelta& sleep_duration) { |
| 142 last_resume_time_ = tick_clock_->NowTicks(); | 141 last_resume_time_ = tick_clock_->NowTicks(); |
| 143 } | 142 } |
| 144 | 143 |
| 145 void TabletPowerButtonController::OnEnterMaximizeMode() { | 144 void TabletPowerButtonController::OnMaximizeModeStarted() { |
| 146 shutdown_timer_.Stop(); | 145 shutdown_timer_.Stop(); |
| 147 if (controller_->CanCancelShutdownAnimation()) | 146 if (controller_->CanCancelShutdownAnimation()) |
| 148 controller_->CancelShutdownAnimation(); | 147 controller_->CancelShutdownAnimation(); |
| 149 } | 148 } |
| 150 | 149 |
| 151 void TabletPowerButtonController::OnLeaveMaximizeMode() { | 150 void TabletPowerButtonController::OnMaximizeModeEnded() { |
| 152 shutdown_timer_.Stop(); | 151 shutdown_timer_.Stop(); |
| 153 if (controller_->CanCancelShutdownAnimation()) | 152 if (controller_->CanCancelShutdownAnimation()) |
| 154 controller_->CancelShutdownAnimation(); | 153 controller_->CancelShutdownAnimation(); |
| 155 } | 154 } |
| 156 | 155 |
| 157 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 156 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
| 158 // Ignore key events generated by the power button since power button activity | 157 // Ignore key events generated by the power button since power button activity |
| 159 // is already handled by OnPowerButtonEvent(). | 158 // is already handled by OnPowerButtonEvent(). |
| 160 if (event->key_code() == ui::VKEY_POWER) | 159 if (event->key_code() == ui::VKEY_POWER) |
| 161 return; | 160 return; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 WmShell::Get()->GetSessionStateDelegate(); | 236 WmShell::Get()->GetSessionStateDelegate(); |
| 238 if (session_state_delegate->ShouldLockScreenAutomatically() && | 237 if (session_state_delegate->ShouldLockScreenAutomatically() && |
| 239 session_state_delegate->CanLockScreen() && | 238 session_state_delegate->CanLockScreen() && |
| 240 !session_state_delegate->IsUserSessionBlocked() && | 239 !session_state_delegate->IsUserSessionBlocked() && |
| 241 !controller_->LockRequested()) { | 240 !controller_->LockRequested()) { |
| 242 session_state_delegate->LockScreen(); | 241 session_state_delegate->LockScreen(); |
| 243 } | 242 } |
| 244 } | 243 } |
| 245 | 244 |
| 246 } // namespace ash | 245 } // namespace ash |
| OLD | NEW |