OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/input_method/input_method_engine_base.h" | 5 #include "chrome/browser/ui/input_method/input_method_engine_base.h" |
6 | 6 |
7 #undef FocusIn | 7 #undef FocusIn |
8 #undef FocusOut | 8 #undef FocusOut |
9 #undef RootWindow | 9 #undef RootWindow |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
23 #include "ui/base/ime/composition_text.h" | 23 #include "ui/base/ime/composition_text.h" |
24 #include "ui/base/ime/ime_bridge.h" | 24 #include "ui/base/ime/ime_bridge.h" |
25 #include "ui/base/ime/text_input_flags.h" | 25 #include "ui/base/ime/text_input_flags.h" |
26 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
27 #include "ui/events/event_processor.h" | 27 #include "ui/events/event_processor.h" |
28 #include "ui/events/event_utils.h" | 28 #include "ui/events/event_utils.h" |
29 #include "ui/events/keycodes/dom/dom_code.h" | 29 #include "ui/events/keycodes/dom/dom_code.h" |
| 30 #include "ui/events/keycodes/dom/keycode_converter.h" |
30 #include "ui/keyboard/keyboard_controller.h" | 31 #include "ui/keyboard/keyboard_controller.h" |
31 #include "ui/keyboard/keyboard_util.h" | 32 #include "ui/keyboard/keyboard_util.h" |
32 | 33 |
33 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
34 #include "ui/base/ime/chromeos/ime_keymap.h" | 35 #include "ui/base/ime/chromeos/ime_keymap.h" |
35 #elif defined(OS_WIN) | 36 #elif defined(OS_WIN) |
36 #include "ui/events/keycodes/dom/keycode_converter.h" | 37 #include "ui/events/keycodes/dom/keycode_converter.h" |
37 #include "ui/events/keycodes/keyboard_codes_win.h" | 38 #include "ui/events/keycodes/keyboard_codes_win.h" |
38 #elif defined(OS_LINUX) | 39 #elif defined(OS_LINUX) |
39 #include "ui/events/keycodes/dom/keycode_converter.h" | 40 #include "ui/events/keycodes/dom/keycode_converter.h" |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 const std::string& component_id, | 413 const std::string& component_id, |
413 ui::IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) { | 414 ui::IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) { |
414 std::string request_id = base::IntToString(next_request_id_); | 415 std::string request_id = base::IntToString(next_request_id_); |
415 ++next_request_id_; | 416 ++next_request_id_; |
416 | 417 |
417 request_map_[request_id] = std::make_pair(component_id, key_data); | 418 request_map_[request_id] = std::make_pair(component_id, key_data); |
418 | 419 |
419 return request_id; | 420 return request_id; |
420 } | 421 } |
421 | 422 |
| 423 bool InputMethodEngineBase::SendKeyEvents( |
| 424 int context_id, |
| 425 const std::vector<KeyboardEvent>& events) { |
| 426 // context_id == 0, means sending key events to non-input field. |
| 427 // context_id_ == -1, means the focus is not in an input field. |
| 428 if (!IsActive() || |
| 429 (context_id != 0 && (context_id != context_id_ || context_id_ == -1))) |
| 430 return false; |
| 431 |
| 432 for (size_t i = 0; i < events.size(); ++i) { |
| 433 const KeyboardEvent& event = events[i]; |
| 434 const ui::EventType type = |
| 435 (event.type == "keyup") ? ui::ET_KEY_RELEASED : ui::ET_KEY_PRESSED; |
| 436 ui::KeyboardCode key_code = static_cast<ui::KeyboardCode>(event.key_code); |
| 437 |
| 438 int flags = ui::EF_NONE; |
| 439 flags |= event.alt_key ? ui::EF_ALT_DOWN : ui::EF_NONE; |
| 440 flags |= event.ctrl_key ? ui::EF_CONTROL_DOWN : ui::EF_NONE; |
| 441 flags |= event.shift_key ? ui::EF_SHIFT_DOWN : ui::EF_NONE; |
| 442 flags |= event.caps_lock ? ui::EF_CAPS_LOCK_ON : ui::EF_NONE; |
| 443 |
| 444 ui::KeyEvent ui_event( |
| 445 type, key_code, ui::KeycodeConverter::CodeStringToDomCode(event.code), |
| 446 flags, ui::KeycodeConverter::KeyStringToDomKey(event.key), |
| 447 ui::EventTimeForNow()); |
| 448 base::AutoReset<const ui::KeyEvent*> reset_sent_key(&sent_key_event_, |
| 449 &ui_event); |
| 450 if (!SendKeyEvent(&ui_event, event.code)) |
| 451 return false; |
| 452 } |
| 453 return true; |
| 454 } |
| 455 |
422 } // namespace input_method | 456 } // namespace input_method |
OLD | NEW |