Commit fada6a15 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

tablet: Do not unlock keyboard when going to clamshell with extern mouse.

Internal keyboard and touchpad events are previously locked when entering
tablet mode and unlocked when leaving. Now, when we attach a mouse, it
will exit tablet mode, but the keyboard should not stay locked as the
keyboard will be facing downwards in the case of flip chromebook. The
lock should instead be controlled by the hinges regardless if change in
hinge causes tablet mode to change.

Also rename EnterTabletMode to AttemptEnterTabletMode as it does not
always enter.

Test: ash_unittests TabletModeControllerTest.LeaveTabletModeWhenExternalMouseConnected
Bug: 870757
Change-Id: I38a537871aa6a1e7cd94311308d421af3dfc2ad1
Reviewed-on: https://chromium-review.googlesource.com/1162512
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580657}
parent 6ea6882f
...@@ -283,7 +283,7 @@ void TabletModeController::LidEventReceived( ...@@ -283,7 +283,7 @@ void TabletModeController::LidEventReceived(
lid_is_closed_ = !open; lid_is_closed_ = !open;
if (!tablet_mode_switch_is_on_) if (!tablet_mode_switch_is_on_)
LeaveTabletMode(false); AttemptLeaveTabletMode(false);
} }
void TabletModeController::TabletModeEventReceived( void TabletModeController::TabletModeEventReceived(
...@@ -304,10 +304,10 @@ void TabletModeController::TabletModeEventReceived( ...@@ -304,10 +304,10 @@ void TabletModeController::TabletModeEventReceived(
// when |on|. However we wish to exit tablet mode at a smaller angle, so // when |on|. However we wish to exit tablet mode at a smaller angle, so
// when |on| is false we ignore if it is possible to calculate the lid angle. // when |on| is false we ignore if it is possible to calculate the lid angle.
if (on && !IsTabletModeWindowManagerEnabled()) { if (on && !IsTabletModeWindowManagerEnabled()) {
EnterTabletMode(); AttemptEnterTabletMode();
} else if (!on && IsTabletModeWindowManagerEnabled() && } else if (!on && IsTabletModeWindowManagerEnabled() &&
!can_detect_lid_angle_) { !can_detect_lid_angle_) {
LeaveTabletMode(false); AttemptLeaveTabletMode(false);
} }
} }
...@@ -391,13 +391,11 @@ void TabletModeController::HandleHingeRotation( ...@@ -391,13 +391,11 @@ void TabletModeController::HandleHingeRotation(
} }
// Toggle tablet mode on or off when corresponding thresholds are passed. // Toggle tablet mode on or off when corresponding thresholds are passed.
if (IsTabletModeWindowManagerEnabled() && is_angle_stable && if (is_angle_stable && lid_angle_ <= kExitTabletModeAngle) {
lid_angle_ <= kExitTabletModeAngle) { AttemptLeaveTabletMode(false);
LeaveTabletMode(false); } else if (!lid_is_closed_ && lid_angle_ >= kEnterTabletModeAngle &&
} else if (!IsTabletModeWindowManagerEnabled() && !lid_is_closed_ &&
lid_angle_ >= kEnterTabletModeAngle &&
(is_angle_stable || CanUseUnstableLidAngle())) { (is_angle_stable || CanUseUnstableLidAngle())) {
EnterTabletMode(); AttemptEnterTabletMode();
} }
// Start reporting the lid angle if we aren't already doing so. // Start reporting the lid angle if we aren't already doing so.
...@@ -409,13 +407,13 @@ void TabletModeController::HandleHingeRotation( ...@@ -409,13 +407,13 @@ void TabletModeController::HandleHingeRotation(
} }
} }
void TabletModeController::EnterTabletMode() { void TabletModeController::AttemptEnterTabletMode() {
event_blocker_.reset();
event_blocker_ = CreateScopedDisableInternalMouseAndKeyboard();
if (IsTabletModeWindowManagerEnabled()) if (IsTabletModeWindowManagerEnabled())
return; return;
DCHECK(!event_blocker_);
event_blocker_ = CreateScopedDisableInternalMouseAndKeyboard();
should_enter_tablet_mode_ = true; should_enter_tablet_mode_ = true;
if (has_external_mouse_) if (has_external_mouse_)
...@@ -424,8 +422,12 @@ void TabletModeController::EnterTabletMode() { ...@@ -424,8 +422,12 @@ void TabletModeController::EnterTabletMode() {
EnableTabletModeWindowManager(true); EnableTabletModeWindowManager(true);
} }
void TabletModeController::LeaveTabletMode(bool called_by_device_update) { void TabletModeController::AttemptLeaveTabletMode(
event_blocker_.reset(); bool called_by_device_update) {
// Do not unlock internal keyboard if we enter clamshell by plugging in an
// external mouse.
if (!called_by_device_update)
event_blocker_.reset();
if (!IsTabletModeWindowManagerEnabled()) if (!IsTabletModeWindowManagerEnabled())
return; return;
...@@ -451,21 +453,21 @@ bool TabletModeController::TriggerRecordLidAngleTimerForTesting() { ...@@ -451,21 +453,21 @@ bool TabletModeController::TriggerRecordLidAngleTimerForTesting() {
void TabletModeController::OnShellInitialized() { void TabletModeController::OnShellInitialized() {
force_ui_mode_ = GetTabletMode(); force_ui_mode_ = GetTabletMode();
if (force_ui_mode_ == UiMode::TABLETMODE) if (force_ui_mode_ == UiMode::TABLETMODE)
EnterTabletMode(); AttemptEnterTabletMode();
} }
void TabletModeController::OnDisplayConfigurationChanged() { void TabletModeController::OnDisplayConfigurationChanged() {
if (!display::Display::HasInternalDisplay() || if (!display::Display::HasInternalDisplay() ||
!Shell::Get()->display_manager()->IsActiveDisplayId( !Shell::Get()->display_manager()->IsActiveDisplayId(
display::Display::InternalDisplayId())) { display::Display::InternalDisplayId())) {
LeaveTabletMode(false); AttemptLeaveTabletMode(false);
} else if (tablet_mode_switch_is_on_ && !IsTabletModeWindowManagerEnabled()) { } else if (tablet_mode_switch_is_on_ && !IsTabletModeWindowManagerEnabled()) {
// The internal display has returned, as we are exiting docked mode. // The internal display has returned, as we are exiting docked mode.
// The device is still in tablet mode, so trigger tablet mode, as this // The device is still in tablet mode, so trigger tablet mode, as this
// switch leads to the ignoring of accelerometer events. When the switch is // switch leads to the ignoring of accelerometer events. When the switch is
// not set the next stable accelerometer readings will trigger maximize // not set the next stable accelerometer readings will trigger maximize
// mode. // mode.
EnterTabletMode(); AttemptEnterTabletMode();
} }
} }
...@@ -529,17 +531,17 @@ void TabletModeController::HandleMouseAddedOrRemoved() { ...@@ -529,17 +531,17 @@ void TabletModeController::HandleMouseAddedOrRemoved() {
has_external_mouse_ = has_external_mouse; has_external_mouse_ = has_external_mouse;
// Exit tablet mode if we are already in tablet mode and // Try to tablet mode if we are already in tablet mode and
// |has_external_mouse| is true. // |has_external_mouse| is true.
if (has_external_mouse) { if (has_external_mouse) {
LeaveTabletMode(true); AttemptLeaveTabletMode(true);
return; return;
} }
// Enter tablet mode if |has_external_mouse| is false and we // Try to enter tablet mode if |has_external_mouse| is false and we
// are in an orientation that should be tablet mode. // are in an orientation that should be tablet mode.
if (should_enter_tablet_mode_) if (should_enter_tablet_mode_)
EnterTabletMode(); AttemptEnterTabletMode();
} }
void TabletModeController::OnChromeTerminating() { void TabletModeController::OnChromeTerminating() {
......
...@@ -83,7 +83,7 @@ class ASH_EXPORT TabletModeController ...@@ -83,7 +83,7 @@ class ASH_EXPORT TabletModeController
// tablet mode becomes enabled. // tablet mode becomes enabled.
bool CanEnterTabletMode(); bool CanEnterTabletMode();
// TODO(jonross): Merge this with EnterTabletMode. Currently these are // TODO(jonross): Merge this with AttemptEnterTabletMode. Currently these are
// separate for several reasons: there is no internal display when running // separate for several reasons: there is no internal display when running
// unittests; the event blocker prevents keyboard input when running ChromeOS // unittests; the event blocker prevents keyboard input when running ChromeOS
// on linux. http://crbug.com/362881 // on linux. http://crbug.com/362881
...@@ -174,13 +174,12 @@ class ASH_EXPORT TabletModeController ...@@ -174,13 +174,12 @@ class ASH_EXPORT TabletModeController
// a certain range of time before using unstable angle. // a certain range of time before using unstable angle.
bool CanUseUnstableLidAngle() const; bool CanUseUnstableLidAngle() const;
// Enables TabletModeWindowManager, and determines the current state of // Attempts to enter tablet mode and locks the internal keyboard and touchpad.
// rotation lock. void AttemptEnterTabletMode();
void EnterTabletMode();
// Removes TabletModeWindowManager and resets the display rotation if there // Attempts to exit tablet mode and unlocks the internal keyboard and touchpad
// is no rotation lock. // if |called_by_device_update| is false.
void LeaveTabletMode(bool called_by_device_update); void AttemptLeaveTabletMode(bool called_by_device_update);
// Record UMA stats tracking TabletMode usage. If |type| is // Record UMA stats tracking TabletMode usage. If |type| is
// TABLET_MODE_INTERVAL_INACTIVE, then record that TabletMode has been // TABLET_MODE_INTERVAL_INACTIVE, then record that TabletMode has been
......
...@@ -792,17 +792,21 @@ TEST_F(TabletModeControllerTest, LeaveTabletModeWhenExternalMouseConnected) { ...@@ -792,17 +792,21 @@ TEST_F(TabletModeControllerTest, LeaveTabletModeWhenExternalMouseConnected) {
// Start in tablet mode. // Start in tablet mode.
OpenLidToAngle(300.0f); OpenLidToAngle(300.0f);
EXPECT_TRUE(IsTabletModeStarted()); EXPECT_TRUE(IsTabletModeStarted());
EXPECT_TRUE(AreEventsBlocked());
// Attach external mouse and keyboard. Verify that tablet mode has ended. // Attach external mouse and keyboard. Verify that tablet mode has ended, but
// events are still blocked because the keyboard is still facing the bottom.
ui::InputDeviceClientTestApi().SetMouseDevices({ui::InputDevice( ui::InputDeviceClientTestApi().SetMouseDevices({ui::InputDevice(
3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "mouse")}); 3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "mouse")});
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(IsTabletModeStarted()); EXPECT_FALSE(IsTabletModeStarted());
EXPECT_TRUE(AreEventsBlocked());
// Verify that after unplugging the mouse, tablet mode will resume. // Verify that after unplugging the mouse, tablet mode will resume.
ui::InputDeviceClientTestApi().SetMouseDevices({}); ui::InputDeviceClientTestApi().SetMouseDevices({});
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(IsTabletModeStarted()); EXPECT_TRUE(IsTabletModeStarted());
EXPECT_TRUE(AreEventsBlocked());
} }
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment