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

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

Issue 2704963002: Selection API: collapseToStart() and collapseToEnd() should recreate a Range. (Closed)
Patch Set: NeedsRebaseline for first-letter-rtc-crash.html Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css/first-letter-rtc-crash-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css/first-letter-rtc-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698