| 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.h" | 5 #include "chrome/browser/ui/input_method/input_method_engine.h" |
| 6 | 6 |
| 7 #include "content/public/browser/render_frame_host.h" | 7 #include "content/public/browser/render_frame_host.h" |
| 8 #include "ui/base/ime/composition_text.h" | 8 #include "ui/base/ime/composition_text.h" |
| 9 #include "ui/base/ime/ime_bridge.h" | 9 #include "ui/base/ime/ime_bridge.h" |
| 10 #include "ui/base/ime/ime_input_context_handler_interface.h" | 10 #include "ui/base/ime/ime_input_context_handler_interface.h" |
| 11 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 const char kErrorFollowCursorWindowExists[] = | 15 const char kErrorFollowCursorWindowExists[] = |
| 15 "A follow cursor IME window exists."; | 16 "A follow cursor IME window exists."; |
| 16 const char kErrorNoInputFocus[] = | 17 const char kErrorNoInputFocus[] = |
| 17 "The follow cursor IME window cannot be created without an input focus."; | 18 "The follow cursor IME window cannot be created without an input focus."; |
| 18 const char kErrorReachMaxWindowCount[] = | 19 const char kErrorReachMaxWindowCount[] = |
| 19 "Cannot create more than 5 normal IME windows."; | 20 "Cannot create more than 5 normal IME windows."; |
| 20 | 21 |
| 21 const int kMaxNormalWindowCount = 5; | 22 const int kMaxNormalWindowCount = 5; |
| 22 | 23 |
| 23 } // namespace | 24 } // namespace |
| 24 | 25 |
| 25 namespace input_method { | 26 namespace input_method { |
| 26 | 27 |
| 27 InputMethodEngine::InputMethodEngine() : follow_cursor_window_(nullptr) {} | 28 InputMethodEngine::InputMethodEngine() : follow_cursor_window_(nullptr) {} |
| 28 | 29 |
| 29 InputMethodEngine::~InputMethodEngine() { | 30 InputMethodEngine::~InputMethodEngine() { |
| 30 CloseImeWindows(); | 31 CloseImeWindows(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 bool InputMethodEngine::SendKeyEvents( | |
| 34 int context_id, | |
| 35 const std::vector<KeyboardEvent>& events) { | |
| 36 // TODO(azurewei) Implement SendKeyEvents funciton | |
| 37 return false; | |
| 38 } | |
| 39 | |
| 40 bool InputMethodEngine::IsActive() const { | 34 bool InputMethodEngine::IsActive() const { |
| 41 return true; | 35 return true; |
| 42 } | 36 } |
| 43 | 37 |
| 44 std::string InputMethodEngine::GetExtensionId() const { | 38 std::string InputMethodEngine::GetExtensionId() const { |
| 45 return extension_id_; | 39 return extension_id_; |
| 46 } | 40 } |
| 47 | 41 |
| 48 int InputMethodEngine::CreateImeWindow( | 42 int InputMethodEngine::CreateImeWindow( |
| 49 const extensions::Extension* extension, | 43 const extensions::Extension* extension, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 follow_cursor_window_->GetFrameId() == window_id) { | 176 follow_cursor_window_->GetFrameId() == window_id) { |
| 183 return follow_cursor_window_; | 177 return follow_cursor_window_; |
| 184 } | 178 } |
| 185 for (auto ime_window : normal_windows_) { | 179 for (auto ime_window : normal_windows_) { |
| 186 if (ime_window->GetFrameId() == window_id) | 180 if (ime_window->GetFrameId() == window_id) |
| 187 return ime_window; | 181 return ime_window; |
| 188 } | 182 } |
| 189 return nullptr; | 183 return nullptr; |
| 190 } | 184 } |
| 191 | 185 |
| 186 bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event, |
| 187 const std::string& code) { |
| 188 DCHECK(event); |
| 189 if (event->key_code() == ui::VKEY_UNKNOWN) |
| 190 event->set_key_code(ui::DomCodeToUsLayoutKeyboardCode(event->code())); |
| 191 |
| 192 ui::IMEInputContextHandlerInterface* input_context = |
| 193 ui::IMEBridge::Get()->GetInputContextHandler(); |
| 194 if (!input_context) |
| 195 return false; |
| 196 input_context->SendKeyEvent(event); |
| 197 |
| 198 return true; |
| 199 } |
| 200 |
| 192 } // namespace input_method | 201 } // namespace input_method |
| OLD | NEW |