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

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

Issue 2708763002: Revert of Selection API: collapseToStart() and collapseToEnd() should recreate a Range. (Closed)
Patch Set: 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 4cc93dfef9ff7b07890d517500dd4fd0230a6310..b359dfe92b8b11a72c3901e13252fe712201355c 100644
--- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
@@ -258,54 +258,40 @@
cacheRangeIfSelectionOfDocument(newRange);
}
-// https://www.w3.org/TR/selection-api/#dom-selection-collapsetoend
void DOMSelection::collapseToEnd(ExceptionState& exceptionState) {
if (!isAvailable())
return;
- // The method must throw InvalidStateError exception if the context object is
- // empty.
- if (rangeCount() == 0) {
+ const VisibleSelection& selection =
+ frame()->selection().computeVisibleSelectionInDOMTreeDeprecated();
+
+ if (selection.isNone()) {
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(newRange->endPosition());
+ builder.collapse(selection.end());
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;
- // The method must throw InvalidStateError ([DOM4]) exception if the context
- // object is empty.
- if (rangeCount() == 0) {
+ const VisibleSelection& selection =
+ frame()->selection().computeVisibleSelectionInDOMTreeDeprecated();
+
+ if (selection.isNone()) {
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(newRange->startPosition());
+ builder.collapse(selection.start());
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