Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Unified Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 2020973002: Reland: Fix setComposingText with empty text when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4d38acf557e100622c98884de4b8462d3d15676e 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -321,6 +321,12 @@ 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;
+ DCHECK_GE(start, 0);
+ DCHECK_LE(start, end);
+
// 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 +345,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 +398,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);
frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream, SelectionDirectionalMode::NonDirectional, NotUserTriggered);
if (underlines.isEmpty()) {

Powered by Google App Engine
This is Rietveld 408576698