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 4debf150004b75497f83efa480177e71d5c8a50a..dbe4b6d7fc5e59efaede8a673e21fa99e854260d 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| @@ -267,13 +267,18 @@ bool InputMethodController::finishComposingText( |
| return result; |
| } |
| - return replaceCompositionAndMoveCaret(composingText(), 0); |
| + return replaceCompositionAndMoveCaret(composingText(), 0, |
| + Vector<CompositionUnderline>()); |
| } |
| -bool InputMethodController::commitText(const String& text, |
| - int relativeCaretPosition) { |
| - if (hasComposition()) |
| - return replaceCompositionAndMoveCaret(text, relativeCaretPosition); |
| +bool InputMethodController::commitText( |
| + const String& text, |
| + const Vector<CompositionUnderline>& underlines, |
| + int relativeCaretPosition) { |
| + if (hasComposition()) { |
| + return replaceCompositionAndMoveCaret(text, relativeCaretPosition, |
| + underlines); |
| + } |
| // We should do nothing in this case, because: |
| // 1. No need to insert text when text is empty. |
| @@ -281,7 +286,8 @@ bool InputMethodController::commitText(const String& text, |
| // duplicate selection change event. |
| if (!text.length() && !relativeCaretPosition) |
| return false; |
| - return insertTextAndMoveCaret(text, relativeCaretPosition); |
| + |
| + return insertTextAndMoveCaret(text, relativeCaretPosition, underlines); |
| } |
| bool InputMethodController::replaceComposition(const String& text) { |
| @@ -324,9 +330,30 @@ static int computeAbsoluteCaretPosition(size_t textStart, |
| return textStart + textLength + relativeCaretPosition; |
| } |
| +void InputMethodController::addCompositionUnderlines( |
| + const Vector<CompositionUnderline>& underlines, |
| + ContainerNode* rootEditableElement, |
| + unsigned offset) { |
| + for (const auto& underline : underlines) { |
| + unsigned underlineStart = offset + underline.startOffset(); |
| + unsigned underlineEnd = offset + underline.endOffset(); |
| + |
| + EphemeralRange ephemeralLineRange = |
| + PlainTextRange(underlineStart, underlineEnd) |
| + .createRange(*rootEditableElement); |
| + if (ephemeralLineRange.isNull()) |
| + continue; |
| + |
| + document().markers().addCompositionMarker( |
| + ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(), |
| + underline.color(), underline.thick(), underline.backgroundColor()); |
| + } |
| +} |
| + |
| bool InputMethodController::replaceCompositionAndMoveCaret( |
| const String& text, |
| - int relativeCaretPosition) { |
| + int relativeCaretPosition, |
| + const Vector<CompositionUnderline>& underlines) { |
| Element* rootEditableElement = frame().selection().rootEditableElement(); |
| if (!rootEditableElement) |
| return false; |
| @@ -340,6 +367,8 @@ bool InputMethodController::replaceCompositionAndMoveCaret( |
| if (!replaceComposition(text)) |
| return false; |
| + addCompositionUnderlines(underlines, rootEditableElement, textStart); |
| + |
| int absoluteCaretPosition = computeAbsoluteCaretPosition( |
| textStart, text.length(), relativeCaretPosition); |
| if (!moveCaret(absoluteCaretPosition)) |
| @@ -359,8 +388,10 @@ bool InputMethodController::insertText(const String& text) { |
| return true; |
| } |
| -bool InputMethodController::insertTextAndMoveCaret(const String& text, |
| - int relativeCaretPosition) { |
| +bool InputMethodController::insertTextAndMoveCaret( |
| + const String& text, |
| + int relativeCaretPosition, |
| + const Vector<CompositionUnderline>& underlines) { |
| PlainTextRange selectionRange = getSelectionOffsets(); |
| if (selectionRange.isNull()) |
| return false; |
| @@ -369,6 +400,11 @@ bool InputMethodController::insertTextAndMoveCaret(const String& text, |
| if (text.length()) { |
| if (!insertText(text)) |
| return false; |
| + |
| + Element* rootEditableElement = frame().selection().rootEditableElement(); |
| + if (rootEditableElement) { |
| + addCompositionUnderlines(underlines, rootEditableElement, textStart); |
| + } |
| } |
| int absoluteCaretPosition = computeAbsoluteCaretPosition( |
| @@ -578,6 +614,9 @@ void InputMethodController::setComposition( |
| LayoutTheme::theme().platformDefaultCompositionBackgroundColor()); |
| return; |
| } |
| + |
| + // Can't use addCompositionUnderlines here because the ranges are constructed |
|
aelias_OOO_until_Jul13
2017/01/10 01:45:35
Is there a good reason for the difference that you
rlanday
2017/01/10 05:02:17
addCompositionUnderlines() takes a root element an
rlanday
2017/01/10 19:25:10
baseNode is guaranteed to be a text node (there's
|
| + // differently |
| for (const auto& underline : underlines) { |
| unsigned underlineStart = baseOffset + underline.startOffset(); |
| unsigned underlineEnd = baseOffset + underline.endOffset(); |
| @@ -627,17 +666,7 @@ void InputMethodController::setCompositionFromExistingText( |
| clear(); |
| - for (const auto& underline : underlines) { |
| - unsigned underlineStart = compositionStart + underline.startOffset(); |
| - unsigned underlineEnd = compositionStart + underline.endOffset(); |
| - EphemeralRange ephemeralLineRange = |
| - PlainTextRange(underlineStart, underlineEnd).createRange(*editable); |
| - if (ephemeralLineRange.isNull()) |
| - continue; |
| - document().markers().addCompositionMarker( |
| - ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(), |
| - underline.color(), underline.thick(), underline.backgroundColor()); |
| - } |
| + addCompositionUnderlines(underlines, editable, compositionStart); |
| m_hasComposition = true; |
| if (!m_compositionRange) |