OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 return DOCUMENT_POSITION_EQUIVALENT; | 1697 return DOCUMENT_POSITION_EQUIVALENT; |
1698 | 1698 |
1699 const Attr* attr1 = nodeType() == ATTRIBUTE_NODE ? toAttr(this) : 0; | 1699 const Attr* attr1 = nodeType() == ATTRIBUTE_NODE ? toAttr(this) : 0; |
1700 const Attr* attr2 = otherNode->nodeType() == ATTRIBUTE_NODE ? toAttr(otherNo
de) : 0; | 1700 const Attr* attr2 = otherNode->nodeType() == ATTRIBUTE_NODE ? toAttr(otherNo
de) : 0; |
1701 | 1701 |
1702 const Node* start1 = attr1 ? attr1->ownerElement() : this; | 1702 const Node* start1 = attr1 ? attr1->ownerElement() : this; |
1703 const Node* start2 = attr2 ? attr2->ownerElement() : otherNode; | 1703 const Node* start2 = attr2 ? attr2->ownerElement() : otherNode; |
1704 | 1704 |
1705 // If either of start1 or start2 is null, then we are disconnected, since on
e of the nodes is | 1705 // If either of start1 or start2 is null, then we are disconnected, since on
e of the nodes is |
1706 // an orphaned attribute node. | 1706 // an orphaned attribute node. |
1707 if (!start1 || !start2) | 1707 if (!start1 || !start2) { |
1708 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION
_SPECIFIC; | 1708 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED
ING : DOCUMENT_POSITION_FOLLOWING; |
| 1709 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION
_SPECIFIC | direction; |
| 1710 } |
1709 | 1711 |
1710 Vector<const Node*, 16> chain1; | 1712 Vector<const Node*, 16> chain1; |
1711 Vector<const Node*, 16> chain2; | 1713 Vector<const Node*, 16> chain2; |
1712 if (attr1) | 1714 if (attr1) |
1713 chain1.append(attr1); | 1715 chain1.append(attr1); |
1714 if (attr2) | 1716 if (attr2) |
1715 chain2.append(attr2); | 1717 chain2.append(attr2); |
1716 | 1718 |
1717 if (attr1 && attr2 && start1 == start2 && start1) { | 1719 if (attr1 && attr2 && start1 == start2 && start1) { |
1718 // We are comparing two attributes on the same node. Crawl our attribute
map and see which one we hit first. | 1720 // We are comparing two attributes on the same node. Crawl our attribute
map and see which one we hit first. |
(...skipping 13 matching lines...) Expand all Loading... |
1732 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI
TION_PRECEDING; | 1734 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI
TION_PRECEDING; |
1733 } | 1735 } |
1734 | 1736 |
1735 ASSERT_NOT_REACHED(); | 1737 ASSERT_NOT_REACHED(); |
1736 return DOCUMENT_POSITION_DISCONNECTED; | 1738 return DOCUMENT_POSITION_DISCONNECTED; |
1737 } | 1739 } |
1738 | 1740 |
1739 // If one node is in the document and the other is not, we must be disconnec
ted. | 1741 // If one node is in the document and the other is not, we must be disconnec
ted. |
1740 // If the nodes have different owning documents, they must be disconnected.
Note that we avoid | 1742 // If the nodes have different owning documents, they must be disconnected.
Note that we avoid |
1741 // comparing Attr nodes here, since they return false from inDocument() all
the time (which seems like a bug). | 1743 // comparing Attr nodes here, since they return false from inDocument() all
the time (which seems like a bug). |
1742 if (start1->inDocument() != start2->inDocument()) | 1744 if (start1->inDocument() != start2->inDocument() || (treatment == TreatShado
wTreesAsDisconnected && start1->treeScope() != start2->treeScope())) { |
1743 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION
_SPECIFIC; | 1745 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED
ING : DOCUMENT_POSITION_FOLLOWING; |
1744 if (treatment == TreatShadowTreesAsDisconnected && start1->treeScope() != st
art2->treeScope()) | 1746 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION
_SPECIFIC | direction; |
1745 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION
_SPECIFIC; | 1747 } |
1746 | 1748 |
1747 // We need to find a common ancestor container, and then compare the indices
of the two immediate children. | 1749 // We need to find a common ancestor container, and then compare the indices
of the two immediate children. |
1748 const Node* current; | 1750 const Node* current; |
1749 for (current = start1; current; current = current->parentOrShadowHostNode()) | 1751 for (current = start1; current; current = current->parentOrShadowHostNode()) |
1750 chain1.append(current); | 1752 chain1.append(current); |
1751 for (current = start2; current; current = current->parentOrShadowHostNode()) | 1753 for (current = start2; current; current = current->parentOrShadowHostNode()) |
1752 chain2.append(current); | 1754 chain2.append(current); |
1753 | 1755 |
1754 unsigned index1 = chain1.size(); | 1756 unsigned index1 = chain1.size(); |
1755 unsigned index2 = chain2.size(); | 1757 unsigned index2 = chain2.size(); |
1756 | 1758 |
1757 // If the two elements don't have a common root, they're not in the same tre
e. | 1759 // If the two elements don't have a common root, they're not in the same tre
e. |
1758 if (chain1[index1 - 1] != chain2[index2 - 1]) { | 1760 if (chain1[index1 - 1] != chain2[index2 - 1]) { |
1759 unsigned short direction = (start1 > start2) ? DOCUMENT_POSITION_PRECEDI
NG : DOCUMENT_POSITION_FOLLOWING; | 1761 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED
ING : DOCUMENT_POSITION_FOLLOWING; |
1760 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION
_SPECIFIC | direction; | 1762 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION
_SPECIFIC | direction; |
1761 } | 1763 } |
1762 | 1764 |
1763 unsigned connection = start1->treeScope() != start2->treeScope() ? DOCUMENT_
POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC : 0; | 1765 unsigned connection = start1->treeScope() != start2->treeScope() ? DOCUMENT_
POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC : 0; |
1764 | 1766 |
1765 // Walk the two chains backwards and look for the first difference. | 1767 // Walk the two chains backwards and look for the first difference. |
1766 for (unsigned i = min(index1, index2); i; --i) { | 1768 for (unsigned i = min(index1, index2); i; --i) { |
1767 const Node* child1 = chain1[--index1]; | 1769 const Node* child1 = chain1[--index1]; |
1768 const Node* child2 = chain2[--index2]; | 1770 const Node* child2 = chain2[--index2]; |
1769 if (child1 != child2) { | 1771 if (child1 != child2) { |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2719 node->showTreeForThis(); | 2721 node->showTreeForThis(); |
2720 } | 2722 } |
2721 | 2723 |
2722 void showNodePath(const WebCore::Node* node) | 2724 void showNodePath(const WebCore::Node* node) |
2723 { | 2725 { |
2724 if (node) | 2726 if (node) |
2725 node->showNodePathForThis(); | 2727 node->showNodePathForThis(); |
2726 } | 2728 } |
2727 | 2729 |
2728 #endif | 2730 #endif |
OLD | NEW |