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