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 0d88e0f740a014a088b732b6340f8ca8bef0e15e..fef659aba5f2fa9f134d9a4d440d94d7aca6af3a 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| @@ -239,7 +239,7 @@ void InputMethodController::cancelCompositionIfSelectionIsInvalid() |
| frame().chromeClient().didCancelCompositionOnSelectionChange(); |
| } |
| -void InputMethodController::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd) |
| +void InputMethodController::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, int selectionStart, int selectionEnd) |
| { |
| Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| @@ -332,9 +332,24 @@ void InputMethodController::setComposition(const String& text, const Vector<Comp |
| if (baseNode->layoutObject()) |
| baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); |
| - unsigned start = std::min(baseOffset + selectionStart, extentOffset); |
| - unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOffset); |
| - Range* selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end); |
| + // In case of exceeding the left boundary. |
| + int selectionOffsetsStart = static_cast<int>(getSelectionOffsets().start()); |
| + int start = std::max(selectionOffsetsStart + selectionStart, 0); |
| + int end = std::max(selectionOffsetsStart + selectionEnd, start); |
| + |
| + Element* rootEditableElement = frame().selection().rootEditableElement(); |
| + if (!rootEditableElement) |
| + return; |
| + |
| + // In case of exceeding the right boundary. |
| + // If both |value1| and |value2| exceed right boundary, |
| + // PlainTextRange(value1, value2)::createRange() will return a default |
| + // value, which is [0,0]. In order to get the right boundary in that case, |
| + // we should make sure |value1| is within range at least. |
| + const EphemeralRange startRange = PlainTextRange(0, start).createRange(*rootEditableElement); |
|
aelias_OOO_until_Jul13
2016/05/10 20:44:11
These ranges are odd, wouldn't it have the same ef
yabinh
2016/05/11 00:28:38
That's right. But in order to create Position obje
aelias_OOO_until_Jul13
2016/05/11 02:49:35
OK, it looks like the algorithm in createRange() i
yosin_UTC9
2016/05/11 05:53:23
nit: s/const EphemeralRange/const EphemeralRange&/
|
| + const EphemeralRange endRange = PlainTextRange(0, end).createRange(*rootEditableElement); |
|
yosin_UTC9
2016/05/11 05:53:23
nit: s/const EphemeralRange/const EphemeralRange&/
|
| + |
| + Range* selectedRange = Range::create(rootEditableElement->document(), startRange.endPosition(), endRange.endPosition()); |
| frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered); |
| if (underlines.isEmpty()) { |