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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/ime/input_method_base.cc
diff --git a/ui/base/ime/input_method_base.cc b/ui/base/ime/input_method_base.cc
index d935889a65a2088af9116004a4e61ba16169710c..5d53a1943dcf1ff8bb907d7d585e33dfa451b63b 100644
--- a/ui/base/ime/input_method_base.cc
+++ b/ui/base/ime/input_method_base.cc
@@ -7,6 +7,8 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/utf_string_conversions.h"
+#include "ui/base/ime/ime_bridge.h"
#include "ui/base/ime/input_method_delegate.h"
#include "ui/base/ime/input_method_observer.h"
#include "ui/base/ime/text_input_client.h"
@@ -15,14 +17,15 @@
namespace ui {
InputMethodBase::InputMethodBase()
- : delegate_(NULL),
- text_input_client_(NULL) {
-}
+ : delegate_(NULL), text_input_client_(NULL) {}
InputMethodBase::~InputMethodBase() {
FOR_EACH_OBSERVER(InputMethodObserver,
observer_list_,
OnInputMethodDestroyed(this));
+ if (ui::IMEBridge::Get() &&
+ ui::IMEBridge::Get()->GetInputContextHandler() == this)
+ ui::IMEBridge::Get()->SetInputContextHandler(nullptr);
}
void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) {
@@ -35,6 +38,8 @@ void InputMethodBase::OnBlur() {}
void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) {
SetFocusedTextInputClientInternal(client);
+ if (ui::IMEBridge::Get())
+ ui::IMEBridge::Get()->SetInputContextHandler(this);
}
void InputMethodBase::DetachTextInputClient(TextInputClient* client) {
@@ -148,4 +153,41 @@ std::vector<gfx::Rect> InputMethodBase::GetCompositionBounds(
return bounds;
}
+bool InputMethodBase::SendFakeProcessKeyEvent(bool pressed) const {
+ KeyEvent evt(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED,
+ pressed ? VKEY_PROCESSKEY : VKEY_UNKNOWN, EF_IME_FABRICATED_KEY);
+ ignore_result(DispatchKeyEventPostIME(&evt));
+ return evt.stopped_propagation();
+}
+
+void InputMethodBase::CommitText(const std::string& text) {
+ if (text.empty() || !GetTextInputClient() || IsTextInputTypeNone())
+ return;
+
+ const base::string16 utf16_text = base::UTF8ToUTF16(text);
+ if (utf16_text.empty())
+ return;
+
+ if (!SendFakeProcessKeyEvent(true))
+ GetTextInputClient()->InsertText(utf16_text);
+ SendFakeProcessKeyEvent(false);
+}
+
+void InputMethodBase::UpdateCompositionText(const CompositionText& composition_,
+ uint32_t cursor_pos,
+ bool visible) {
+ if (IsTextInputTypeNone() || composition_.text.empty())
+ return;
+
+ if (!SendFakeProcessKeyEvent(true)) {
+ if (visible)
+ GetTextInputClient()->SetCompositionText(composition_);
+ else
+ GetTextInputClient()->ClearCompositionText();
+ }
+ SendFakeProcessKeyEvent(false);
+}
+
+void InputMethodBase::DeleteSurroundingText(int32_t offset, uint32_t length) {}
+
} // namespace ui
« 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