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

Unified Diff: third_party/WebKit/Source/core/dom/Range.cpp

Issue 2531483003: Make Range::createAdjustedToTreeScope() to handle the shadow root at end of document tree correctly. (Closed)
Patch Set: Created 4 years, 1 month 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/dom/RangeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Range.cpp
diff --git a/third_party/WebKit/Source/core/dom/Range.cpp b/third_party/WebKit/Source/core/dom/Range.cpp
index e10fad1ec9cf5b42806ab0343aadb623f0e7792e..ffd6bb114b4c732b74dd83f61212aa1247971d16 100644
--- a/third_party/WebKit/Source/core/dom/Range.cpp
+++ b/third_party/WebKit/Source/core/dom/Range.cpp
@@ -100,25 +100,19 @@ Range* Range::create(Document& ownerDocument,
end.computeOffsetInContainerNode());
}
+// TODO(yosin): We should move |Range::createAdjustedToTreeScope()| to
+// "Document.cpp" since it is use only one place in "Document.cpp".
Range* Range::createAdjustedToTreeScope(const TreeScope& treeScope,
const Position& position) {
- Range* range = create(treeScope.document(), position, position);
-
- // Make sure the range is in this scope.
- Node* firstNode = range->firstNode();
- DCHECK(firstNode);
- Node* shadowHostInThisScopeOrFirstNode =
- treeScope.ancestorInThisScope(firstNode);
- DCHECK(shadowHostInThisScopeOrFirstNode);
- if (shadowHostInThisScopeOrFirstNode == firstNode)
- return range;
-
- // If not, create a range for the shadow host in this scope.
- ContainerNode* container = shadowHostInThisScopeOrFirstNode->parentNode();
- DCHECK(container);
- unsigned offset = shadowHostInThisScopeOrFirstNode->nodeIndex();
- return Range::create(treeScope.document(), container, offset, container,
- offset);
+ DCHECK(position.isNotNull());
+ // Note: Since |Position::computeContanerNode()| returns |nullptr| if
+ // |position| is |BeforeAnchor| or |AfterAnchor|.
+ Node* const anchorNode = position.anchorNode();
+ if (anchorNode->treeScope() == treeScope)
+ return create(treeScope.document(), position, position);
+ Node* const shadowHost = treeScope.ancestorInThisScope(anchorNode);
+ return Range::create(treeScope.document(), Position::beforeNode(shadowHost),
+ Position::beforeNode(shadowHost));
}
void Range::dispose() {
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/RangeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698