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 "chrome/browser/ui/browser.h" | |
8 #include "chrome/browser/ui/browser_finder.h" | |
9 #include "chrome/browser/ui/browser_window.h" | |
7 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
11 #include "ui/aura/window.h" | |
12 #include "ui/aura/window_tree_host.h" | |
8 #include "ui/base/ime/composition_text.h" | 13 #include "ui/base/ime/composition_text.h" |
9 #include "ui/base/ime/ime_bridge.h" | 14 #include "ui/base/ime/ime_bridge.h" |
10 #include "ui/base/ime/ime_input_context_handler_interface.h" | 15 #include "ui/base/ime/ime_input_context_handler_interface.h" |
16 #include "ui/base/ime/input_method.h" | |
17 #include "ui/events/keycodes/keyboard_code_conversion.h" | |
11 | 18 |
12 namespace { | 19 namespace { |
13 | 20 |
14 const char kErrorFollowCursorWindowExists[] = | 21 const char kErrorFollowCursorWindowExists[] = |
15 "A follow cursor IME window exists."; | 22 "A follow cursor IME window exists."; |
16 const char kErrorNoInputFocus[] = | 23 const char kErrorNoInputFocus[] = |
17 "The follow cursor IME window cannot be created without an input focus."; | 24 "The follow cursor IME window cannot be created without an input focus."; |
18 const char kErrorReachMaxWindowCount[] = | 25 const char kErrorReachMaxWindowCount[] = |
19 "Cannot create more than 5 normal IME windows."; | 26 "Cannot create more than 5 normal IME windows."; |
20 | 27 |
21 const int kMaxNormalWindowCount = 5; | 28 const int kMaxNormalWindowCount = 5; |
22 | 29 |
23 } // namespace | 30 } // namespace |
24 | 31 |
25 namespace input_method { | 32 namespace input_method { |
26 | 33 |
27 InputMethodEngine::InputMethodEngine() : follow_cursor_window_(nullptr) {} | 34 InputMethodEngine::InputMethodEngine() : follow_cursor_window_(nullptr) {} |
28 | 35 |
29 InputMethodEngine::~InputMethodEngine() { | 36 InputMethodEngine::~InputMethodEngine() { |
30 CloseImeWindows(); | 37 CloseImeWindows(); |
31 } | 38 } |
32 | 39 |
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 { | 40 bool InputMethodEngine::IsActive() const { |
41 return true; | 41 return true; |
42 } | 42 } |
43 | 43 |
44 std::string InputMethodEngine::GetExtensionId() const { | 44 std::string InputMethodEngine::GetExtensionId() const { |
45 return extension_id_; | 45 return extension_id_; |
46 } | 46 } |
47 | 47 |
48 int InputMethodEngine::CreateImeWindow( | 48 int InputMethodEngine::CreateImeWindow( |
49 const extensions::Extension* extension, | 49 const extensions::Extension* extension, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 if (ime_window == follow_cursor_window_) { | 159 if (ime_window == follow_cursor_window_) { |
160 follow_cursor_window_ = nullptr; | 160 follow_cursor_window_ = nullptr; |
161 } else { | 161 } else { |
162 auto it = std::find( | 162 auto it = std::find( |
163 normal_windows_.begin(), normal_windows_.end(), ime_window); | 163 normal_windows_.begin(), normal_windows_.end(), ime_window); |
164 if (it != normal_windows_.end()) | 164 if (it != normal_windows_.end()) |
165 normal_windows_.erase(it); | 165 normal_windows_.erase(it); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event) { | |
170 Browser* browser = chrome::FindLastActiveWithProfile(profile_); | |
171 if (!browser) | |
172 return false; | |
173 | |
174 if (event->key_code() == ui::VKEY_UNKNOWN) | |
175 event->set_key_code(ui::DomCodeToUsLayoutKeyboardCode(event->code())); | |
176 | |
177 ui::InputMethod* input_method = | |
178 browser->window()->GetNativeWindow()->GetHost()->GetInputMethod(); | |
179 | |
180 #if defined(OS_WIN) | |
Shu Chen
2016/03/08 14:38:03
I think we should NOT hack for OS_WIN here.
Instea
Shu Chen
2016/03/09 04:00:24
Per offline discussion, please add SendKeyEvents()
Azure Wei
2016/03/09 05:01:57
Done. Please review the latest patch set.
| |
181 const uint16_t kNativeCode = | |
182 ui::KeycodeConverter::DomCodeToNativeKeycode(event->code()); | |
183 const LPARAM lParam = ui::GetLParamFromScanCode(kNativeCode); | |
184 | |
185 MSG native_event; | |
186 if (event->type() == ui::ET_KEY_PRESSED) | |
187 native_event = {NULL, WM_KEYDOWN, event->key_code(), lParam}; | |
188 else | |
189 native_event = {NULL, WM_KEYUP, event->key_code(), lParam}; | |
190 ui::KeyEvent key_event(native_event); | |
191 input_method->DispatchKeyEvent(&key_event); | |
192 | |
193 if (event->type() == ui::ET_KEY_PRESSED && event->GetDomKey().IsCharacter()) { | |
194 MSG native_event_char = {NULL, WM_CHAR, event->GetCharacter(), lParam}; | |
195 ui::KeyEvent key_event_char(native_event_char); | |
196 input_method->DispatchKeyEvent(&key_event_char); | |
197 } | |
198 #else | |
199 input_method->DispatchKeyEvent(event); | |
200 #endif | |
201 | |
202 return true; | |
203 } | |
204 | |
169 } // namespace input_method | 205 } // namespace input_method |
OLD | NEW |