| Index: third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| diff --git a/third_party/WebKit/Source/core/editing/DOMSelection.cpp b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| index 3ab419529702509df17ffbfecacbd19b315181d1..e38f0d7e42fdbde9b633cc4c0e733d008db35ad8 100644
|
| --- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
|
| @@ -258,40 +258,54 @@ void DOMSelection::collapse(Node* node,
|
| cacheRangeIfSelectionOfDocument(newRange);
|
| }
|
|
|
| +// https://www.w3.org/TR/selection-api/#dom-selection-collapsetoend
|
| void DOMSelection::collapseToEnd(ExceptionState& exceptionState) {
|
| if (!isAvailable())
|
| return;
|
|
|
| - const VisibleSelection& selection =
|
| - frame()->selection().computeVisibleSelectionInDOMTreeDeprecated();
|
| -
|
| - if (selection.isNone()) {
|
| + // The method must throw InvalidStateError exception if the context object is
|
| + // empty.
|
| + if (rangeCount() == 0) {
|
| exceptionState.throwDOMException(InvalidStateError,
|
| "there is no selection.");
|
| return;
|
| }
|
|
|
| + // Otherwise, it must create a new range, set both its start and end to the
|
| + // end of the context object's range,
|
| + Range* newRange = getRangeAt(0, ASSERT_NO_EXCEPTION)->cloneRange();
|
| + newRange->collapse(false);
|
| +
|
| + // and then set the context object's range to the newly-created range.
|
| SelectionInDOMTree::Builder builder;
|
| - builder.collapse(selection.end());
|
| + builder.collapse(newRange->endPosition());
|
| frame()->selection().setSelection(builder.build());
|
| + cacheRangeIfSelectionOfDocument(newRange);
|
| }
|
|
|
| +// https://www.w3.org/TR/selection-api/#dom-selection-collapsetostart
|
| void DOMSelection::collapseToStart(ExceptionState& exceptionState) {
|
| if (!isAvailable())
|
| return;
|
|
|
| - const VisibleSelection& selection =
|
| - frame()->selection().computeVisibleSelectionInDOMTreeDeprecated();
|
| -
|
| - if (selection.isNone()) {
|
| + // The method must throw InvalidStateError ([DOM4]) exception if the context
|
| + // object is empty.
|
| + if (rangeCount() == 0) {
|
| exceptionState.throwDOMException(InvalidStateError,
|
| "there is no selection.");
|
| return;
|
| }
|
|
|
| + // Otherwise, it must create a new range, set both its start and end to the
|
| + // start of the context object's range,
|
| + Range* newRange = getRangeAt(0, ASSERT_NO_EXCEPTION)->cloneRange();
|
| + newRange->collapse(true);
|
| +
|
| + // and then set the context object's range to the newly-created range.
|
| SelectionInDOMTree::Builder builder;
|
| - builder.collapse(selection.start());
|
| + builder.collapse(newRange->startPosition());
|
| frame()->selection().setSelection(builder.build());
|
| + cacheRangeIfSelectionOfDocument(newRange);
|
| }
|
|
|
| void DOMSelection::empty() {
|
|
|