Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Unified Diff: ui/events/ozone/evdev/keyboard_evdev.cc

Issue 1052273006: ozone: evdev: Make cancellation of repeats on key up more robust (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge DispatchKeyRepeat Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/ozone/evdev/keyboard_evdev.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/ozone/evdev/keyboard_evdev.cc
diff --git a/ui/events/ozone/evdev/keyboard_evdev.cc b/ui/events/ozone/evdev/keyboard_evdev.cc
index c0bd7e7d37a2b474b31e073656223d875190d0c2..1de30ff8a49be365e8ab0886e183bfb87991abe8 100644
--- a/ui/events/ozone/evdev/keyboard_evdev.cc
+++ b/ui/events/ozone/evdev/keyboard_evdev.cc
@@ -4,6 +4,8 @@
#include "ui/events/ozone/evdev/keyboard_evdev.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
@@ -59,7 +61,9 @@ KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers,
modifiers_(modifiers),
keyboard_layout_engine_(keyboard_layout_engine),
repeat_enabled_(true),
- repeat_key_(KEY_RESERVED) {
+ repeat_key_(KEY_RESERVED),
+ repeat_sequence_(0),
+ weak_ptr_factory_(this) {
repeat_delay_ = base::TimeDelta::FromMilliseconds(kRepeatDelayMs);
repeat_interval_ = base::TimeDelta::FromMilliseconds(kRepeatIntervalMs);
}
@@ -146,31 +150,30 @@ void KeyboardEvdev::UpdateKeyRepeat(unsigned int key, bool down) {
void KeyboardEvdev::StartKeyRepeat(unsigned int key) {
repeat_key_ = key;
- repeat_delay_timer_.Start(
- FROM_HERE, repeat_delay_,
- base::Bind(&KeyboardEvdev::OnRepeatDelayTimeout, base::Unretained(this)));
- repeat_interval_timer_.Stop();
+ repeat_sequence_++;
+
+ ScheduleKeyRepeat(repeat_delay_);
}
void KeyboardEvdev::StopKeyRepeat() {
- repeat_key_ = KEY_RESERVED;
- repeat_delay_timer_.Stop();
- repeat_interval_timer_.Stop();
+ repeat_sequence_++;
}
-void KeyboardEvdev::OnRepeatDelayTimeout() {
- DispatchKey(repeat_key_, true /* down */, true /* repeat */,
- EventTimeForNow());
-
- repeat_interval_timer_.Start(
- FROM_HERE, repeat_interval_,
- base::Bind(&KeyboardEvdev::OnRepeatIntervalTimeout,
- base::Unretained(this)));
+void KeyboardEvdev::ScheduleKeyRepeat(const base::TimeDelta& delay) {
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, base::Bind(&KeyboardEvdev::OnRepeatTimeout,
+ weak_ptr_factory_.GetWeakPtr(), repeat_sequence_),
+ delay);
}
-void KeyboardEvdev::OnRepeatIntervalTimeout() {
+void KeyboardEvdev::OnRepeatTimeout(unsigned int sequence) {
+ if (repeat_sequence_ != sequence)
+ return;
+
DispatchKey(repeat_key_, true /* down */, true /* repeat */,
EventTimeForNow());
+
+ ScheduleKeyRepeat(repeat_interval_);
}
void KeyboardEvdev::DispatchKey(unsigned int key,
« no previous file with comments | « ui/events/ozone/evdev/keyboard_evdev.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698