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

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

Issue 2451613003: Get rid of createVisibleSelection() taking two Position (Closed)
Patch Set: 2016-10-26T15:09:55 Created 4 years, 2 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 | « no previous file | third_party/WebKit/Source/core/editing/FrameSelection.cpp » ('j') | 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 113ff3500dc734c3651ff1378fe245c0cc671a37..0a1501f0ffea6ca18800ee7703434d1d08b6bad4 100644
--- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
@@ -47,13 +47,6 @@
namespace blink {
-static Position createPosition(Node* node, int offset) {
- DCHECK_GE(offset, 0);
- if (!node)
- return Position();
- return Position(node, offset);
-}
-
static Node* selectionShadowAncestor(LocalFrame* frame) {
Node* node = frame->selection().selection().base().anchorNode();
if (!node)
@@ -299,19 +292,23 @@ void DOMSelection::setBaseAndExtent(Node* baseNode,
if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
return;
- Position base = createPosition(baseNode, baseOffset);
- Position extent = createPosition(extentNode, extentOffset);
- const bool selectionHasDirection = true;
-
- // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
+ // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
// In the long term, we should change FrameSelection::setSelection to take a
// parameter that does not require clean layout, so that modifying selection
// no longer performs synchronous layout by itself.
+ // TODO(editing-dev): Once SVG USE element doesn't modifies DOM tree, we
+ // should get rid of this update layout call.
+ // See http://crbug.com/566281
+ // See "svg/text/textpath-reference-crash.html"
frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
- frame()->selection().setSelection(createVisibleSelection(
- base, extent, SelDefaultAffinity, selectionHasDirection));
+ frame()->selection().setSelection(
+ SelectionInDOMTree::Builder()
+ .setBaseAndExtentDeprecated(Position(baseNode, baseOffset),
+ Position(extentNode, extentOffset))
+ .setIsDirectional(true)
+ .build());
}
void DOMSelection::modify(const String& alterString,
@@ -393,19 +390,20 @@ void DOMSelection::extend(Node* node,
return;
const Position& base = frame()->selection().base();
- const Position& extent = createPosition(node, offset);
- const bool selectionHasDirection = true;
-
- // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
- // needs to be audited. See http://crbug.com/590369 for more details.
- // In the long term, we should change FrameSelection::setSelection to take a
- // parameter that does not require clean layout, so that modifying selection
- // no longer performs synchronous layout by itself.
- frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
-
- const VisibleSelection newSelection = createVisibleSelection(
- base, extent, TextAffinity::Downstream, selectionHasDirection);
- frame()->selection().setSelection(newSelection);
+ if (base.isNull()) {
+ // TODO(editing-dev): We should throw |InvalidStateError| if selection is
+ // none to follow the spec.
+ frame()->selection().setSelection(SelectionInDOMTree::Builder()
+ .collapse(Position(node, offset))
+ .setIsDirectional(true)
+ .build());
+ return;
+ }
+ frame()->selection().setSelection(SelectionInDOMTree::Builder()
+ .collapse(base)
+ .extend(Position(node, offset))
+ .setIsDirectional(true)
+ .build());
}
Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) {
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/FrameSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698