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

Side by Side Diff: ui/base/ime/input_method_base.cc

Issue 1657593007: Implement chrome.input.ime.setComposition/commitText API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use Xxx::Results::Create(). Created 4 years, 10 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
« no previous file with comments | « ui/base/ime/input_method_base.h ('k') | ui/base/ime/input_method_chromeos.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/ime/input_method_base.h" 5 #include "ui/base/ime/input_method_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/base/ime/ime_bridge.h"
10 #include "ui/base/ime/input_method_delegate.h" 12 #include "ui/base/ime/input_method_delegate.h"
11 #include "ui/base/ime/input_method_observer.h" 13 #include "ui/base/ime/input_method_observer.h"
12 #include "ui/base/ime/text_input_client.h" 14 #include "ui/base/ime/text_input_client.h"
13 #include "ui/events/event.h" 15 #include "ui/events/event.h"
14 16
15 namespace ui { 17 namespace ui {
16 18
17 InputMethodBase::InputMethodBase() 19 InputMethodBase::InputMethodBase()
18 : delegate_(NULL), 20 : delegate_(NULL), text_input_client_(NULL) {}
19 text_input_client_(NULL) {
20 }
21 21
22 InputMethodBase::~InputMethodBase() { 22 InputMethodBase::~InputMethodBase() {
23 FOR_EACH_OBSERVER(InputMethodObserver, 23 FOR_EACH_OBSERVER(InputMethodObserver,
24 observer_list_, 24 observer_list_,
25 OnInputMethodDestroyed(this)); 25 OnInputMethodDestroyed(this));
26 if (ui::IMEBridge::Get() &&
27 ui::IMEBridge::Get()->GetInputContextHandler() == this)
28 ui::IMEBridge::Get()->SetInputContextHandler(nullptr);
26 } 29 }
27 30
28 void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { 31 void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) {
29 delegate_ = delegate; 32 delegate_ = delegate;
30 } 33 }
31 34
32 void InputMethodBase::OnFocus() {} 35 void InputMethodBase::OnFocus() {}
33 36
34 void InputMethodBase::OnBlur() {} 37 void InputMethodBase::OnBlur() {}
35 38
36 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { 39 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) {
37 SetFocusedTextInputClientInternal(client); 40 SetFocusedTextInputClientInternal(client);
41 if (ui::IMEBridge::Get())
42 ui::IMEBridge::Get()->SetInputContextHandler(this);
38 } 43 }
39 44
40 void InputMethodBase::DetachTextInputClient(TextInputClient* client) { 45 void InputMethodBase::DetachTextInputClient(TextInputClient* client) {
41 if (text_input_client_ != client) 46 if (text_input_client_ != client)
42 return; 47 return;
43 SetFocusedTextInputClientInternal(NULL); 48 SetFocusedTextInputClientInternal(NULL);
44 } 49 }
45 50
46 TextInputClient* InputMethodBase::GetTextInputClient() const { 51 TextInputClient* InputMethodBase::GetTextInputClient() const {
47 return text_input_client_; 52 return text_input_client_;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 bounds.push_back(rect); 146 bounds.push_back(rect);
142 } else { 147 } else {
143 // For case of no composition at present, use caret bounds which is required 148 // For case of no composition at present, use caret bounds which is required
144 // by the IME extension for certain features (e.g. physical keyboard 149 // by the IME extension for certain features (e.g. physical keyboard
145 // auto-correct). 150 // auto-correct).
146 bounds.push_back(client->GetCaretBounds()); 151 bounds.push_back(client->GetCaretBounds());
147 } 152 }
148 return bounds; 153 return bounds;
149 } 154 }
150 155
156 bool InputMethodBase::SendFakeProcessKeyEvent(bool pressed) const {
157 KeyEvent evt(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED,
158 pressed ? VKEY_PROCESSKEY : VKEY_UNKNOWN, EF_IME_FABRICATED_KEY);
159 ignore_result(DispatchKeyEventPostIME(&evt));
160 return evt.stopped_propagation();
161 }
162
163 void InputMethodBase::CommitText(const std::string& text) {
164 if (text.empty() || !GetTextInputClient() || IsTextInputTypeNone())
165 return;
166
167 const base::string16 utf16_text = base::UTF8ToUTF16(text);
168 if (utf16_text.empty())
169 return;
170
171 if (!SendFakeProcessKeyEvent(true))
172 GetTextInputClient()->InsertText(utf16_text);
173 SendFakeProcessKeyEvent(false);
174 }
175
176 void InputMethodBase::UpdateCompositionText(const CompositionText& composition_,
177 uint32_t cursor_pos,
178 bool visible) {
179 if (IsTextInputTypeNone() || composition_.text.empty())
180 return;
181
182 if (!SendFakeProcessKeyEvent(true)) {
183 if (visible)
184 GetTextInputClient()->SetCompositionText(composition_);
185 else
186 GetTextInputClient()->ClearCompositionText();
187 }
188 SendFakeProcessKeyEvent(false);
189 }
190
191 void InputMethodBase::DeleteSurroundingText(int32_t offset, uint32_t length) {}
192
151 } // namespace ui 193 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_base.h ('k') | ui/base/ime/input_method_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698