| 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/power/tablet_power_button_controller.h" | 5 #include "ash/system/power/tablet_power_button_controller.h" |
| 6 | 6 |
| 7 #include "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
| 8 #include "ash/session/session_controller.h" | 8 #include "ash/session/session_controller.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_delegate.h" | 10 #include "ash/shell_delegate.h" |
| 11 #include "ash/wm/lock_state_controller.h" | 11 #include "ash/wm/lock_state_controller.h" |
| 12 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/wm/tablet_mode/tablet_mode_controller.h" |
| 13 #include "base/time/default_tick_clock.h" | 13 #include "base/time/default_tick_clock.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 15 #include "ui/events/devices/input_device_manager.h" | 15 #include "ui/events/devices/input_device_manager.h" |
| 16 #include "ui/events/devices/stylus_state.h" | 16 #include "ui/events/devices/stylus_state.h" |
| 17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 // ignored. | 34 // ignored. |
| 35 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; | 35 constexpr int kIgnorePowerButtonAfterResumeMs = 2000; |
| 36 | 36 |
| 37 // Ignore button-up events occurring within this many milliseconds of the | 37 // Ignore button-up events occurring within this many milliseconds of the |
| 38 // previous button-up event. This prevents us from falling behind if the power | 38 // previous button-up event. This prevents us from falling behind if the power |
| 39 // button is pressed repeatedly. | 39 // button is pressed repeatedly. |
| 40 constexpr int kIgnoreRepeatedButtonUpMs = 500; | 40 constexpr int kIgnoreRepeatedButtonUpMs = 500; |
| 41 | 41 |
| 42 // Returns true if device is a convertible/tablet device, otherwise false. | 42 // Returns true if device is a convertible/tablet device, otherwise false. |
| 43 bool IsTabletModeSupported() { | 43 bool IsTabletModeSupported() { |
| 44 MaximizeModeController* maximize_mode_controller = | 44 TabletModeController* tablet_mode_controller = |
| 45 Shell::Get()->maximize_mode_controller(); | 45 Shell::Get()->tablet_mode_controller(); |
| 46 return maximize_mode_controller && | 46 return tablet_mode_controller && tablet_mode_controller->CanEnterTabletMode(); |
| 47 maximize_mode_controller->CanEnterMaximizeMode(); | |
| 48 } | 47 } |
| 49 | 48 |
| 50 // Returns true if device is currently in tablet/maximize mode, otherwise false. | 49 // Returns true if device is currently in tablet/tablet mode, otherwise false. |
| 51 bool IsTabletModeActive() { | 50 bool IsTabletModeActive() { |
| 52 MaximizeModeController* maximize_mode_controller = | 51 TabletModeController* tablet_mode_controller = |
| 53 Shell::Get()->maximize_mode_controller(); | 52 Shell::Get()->tablet_mode_controller(); |
| 54 return maximize_mode_controller && | 53 return tablet_mode_controller && |
| 55 maximize_mode_controller->IsMaximizeModeWindowManagerEnabled(); | 54 tablet_mode_controller->IsTabletModeWindowManagerEnabled(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 } // namespace | 57 } // namespace |
| 59 | 58 |
| 60 TabletPowerButtonController::TestApi::TestApi( | 59 TabletPowerButtonController::TestApi::TestApi( |
| 61 TabletPowerButtonController* controller) | 60 TabletPowerButtonController* controller) |
| 62 : controller_(controller) {} | 61 : controller_(controller) {} |
| 63 | 62 |
| 64 TabletPowerButtonController::TestApi::~TestApi() {} | 63 TabletPowerButtonController::TestApi::~TestApi() {} |
| 65 | 64 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 const base::TimeDelta& sleep_duration) { | 159 const base::TimeDelta& sleep_duration) { |
| 161 last_resume_time_ = tick_clock_->NowTicks(); | 160 last_resume_time_ = tick_clock_->NowTicks(); |
| 162 } | 161 } |
| 163 | 162 |
| 164 void TabletPowerButtonController::LidEventReceived( | 163 void TabletPowerButtonController::LidEventReceived( |
| 165 chromeos::PowerManagerClient::LidState state, | 164 chromeos::PowerManagerClient::LidState state, |
| 166 const base::TimeTicks& timestamp) { | 165 const base::TimeTicks& timestamp) { |
| 167 SetDisplayForcedOff(false); | 166 SetDisplayForcedOff(false); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void TabletPowerButtonController::OnMaximizeModeStarted() { | 169 void TabletPowerButtonController::OnTabletModeStarted() { |
| 171 shutdown_timer_.Stop(); | 170 shutdown_timer_.Stop(); |
| 172 if (controller_->CanCancelShutdownAnimation()) | 171 if (controller_->CanCancelShutdownAnimation()) |
| 173 controller_->CancelShutdownAnimation(); | 172 controller_->CancelShutdownAnimation(); |
| 174 } | 173 } |
| 175 | 174 |
| 176 void TabletPowerButtonController::OnMaximizeModeEnded() { | 175 void TabletPowerButtonController::OnTabletModeEnded() { |
| 177 shutdown_timer_.Stop(); | 176 shutdown_timer_.Stop(); |
| 178 if (controller_->CanCancelShutdownAnimation()) | 177 if (controller_->CanCancelShutdownAnimation()) |
| 179 controller_->CancelShutdownAnimation(); | 178 controller_->CancelShutdownAnimation(); |
| 180 } | 179 } |
| 181 | 180 |
| 182 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { | 181 void TabletPowerButtonController::OnKeyEvent(ui::KeyEvent* event) { |
| 183 // Ignore key events generated by the power button since power button activity | 182 // Ignore key events generated by the power button since power button activity |
| 184 // is already handled by OnPowerButtonEvent(). | 183 // is already handled by OnPowerButtonEvent(). |
| 185 if (event->key_code() == ui::VKEY_POWER) | 184 if (event->key_code() == ui::VKEY_POWER) |
| 186 return; | 185 return; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 SessionController* session_controller = Shell::Get()->session_controller(); | 262 SessionController* session_controller = Shell::Get()->session_controller(); |
| 264 if (session_controller->ShouldLockScreenAutomatically() && | 263 if (session_controller->ShouldLockScreenAutomatically() && |
| 265 session_controller->CanLockScreen() && | 264 session_controller->CanLockScreen() && |
| 266 !session_controller->IsUserSessionBlocked() && | 265 !session_controller->IsUserSessionBlocked() && |
| 267 !controller_->LockRequested()) { | 266 !controller_->LockRequested()) { |
| 268 session_controller->LockScreen(); | 267 session_controller->LockScreen(); |
| 269 } | 268 } |
| 270 } | 269 } |
| 271 | 270 |
| 272 } // namespace ash | 271 } // namespace ash |
| OLD | NEW |