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

Unified Diff: chrome/browser/ui/input_method/input_method_engine.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
Index: chrome/browser/ui/input_method/input_method_engine.cc
diff --git a/chrome/browser/ui/input_method/input_method_engine.cc b/chrome/browser/ui/input_method/input_method_engine.cc
index a03580c9e03f21aaf2031c240011098ed4d96ef6..f1c5e8e017c137b53925cf0bd43bd0523cba56a6 100644
--- a/chrome/browser/ui/input_method/input_method_engine.cc
+++ b/chrome/browser/ui/input_method/input_method_engine.cc
@@ -4,6 +4,10 @@
#include "chrome/browser/ui/input_method/input_method_engine.h"
+#include "ui/base/ime/composition_text.h"
+#include "ui/base/ime/ime_bridge.h"
+#include "ui/base/ime/ime_input_context_handler_interface.h"
+
namespace input_method {
InputMethodEngine::InputMethodEngine() {}
@@ -25,4 +29,44 @@ std::string InputMethodEngine::GetExtensionId() const {
return extension_id_;
}
+void InputMethodEngine::UpdateComposition(
+ const ui::CompositionText& composition_text,
+ uint32_t cursor_pos,
+ bool is_visible) {
+ composition_.CopyFrom(composition_text);
+
+ // Use a black thin underline by default.
+ if (composition_.underlines.empty()) {
+ composition_.underlines.push_back(
+ ui::CompositionUnderline(0, composition_.text.length(), SK_ColorBLACK,
+ false /* thick */, SK_ColorTRANSPARENT));
+ }
+
+ ui::IMEInputContextHandlerInterface* input_context =
+ ui::IMEBridge::Get()->GetInputContextHandler();
+ // If the IME extension is handling key event, hold the composition text
+ // until the key event is handled.
+ if (input_context && !handling_key_event_) {
+ input_context->UpdateCompositionText(composition_text, cursor_pos,
+ is_visible);
+ composition_.Clear();
+ }
+}
+
+void InputMethodEngine::CommitTextToInputContext(int context_id,
+ const std::string& text) {
+ // Append the text to the buffer, as it allows committing text multiple times
+ // when processing a key event.
+ text_ += text;
+
+ ui::IMEInputContextHandlerInterface* input_context =
+ ui::IMEBridge::Get()->GetInputContextHandler();
+ // If the IME extension is handling key event, hold the text until the key
+ // event is handled.
+ if (input_context && !handling_key_event_) {
+ input_context->CommitText(text_);
+ text_ = "";
+ }
+}
+
} // namespace input_method
« no previous file with comments | « chrome/browser/ui/input_method/input_method_engine.h ('k') | chrome/browser/ui/input_method/input_method_engine_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698