OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/keyboard/keyboard_util.h" | 5 #include "ui/keyboard/keyboard_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "grit/keyboard_resources.h" | 14 #include "grit/keyboard_resources.h" |
15 #include "grit/keyboard_resources_map.h" | 15 #include "grit/keyboard_resources_map.h" |
16 #include "ui/aura/client/aura_constants.h" | 16 #include "ui/aura/client/aura_constants.h" |
17 #include "ui/aura/window_tree_host.h" | 17 #include "ui/aura/window_tree_host.h" |
18 #include "ui/base/ime/input_method.h" | 18 #include "ui/base/ime/input_method.h" |
19 #include "ui/base/ime/text_input_client.h" | 19 #include "ui/base/ime/text_input_client.h" |
20 #include "ui/events/event_processor.h" | 20 #include "ui/events/event_processor.h" |
21 #include "ui/events/event_utils.h" | |
22 #include "ui/events/keycodes/dom3/dom_code.h" | |
23 #include "ui/events/keycodes/dom3/dom_key.h" | |
21 #include "ui/events/keycodes/dom4/keycode_converter.h" | 24 #include "ui/events/keycodes/dom4/keycode_converter.h" |
25 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
22 #include "ui/keyboard/keyboard_controller.h" | 26 #include "ui/keyboard/keyboard_controller.h" |
23 #include "ui/keyboard/keyboard_controller_proxy.h" | 27 #include "ui/keyboard/keyboard_controller_proxy.h" |
24 #include "ui/keyboard/keyboard_switches.h" | 28 #include "ui/keyboard/keyboard_switches.h" |
25 #include "url/gurl.h" | 29 #include "url/gurl.h" |
26 | 30 |
27 namespace { | 31 namespace { |
28 | 32 |
29 const char kKeyDown[] ="keydown"; | 33 const char kKeyDown[] ="keydown"; |
30 const char kKeyUp[] = "keyup"; | 34 const char kKeyUp[] = "keyup"; |
31 | 35 |
32 void SendProcessKeyEvent(ui::EventType type, | 36 void SendProcessKeyEvent(ui::EventType type, |
33 aura::WindowTreeHost* host) { | 37 aura::WindowTreeHost* host) { |
34 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::EF_NONE); | 38 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::DomCode::NONE, ui::EF_NONE, |
39 ui::DomKey::PROCESS, 0, ui::EventTimeForNow()); | |
35 event.SetTranslated(true); | 40 event.SetTranslated(true); |
36 ui::EventDispatchDetails details = | 41 ui::EventDispatchDetails details = |
37 host->event_processor()->OnEventFromSource(&event); | 42 host->event_processor()->OnEventFromSource(&event); |
38 CHECK(!details.dispatcher_destroyed); | 43 CHECK(!details.dispatcher_destroyed); |
39 } | 44 } |
40 | 45 |
41 base::LazyInstance<base::Time> g_keyboard_load_time_start = | 46 base::LazyInstance<base::Time> g_keyboard_load_time_start = |
42 LAZY_INSTANCE_INITIALIZER; | 47 LAZY_INSTANCE_INITIALIZER; |
43 | 48 |
44 bool g_accessibility_keyboard_enabled = false; | 49 bool g_accessibility_keyboard_enabled = false; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 // ui::TextInputClient interface, say MoveCaretInDirection(). The code in | 191 // ui::TextInputClient interface, say MoveCaretInDirection(). The code in |
187 // here would get the ui::InputMethod from the root_window, and the | 192 // here would get the ui::InputMethod from the root_window, and the |
188 // ui::TextInputClient from that (see above in InsertText()). | 193 // ui::TextInputClient from that (see above in InsertText()). |
189 bool MoveCursor(int swipe_direction, | 194 bool MoveCursor(int swipe_direction, |
190 int modifier_flags, | 195 int modifier_flags, |
191 aura::WindowTreeHost* host) { | 196 aura::WindowTreeHost* host) { |
192 if (!host) | 197 if (!host) |
193 return false; | 198 return false; |
194 ui::KeyboardCode codex = ui::VKEY_UNKNOWN; | 199 ui::KeyboardCode codex = ui::VKEY_UNKNOWN; |
195 ui::KeyboardCode codey = ui::VKEY_UNKNOWN; | 200 ui::KeyboardCode codey = ui::VKEY_UNKNOWN; |
196 if (swipe_direction & kCursorMoveRight) | 201 ui::DomCode domcodex = ui::DomCode::NONE; |
202 ui::DomCode domcodey = ui::DomCode::NONE; | |
203 ui::DomKey domkeyx = ui::DomKey::NONE; | |
204 ui::DomKey domkeyy = ui::DomKey::NONE; | |
205 if (swipe_direction & kCursorMoveRight) { | |
197 codex = ui::VKEY_RIGHT; | 206 codex = ui::VKEY_RIGHT; |
198 else if (swipe_direction & kCursorMoveLeft) | 207 domcodex = ui::DomCode::ARROW_RIGHT; |
208 domkeyx = ui::DomKey::ARROW_RIGHT; | |
209 } else if (swipe_direction & kCursorMoveLeft) { | |
199 codex = ui::VKEY_LEFT; | 210 codex = ui::VKEY_LEFT; |
211 domcodex = ui::DomCode::ARROW_LEFT; | |
212 domkeyx = ui::DomKey::ARROW_LEFT; | |
213 } | |
200 | 214 |
201 if (swipe_direction & kCursorMoveUp) | 215 if (swipe_direction & kCursorMoveUp) { |
202 codey = ui::VKEY_UP; | 216 codey = ui::VKEY_UP; |
203 else if (swipe_direction & kCursorMoveDown) | 217 domcodey = ui::DomCode::ARROW_UP; |
218 domkeyy = ui::DomKey::ARROW_UP; | |
219 } else if (swipe_direction & kCursorMoveDown) { | |
204 codey = ui::VKEY_DOWN; | 220 codey = ui::VKEY_DOWN; |
221 domcodey = ui::DomCode::ARROW_DOWN; | |
222 domkeyy = ui::DomKey::ARROW_DOWN; | |
223 } | |
sadrul
2015/04/21 18:48:16
This seems a bit unfortunate. Is it possible to au
kpschoedel
2015/04/21 19:32:07
Done, using DomCode as the source of truth. In the
| |
205 | 224 |
206 // First deal with the x movement. | 225 // First deal with the x movement. |
207 if (codex != ui::VKEY_UNKNOWN) { | 226 if (codex != ui::VKEY_UNKNOWN) { |
208 ui::KeyEvent press_event(ui::ET_KEY_PRESSED, codex, modifier_flags); | 227 ui::KeyEvent press_event(ui::ET_KEY_PRESSED, codex, domcodex, |
228 modifier_flags, domkeyx, 0, ui::EventTimeForNow()); | |
209 ui::EventDispatchDetails details = | 229 ui::EventDispatchDetails details = |
210 host->event_processor()->OnEventFromSource(&press_event); | 230 host->event_processor()->OnEventFromSource(&press_event); |
211 CHECK(!details.dispatcher_destroyed); | 231 CHECK(!details.dispatcher_destroyed); |
212 ui::KeyEvent release_event(ui::ET_KEY_RELEASED, codex, modifier_flags); | 232 ui::KeyEvent release_event(ui::ET_KEY_RELEASED, codex, domcodex, |
233 modifier_flags, domkeyx, 0, | |
234 ui::EventTimeForNow()); | |
213 details = host->event_processor()->OnEventFromSource(&release_event); | 235 details = host->event_processor()->OnEventFromSource(&release_event); |
214 CHECK(!details.dispatcher_destroyed); | 236 CHECK(!details.dispatcher_destroyed); |
215 } | 237 } |
216 | 238 |
217 // Then deal with the y movement. | 239 // Then deal with the y movement. |
218 if (codey != ui::VKEY_UNKNOWN) { | 240 if (codey != ui::VKEY_UNKNOWN) { |
219 ui::KeyEvent press_event(ui::ET_KEY_PRESSED, codey, modifier_flags); | 241 ui::KeyEvent press_event(ui::ET_KEY_PRESSED, codey, domcodey, |
242 modifier_flags, domkeyy, 0, ui::EventTimeForNow()); | |
220 ui::EventDispatchDetails details = | 243 ui::EventDispatchDetails details = |
221 host->event_processor()->OnEventFromSource(&press_event); | 244 host->event_processor()->OnEventFromSource(&press_event); |
222 CHECK(!details.dispatcher_destroyed); | 245 CHECK(!details.dispatcher_destroyed); |
223 ui::KeyEvent release_event(ui::ET_KEY_RELEASED, codey, modifier_flags); | 246 ui::KeyEvent release_event(ui::ET_KEY_RELEASED, codey, domcodey, |
247 modifier_flags, domkeyy, 0, | |
248 ui::EventTimeForNow()); | |
224 details = host->event_processor()->OnEventFromSource(&release_event); | 249 details = host->event_processor()->OnEventFromSource(&release_event); |
225 CHECK(!details.dispatcher_destroyed); | 250 CHECK(!details.dispatcher_destroyed); |
226 } | 251 } |
227 return true; | 252 return true; |
228 } | 253 } |
229 | 254 |
230 bool SendKeyEvent(const std::string type, | 255 bool SendKeyEvent(const std::string type, |
231 int key_value, | 256 int key_value, |
232 int key_code, | 257 int key_code, |
233 std::string key_name, | 258 std::string key_name, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 // metric will be used to determine the error rate for the keyboard. | 292 // metric will be used to determine the error rate for the keyboard. |
268 UMA_HISTOGRAM_CUSTOM_COUNTS( | 293 UMA_HISTOGRAM_CUSTOM_COUNTS( |
269 "VirtualKeyboard.KeystrokesBetweenBackspaces", | 294 "VirtualKeyboard.KeystrokesBetweenBackspaces", |
270 keys_seen, 1, 1000, 50); | 295 keys_seen, 1, 1000, 50); |
271 keys_seen = 0; | 296 keys_seen = 0; |
272 } else { | 297 } else { |
273 ++keys_seen; | 298 ++keys_seen; |
274 } | 299 } |
275 } | 300 } |
276 | 301 |
302 ui::DomCode dom_code = ui::DomCode::NONE; | |
303 if (!key_name.empty()) | |
304 dom_code = ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str()); | |
305 if (dom_code == ui::DomCode::NONE) | |
306 dom_code = ui::UsLayoutKeyboardCodeToDomCode(code); | |
307 CHECK(dom_code != ui::DomCode::NONE); | |
277 ui::KeyEvent event( | 308 ui::KeyEvent event( |
278 event_type, | 309 event_type, |
279 code, | 310 code, |
280 ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str()), | 311 dom_code, |
281 modifiers); | 312 modifiers); |
kpschoedel
2015/04/21 19:32:07
Remark: if the virtual keyboard knows the intended
| |
282 ui::EventDispatchDetails details = | 313 ui::EventDispatchDetails details = |
283 host->event_processor()->OnEventFromSource(&event); | 314 host->event_processor()->OnEventFromSource(&event); |
284 CHECK(!details.dispatcher_destroyed); | 315 CHECK(!details.dispatcher_destroyed); |
285 } | 316 } |
286 return true; | 317 return true; |
287 } | 318 } |
288 | 319 |
289 void MarkKeyboardLoadStarted() { | 320 void MarkKeyboardLoadStarted() { |
290 if (!g_keyboard_load_time_start.Get().ToInternalValue()) | 321 if (!g_keyboard_load_time_start.Get().ToInternalValue()) |
291 g_keyboard_load_time_start.Get() = base::Time::Now(); | 322 g_keyboard_load_time_start.Get() = base::Time::Now(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 } | 426 } |
396 | 427 |
397 void LogKeyboardControlEvent(KeyboardControlEvent event) { | 428 void LogKeyboardControlEvent(KeyboardControlEvent event) { |
398 UMA_HISTOGRAM_ENUMERATION( | 429 UMA_HISTOGRAM_ENUMERATION( |
399 "VirtualKeyboard.KeyboardControlEvent", | 430 "VirtualKeyboard.KeyboardControlEvent", |
400 event, | 431 event, |
401 keyboard::KEYBOARD_CONTROL_MAX); | 432 keyboard::KEYBOARD_CONTROL_MAX); |
402 } | 433 } |
403 | 434 |
404 } // namespace keyboard | 435 } // namespace keyboard |
OLD | NEW |