| 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 e36cea49358ce24b90a500afbec5b97eb29f8242..fd9f11c877fc25da37f18aca218068bf7c11f140 100644
|
| --- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
|
| @@ -321,11 +321,6 @@
|
| if (!target)
|
| return;
|
|
|
| - int selectionOffsetsStart = static_cast<int>(getSelectionOffsets().start());
|
| - int start = selectionOffsetsStart + selectionStart;
|
| - int end = selectionOffsetsStart + selectionEnd;
|
| - PlainTextRange selectedRange = createRangeForSelection(start, end, text.length());
|
| -
|
| // 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:
|
| @@ -344,13 +339,11 @@
|
| if (text.isEmpty()) {
|
| if (hasComposition()) {
|
| confirmComposition(emptyString());
|
| - } 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);
|
| + return;
|
| }
|
| -
|
| - setEditableSelectionOffsets(selectedRange);
|
| + // 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);
|
| return;
|
| }
|
|
|
| @@ -401,7 +394,31 @@
|
| if (baseNode->layoutObject())
|
| baseNode->layoutObject()->setShouldDoFullPaintInvalidation();
|
|
|
| - setEditableSelectionOffsets(selectedRange);
|
| + // 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);
|
|
|
| if (underlines.isEmpty()) {
|
| frame().document()->markers().addCompositionMarker(m_compositionRange->startPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTheme::theme().platformDefaultCompositionBackgroundColor());
|
| @@ -508,38 +525,6 @@
|
| if (!editor().canEdit())
|
| return false;
|
| return setSelectionOffsets(selectionOffsets);
|
| -}
|
| -
|
| -PlainTextRange InputMethodController::createRangeForSelection(int start, int end, size_t textLength) const
|
| -{
|
| - // In case of exceeding the left boundary.
|
| - start = std::max(start, 0);
|
| - end = std::max(end, start);
|
| -
|
| - // In case of exceeding the right boundary.
|
| - Element* rootEditableElement = frame().selection().rootEditableElement();
|
| - if (!rootEditableElement)
|
| - return PlainTextRange();
|
| - const EphemeralRange& range = EphemeralRange::rangeOfContents(*rootEditableElement);
|
| - if (range.isNull())
|
| - return PlainTextRange();
|
| -
|
| - const TextIteratorBehaviorFlags behaviorFlags = TextIteratorEmitsObjectReplacementCharacter | TextIteratorEmitsCharactersBetweenAllVisiblePositions;
|
| - TextIterator it(range.startPosition(), range.endPosition(), behaviorFlags);
|
| -
|
| - int rightBoundary = 0;
|
| - for (; !it.atEnd(); it.advance())
|
| - rightBoundary += it.length();
|
| -
|
| - if (hasComposition())
|
| - rightBoundary -= compositionRange()->text().length();
|
| -
|
| - rightBoundary += textLength;
|
| -
|
| - start = std::min(start, rightBoundary);
|
| - end = std::min(end, rightBoundary);
|
| -
|
| - return PlainTextRange(start, end);
|
| }
|
|
|
| void InputMethodController::extendSelectionAndDelete(int before, int after)
|
|
|