Commit 2cfbefe0 authored by Darren Shen's avatar Darren Shen Committed by Chromium LUCI CQ

ime: Fix handling autocorrect during key event.

When an IME issues autocorrect related operations during a key event,
the operation is not immediately executed, but stored as 'pending'.
After the key event is handled, the pending operation is executed.

However, there is a boolean guard to see if there is any pending
operations in the first place. Unfortunately, the guard doesn't check
for autocorrect related operations, only commits and compositions.

So pending autocorrects are executed only when it is accompanied by a
pending commit / composition.

To fix this in a robust way, simply delete the guard, since we do the
same check in the function that executes the pending operations anyway.
Eliminating the check means we don't have to remember to update the
guard whenever we add a new type of pending operation.

Bug: b/176942429
Change-Id: Ie6178d1b139d27fb9ffb40cffe3d29ddd2b548d6
Fixed: b/176942429
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2612551Reviewed-by: default avatarJohn Palmer <jopalmer@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841342}
parent c40111ec
...@@ -501,8 +501,7 @@ ui::EventDispatchDetails InputMethodChromeOS::ProcessKeyEventPostIME( ...@@ -501,8 +501,7 @@ ui::EventDispatchDetails InputMethodChromeOS::ProcessKeyEventPostIME(
if (client != GetTextInputClient()) if (client != GetTextInputClient())
return dispatch_details; return dispatch_details;
if (HasInputMethodResult()) MaybeProcessPendingInputMethodResult(event, handled);
ProcessInputMethodResult(event, handled);
// In case the focus was changed when sending input method results to the // In case the focus was changed when sending input method results to the
// focused window. // focused window.
...@@ -564,8 +563,9 @@ ui::EventDispatchDetails InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( ...@@ -564,8 +563,9 @@ ui::EventDispatchDetails InputMethodChromeOS::ProcessUnfilteredKeyPressEvent(
return details; return details;
} }
void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event, void InputMethodChromeOS::MaybeProcessPendingInputMethodResult(
bool handled) { ui::KeyEvent* event,
bool handled) {
TextInputClient* client = GetTextInputClient(); TextInputClient* client = GetTextInputClient();
DCHECK(client); DCHECK(client);
...@@ -621,10 +621,6 @@ bool InputMethodChromeOS::NeedInsertChar() const { ...@@ -621,10 +621,6 @@ bool InputMethodChromeOS::NeedInsertChar() const {
(!composing_text_ && result_text_.length() == 1)); (!composing_text_ && result_text_.length() == 1));
} }
bool InputMethodChromeOS::HasInputMethodResult() const {
return result_text_.length() || composition_changed_;
}
void InputMethodChromeOS::CommitText(const std::string& text) { void InputMethodChromeOS::CommitText(const std::string& text) {
if (text.empty()) if (text.empty())
return; return;
......
...@@ -122,9 +122,9 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodChromeOS ...@@ -122,9 +122,9 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) InputMethodChromeOS
ui::EventDispatchDetails ProcessUnfilteredKeyPressEvent(ui::KeyEvent* event) ui::EventDispatchDetails ProcessUnfilteredKeyPressEvent(ui::KeyEvent* event)
WARN_UNUSED_RESULT; WARN_UNUSED_RESULT;
// Sends input method result caused by the given key event to the focused text // Processes any pending input method operations that issued while handling
// input client. // the key event. Does not do anything if there were no pending operations.
void ProcessInputMethodResult(ui::KeyEvent* event, bool filtered); void MaybeProcessPendingInputMethodResult(ui::KeyEvent* event, bool filtered);
// Checks if the pending input method result needs inserting into the focused // Checks if the pending input method result needs inserting into the focused
// text input client as a single character. // text input client as a single character.
......
...@@ -1175,6 +1175,20 @@ TEST_F(InputMethodChromeOSKeyEventTest, JP106KeyTest) { ...@@ -1175,6 +1175,20 @@ TEST_F(InputMethodChromeOSKeyEventTest, JP106KeyTest) {
EXPECT_FALSE(input_method_manager_->state()->is_jp_ime()); EXPECT_FALSE(input_method_manager_->state()->is_jp_ime());
} }
TEST_F(InputMethodChromeOSKeyEventTest, SetAutocorrectRangeRunsAfterKeyEvent) {
input_type_ = TEXT_INPUT_TYPE_TEXT;
ime_->OnTextInputTypeChanged(this);
ime_->CommitText("a");
ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
ime_->DispatchKeyEvent(&event);
ime_->SetAutocorrectRange(gfx::Range(0, 1));
std::move(mock_ime_engine_handler_->last_passed_callback())
.Run(/*handled=*/true);
EXPECT_EQ(gfx::Range(0, 1), GetAutocorrectRange());
}
TEST_F(InputMethodChromeOSKeyEventTest, TEST_F(InputMethodChromeOSKeyEventTest,
SetAutocorrectRangeRunsAfterCommitText) { SetAutocorrectRangeRunsAfterCommitText) {
input_type_ = TEXT_INPUT_TYPE_TEXT; input_type_ = TEXT_INPUT_TYPE_TEXT;
......
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