[DisableTouchpad] Fix touchpad re-enable on long Shift press
Switched from onKeyPress to onKeyRelease for Shift key handling to address ChromeOS's behavior of interpreting held keys as multiple presses. Bug: 400334863 Change-Id: I77c383cc27bdcdd2c48e8aa65ce60d77237bf922 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6367698 Reviewed-by: Akihiro Ota <akihiroota@chromium.org> Commit-Queue: Jesulayomi Kupoluyi <lkupo@google.com> Cr-Commit-Position: refs/heads/main@{#1434930}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
a9a6230465
commit
e18d6fdc9b
ash/accessibility
@@ -145,37 +145,37 @@ ui::EventDispatchDetails DisableTouchpadEventRewriter::HandleMouseOrScrollEvent(
|
||||
}
|
||||
|
||||
void DisableTouchpadEventRewriter::HandleKeyEvent(const ui::KeyEvent* event) {
|
||||
if (event->type() != ui::EventType::kKeyPressed) {
|
||||
if (event->type() != ui::EventType::kKeyReleased) {
|
||||
return;
|
||||
}
|
||||
event->key_code() == ui::VKEY_SHIFT ? HandleShiftKeyPress()
|
||||
: ResetShiftKeyPressTracking();
|
||||
event->key_code() == ui::VKEY_SHIFT ? HandleShiftKeyRelease()
|
||||
: ResetShiftKeyReleaseTracking();
|
||||
}
|
||||
|
||||
void DisableTouchpadEventRewriter::HandleShiftKeyPress() {
|
||||
if (shift_press_count_ == 0) {
|
||||
first_shift_press_time_ = ui::EventTimeForNow();
|
||||
void DisableTouchpadEventRewriter::HandleShiftKeyRelease() {
|
||||
if (shift_release_count_ == 0) {
|
||||
first_shift_release_time_ = ui::EventTimeForNow();
|
||||
}
|
||||
|
||||
++shift_press_count_;
|
||||
++shift_release_count_;
|
||||
base::TimeDelta elapsed_time =
|
||||
ui::EventTimeForNow() - first_shift_press_time_;
|
||||
ui::EventTimeForNow() - first_shift_release_time_;
|
||||
|
||||
if (elapsed_time > kEnableTouchpadKeyPressWindow) {
|
||||
ResetShiftKeyPressTracking();
|
||||
ResetShiftKeyReleaseTracking();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shift_press_count_ >= 5) {
|
||||
if (shift_release_count_ >= 5) {
|
||||
SetEnabled(false);
|
||||
Shell::Get()->accessibility_controller()->EnableInternalTouchpad();
|
||||
ResetShiftKeyPressTracking();
|
||||
ResetShiftKeyReleaseTracking();
|
||||
}
|
||||
}
|
||||
|
||||
void DisableTouchpadEventRewriter::ResetShiftKeyPressTracking() {
|
||||
shift_press_count_ = 0;
|
||||
first_shift_press_time_ = base::TimeTicks();
|
||||
void DisableTouchpadEventRewriter::ResetShiftKeyReleaseTracking() {
|
||||
shift_release_count_ = 0;
|
||||
first_shift_release_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 HandleShiftKeyPress();
|
||||
void ResetShiftKeyPressTracking();
|
||||
void HandleShiftKeyRelease();
|
||||
void ResetShiftKeyReleaseTracking();
|
||||
ui::EventDispatchDetails HandleMouseOrScrollEvent(
|
||||
const ui::Event& event,
|
||||
const Continuation continuation);
|
||||
|
||||
bool enabled_ = false;
|
||||
int shift_press_count_ = 0;
|
||||
base::TimeTicks first_shift_press_time_ = base::TimeTicks();
|
||||
int shift_release_count_ = 0;
|
||||
base::TimeTicks first_shift_release_time_ = base::TimeTicks();
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
Reference in New Issue
Block a user