| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 if (ime_window == follow_cursor_window_) { | 153 if (ime_window == follow_cursor_window_) { |
| 160 follow_cursor_window_ = nullptr; | 154 follow_cursor_window_ = nullptr; |
| 161 } else { | 155 } else { |
| 162 auto it = std::find( | 156 auto it = std::find( |
| 163 normal_windows_.begin(), normal_windows_.end(), ime_window); | 157 normal_windows_.begin(), normal_windows_.end(), ime_window); |
| 164 if (it != normal_windows_.end()) | 158 if (it != normal_windows_.end()) |
| 165 normal_windows_.erase(it); | 159 normal_windows_.erase(it); |
| 166 } | 160 } |
| 167 } | 161 } |
| 168 | 162 |
| 163 bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event) { |
| 164 if (event->key_code() == ui::VKEY_UNKNOWN) |
| 165 event->set_key_code(ui::DomCodeToUsLayoutKeyboardCode(event->code())); |
| 166 |
| 167 ui::IMEInputContextHandlerInterface* input_context = |
| 168 ui::IMEBridge::Get()->GetInputContextHandler(); |
| 169 if (!input_context) |
| 170 return false; |
| 171 input_context->SendKeyEvent(event); |
| 172 |
| 173 return true; |
| 174 } |
| 175 |
| 169 } // namespace input_method | 176 } // namespace input_method |
| OLD | NEW |