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 0bd3b86d91b2380d6a7380e89bc63feae01cc7e0..661aca2fd3d9026b5b6054d730a3347f07e9d82f 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| @@ -321,6 +321,10 @@ void InputMethodController::setComposition(const String& text, const Vector<Comp |
| if (!target) |
| return; |
| + int selectionOffsetsStart = static_cast<int>(getSelectionOffsets().start()); |
| + int start = selectionOffsetsStart + selectionStart; |
| + int end = selectionOffsetsStart + selectionEnd; |
| + |
|
yosin_UTC9
2016/06/15 05:34:41
Could you add DCHECK_XX() to validate |start| and
yosin_UTC9
2016/06/15 19:00:21
I mean
DCHECK_GE(selctionStart, 0);
DCHECK_LE(sel
|
| // Dispatch an appropriate composition event to the focused node. |
| // We check the composition status and choose an appropriate composition event since this |
| // function is used for three purposes: |
| @@ -339,11 +343,13 @@ void InputMethodController::setComposition(const String& text, const Vector<Comp |
| if (text.isEmpty()) { |
| if (hasComposition()) { |
| confirmComposition(emptyString()); |
| - return; |
| + } else { |
| + // It's weird to call |setComposition()| with empty text outside composition, however some IME |
| + // (e.g. Japanese IBus-Anthy) did this, so we simply delete selection without sending extra events. |
| + TypingCommand::deleteSelection(*frame().document(), TypingCommand::PreventSpellChecking); |
| } |
| - // It's weird to call |setComposition()| with empty text outside composition, however some IME |
| - // (e.g. Japanese IBus-Anthy) did this, so we simply delete selection without sending extra events. |
| - TypingCommand::deleteSelection(*frame().document(), TypingCommand::PreventSpellChecking); |
| + |
| + setEditableSelectionOffsets(PlainTextRange(start, end)); |
| return; |
| } |
| @@ -390,30 +396,11 @@ void InputMethodController::setComposition(const String& text, const Vector<Comp |
| if (baseNode->layoutObject()) |
| baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); |
| - // 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 correct Position in that case, |
| - // we should make sure |value1| is within range at least. |
| - const EphemeralRange& startRange = PlainTextRange(0, start).createRange(*rootEditableElement); |
| - const EphemeralRange& endRange = PlainTextRange(0, end).createRange(*rootEditableElement); |
| - |
| - // TODO(yabinh): There should be a better way to create |startPosition| and |
| - // |endPosition|. But for now, since we can't get |anchorNode| and |offset|, |
| - // we can't create the 2 Position objects directly. So we use |
| - // PlainTextRange::createRange as a workaround. |
| - const Position& startPosition = startRange.endPosition(); |
| - const Position& endPosition = endRange.endPosition(); |
| - const EphemeralRange selectedRange(startPosition, endPosition); |
| + const EphemeralRange selectedRange = PlainTextRange(start, end).createRange(*rootEditableElement); |
|
yosin_UTC9
2016/06/15 05:34:41
s/const EphemeralRange/const EphmeralRange&/
to av
|
| frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered); |
| if (underlines.isEmpty()) { |