Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: chrome/browser/ui/input_method/input_method_engine.cc

Issue 1771173002: Implement input.ime.sendKeyEvents API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update test. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "ui/aura/window.h"
11 #include "ui/aura/window_tree_host.h"
7 #include "ui/base/ime/composition_text.h" 12 #include "ui/base/ime/composition_text.h"
8 #include "ui/base/ime/ime_bridge.h" 13 #include "ui/base/ime/ime_bridge.h"
9 #include "ui/base/ime/ime_input_context_handler_interface.h" 14 #include "ui/base/ime/ime_input_context_handler_interface.h"
15 #include "ui/base/ime/input_method.h"
16 #include "ui/events/keycodes/keyboard_code_conversion.h"
10 17
11 namespace { 18 namespace {
12 19
13 const char kErrorFollowCursorWindowExists[] = 20 const char kErrorFollowCursorWindowExists[] =
14 "A follow cursor IME window exists."; 21 "A follow cursor IME window exists.";
15 const char kErrorNoInputFocus[] = 22 const char kErrorNoInputFocus[] =
16 "The follow cursor IME window cannot be created without an input focus."; 23 "The follow cursor IME window cannot be created without an input focus.";
17 const char kErrorReachMaxWindowCount[] = 24 const char kErrorReachMaxWindowCount[] =
18 "Cannot create more than 5 normal IME windows."; 25 "Cannot create more than 5 normal IME windows.";
19 26
20 const int kMaxNormalWindowCount = 5; 27 const int kMaxNormalWindowCount = 5;
21 28
22 } // namespace 29 } // namespace
23 30
24 namespace input_method { 31 namespace input_method {
25 32
26 InputMethodEngine::InputMethodEngine() : follow_cursor_window_(nullptr) {} 33 InputMethodEngine::InputMethodEngine() : follow_cursor_window_(nullptr) {}
27 34
28 InputMethodEngine::~InputMethodEngine() { 35 InputMethodEngine::~InputMethodEngine() {
29 CloseImeWindows(); 36 CloseImeWindows();
30 } 37 }
31 38
32 bool InputMethodEngine::SendKeyEvents(
33 int context_id,
34 const std::vector<KeyboardEvent>& events) {
35 // TODO(azurewei) Implement SendKeyEvents funciton
36 return false;
37 }
38
39 bool InputMethodEngine::IsActive() const { 39 bool InputMethodEngine::IsActive() const {
40 return true; 40 return true;
41 } 41 }
42 42
43 std::string InputMethodEngine::GetExtensionId() const { 43 std::string InputMethodEngine::GetExtensionId() const {
44 return extension_id_; 44 return extension_id_;
45 } 45 }
46 46
47 int InputMethodEngine::CreateImeWindow(const extensions::Extension* extension, 47 int InputMethodEngine::CreateImeWindow(const extensions::Extension* extension,
48 const std::string& url, 48 const std::string& url,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (ime_window == follow_cursor_window_) { 156 if (ime_window == follow_cursor_window_) {
157 follow_cursor_window_ = nullptr; 157 follow_cursor_window_ = nullptr;
158 } else { 158 } else {
159 auto it = std::find( 159 auto it = std::find(
160 normal_windows_.begin(), normal_windows_.end(), ime_window); 160 normal_windows_.begin(), normal_windows_.end(), ime_window);
161 if (it != normal_windows_.end()) 161 if (it != normal_windows_.end())
162 normal_windows_.erase(it); 162 normal_windows_.erase(it);
163 } 163 }
164 } 164 }
165 165
166 bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event) {
167 Browser* browser = chrome::FindLastActiveWithProfile(profile_);
168 if (!browser)
169 return false;
170
171 if (event->key_code() == ui::VKEY_UNKNOWN)
172 event->set_key_code(ui::DomCodeToUsLayoutKeyboardCode(event->code()));
173
174 ui::InputMethod* input_method =
175 browser->window()->GetNativeWindow()->GetHost()->GetInputMethod();
176 input_method->DispatchKeyEvent(event);
177 return true;
178 }
179
166 } // namespace input_method 180 } // namespace input_method
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698