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

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

Issue 2877793003: Merge "Selection API: collapseToStart() and collapseToEnd() should work for text fields." to M59 (Closed)
Patch Set: Created 3 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
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/selection/collapseto_in_text_fields.html ('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 90dc0379be7f40986f8fb36f15287371557c8b2b..38750e2be637694377da7b87448ebc50d72b8537 100644
--- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
@@ -294,15 +294,24 @@ void DOMSelection::collapseToEnd(ExceptionState& exception_state) {
return;
}
- // Otherwise, it must create a new range, set both its start and end to the
- // end of the context object's range,
- Range* new_range = getRangeAt(0, ASSERT_NO_EXCEPTION)->cloneRange();
- new_range->collapse(false);
-
- // and then set the context object's range to the newly-created range.
- SelectionInDOMTree::Builder builder;
- builder.Collapse(new_range->EndPosition());
- UpdateFrameSelection(builder.Build(), new_range);
+ if (Range* current_range = DocumentCachedRange()) {
+ // Otherwise, it must create a new range, set both its start and end to the
+ // end of the context object's range,
+ Range* new_range = current_range->cloneRange();
+ new_range->collapse(false);
+
+ // and then set the context object's range to the newly-created range.
+ SelectionInDOMTree::Builder builder;
+ builder.Collapse(new_range->EndPosition());
+ UpdateFrameSelection(builder.Build(), new_range);
+ } else {
+ // TODO(tkent): The Selection API doesn't define this behavior. We should
+ // discuss this on https://github.com/w3c/selection-api/issues/83.
+ SelectionInDOMTree::Builder builder;
+ builder.Collapse(
+ GetFrame()->Selection().GetSelectionInDOMTree().ComputeEndPosition());
+ UpdateFrameSelection(builder.Build(), nullptr);
+ }
}
// https://www.w3.org/TR/selection-api/#dom-selection-collapsetostart
@@ -318,15 +327,24 @@ void DOMSelection::collapseToStart(ExceptionState& exception_state) {
return;
}
- // Otherwise, it must create a new range, set both its start and end to the
- // start of the context object's range,
- Range* new_range = getRangeAt(0, ASSERT_NO_EXCEPTION)->cloneRange();
- new_range->collapse(true);
+ if (Range* current_range = DocumentCachedRange()) {
+ // Otherwise, it must create a new range, set both its start and end to the
+ // start of the context object's range,
+ Range* new_range = current_range->cloneRange();
+ new_range->collapse(true);
- // and then set the context object's range to the newly-created range.
- SelectionInDOMTree::Builder builder;
- builder.Collapse(new_range->StartPosition());
- UpdateFrameSelection(builder.Build(), new_range);
+ // and then set the context object's range to the newly-created range.
+ SelectionInDOMTree::Builder builder;
+ builder.Collapse(new_range->StartPosition());
+ UpdateFrameSelection(builder.Build(), new_range);
+ } else {
+ // TODO(tkent): The Selection API doesn't define this behavior. We should
+ // discuss this on https://github.com/w3c/selection-api/issues/83.
+ SelectionInDOMTree::Builder builder;
+ builder.Collapse(
+ GetFrame()->Selection().GetSelectionInDOMTree().ComputeStartPosition());
+ UpdateFrameSelection(builder.Build(), nullptr);
+ }
}
void DOMSelection::empty() {
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/selection/collapseto_in_text_fields.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698