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

Unified Diff: Source/core/dom/Node.cpp

Issue 20042003: compareDocumentPosition() should report PRECEEDING or FOLLOWING information even if nodes are disco… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add failing test to TestExpectations Created 7 years, 5 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 | « LayoutTests/fast/dom/shadow/compare-treescope-position-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Node.cpp
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp
index 40451028714cdc68d6d185eb6649bd53ceb980b1..73c249cdb1e28730d1a69233b26657319751f0fe 100644
--- a/Source/core/dom/Node.cpp
+++ b/Source/core/dom/Node.cpp
@@ -1704,8 +1704,10 @@ unsigned short Node::compareDocumentPositionInternal(const Node* otherNode, Shad
// If either of start1 or start2 is null, then we are disconnected, since one of the nodes is
// an orphaned attribute node.
- if (!start1 || !start2)
- return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
+ if (!start1 || !start2) {
+ unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
+ return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | direction;
+ }
Vector<const Node*, 16> chain1;
Vector<const Node*, 16> chain2;
@@ -1739,10 +1741,10 @@ unsigned short Node::compareDocumentPositionInternal(const Node* otherNode, Shad
// If one node is in the document and the other is not, we must be disconnected.
// If the nodes have different owning documents, they must be disconnected. Note that we avoid
// comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug).
- if (start1->inDocument() != start2->inDocument())
- return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
- if (treatment == TreatShadowTreesAsDisconnected && start1->treeScope() != start2->treeScope())
- return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
+ if (start1->inDocument() != start2->inDocument() || (treatment == TreatShadowTreesAsDisconnected && start1->treeScope() != start2->treeScope())) {
+ unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
+ return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | direction;
+ }
// We need to find a common ancestor container, and then compare the indices of the two immediate children.
const Node* current;
@@ -1756,7 +1758,7 @@ unsigned short Node::compareDocumentPositionInternal(const Node* otherNode, Shad
// If the two elements don't have a common root, they're not in the same tree.
if (chain1[index1 - 1] != chain2[index2 - 1]) {
- unsigned short direction = (start1 > start2) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
+ unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | direction;
}
« no previous file with comments | « LayoutTests/fast/dom/shadow/compare-treescope-position-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698