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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « ui/events/ozone/evdev/keyboard_evdev.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/events/ozone/evdev/keyboard_evdev.h" 5 #include "ui/events/ozone/evdev/keyboard_evdev.h"
6 6
7 #include "base/single_thread_task_runner.h"
8 #include "base/thread_task_runner_handle.h"
7 #include "ui/events/event.h" 9 #include "ui/events/event.h"
8 #include "ui/events/event_constants.h" 10 #include "ui/events/event_constants.h"
9 #include "ui/events/event_utils.h" 11 #include "ui/events/event_utils.h"
10 #include "ui/events/keycodes/dom4/keycode_converter.h" 12 #include "ui/events/keycodes/dom4/keycode_converter.h"
11 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" 13 #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
12 #include "ui/events/ozone/evdev/keyboard_util_evdev.h" 14 #include "ui/events/ozone/evdev/keyboard_util_evdev.h"
13 #include "ui/events/ozone/layout/keyboard_layout_engine.h" 15 #include "ui/events/ozone/layout/keyboard_layout_engine.h"
14 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" 16 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
15 #include "ui/events/ozone/layout/layout_util.h" 17 #include "ui/events/ozone/layout/layout_util.h"
16 18
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 54
53 } // namespace 55 } // namespace
54 56
55 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers, 57 KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers,
56 KeyboardLayoutEngine* keyboard_layout_engine, 58 KeyboardLayoutEngine* keyboard_layout_engine,
57 const EventDispatchCallback& callback) 59 const EventDispatchCallback& callback)
58 : callback_(callback), 60 : callback_(callback),
59 modifiers_(modifiers), 61 modifiers_(modifiers),
60 keyboard_layout_engine_(keyboard_layout_engine), 62 keyboard_layout_engine_(keyboard_layout_engine),
61 repeat_enabled_(true), 63 repeat_enabled_(true),
62 repeat_key_(KEY_RESERVED) { 64 repeat_key_(KEY_RESERVED),
65 repeat_sequence_(0),
66 weak_ptr_factory_(this) {
63 repeat_delay_ = base::TimeDelta::FromMilliseconds(kRepeatDelayMs); 67 repeat_delay_ = base::TimeDelta::FromMilliseconds(kRepeatDelayMs);
64 repeat_interval_ = base::TimeDelta::FromMilliseconds(kRepeatIntervalMs); 68 repeat_interval_ = base::TimeDelta::FromMilliseconds(kRepeatIntervalMs);
65 } 69 }
66 70
67 KeyboardEvdev::~KeyboardEvdev() { 71 KeyboardEvdev::~KeyboardEvdev() {
68 } 72 }
69 73
70 void KeyboardEvdev::OnKeyChange(unsigned int key, 74 void KeyboardEvdev::OnKeyChange(unsigned int key,
71 bool down, 75 bool down,
72 base::TimeDelta timestamp) { 76 base::TimeDelta timestamp) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if (!repeat_enabled_) 143 if (!repeat_enabled_)
140 StopKeyRepeat(); 144 StopKeyRepeat();
141 else if (key != repeat_key_ && down) 145 else if (key != repeat_key_ && down)
142 StartKeyRepeat(key); 146 StartKeyRepeat(key);
143 else if (key == repeat_key_ && !down) 147 else if (key == repeat_key_ && !down)
144 StopKeyRepeat(); 148 StopKeyRepeat();
145 } 149 }
146 150
147 void KeyboardEvdev::StartKeyRepeat(unsigned int key) { 151 void KeyboardEvdev::StartKeyRepeat(unsigned int key) {
148 repeat_key_ = key; 152 repeat_key_ = key;
149 repeat_delay_timer_.Start( 153 repeat_sequence_++;
150 FROM_HERE, repeat_delay_, 154
151 base::Bind(&KeyboardEvdev::OnRepeatDelayTimeout, base::Unretained(this))); 155 ScheduleKeyRepeat(repeat_delay_);
152 repeat_interval_timer_.Stop();
153 } 156 }
154 157
155 void KeyboardEvdev::StopKeyRepeat() { 158 void KeyboardEvdev::StopKeyRepeat() {
156 repeat_key_ = KEY_RESERVED; 159 repeat_sequence_++;
157 repeat_delay_timer_.Stop();
158 repeat_interval_timer_.Stop();
159 } 160 }
160 161
161 void KeyboardEvdev::OnRepeatDelayTimeout() { 162 void KeyboardEvdev::ScheduleKeyRepeat(const base::TimeDelta& delay) {
162 DispatchKey(repeat_key_, true /* down */, true /* repeat */, 163 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
163 EventTimeForNow()); 164 FROM_HERE, base::Bind(&KeyboardEvdev::OnRepeatTimeout,
164 165 weak_ptr_factory_.GetWeakPtr(), repeat_sequence_),
165 repeat_interval_timer_.Start( 166 delay);
166 FROM_HERE, repeat_interval_,
167 base::Bind(&KeyboardEvdev::OnRepeatIntervalTimeout,
168 base::Unretained(this)));
169 } 167 }
170 168
171 void KeyboardEvdev::OnRepeatIntervalTimeout() { 169 void KeyboardEvdev::OnRepeatTimeout(unsigned int sequence) {
170 if (repeat_sequence_ != sequence)
171 return;
172
173 DispatchKeyRepeat(repeat_key_);
alexst (slow to review) 2015/04/07 18:20:58 Probably worth just moving DispatchKey from Dispat
spang 2015/04/07 18:28:49 Done.
174 ScheduleKeyRepeat(repeat_interval_);
175 }
176
177 void KeyboardEvdev::DispatchKeyRepeat(unsigned int key) {
172 DispatchKey(repeat_key_, true /* down */, true /* repeat */, 178 DispatchKey(repeat_key_, true /* down */, true /* repeat */,
173 EventTimeForNow()); 179 EventTimeForNow());
174 } 180 }
175 181
176 void KeyboardEvdev::DispatchKey(unsigned int key, 182 void KeyboardEvdev::DispatchKey(unsigned int key,
177 bool down, 183 bool down,
178 bool repeat, 184 bool repeat,
179 base::TimeDelta timestamp) { 185 base::TimeDelta timestamp) {
180 DomCode dom_code = 186 DomCode dom_code =
181 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key)); 187 KeycodeConverter::NativeKeycodeToDomCode(EvdevCodeToNativeCode(key));
(...skipping 14 matching lines...) Expand all
196 UpdateModifier(ModifierDomKeyToEventFlag(dom_key), down); 202 UpdateModifier(ModifierDomKeyToEventFlag(dom_key), down);
197 203
198 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code, 204 KeyEvent event(down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code,
199 modifiers_->GetModifierFlags(), dom_key, character, timestamp); 205 modifiers_->GetModifierFlags(), dom_key, character, timestamp);
200 if (platform_keycode) 206 if (platform_keycode)
201 event.set_platform_keycode(platform_keycode); 207 event.set_platform_keycode(platform_keycode);
202 callback_.Run(&event); 208 callback_.Run(&event);
203 } 209 }
204 210
205 } // namespace ui 211 } // namespace ui
OLDNEW
« 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