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

Unified Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 1995333002: Handle newCursorPosition correctly for Android's commitText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Almost the same to the previous patch. Created 4 years, 4 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: third_party/WebKit/Source/core/editing/InputMethodController.cpp
diff --git a/third_party/WebKit/Source/core/editing/InputMethodController.cpp b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
index 343e89aad7a0aaf3644dca5f79449d6d75138bc9..0ccd00d0eb534945ef4d3844b07b7cb293d287f9 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -233,8 +233,35 @@ bool InputMethodController::confirmComposition(const String& text, ConfirmCompos
return true;
}
-bool InputMethodController::confirmCompositionOrInsertText(const String& text, ConfirmCompositionBehavior confirmBehavior)
+bool InputMethodController::confirmCompositionOrInsertText(const String& text, ConfirmCompositionBehavior confirmBehavior, int newCursorPosition)
{
+ if (confirmBehavior == DoNotKeepSelection) {
+ // If newCursorPosition > 0, it's relative to the end of the text - 1;
+ // if newCursorPosition <= 0, it is relative to the start of the text.
+ if (newCursorPosition > 0)
+ newCursorPosition += text.length() - 1;
+
+ // According to Android documentation, the new cursor position is
Changwan Ryu 2016/08/24 01:32:03 This comment is platform-specific. Could you make
yabinh 2016/08/24 06:05:01 Done.
+ // relative to the composing text if any, or relative to the selection
+ // if no composing text.
+ if (hasComposition()) {
+ Element* rootEditableElement = frame().selection().rootEditableElement();
+ if (!rootEditableElement)
+ return false;
+ PlainTextRange compositionRange = PlainTextRange::create(*rootEditableElement, *m_compositionRange);
+
+ if (text.length() == 0)
+ newCursorPosition += compositionRange.end();
+ else
+ newCursorPosition += compositionRange.start();
+ } else {
+ PlainTextRange selectionRange = getSelectionOffsets();
+ if (selectionRange.isNull())
+ return false;
+ newCursorPosition += getSelectionOffsets().start();
+ }
+ }
+
if (!hasComposition()) {
if (!text.length())
return false;
@@ -243,19 +270,25 @@ bool InputMethodController::confirmCompositionOrInsertText(const String& text, C
return false;
editor().insertText(text, 0);
- return true;
+ } else if (text.length()) {
+ confirmComposition(text);
+ } else if (confirmBehavior == DoNotKeepSelection) {
+ if (!confirmComposition(composingText(), DoNotKeepSelection))
+ return false;
+ } else {
+ SelectionOffsetsScope selectionOffsetsScope(this);
+ return confirmComposition();
}
- if (text.length()) {
- confirmComposition(text);
+ if (confirmBehavior == KeepSelection)
return true;
- }
- if (confirmBehavior == DoNotKeepSelection)
- return confirmComposition(composingText(), DoNotKeepSelection);
+ frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
- SelectionOffsetsScope selectionOffsetsScope(this);
- return confirmComposition();
+ PlainTextRange selectedRange = createRangeForSelection(newCursorPosition, newCursorPosition, 0);
+ if (selectedRange.isNull())
+ return false;
+ return setEditableSelectionOffsets(selectedRange);
}
void InputMethodController::cancelComposition()

Powered by Google App Engine
This is Rietveld 408576698