Chromium Code Reviews| 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() |