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

Side by Side Diff: Source/core/dom/Node.cpp

Issue 23890025: WIP (Introduce WTF::NonNullPtr<T>.) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/SelectorQuery.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 return; 903 return;
904 } 904 }
905 // Attribute-specific checks are in Attr::setPrefix(). 905 // Attribute-specific checks are in Attr::setPrefix().
906 } 906 }
907 907
908 bool Node::isDescendantOf(const Node *other) const 908 bool Node::isDescendantOf(const Node *other) const
909 { 909 {
910 // Return true if other is an ancestor of this, otherwise false 910 // Return true if other is an ancestor of this, otherwise false
911 if (!other || !other->hasChildNodes() || inDocument() != other->inDocument() ) 911 if (!other || !other->hasChildNodes() || inDocument() != other->inDocument() )
912 return false; 912 return false;
913 if (&other->treeScope() != &treeScope()) 913 if (other->treeScope() != treeScope())
914 return false; 914 return false;
915 if (other->isTreeScope()) 915 if (other->isTreeScope())
916 return !isTreeScope(); 916 return !isTreeScope();
917 for (const ContainerNode* n = parentNode(); n; n = n->parentNode()) { 917 for (const ContainerNode* n = parentNode(); n; n = n->parentNode()) {
918 if (n == other) 918 if (n == other)
919 return true; 919 return true;
920 } 920 }
921 return false; 921 return false;
922 } 922 }
923 923
(...skipping 17 matching lines...) Expand all
941 941
942 if (inDocument() != node->inDocument()) 942 if (inDocument() != node->inDocument())
943 return false; 943 return false;
944 944
945 bool hasChildren = isContainerNode() && toContainerNode(this)->hasChildNodes (); 945 bool hasChildren = isContainerNode() && toContainerNode(this)->hasChildNodes ();
946 bool hasShadow = isElementNode() && toElement(this)->shadow(); 946 bool hasShadow = isElementNode() && toElement(this)->shadow();
947 if (!hasChildren && !hasShadow) 947 if (!hasChildren && !hasShadow)
948 return false; 948 return false;
949 949
950 for (; node; node = node->shadowHost()) { 950 for (; node; node = node->shadowHost()) {
951 if (&treeScope() == &node->treeScope()) 951 if (treeScope() == node->treeScope())
952 return contains(node); 952 return contains(node);
953 } 953 }
954 954
955 return false; 955 return false;
956 } 956 }
957 957
958 bool Node::containsIncludingHostElements(const Node* node) const 958 bool Node::containsIncludingHostElements(const Node* node) const
959 { 959 {
960 while (node) { 960 while (node) {
961 if (node == this) 961 if (node == this)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 Node* Node::deprecatedShadowAncestorNode() const 1152 Node* Node::deprecatedShadowAncestorNode() const
1153 { 1153 {
1154 if (ShadowRoot* root = containingShadowRoot()) 1154 if (ShadowRoot* root = containingShadowRoot())
1155 return root->host(); 1155 return root->host();
1156 1156
1157 return const_cast<Node*>(this); 1157 return const_cast<Node*>(this);
1158 } 1158 }
1159 1159
1160 ShadowRoot* Node::containingShadowRoot() const 1160 ShadowRoot* Node::containingShadowRoot() const
1161 { 1161 {
1162 Node* root = treeScope().rootNode(); 1162 Node* root = treeScope()->rootNode();
1163 return root && root->isShadowRoot() ? toShadowRoot(root) : 0; 1163 return root && root->isShadowRoot() ? toShadowRoot(root) : 0;
1164 } 1164 }
1165 1165
1166 Node* Node::nonBoundaryShadowTreeRootNode() 1166 Node* Node::nonBoundaryShadowTreeRootNode()
1167 { 1167 {
1168 ASSERT(!isShadowRoot()); 1168 ASSERT(!isShadowRoot());
1169 Node* root = this; 1169 Node* root = this;
1170 while (root) { 1170 while (root) {
1171 if (root->isShadowRoot()) 1171 if (root->isShadowRoot())
1172 return root; 1172 return root;
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_PRECEDING; 1700 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_PRECEDING;
1701 } 1701 }
1702 1702
1703 ASSERT_NOT_REACHED(); 1703 ASSERT_NOT_REACHED();
1704 return DOCUMENT_POSITION_DISCONNECTED; 1704 return DOCUMENT_POSITION_DISCONNECTED;
1705 } 1705 }
1706 1706
1707 // If one node is in the document and the other is not, we must be disconnec ted. 1707 // If one node is in the document and the other is not, we must be disconnec ted.
1708 // If the nodes have different owning documents, they must be disconnected. Note that we avoid 1708 // If the nodes have different owning documents, they must be disconnected. Note that we avoid
1709 // comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug). 1709 // comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug).
1710 if (start1->inDocument() != start2->inDocument() || (treatment == TreatShado wTreesAsDisconnected && &start1->treeScope() != &start2->treeScope())) { 1710 if (start1->inDocument() != start2->inDocument() || (treatment == TreatShado wTreesAsDisconnected && start1->treeScope() != start2->treeScope())) {
1711 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING; 1711 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING;
1712 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction; 1712 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction;
1713 } 1713 }
1714 1714
1715 // We need to find a common ancestor container, and then compare the indices of the two immediate children. 1715 // We need to find a common ancestor container, and then compare the indices of the two immediate children.
1716 const Node* current; 1716 const Node* current;
1717 for (current = start1; current; current = current->parentOrShadowHostNode()) 1717 for (current = start1; current; current = current->parentOrShadowHostNode())
1718 chain1.append(current); 1718 chain1.append(current);
1719 for (current = start2; current; current = current->parentOrShadowHostNode()) 1719 for (current = start2; current; current = current->parentOrShadowHostNode())
1720 chain2.append(current); 1720 chain2.append(current);
1721 1721
1722 unsigned index1 = chain1.size(); 1722 unsigned index1 = chain1.size();
1723 unsigned index2 = chain2.size(); 1723 unsigned index2 = chain2.size();
1724 1724
1725 // If the two elements don't have a common root, they're not in the same tre e. 1725 // If the two elements don't have a common root, they're not in the same tre e.
1726 if (chain1[index1 - 1] != chain2[index2 - 1]) { 1726 if (chain1[index1 - 1] != chain2[index2 - 1]) {
1727 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING; 1727 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING;
1728 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction; 1728 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction;
1729 } 1729 }
1730 1730
1731 unsigned connection = &start1->treeScope() != &start2->treeScope() ? DOCUMEN T_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC : 0; 1731 unsigned connection = start1->treeScope() != start2->treeScope() ? DOCUMENT_ POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC : 0;
1732 1732
1733 // Walk the two chains backwards and look for the first difference. 1733 // Walk the two chains backwards and look for the first difference.
1734 for (unsigned i = min(index1, index2); i; --i) { 1734 for (unsigned i = min(index1, index2); i; --i) {
1735 const Node* child1 = chain1[--index1]; 1735 const Node* child1 = chain1[--index1];
1736 const Node* child2 = chain2[--index2]; 1736 const Node* child2 = chain2[--index2];
1737 if (child1 != child2) { 1737 if (child1 != child2) {
1738 // If one of the children is an attribute, it wins. 1738 // If one of the children is an attribute, it wins.
1739 if (child1->nodeType() == ATTRIBUTE_NODE) 1739 if (child1->nodeType() == ATTRIBUTE_NODE)
1740 return DOCUMENT_POSITION_FOLLOWING | connection; 1740 return DOCUMENT_POSITION_FOLLOWING | connection;
1741 if (child2->nodeType() == ATTRIBUTE_NODE) 1741 if (child2->nodeType() == ATTRIBUTE_NODE)
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2500 } 2500 }
2501 2501
2502 // It's important not to inline removedLastRef, because we don't want to inline the code to 2502 // It's important not to inline removedLastRef, because we don't want to inline the code to
2503 // delete a Node at each deref call site. 2503 // delete a Node at each deref call site.
2504 void Node::removedLastRef() 2504 void Node::removedLastRef()
2505 { 2505 {
2506 // An explicit check for Document here is better than a virtual function sin ce it is 2506 // An explicit check for Document here is better than a virtual function sin ce it is
2507 // faster for non-Document nodes, and because the call to removedLastRef tha t is inlined 2507 // faster for non-Document nodes, and because the call to removedLastRef tha t is inlined
2508 // at all deref call sites is smaller if it's a non-virtual function. 2508 // at all deref call sites is smaller if it's a non-virtual function.
2509 if (isTreeScope()) { 2509 if (isTreeScope()) {
2510 treeScope().removedLastRefToScope(); 2510 treeScope()->removedLastRefToScope();
2511 return; 2511 return;
2512 } 2512 }
2513 2513
2514 #ifndef NDEBUG 2514 #ifndef NDEBUG
2515 m_deletionHasBegun = true; 2515 m_deletionHasBegun = true;
2516 #endif 2516 #endif
2517 delete this; 2517 delete this;
2518 } 2518 }
2519 2519
2520 void Node::textRects(Vector<IntRect>& rects) const 2520 void Node::textRects(Vector<IntRect>& rects) const
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 node->showTreeForThis(); 2678 node->showTreeForThis();
2679 } 2679 }
2680 2680
2681 void showNodePath(const WebCore::Node* node) 2681 void showNodePath(const WebCore::Node* node)
2682 { 2682 {
2683 if (node) 2683 if (node)
2684 node->showNodePathForThis(); 2684 node->showNodePathForThis();
2685 } 2685 }
2686 2686
2687 #endif 2687 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/SelectorQuery.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698