[DisableTrackpad] Change re-enable touchpad shortcut to shift
Bug: 365813554 Change-Id: Iee41cefe068a4538112aae26bdaf4a817744b119 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5983523 Reviewed-by: Connie Xu <conniekxu@chromium.org> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org> Reviewed-by: Akihiro Ota <akihiroota@chromium.org> Commit-Queue: Jesulayomi Kupoluyi <lkupo@google.com> Cr-Commit-Position: refs/heads/main@{#1377758}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
6567bbee4c
commit
8072b6d084
ash
accessibility
accessibility_controller_unittest.ccdisable_touchpad_event_rewriter.ccdisable_touchpad_event_rewriter.hdisable_touchpad_event_rewriter_unittest.cc
ash_strings.grdash_strings_grd
chrome/app
@ -2545,7 +2545,7 @@ TEST_F(AccessibilityControllerDisableTouchpadTest,
|
||||
|
||||
const std::u16string kTouchpadDisabled = u"Built-in touchpad is disabled";
|
||||
const std::u16string kPressEscape =
|
||||
u"Press Esc 5 times to enable the touchpad";
|
||||
u"Press Shift 5 times to enable the touchpad";
|
||||
|
||||
notifications = MessageCenter::Get()->GetVisibleNotifications();
|
||||
|
||||
|
@ -76,7 +76,7 @@ bool IsFromInternalTouchpad(const ui::Event& event) {
|
||||
return event.source_device_id() == GetInternalTouchpadDeviceId();
|
||||
}
|
||||
|
||||
constexpr base::TimeDelta kEnableTouchpadKeyPressWindow = base::Seconds(3);
|
||||
constexpr base::TimeDelta kEnableTouchpadKeyPressWindow = base::Seconds(2);
|
||||
} // namespace
|
||||
|
||||
DisableTouchpadEventRewriter::DisableTouchpadEventRewriter() {
|
||||
@ -145,39 +145,37 @@ ui::EventDispatchDetails DisableTouchpadEventRewriter::HandleMouseOrScrollEvent(
|
||||
}
|
||||
|
||||
void DisableTouchpadEventRewriter::HandleKeyEvent(const ui::KeyEvent* event) {
|
||||
// TODO(b/365813554): Prevent escape key from propagating to the system before
|
||||
// a specified time window between escape key presses.
|
||||
if (event->type() != ui::EventType::kKeyPressed) {
|
||||
return;
|
||||
}
|
||||
event->key_code() == ui::VKEY_ESCAPE ? HandleEscapeKeyPress()
|
||||
: ResetEscapeKeyPressTracking();
|
||||
event->key_code() == ui::VKEY_SHIFT ? HandleShiftKeyPress()
|
||||
: ResetShiftKeyPressTracking();
|
||||
}
|
||||
|
||||
void DisableTouchpadEventRewriter::HandleEscapeKeyPress() {
|
||||
if (escape_press_count_ == 0) {
|
||||
first_escape_press_time_ = ui::EventTimeForNow();
|
||||
void DisableTouchpadEventRewriter::HandleShiftKeyPress() {
|
||||
if (shift_press_count_ == 0) {
|
||||
first_shift_press_time_ = ui::EventTimeForNow();
|
||||
}
|
||||
|
||||
++escape_press_count_;
|
||||
++shift_press_count_;
|
||||
base::TimeDelta elapsed_time =
|
||||
ui::EventTimeForNow() - first_escape_press_time_;
|
||||
ui::EventTimeForNow() - first_shift_press_time_;
|
||||
|
||||
if (elapsed_time > kEnableTouchpadKeyPressWindow) {
|
||||
ResetEscapeKeyPressTracking();
|
||||
ResetShiftKeyPressTracking();
|
||||
return;
|
||||
}
|
||||
|
||||
if (escape_press_count_ >= 5) {
|
||||
if (shift_press_count_ >= 5) {
|
||||
SetEnabled(false);
|
||||
Shell::Get()->accessibility_controller()->EnableInternalTouchpad();
|
||||
ResetEscapeKeyPressTracking();
|
||||
ResetShiftKeyPressTracking();
|
||||
}
|
||||
}
|
||||
|
||||
void DisableTouchpadEventRewriter::ResetEscapeKeyPressTracking() {
|
||||
escape_press_count_ = 0;
|
||||
first_escape_press_time_ = base::TimeTicks();
|
||||
void DisableTouchpadEventRewriter::ResetShiftKeyPressTracking() {
|
||||
shift_press_count_ = 0;
|
||||
first_shift_press_time_ = base::TimeTicks();
|
||||
}
|
||||
|
||||
} // namespace ash
|
||||
|
@ -29,15 +29,15 @@ class ASH_EXPORT DisableTouchpadEventRewriter : public ui::EventRewriter {
|
||||
const Continuation continuation) override;
|
||||
|
||||
void HandleKeyEvent(const ui::KeyEvent* event);
|
||||
void HandleEscapeKeyPress();
|
||||
void ResetEscapeKeyPressTracking();
|
||||
void HandleShiftKeyPress();
|
||||
void ResetShiftKeyPressTracking();
|
||||
ui::EventDispatchDetails HandleMouseOrScrollEvent(
|
||||
const ui::Event& event,
|
||||
const Continuation continuation);
|
||||
|
||||
bool enabled_ = false;
|
||||
int escape_press_count_ = 0;
|
||||
base::TimeTicks first_escape_press_time_ = base::TimeTicks();
|
||||
int shift_press_count_ = 0;
|
||||
base::TimeTicks first_shift_press_time_ = base::TimeTicks();
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
@ -85,9 +85,9 @@ class DisableTouchpadEventRewriterTest : public AshTestBase {
|
||||
const DisableTouchpadEventRewriterTest&) = delete;
|
||||
~DisableTouchpadEventRewriterTest() override = default;
|
||||
|
||||
void PressAndReleaseEscapeKey() {
|
||||
generator()->PressKey(ui::VKEY_ESCAPE, ui::EF_NONE);
|
||||
generator()->ReleaseKey(ui::VKEY_ESCAPE, ui::EF_NONE);
|
||||
void PressAndReleaseShiftKey() {
|
||||
generator()->PressKey(ui::VKEY_SHIFT, ui::EF_NONE);
|
||||
generator()->ReleaseKey(ui::VKEY_SHIFT, ui::EF_NONE);
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
@ -175,19 +175,19 @@ TEST_F(DisableTouchpadEventRewriterTest, MouseButtonsCanceledInAlwaysMode) {
|
||||
EXPECT_EQ(0U, event_recorder()->events().size());
|
||||
}
|
||||
|
||||
TEST_F(DisableTouchpadEventRewriterTest, DisableAfterFiveEscapeKeyPresses) {
|
||||
TEST_F(DisableTouchpadEventRewriterTest, DisableAfterFiveShiftKeyPresses) {
|
||||
event_rewriter()->SetEnabled(true);
|
||||
|
||||
int escapeKeyPressCount = 0;
|
||||
int shiftKeyPressCount = 0;
|
||||
|
||||
// Simulate pressing and releasing the escape key 5 times.
|
||||
// Simulate pressing and releasing the shift key 5 times.
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
PressAndReleaseEscapeKey();
|
||||
generator()->AdvanceClock(base::Milliseconds(500));
|
||||
++escapeKeyPressCount;
|
||||
PressAndReleaseShiftKey();
|
||||
generator()->AdvanceClock(base::Milliseconds(100));
|
||||
++shiftKeyPressCount;
|
||||
|
||||
// After the 5th press, check if the rewriter is disabled.
|
||||
if (escapeKeyPressCount == 5) {
|
||||
if (shiftKeyPressCount == 5) {
|
||||
EXPECT_FALSE(event_rewriter()->IsEnabled());
|
||||
} else {
|
||||
EXPECT_TRUE(event_rewriter()->IsEnabled());
|
||||
@ -196,46 +196,45 @@ TEST_F(DisableTouchpadEventRewriterTest, DisableAfterFiveEscapeKeyPresses) {
|
||||
}
|
||||
|
||||
TEST_F(DisableTouchpadEventRewriterTest,
|
||||
EscapePressesExceedTimeWindowStaysEnabled) {
|
||||
ShiftPressesExceedTimeWindowStaysEnabled) {
|
||||
event_rewriter()->SetEnabled(true);
|
||||
|
||||
// Simulate pressing and releasing the escape key 4 times.
|
||||
// Simulate pressing and releasing the shift key 4 times.
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
PressAndReleaseEscapeKey();
|
||||
generator()->AdvanceClock(base::Milliseconds(500));
|
||||
PressAndReleaseShiftKey();
|
||||
generator()->AdvanceClock(base::Milliseconds(100));
|
||||
EXPECT_TRUE(event_rewriter()->IsEnabled());
|
||||
}
|
||||
|
||||
// Exceed escape key time window on final key press.
|
||||
generator()->AdvanceClock(base::Seconds(2));
|
||||
PressAndReleaseEscapeKey();
|
||||
// Exceed shift key time window on final key press.
|
||||
generator()->AdvanceClock(base::Seconds(3));
|
||||
PressAndReleaseShiftKey();
|
||||
EXPECT_TRUE(event_rewriter()->IsEnabled());
|
||||
}
|
||||
|
||||
TEST_F(DisableTouchpadEventRewriterTest,
|
||||
ResetEscapeKeyCountOnNonEscapeKeyPress) {
|
||||
TEST_F(DisableTouchpadEventRewriterTest, ResetShiftKeyCountOnNonShiftKeyPress) {
|
||||
event_rewriter()->SetEnabled(true);
|
||||
|
||||
// Simulate pressing escape key and releasing the escape key 3 times.
|
||||
// Simulate pressing shift key and releasing the shift key 3 times.
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
PressAndReleaseEscapeKey();
|
||||
PressAndReleaseShiftKey();
|
||||
EXPECT_TRUE(event_rewriter()->IsEnabled());
|
||||
}
|
||||
|
||||
// Press non escape key resets the escape key count.
|
||||
// Press non shift key resets the shift key count.
|
||||
generator()->PressKey(ui::VKEY_A, ui::EF_NONE);
|
||||
generator()->ReleaseKey(ui::VKEY_A, ui::EF_NONE);
|
||||
|
||||
EXPECT_TRUE(event_rewriter()->IsEnabled());
|
||||
|
||||
int escapeKeyPressCount = 0;
|
||||
int shiftKeyPressCount = 0;
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
PressAndReleaseEscapeKey();
|
||||
generator()->AdvanceClock(base::Milliseconds(500));
|
||||
++escapeKeyPressCount;
|
||||
PressAndReleaseShiftKey();
|
||||
generator()->AdvanceClock(base::Milliseconds(100));
|
||||
++shiftKeyPressCount;
|
||||
|
||||
if (escapeKeyPressCount == 5) {
|
||||
if (shiftKeyPressCount == 5) {
|
||||
EXPECT_FALSE(event_rewriter()->IsEnabled());
|
||||
} else {
|
||||
EXPECT_TRUE(event_rewriter()->IsEnabled());
|
||||
|
@ -405,7 +405,7 @@ Style notes:
|
||||
Switch Access enabled
|
||||
</message>
|
||||
<message name="IDS_ASH_STATUS_TRAY_TOUCHPAD_DISABLED_DESCRIPTION" desc="The message shown on a notification when the internal touchpad is disabled.">
|
||||
Press Esc 5 times to enable the touchpad
|
||||
Press Shift 5 times to enable the touchpad
|
||||
</message>
|
||||
<message name="IDS_ASH_STATUS_TRAY_TOUCHPAD_DISABLED_TURN_ON" desc="Title of the dialog for disabling the internal touchpad.">
|
||||
Turn on
|
||||
|
@ -1 +1 @@
|
||||
2d981bb5924605ffe6e463040262c4a5c320abfa
|
||||
9624da100879ccf6a507df80d49b58e539f09039
|
@ -1945,7 +1945,7 @@
|
||||
When a mouse is connected
|
||||
</message>
|
||||
<message name="IDS_SETTINGS_RE_ENABLE_TOUCHPAD" desc="A label to show how to re-enable the internal touchpad.">
|
||||
Press esc 5 times to re-enable it
|
||||
Press shift 5 times to re-enable it
|
||||
</message>
|
||||
<message name="IDS_SETTINGS_DISABLE_TOUCHPAD_NEVER" desc="A dropdown item that lets the user never disable the internal touchpad.">
|
||||
Never
|
||||
|
@ -1 +1 @@
|
||||
9ff7e25d5b4e2d8cae2513077a1e44ce09367db1
|
||||
9e1a3be4443602533f4e163b49ee5dceec1146bc
|
Reference in New Issue
Block a user