| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/chromeos/input_method/input_method_engine.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #undef FocusIn | 9 #undef FocusIn |
| 10 #undef FocusOut | 10 #undef FocusOut |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 is_vertical(false), | 66 is_vertical(false), |
| 67 show_window_at_composition(false) {} | 67 show_window_at_composition(false) {} |
| 68 | 68 |
| 69 InputMethodEngine::CandidateWindowProperty::~CandidateWindowProperty() {} | 69 InputMethodEngine::CandidateWindowProperty::~CandidateWindowProperty() {} |
| 70 | 70 |
| 71 InputMethodEngine::InputMethodEngine() | 71 InputMethodEngine::InputMethodEngine() |
| 72 : candidate_window_(new ui::CandidateWindow()), window_visible_(false) {} | 72 : candidate_window_(new ui::CandidateWindow()), window_visible_(false) {} |
| 73 | 73 |
| 74 InputMethodEngine::~InputMethodEngine() {} | 74 InputMethodEngine::~InputMethodEngine() {} |
| 75 | 75 |
| 76 bool InputMethodEngine::SendKeyEvents( | |
| 77 int context_id, | |
| 78 const std::vector<KeyboardEvent>& events) { | |
| 79 if (!IsActive()) { | |
| 80 return false; | |
| 81 } | |
| 82 // context_id == 0, means sending key events to non-input field. | |
| 83 // context_id_ == -1, means the focus is not in an input field. | |
| 84 if (context_id != 0 && (context_id != context_id_ || context_id_ == -1)) { | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 ui::EventProcessor* dispatcher = | |
| 89 ash::Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); | |
| 90 | |
| 91 for (size_t i = 0; i < events.size(); ++i) { | |
| 92 const KeyboardEvent& event = events[i]; | |
| 93 const ui::EventType type = | |
| 94 (event.type == "keyup") ? ui::ET_KEY_RELEASED : ui::ET_KEY_PRESSED; | |
| 95 ui::KeyboardCode key_code = static_cast<ui::KeyboardCode>(event.key_code); | |
| 96 if (key_code == ui::VKEY_UNKNOWN) | |
| 97 key_code = ui::DomKeycodeToKeyboardCode(event.code); | |
| 98 | |
| 99 int flags = ui::EF_NONE; | |
| 100 flags |= event.alt_key ? ui::EF_ALT_DOWN : ui::EF_NONE; | |
| 101 flags |= event.ctrl_key ? ui::EF_CONTROL_DOWN : ui::EF_NONE; | |
| 102 flags |= event.shift_key ? ui::EF_SHIFT_DOWN : ui::EF_NONE; | |
| 103 flags |= event.caps_lock ? ui::EF_CAPS_LOCK_ON : ui::EF_NONE; | |
| 104 | |
| 105 ui::KeyEvent ui_event( | |
| 106 type, key_code, | |
| 107 ui::KeycodeConverter::CodeStringToDomCode(event.code), flags, | |
| 108 ui::KeycodeConverter::KeyStringToDomKey(event.key), | |
| 109 ui::EventTimeForNow()); | |
| 110 base::AutoReset<const ui::KeyEvent*> reset_sent_key(&sent_key_event_, | |
| 111 &ui_event); | |
| 112 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&ui_event); | |
| 113 if (details.dispatcher_destroyed) | |
| 114 break; | |
| 115 } | |
| 116 | |
| 117 return true; | |
| 118 } | |
| 119 | |
| 120 const InputMethodEngine::CandidateWindowProperty& | 76 const InputMethodEngine::CandidateWindowProperty& |
| 121 InputMethodEngine::GetCandidateWindowProperty() const { | 77 InputMethodEngine::GetCandidateWindowProperty() const { |
| 122 return candidate_window_property_; | 78 return candidate_window_property_; |
| 123 } | 79 } |
| 124 | 80 |
| 125 void InputMethodEngine::SetCandidateWindowProperty( | 81 void InputMethodEngine::SetCandidateWindowProperty( |
| 126 const CandidateWindowProperty& property) { | 82 const CandidateWindowProperty& property) { |
| 127 // Type conversion from InputMethodEngine::CandidateWindowProperty to | 83 // Type conversion from InputMethodEngine::CandidateWindowProperty to |
| 128 // CandidateWindow::CandidateWindowProperty defined in chromeos/ime/. | 84 // CandidateWindow::CandidateWindowProperty defined in chromeos/ime/. |
| 129 ui::CandidateWindow::CandidateWindowProperty dest_property; | 85 ui::CandidateWindow::CandidateWindowProperty dest_property; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 317 |
| 362 // Records histograms for committed characters. | 318 // Records histograms for committed characters. |
| 363 if (!composition_text_->text.empty()) { | 319 if (!composition_text_->text.empty()) { |
| 364 base::string16 wtext = base::UTF8ToUTF16(text); | 320 base::string16 wtext = base::UTF8ToUTF16(text); |
| 365 UMA_HISTOGRAM_CUSTOM_COUNTS("InputMethod.CommitLength", wtext.length(), 1, | 321 UMA_HISTOGRAM_CUSTOM_COUNTS("InputMethod.CommitLength", wtext.length(), 1, |
| 366 25, 25); | 322 25, 25); |
| 367 composition_text_.reset(new ui::CompositionText()); | 323 composition_text_.reset(new ui::CompositionText()); |
| 368 } | 324 } |
| 369 } | 325 } |
| 370 | 326 |
| 327 bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event, |
| 328 const std::string& code) { |
| 329 DCHECK(event); |
| 330 if (event->key_code() == ui::VKEY_UNKNOWN) |
| 331 event->set_key_code(ui::DomKeycodeToKeyboardCode(code)); |
| 332 |
| 333 ui::EventProcessor* dispatcher = |
| 334 ash::Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
| 335 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(event); |
| 336 return !details.dispatcher_destroyed; |
| 337 } |
| 338 |
| 371 } // namespace chromeos | 339 } // namespace chromeos |
| OLD | NEW |