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

ime: Implement commitText with cursor behavior for web inputs.

Bug: b/174588692
Change-Id: I37c08ef6977cacd50045209a867048bdbc2d2f8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2583666Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837381}
parent d5b683b7
...@@ -1146,9 +1146,13 @@ void RenderWidgetHostViewAura::InsertText( ...@@ -1146,9 +1146,13 @@ void RenderWidgetHostViewAura::InsertText(
if (text_input_manager_ && text_input_manager_->GetActiveWidget()) { if (text_input_manager_ && text_input_manager_->GetActiveWidget()) {
if (text.length()) { if (text.length()) {
// TODO(crbug.com/1155331): Handle |cursor_behavior| correctly. const int relative_cursor_position =
cursor_behavior == InsertTextCursorBehavior::kMoveCursorBeforeText
? -text.length()
: 0;
text_input_manager_->GetActiveWidget()->ImeCommitText( text_input_manager_->GetActiveWidget()->ImeCommitText(
text, std::vector<ui::ImeTextSpan>(), gfx::Range::InvalidRange(), 0); text, std::vector<ui::ImeTextSpan>(), gfx::Range::InvalidRange(),
relative_cursor_position);
} else if (has_composition_text_) { } else if (has_composition_text_) {
text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false); text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false);
} }
......
...@@ -6025,6 +6025,28 @@ TEST_F(InputMethodResultAuraTest, CommitText) { ...@@ -6025,6 +6025,28 @@ TEST_F(InputMethodResultAuraTest, CommitText) {
} }
} }
TEST_F(InputMethodResultAuraTest, CommitTextBeforeCursor) {
base::RepeatingClosure ime_call = base::BindRepeating(
&ui::TextInputClient::InsertText, base::Unretained(text_input_client()),
base::UTF8ToUTF16("hello"),
ui::TextInputClient::InsertTextCursorBehavior::kMoveCursorBeforeText);
for (auto index : active_view_sequence_) {
ActivateViewForTextInputManager(views_[index], ui::TEXT_INPUT_TYPE_TEXT);
ime_call.Run();
base::RunLoop().RunUntilIdle();
MockWidgetInputHandler::MessageVector events =
widget_hosts_[index]->input_handler()->GetAndResetDispatchedMessages();
EXPECT_EQ("CommitText", GetMessageNames(events));
MockWidgetInputHandler::DispatchedIMEMessage* ime_message =
events[0]->ToIME();
EXPECT_TRUE(ime_message);
EXPECT_TRUE(ime_message->Matches(base::ASCIIToUTF16("hello"), {},
gfx::Range::InvalidRange(), -5, -5));
}
}
// This test is for RenderWidgetHostViewAura::FinishImeCompositionSession which // This test is for RenderWidgetHostViewAura::FinishImeCompositionSession which
// is in response to a mouse click during an ongoing composition. // is in response to a mouse click during an ongoing composition.
TEST_F(InputMethodResultAuraTest, FinishImeCompositionSession) { TEST_F(InputMethodResultAuraTest, FinishImeCompositionSession) {
......
...@@ -87,6 +87,9 @@ class COMPONENT_EXPORT(UI_BASE_IME) TextInputClient { ...@@ -87,6 +87,9 @@ class COMPONENT_EXPORT(UI_BASE_IME) TextInputClient {
// Move cursor to the position after the last character in the text. // Move cursor to the position after the last character in the text.
// e.g. for "hello", the cursor will be right after "o". // e.g. for "hello", the cursor will be right after "o".
kMoveCursorAfterText, kMoveCursorAfterText,
// Move cursor to the position before the first character in the text.
// e.g. for "hello", the cursor will be right before "h".
kMoveCursorBeforeText,
}; };
// Inserts a given text at the insertion point. Current composition text or // Inserts a given text at the insertion point. Current composition text or
......
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