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()) |