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/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "grit/keyboard_resources.h" | 15 #include "grit/keyboard_resources.h" |
16 #include "grit/keyboard_resources_map.h" | 16 #include "grit/keyboard_resources_map.h" |
17 #include "ui/aura/client/aura_constants.h" | 17 #include "ui/aura/client/aura_constants.h" |
James Cook
2015/06/01 22:21:00
Can this be removed?
Shu Chen
2015/06/02 04:11:17
Yes, it can be remvoed.
| |
18 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
19 #include "ui/base/ime/input_method.h" | 19 #include "ui/base/ime/input_method.h" |
20 #include "ui/base/ime/text_input_client.h" | 20 #include "ui/base/ime/text_input_client.h" |
21 #include "ui/events/event_processor.h" | 21 #include "ui/events/event_processor.h" |
22 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
23 #include "ui/events/keycodes/dom/dom_code.h" | 23 #include "ui/events/keycodes/dom/dom_code.h" |
24 #include "ui/events/keycodes/dom/dom_key.h" | 24 #include "ui/events/keycodes/dom/dom_key.h" |
25 #include "ui/events/keycodes/dom/keycode_converter.h" | 25 #include "ui/events/keycodes/dom/keycode_converter.h" |
26 #include "ui/events/keycodes/keyboard_code_conversion.h" | 26 #include "ui/events/keycodes/keyboard_code_conversion.h" |
27 #include "ui/keyboard/keyboard_controller.h" | 27 #include "ui/keyboard/keyboard_controller.h" |
28 #include "ui/keyboard/keyboard_controller_proxy.h" | 28 #include "ui/keyboard/keyboard_controller_proxy.h" |
29 #include "ui/keyboard/keyboard_switches.h" | 29 #include "ui/keyboard/keyboard_switches.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kKeyDown[] ="keydown"; | 34 const char kKeyDown[] ="keydown"; |
35 const char kKeyUp[] = "keyup"; | 35 const char kKeyUp[] = "keyup"; |
36 | 36 |
37 void SendProcessKeyEvent(ui::EventType type, | 37 void SendProcessKeyEvent(ui::EventType type, |
38 aura::WindowTreeHost* host) { | 38 aura::WindowTreeHost* host) { |
39 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::DomCode::NONE, ui::EF_NONE, | 39 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::DomCode::NONE, ui::EF_NONE, |
40 ui::DomKey::PROCESS, 0, ui::EventTimeForNow()); | 40 ui::DomKey::PROCESS, 0, ui::EventTimeForNow()); |
41 event.SetTranslated(true); | |
42 ui::EventDispatchDetails details = | 41 ui::EventDispatchDetails details = |
43 host->event_processor()->OnEventFromSource(&event); | 42 host->event_processor()->OnEventFromSource(&event); |
44 CHECK(!details.dispatcher_destroyed); | 43 CHECK(!details.dispatcher_destroyed); |
45 } | 44 } |
46 | 45 |
47 base::LazyInstance<base::Time> g_keyboard_load_time_start = | 46 base::LazyInstance<base::Time> g_keyboard_load_time_start = |
48 LAZY_INSTANCE_INITIALIZER; | 47 LAZY_INSTANCE_INITIALIZER; |
49 | 48 |
50 bool g_accessibility_keyboard_enabled = false; | 49 bool g_accessibility_keyboard_enabled = false; |
51 | 50 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 ui::EventType event_type = ui::ET_UNKNOWN; | 276 ui::EventType event_type = ui::ET_UNKNOWN; |
278 if (type == kKeyDown) | 277 if (type == kKeyDown) |
279 event_type = ui::ET_KEY_PRESSED; | 278 event_type = ui::ET_KEY_PRESSED; |
280 else if (type == kKeyUp) | 279 else if (type == kKeyUp) |
281 event_type = ui::ET_KEY_RELEASED; | 280 event_type = ui::ET_KEY_RELEASED; |
282 if (event_type == ui::ET_UNKNOWN) | 281 if (event_type == ui::ET_UNKNOWN) |
283 return false; | 282 return false; |
284 | 283 |
285 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code); | 284 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code); |
286 | 285 |
286 ui::InputMethod* input_method = host->GetInputMethod(); | |
287 if (code == ui::VKEY_UNKNOWN) { | 287 if (code == ui::VKEY_UNKNOWN) { |
288 // Handling of special printable characters (e.g. accented characters) for | 288 // Handling of special printable characters (e.g. accented characters) for |
289 // which there is no key code. | 289 // which there is no key code. |
290 if (event_type == ui::ET_KEY_RELEASED) { | 290 if (event_type == ui::ET_KEY_RELEASED) { |
291 ui::InputMethod* input_method = host->window()->GetProperty( | |
292 aura::client::kRootWindowInputMethodKey); | |
293 if (!input_method) | 291 if (!input_method) |
294 return false; | 292 return false; |
295 | 293 |
296 ui::TextInputClient* tic = input_method->GetTextInputClient(); | 294 ui::TextInputClient* tic = input_method->GetTextInputClient(); |
297 | 295 |
298 SendProcessKeyEvent(ui::ET_KEY_PRESSED, host); | 296 SendProcessKeyEvent(ui::ET_KEY_PRESSED, host); |
299 tic->InsertChar(static_cast<uint16>(key_value), ui::EF_NONE); | 297 tic->InsertChar(static_cast<uint16>(key_value), ui::EF_NONE); |
300 SendProcessKeyEvent(ui::ET_KEY_RELEASED, host); | 298 SendProcessKeyEvent(ui::ET_KEY_RELEASED, host); |
301 } | 299 } |
302 } else { | 300 } else { |
(...skipping 16 matching lines...) Expand all Loading... | |
319 if (!key_name.empty()) | 317 if (!key_name.empty()) |
320 dom_code = ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str()); | 318 dom_code = ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str()); |
321 if (dom_code == ui::DomCode::NONE) | 319 if (dom_code == ui::DomCode::NONE) |
322 dom_code = ui::UsLayoutKeyboardCodeToDomCode(code); | 320 dom_code = ui::UsLayoutKeyboardCodeToDomCode(code); |
323 CHECK(dom_code != ui::DomCode::NONE); | 321 CHECK(dom_code != ui::DomCode::NONE); |
324 ui::KeyEvent event( | 322 ui::KeyEvent event( |
325 event_type, | 323 event_type, |
326 code, | 324 code, |
327 dom_code, | 325 dom_code, |
328 modifiers); | 326 modifiers); |
329 ui::EventDispatchDetails details = | 327 if (input_method) { |
330 host->event_processor()->OnEventFromSource(&event); | 328 input_method->DispatchKeyEvent(event); |
331 CHECK(!details.dispatcher_destroyed); | 329 } else { |
330 ui::EventDispatchDetails details = | |
331 host->event_processor()->OnEventFromSource(&event); | |
332 CHECK(!details.dispatcher_destroyed); | |
333 } | |
332 } | 334 } |
333 return true; | 335 return true; |
334 } | 336 } |
335 | 337 |
336 void MarkKeyboardLoadStarted() { | 338 void MarkKeyboardLoadStarted() { |
337 if (!g_keyboard_load_time_start.Get().ToInternalValue()) | 339 if (!g_keyboard_load_time_start.Get().ToInternalValue()) |
338 g_keyboard_load_time_start.Get() = base::Time::Now(); | 340 g_keyboard_load_time_start.Get() = base::Time::Now(); |
339 } | 341 } |
340 | 342 |
341 void MarkKeyboardLoadFinished() { | 343 void MarkKeyboardLoadFinished() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 } | 444 } |
443 | 445 |
444 void LogKeyboardControlEvent(KeyboardControlEvent event) { | 446 void LogKeyboardControlEvent(KeyboardControlEvent event) { |
445 UMA_HISTOGRAM_ENUMERATION( | 447 UMA_HISTOGRAM_ENUMERATION( |
446 "VirtualKeyboard.KeyboardControlEvent", | 448 "VirtualKeyboard.KeyboardControlEvent", |
447 event, | 449 event, |
448 keyboard::KEYBOARD_CONTROL_MAX); | 450 keyboard::KEYBOARD_CONTROL_MAX); |
449 } | 451 } |
450 | 452 |
451 } // namespace keyboard | 453 } // namespace keyboard |
OLD | NEW |