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

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

Issue 1995333002: Handle newCursorPosition correctly for Android's commitText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 b70befe6440a692d856ddb169fc145088ea45c63..65a42cc0e3c58744753640e134582c9912ef3e8d 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp
@@ -457,6 +457,40 @@ bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se
return setSelectionOffsets(selectionOffsets);
}
+bool InputMethodController::setEditableSelectionOffsetsWithBoundaryCheck(int start, int end)
+{
+ if (!editor().canEdit())
+ return false;
+
+ // In case of exceeding left boundary.
+ start = std::max(start, 0);
+ end = std::max(end, 0);
Changwan Ryu 2016/05/24 08:35:50 s/0/start/ ?
+
+ Element* rootEditableElement = frame().selection().rootEditableElement();
+ if (!rootEditableElement)
+ return false;
+
+ // 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;
+
+ 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)
{
if (!editor().canEdit())

Powered by Google App Engine
This is Rietveld 408576698