[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/khtml/xml
From:       Maks Orlovich <maksim () kde ! org>
Date:       2010-05-09 14:30:58
Message-ID: 20100509143058.33488AC8B1 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1124581 by orlovich:

Make compareDocumentPosition smarter about how it handles attribute 
nodes, always ordering them in order they occur on the element. 
This both makes more sense and is expected by XPath.


 M  +23 -0     dom_nodeimpl.cpp  


--- trunk/KDE/kdelibs/khtml/xml/dom_nodeimpl.cpp #1124580:1124581
@@ -1366,6 +1366,29 @@
             return (thisAnc->nodeType() < otherAnc->nodeType()) ? 
                 Node::DOCUMENT_POSITION_FOLLOWING : \
Node::DOCUMENT_POSITION_PRECEDING;  
+        // If both are argument nodes, they have to be in the same element,
+        // as otherwise the first difference would be in two different elements
+        // or above, which would not have logical parents unless they were
+        // disconnected, which would have been handled above.
+        // In this case, order them by their position in the
+        // attribute list. This is helpful for XPath.
+
+        if (thisAnc->nodeType() == Node::ATTRIBUTE_NODE) {
+            const AttrImpl* thisAncAttr  = static_cast<const AttrImpl*>(thisAnc);
+            const AttrImpl* otherAncAttr = static_cast<const AttrImpl*>(otherAnc);
+
+            NamedAttrMapImpl* attrs = thisAncAttr->ownerElement()->attributes();
+
+            unsigned l = attrs->length();
+            for (unsigned i = 0; i < l; ++i) {
+                if (attrs->attrAt(i) == thisAncAttr)
+                    return Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | \
Node::DOCUMENT_POSITION_FOLLOWING; +                if (attrs->attrAt(i) == \
otherAncAttr) +                    return \
Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node::DOCUMENT_POSITION_PRECEDING; \
+            } +            assert(false);
+        }
+                
         // If not, another implementation-specific order.
         return Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC |
                (this > other ? Node::DOCUMENT_POSITION_PRECEDING : \
Node::DOCUMENT_POSITION_FOLLOWING);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic