Commit 6bf841ec authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

ime: Clear pending composition after setting composition.

Currently we queue composition operations as "pending" if we are
currently handling a PK event. However, the pending composition is not
cleared after we handle the pending composition, so IMF thinks that
there's still some pending composition to be run in the next operation.

Bug: 1004149
Change-Id: Ibe7d6d49cd2d532f2a3300d63df15cd54eda98e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1806154Reviewed-by: default avatarShu Chen <shuchen@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697513}
parent c3adf63f
...@@ -355,7 +355,7 @@ void InputMethodChromeOS::ResetContext(bool reset_engine) { ...@@ -355,7 +355,7 @@ void InputMethodChromeOS::ResetContext(bool reset_engine) {
if (!IsNonPasswordInputFieldFocused() || !GetTextInputClient()) if (!IsNonPasswordInputFieldFocused() || !GetTextInputClient())
return; return;
composition_ = CompositionText(); pending_composition_ = CompositionText();
result_text_.clear(); result_text_.clear();
composing_text_ = false; composing_text_ = false;
composition_changed_ = false; composition_changed_ = false;
...@@ -500,13 +500,14 @@ void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event, ...@@ -500,13 +500,14 @@ void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event,
pending_composition_range_->range, pending_composition_range_->range,
pending_composition_range_->text_spans); pending_composition_range_->text_spans);
} }
if (composition_.text.length()) { if (pending_composition_.text.length()) {
composing_text_ = true; composing_text_ = true;
client->SetCompositionText(composition_); client->SetCompositionText(pending_composition_);
} else if (result_text_.empty() && !pending_composition_range_) { } else if (result_text_.empty() && !pending_composition_range_) {
client->ClearCompositionText(); client->ClearCompositionText();
} }
pending_composition_ = CompositionText();
pending_composition_range_.reset(); pending_composition_range_.reset();
} }
...@@ -584,22 +585,22 @@ void InputMethodChromeOS::UpdateCompositionText(const CompositionText& text, ...@@ -584,22 +585,22 @@ void InputMethodChromeOS::UpdateCompositionText(const CompositionText& text,
return; return;
} }
ExtractCompositionText(text, cursor_pos, &composition_); ExtractCompositionText(text, cursor_pos, &pending_composition_);
composition_changed_ = true; composition_changed_ = true;
// In case OnShowPreeditText() is not called. // In case OnShowPreeditText() is not called.
if (composition_.text.length()) if (pending_composition_.text.length())
composing_text_ = true; composing_text_ = true;
if (!handling_key_event_) { if (!handling_key_event_) {
// If we receive a composition text without pending key event, then we need // If we receive a composition text without pending key event, then we need
// to send it to the focused text input client directly. // to send it to the focused text input client directly.
if (!SendFakeProcessKeyEvent(true)) if (!SendFakeProcessKeyEvent(true))
GetTextInputClient()->SetCompositionText(composition_); GetTextInputClient()->SetCompositionText(pending_composition_);
SendFakeProcessKeyEvent(false); SendFakeProcessKeyEvent(false);
composition_changed_ = false; composition_changed_ = false;
composition_ = CompositionText(); pending_composition_ = CompositionText();
} }
} }
...@@ -609,7 +610,7 @@ void InputMethodChromeOS::HidePreeditText() { ...@@ -609,7 +610,7 @@ void InputMethodChromeOS::HidePreeditText() {
// Intentionally leaves |composing_text_| unchanged. // Intentionally leaves |composing_text_| unchanged.
composition_changed_ = true; composition_changed_ = true;
composition_ = CompositionText(); pending_composition_ = CompositionText();
if (!handling_key_event_) { if (!handling_key_event_) {
TextInputClient* client = GetTextInputClient(); TextInputClient* client = GetTextInputClient();
...@@ -624,13 +625,14 @@ void InputMethodChromeOS::HidePreeditText() { ...@@ -624,13 +625,14 @@ void InputMethodChromeOS::HidePreeditText() {
void InputMethodChromeOS::DeleteSurroundingText(int32_t offset, void InputMethodChromeOS::DeleteSurroundingText(int32_t offset,
uint32_t length) { uint32_t length) {
if (!composition_.text.empty()) if (!GetTextInputClient())
return; // do nothing if there is ongoing composition. return;
if (GetTextInputClient()) { if (GetTextInputClient()->HasCompositionText())
uint32_t before = offset >= 0 ? 0U : static_cast<uint32_t>(-1 * offset); return;
GetTextInputClient()->ExtendSelectionAndDelete(before, length - before);
} uint32_t before = offset >= 0 ? 0U : static_cast<uint32_t>(-1 * offset);
GetTextInputClient()->ExtendSelectionAndDelete(before, length - before);
} }
bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) { bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) {
......
...@@ -141,7 +141,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodChromeOS ...@@ -141,7 +141,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodChromeOS
// Pending composition text generated by the current pending key event. // Pending composition text generated by the current pending key event.
// It'll be sent to the focused text input client as soon as we receive the // It'll be sent to the focused text input client as soon as we receive the
// processing result of the pending key event. // processing result of the pending key event.
CompositionText composition_; CompositionText pending_composition_;
// Pending result text generated by the current pending key event. // Pending result text generated by the current pending key event.
// It'll be sent to the focused text input client as soon as we receive the // It'll be sent to the focused text input client as soon as we receive the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment