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

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

Issue 1885453002: Rename Node::treeScope() to Node::treeScopeOrDocument() Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 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
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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 last = currentElement->pseudoElement(PseudoIdBefore); 450 last = currentElement->pseudoElement(PseudoIdBefore);
451 return last; 451 return last;
452 } 452 }
453 453
454 return lastChild(); 454 return lastChild();
455 } 455 }
456 456
457 Node& Node::treeRoot() const 457 Node& Node::treeRoot() const
458 { 458 {
459 if (isInTreeScope()) 459 if (isInTreeScope())
460 return treeScope().rootNode(); 460 return treeScopeOrDocument().rootNode();
461 const Node* node = this; 461 const Node* node = this;
462 while (node->parentNode()) 462 while (node->parentNode())
463 node = node->parentNode(); 463 node = node->parentNode();
464 return const_cast<Node&>(*node); 464 return const_cast<Node&>(*node);
465 } 465 }
466 466
467 Node* Node::insertBefore(Node* newChild, Node* refChild, ExceptionState& excepti onState) 467 Node* Node::insertBefore(Node* newChild, Node* refChild, ExceptionState& excepti onState)
468 { 468 {
469 if (isContainerNode()) 469 if (isContainerNode())
470 return toContainerNode(this)->insertBefore(newChild, refChild, exception State); 470 return toContainerNode(this)->insertBefore(newChild, refChild, exception State);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 void Node::clearNodeLists() 791 void Node::clearNodeLists()
792 { 792 {
793 rareData()->clearNodeLists(); 793 rareData()->clearNodeLists();
794 } 794 }
795 795
796 bool Node::isDescendantOf(const Node *other) const 796 bool Node::isDescendantOf(const Node *other) const
797 { 797 {
798 // Return true if other is an ancestor of this, otherwise false 798 // Return true if other is an ancestor of this, otherwise false
799 if (!other || !other->hasChildren() || inShadowIncludingDocument() != other- >inShadowIncludingDocument()) 799 if (!other || !other->hasChildren() || inShadowIncludingDocument() != other- >inShadowIncludingDocument())
800 return false; 800 return false;
801 if (other->treeScope() != treeScope()) 801 if (other->treeScopeOrDocument() != treeScopeOrDocument())
802 return false; 802 return false;
803 if (other->isTreeScope()) 803 if (other->isTreeScope())
804 return !isTreeScope(); 804 return !isTreeScope();
805 for (const ContainerNode* n = parentNode(); n; n = n->parentNode()) { 805 for (const ContainerNode* n = parentNode(); n; n = n->parentNode()) {
806 if (n == other) 806 if (n == other)
807 return true; 807 return true;
808 } 808 }
809 return false; 809 return false;
810 } 810 }
811 811
(...skipping 17 matching lines...) Expand all
829 829
830 if (inShadowIncludingDocument() != node->inShadowIncludingDocument()) 830 if (inShadowIncludingDocument() != node->inShadowIncludingDocument())
831 return false; 831 return false;
832 832
833 bool hasChildren = isContainerNode() && toContainerNode(this)->hasChildren() ; 833 bool hasChildren = isContainerNode() && toContainerNode(this)->hasChildren() ;
834 bool hasShadow = isElementNode() && toElement(this)->shadow(); 834 bool hasShadow = isElementNode() && toElement(this)->shadow();
835 if (!hasChildren && !hasShadow) 835 if (!hasChildren && !hasShadow)
836 return false; 836 return false;
837 837
838 for (; node; node = node->shadowHost()) { 838 for (; node; node = node->shadowHost()) {
839 if (treeScope() == node->treeScope()) 839 if (treeScopeOrDocument() == node->treeScopeOrDocument())
840 return contains(node); 840 return contains(node);
841 } 841 }
842 842
843 return false; 843 return false;
844 } 844 }
845 845
846 Node* Node::retarget(const Node& target) const 846 Node* Node::retarget(const Node& target) const
847 { 847 {
848 for (const Node* ancestor = &target; ancestor; ancestor = ancestor->shadowHo st()) { 848 for (const Node* ancestor = &target; ancestor; ancestor = ancestor->shadowHo st()) {
849 if (treeScope() == ancestor->treeScope()) 849 if (treeScopeOrDocument() == ancestor->treeScopeOrDocument())
850 return const_cast<Node*>(ancestor); 850 return const_cast<Node*>(ancestor);
851 } 851 }
852 return nullptr; 852 return nullptr;
853 } 853 }
854 854
855 bool Node::containsIncludingHostElements(const Node& node) const 855 bool Node::containsIncludingHostElements(const Node& node) const
856 { 856 {
857 const Node* current = &node; 857 const Node* current = &node;
858 do { 858 do {
859 if (current == this) 859 if (current == this)
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1042
1043 Element* Node::shadowHost() const 1043 Element* Node::shadowHost() const
1044 { 1044 {
1045 if (ShadowRoot* root = containingShadowRoot()) 1045 if (ShadowRoot* root = containingShadowRoot())
1046 return root->host(); 1046 return root->host();
1047 return nullptr; 1047 return nullptr;
1048 } 1048 }
1049 1049
1050 ShadowRoot* Node::containingShadowRoot() const 1050 ShadowRoot* Node::containingShadowRoot() const
1051 { 1051 {
1052 Node& root = treeScope().rootNode(); 1052 Node& root = treeScopeOrDocument().rootNode();
1053 return root.isShadowRoot() ? toShadowRoot(&root) : nullptr; 1053 return root.isShadowRoot() ? toShadowRoot(&root) : nullptr;
1054 } 1054 }
1055 1055
1056 Node* Node::nonBoundaryShadowTreeRootNode() 1056 Node* Node::nonBoundaryShadowTreeRootNode()
1057 { 1057 {
1058 DCHECK(!isShadowRoot()); 1058 DCHECK(!isShadowRoot());
1059 Node* root = this; 1059 Node* root = this;
1060 while (root) { 1060 while (root) {
1061 if (root->isShadowRoot()) 1061 if (root->isShadowRoot())
1062 return root; 1062 return root;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_PRECEDING; 1434 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_PRECEDING;
1435 } 1435 }
1436 1436
1437 ASSERT_NOT_REACHED(); 1437 ASSERT_NOT_REACHED();
1438 return DOCUMENT_POSITION_DISCONNECTED; 1438 return DOCUMENT_POSITION_DISCONNECTED;
1439 } 1439 }
1440 1440
1441 // If one node is in the document and the other is not, we must be disconnec ted. 1441 // If one node is in the document and the other is not, we must be disconnec ted.
1442 // If the nodes have different owning documents, they must be disconnected. Note that we avoid 1442 // If the nodes have different owning documents, they must be disconnected. Note that we avoid
1443 // comparing Attr nodes here, since they return false from inShadowIncluding Document() all the time (which seems like a bug). 1443 // comparing Attr nodes here, since they return false from inShadowIncluding Document() all the time (which seems like a bug).
1444 if (start1->inShadowIncludingDocument() != start2->inShadowIncludingDocument () || (treatment == TreatShadowTreesAsDisconnected && start1->treeScope() != sta rt2->treeScope())) { 1444 if (start1->inShadowIncludingDocument() != start2->inShadowIncludingDocument () || (treatment == TreatShadowTreesAsDisconnected && start1->treeScopeOrDocumen t() != start2->treeScopeOrDocument())) {
1445 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING; 1445 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING;
1446 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction; 1446 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction;
1447 } 1447 }
1448 1448
1449 // We need to find a common ancestor container, and then compare the indices of the two immediate children. 1449 // We need to find a common ancestor container, and then compare the indices of the two immediate children.
1450 const Node* current; 1450 const Node* current;
1451 for (current = start1; current; current = current->parentOrShadowHostNode()) 1451 for (current = start1; current; current = current->parentOrShadowHostNode())
1452 chain1.append(current); 1452 chain1.append(current);
1453 for (current = start2; current; current = current->parentOrShadowHostNode()) 1453 for (current = start2; current; current = current->parentOrShadowHostNode())
1454 chain2.append(current); 1454 chain2.append(current);
1455 1455
1456 unsigned index1 = chain1.size(); 1456 unsigned index1 = chain1.size();
1457 unsigned index2 = chain2.size(); 1457 unsigned index2 = chain2.size();
1458 1458
1459 // If the two elements don't have a common root, they're not in the same tre e. 1459 // If the two elements don't have a common root, they're not in the same tre e.
1460 if (chain1[index1 - 1] != chain2[index2 - 1]) { 1460 if (chain1[index1 - 1] != chain2[index2 - 1]) {
1461 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING; 1461 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING;
1462 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction; 1462 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction;
1463 } 1463 }
1464 1464
1465 unsigned connection = start1->treeScope() != start2->treeScope() ? DOCUMENT_ POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC : 0; 1465 unsigned connection = start1->treeScopeOrDocument() != start2->treeScopeOrDo cument() ? DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPE CIFIC : 0;
1466 1466
1467 // Walk the two chains backwards and look for the first difference. 1467 // Walk the two chains backwards and look for the first difference.
1468 for (unsigned i = std::min(index1, index2); i; --i) { 1468 for (unsigned i = std::min(index1, index2); i; --i) {
1469 const Node* child1 = chain1[--index1]; 1469 const Node* child1 = chain1[--index1];
1470 const Node* child2 = chain2[--index2]; 1470 const Node* child2 = chain2[--index2];
1471 if (child1 != child2) { 1471 if (child1 != child2) {
1472 // If one of the children is an attribute, it wins. 1472 // If one of the children is an attribute, it wins.
1473 if (child1->getNodeType() == ATTRIBUTE_NODE) 1473 if (child1->getNodeType() == ATTRIBUTE_NODE)
1474 return DOCUMENT_POSITION_FOLLOWING | connection; 1474 return DOCUMENT_POSITION_FOLLOWING | connection;
1475 if (child2->getNodeType() == ATTRIBUTE_NODE) 1475 if (child2->getNodeType() == ATTRIBUTE_NODE)
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 } 2255 }
2256 2256
2257 // It's important not to inline removedLastRef, because we don't want to inline the code to 2257 // It's important not to inline removedLastRef, because we don't want to inline the code to
2258 // delete a Node at each deref call site. 2258 // delete a Node at each deref call site.
2259 void Node::removedLastRef() 2259 void Node::removedLastRef()
2260 { 2260 {
2261 // An explicit check for Document here is better than a virtual function sin ce it is 2261 // An explicit check for Document here is better than a virtual function sin ce it is
2262 // faster for non-Document nodes, and because the call to removedLastRef tha t is inlined 2262 // faster for non-Document nodes, and because the call to removedLastRef tha t is inlined
2263 // at all deref call sites is smaller if it's a non-virtual function. 2263 // at all deref call sites is smaller if it's a non-virtual function.
2264 if (isTreeScope()) { 2264 if (isTreeScope()) {
2265 treeScope().removedLastRefToScope(); 2265 treeScopeOrDocument().removedLastRefToScope();
2266 return; 2266 return;
2267 } 2267 }
2268 2268
2269 #if ENABLE(SECURITY_ASSERT) 2269 #if ENABLE(SECURITY_ASSERT)
2270 m_deletionHasBegun = true; 2270 m_deletionHasBegun = true;
2271 #endif 2271 #endif
2272 delete this; 2272 delete this;
2273 } 2273 }
2274 #endif 2274 #endif
2275 2275
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 2468
2469 void showNodePath(const blink::Node* node) 2469 void showNodePath(const blink::Node* node)
2470 { 2470 {
2471 if (node) 2471 if (node)
2472 node->showNodePathForThis(); 2472 node->showNodePathForThis();
2473 else 2473 else
2474 fprintf(stderr, "Cannot showNodePath for (nil)\n"); 2474 fprintf(stderr, "Cannot showNodePath for (nil)\n");
2475 } 2475 }
2476 2476
2477 #endif 2477 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.h ('k') | third_party/WebKit/Source/core/dom/PseudoElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698