| 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..f5c91b1d36eba691b44fe78db2c1ec2ae16baa15 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;
|
| +
|
| // 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());
|
| + setEditableSelectionOffsets(start, end);
|
| return;
|
| }
|
| // 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(start, end);
|
| return;
|
| }
|
|
|
| @@ -390,31 +396,7 @@ 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);
|
| - frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered);
|
| + setEditableSelectionOffsets(start, end);
|
|
|
| if (underlines.isEmpty()) {
|
| frame().document()->markers().addCompositionMarker(m_compositionRange->startPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTheme::theme().platformDefaultCompositionBackgroundColor());
|
| @@ -508,11 +490,42 @@ bool InputMethodController::setSelectionOffsets(const PlainTextRange& selectionO
|
| return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional, FrameSelection::CloseTyping);
|
| }
|
|
|
| -bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& selectionOffsets)
|
| +bool InputMethodController::setEditableSelectionOffsets(int start, int end)
|
| {
|
| if (!editor().canEdit())
|
| return false;
|
| - return setSelectionOffsets(selectionOffsets);
|
| +
|
| + Element* rootEditableElement = frame().selection().rootEditableElement();
|
| + if (!rootEditableElement)
|
| + return false;
|
| +
|
| + // In case of exceeding the left boundary.
|
| + start = std::max(start, 0);
|
| + end = std::max(end, start);
|
| +
|
| + // 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);
|
| + if (startRange.isNull())
|
| + return false;
|
| + const EphemeralRange& endRange = PlainTextRange(0, end).createRange(*rootEditableElement);
|
| + if (endRange.isNull())
|
| + return false;
|
| +
|
| + // 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& range = EphemeralRange(startPosition, endPosition);
|
| + if (range.isNull())
|
| + return false;
|
| +
|
| + return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional, FrameSelection::CloseTyping);
|
| }
|
|
|
| void InputMethodController::extendSelectionAndDelete(int before, int after)
|
|
|