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

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

Issue 674553002: Move parts of core/dom to C++11 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make Windows shut up when I just try following the style guide Created 6 years, 2 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/PresentationAttributeStyle.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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 118
119 void Node::operator delete(void* ptr) 119 void Node::operator delete(void* ptr)
120 { 120 {
121 ASSERT(isMainThread()); 121 ASSERT(isMainThread());
122 partitionFree(ptr); 122 partitionFree(ptr);
123 } 123 }
124 #endif 124 #endif
125 125
126 #if DUMP_NODE_STATISTICS 126 #if DUMP_NODE_STATISTICS
127 typedef WillBeHeapHashSet<RawPtrWillBeWeakMember<Node> > WeakNodeSet; 127 using WeakNodeSet = WillBeHeapHashSet<RawPtrWillBeWeakMember<Node>>;
128 static WeakNodeSet& liveNodeSet() 128 static WeakNodeSet& liveNodeSet()
129 { 129 {
130 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WeakNodeSet>, set, (adoptPtrWillB eNoop(new WeakNodeSet()))); 130 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WeakNodeSet>, set, (adoptPtrWillB eNoop(new WeakNodeSet())));
131 return *set; 131 return *set;
132 } 132 }
133 #endif 133 #endif
134 134
135 void Node::dumpStatistics() 135 void Node::dumpStatistics()
136 { 136 {
137 #if DUMP_NODE_STATISTICS 137 #if DUMP_NODE_STATISTICS
(...skipping 10 matching lines...) Expand all
148 size_t fragmentNodes = 0; 148 size_t fragmentNodes = 0;
149 size_t shadowRootNodes = 0; 149 size_t shadowRootNodes = 0;
150 150
151 HashMap<String, size_t> perTagCount; 151 HashMap<String, size_t> perTagCount;
152 152
153 size_t attributes = 0; 153 size_t attributes = 0;
154 size_t elementsWithAttributeStorage = 0; 154 size_t elementsWithAttributeStorage = 0;
155 size_t elementsWithRareData = 0; 155 size_t elementsWithRareData = 0;
156 size_t elementsWithNamedNodeMap = 0; 156 size_t elementsWithNamedNodeMap = 0;
157 157
158 for (WeakNodeSet::iterator it = liveNodeSet().begin(); it != liveNodeSet().e nd(); ++it) { 158 for (Node* node : liveNodeSet()) {
159 Node* node = *it;
160
161 if (node->hasRareData()) { 159 if (node->hasRareData()) {
162 ++nodesWithRareData; 160 ++nodesWithRareData;
163 if (node->isElementNode()) { 161 if (node->isElementNode()) {
164 ++elementsWithRareData; 162 ++elementsWithRareData;
165 if (toElement(node)->hasNamedNodeMap()) 163 if (toElement(node)->hasNamedNodeMap())
166 ++elementsWithNamedNodeMap; 164 ++elementsWithNamedNodeMap;
167 } 165 }
168 } 166 }
169 167
170 switch (node->nodeType()) { 168 switch (node->nodeType()) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 printf(" Number of Text nodes: %zu\n", textNodes); 228 printf(" Number of Text nodes: %zu\n", textNodes);
231 printf(" Number of CDATASection nodes: %zu\n", cdataNodes); 229 printf(" Number of CDATASection nodes: %zu\n", cdataNodes);
232 printf(" Number of Comment nodes: %zu\n", commentNodes); 230 printf(" Number of Comment nodes: %zu\n", commentNodes);
233 printf(" Number of ProcessingInstruction nodes: %zu\n", piNodes); 231 printf(" Number of ProcessingInstruction nodes: %zu\n", piNodes);
234 printf(" Number of Document nodes: %zu\n", documentNodes); 232 printf(" Number of Document nodes: %zu\n", documentNodes);
235 printf(" Number of DocumentType nodes: %zu\n", docTypeNodes); 233 printf(" Number of DocumentType nodes: %zu\n", docTypeNodes);
236 printf(" Number of DocumentFragment nodes: %zu\n", fragmentNodes); 234 printf(" Number of DocumentFragment nodes: %zu\n", fragmentNodes);
237 printf(" Number of ShadowRoot nodes: %zu\n", shadowRootNodes); 235 printf(" Number of ShadowRoot nodes: %zu\n", shadowRootNodes);
238 236
239 printf("Element tag name distibution:\n"); 237 printf("Element tag name distibution:\n");
240 for (HashMap<String, size_t>::iterator it = perTagCount.begin(); it != perTa gCount.end(); ++it) 238 for (const auto& entry : perTagCount)
241 printf(" Number of <%s> tags: %zu\n", it->key.utf8().data(), it->value) ; 239 printf(" Number of <%s> tags: %zu\n", entry.key.utf8().data(), entry.va lue);
242 240
243 printf("Attributes:\n"); 241 printf("Attributes:\n");
244 printf(" Number of Attributes (non-Node and Node): %zu [%zu]\n", attributes , sizeof(Attribute)); 242 printf(" Number of Attributes (non-Node and Node): %zu [%zu]\n", attributes , sizeof(Attribute));
245 printf(" Number of Elements with attribute storage: %zu [%zu]\n", elementsW ithAttributeStorage, sizeof(ElementData)); 243 printf(" Number of Elements with attribute storage: %zu [%zu]\n", elementsW ithAttributeStorage, sizeof(ElementData));
246 printf(" Number of Elements with RareData: %zu\n", elementsWithRareData); 244 printf(" Number of Elements with RareData: %zu\n", elementsWithRareData);
247 printf(" Number of Elements with NamedNodeMap: %zu [%zu]\n", elementsWithNa medNodeMap, sizeof(NamedNodeMap)); 245 printf(" Number of Elements with NamedNodeMap: %zu [%zu]\n", elementsWithNa medNodeMap, sizeof(NamedNodeMap));
248 #endif 246 #endif
249 } 247 }
250 248
251 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, nodeCounter, ("WebCoreNode" )); 249 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, nodeCounter, ("WebCoreNode" ));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 291
294 if (hasRareData()) 292 if (hasRareData())
295 clearRareData(); 293 clearRareData();
296 294
297 RELEASE_ASSERT(!renderer()); 295 RELEASE_ASSERT(!renderer());
298 296
299 if (!isContainerNode()) 297 if (!isContainerNode())
300 willBeDeletedFromDocument(); 298 willBeDeletedFromDocument();
301 299
302 if (m_previous) 300 if (m_previous)
303 m_previous->setNextSibling(0); 301 m_previous->setNextSibling(nullptr);
304 if (m_next) 302 if (m_next)
305 m_next->setPreviousSibling(0); 303 m_next->setPreviousSibling(nullptr);
306 304
307 if (m_treeScope) 305 if (m_treeScope)
308 m_treeScope->guardDeref(); 306 m_treeScope->guardDeref();
309 307
310 if (getFlag(HasWeakReferencesFlag)) 308 if (getFlag(HasWeakReferencesFlag))
311 WeakNodeMap::notifyNodeDestroyed(this); 309 WeakNodeMap::notifyNodeDestroyed(this);
312 #else 310 #else
313 // With Oilpan, the rare data finalizer also asserts for 311 // With Oilpan, the rare data finalizer also asserts for
314 // this condition (we cannot directly access it here.) 312 // this condition (we cannot directly access it here.)
315 RELEASE_ASSERT(hasRareData() || !renderer()); 313 RELEASE_ASSERT(hasRareData() || !renderer());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 592
595 if (AXObjectCache* cache = document().existingAXObjectCache()) 593 if (AXObjectCache* cache = document().existingAXObjectCache())
596 return cache->rootAXEditableElement(this); 594 return cache->rootAXEditableElement(this);
597 595
598 return false; 596 return false;
599 } 597 }
600 598
601 RenderBox* Node::renderBox() const 599 RenderBox* Node::renderBox() const
602 { 600 {
603 RenderObject* renderer = this->renderer(); 601 RenderObject* renderer = this->renderer();
604 return renderer && renderer->isBox() ? toRenderBox(renderer) : 0; 602 return renderer && renderer->isBox() ? toRenderBox(renderer) : nullptr;
605 } 603 }
606 604
607 RenderBoxModelObject* Node::renderBoxModelObject() const 605 RenderBoxModelObject* Node::renderBoxModelObject() const
608 { 606 {
609 RenderObject* renderer = this->renderer(); 607 RenderObject* renderer = this->renderer();
610 return renderer && renderer->isBoxModelObject() ? toRenderBoxModelObject(ren derer) : 0; 608 return renderer && renderer->isBoxModelObject() ? toRenderBoxModelObject(ren derer) : nullptr;
611 } 609 }
612 610
613 LayoutRect Node::boundingBox() const 611 LayoutRect Node::boundingBox() const
614 { 612 {
615 if (renderer()) 613 if (renderer())
616 return renderer()->absoluteBoundingBoxRect(); 614 return renderer()->absoluteBoundingBoxRect();
617 return LayoutRect(); 615 return LayoutRect();
618 } 616 }
619 617
620 bool Node::hasNonEmptyBoundingBox() const 618 bool Node::hasNonEmptyBoundingBox() const
(...skipping 14 matching lines...) Expand all
635 if (!rects[i].isEmpty()) 633 if (!rects[i].isEmpty())
636 return true; 634 return true;
637 635
638 return false; 636 return false;
639 } 637 }
640 638
641 #ifndef NDEBUG 639 #ifndef NDEBUG
642 inline static ShadowRoot* oldestShadowRootFor(const Node* node) 640 inline static ShadowRoot* oldestShadowRootFor(const Node* node)
643 { 641 {
644 if (!node->isElementNode()) 642 if (!node->isElementNode())
645 return 0; 643 return nullptr;
646 if (ElementShadow* shadow = toElement(node)->shadow()) 644 if (ElementShadow* shadow = toElement(node)->shadow())
647 return shadow->oldestShadowRoot(); 645 return shadow->oldestShadowRoot();
648 return 0; 646 return nullptr;
649 } 647 }
650 #endif 648 #endif
651 649
652 void Node::recalcDistribution() 650 void Node::recalcDistribution()
653 { 651 {
654 if (isElementNode()) { 652 if (isElementNode()) {
655 if (ElementShadow* shadow = toElement(this)->shadow()) 653 if (ElementShadow* shadow = toElement(this)->shadow())
656 shadow->distributeIfNeeded(); 654 shadow->distributeIfNeeded();
657 } 655 }
658 656
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 { 757 {
760 const HTMLDialogElement* dialog = document().activeModalDialog(); 758 const HTMLDialogElement* dialog = document().activeModalDialog();
761 if (dialog && this != document() && !NodeRenderingTraversal::contains(dialog , this)) 759 if (dialog && this != document() && !NodeRenderingTraversal::contains(dialog , this))
762 return true; 760 return true;
763 return document().ownerElement() && document().ownerElement()->isInert(); 761 return document().ownerElement() && document().ownerElement()->isInert();
764 } 762 }
765 763
766 unsigned Node::nodeIndex() const 764 unsigned Node::nodeIndex() const
767 { 765 {
768 Node *_tempNode = previousSibling(); 766 Node *_tempNode = previousSibling();
769 unsigned count=0; 767 unsigned count = 0;
770 for ( count=0; _tempNode; count++ ) 768 for (count = 0; _tempNode; count++)
771 _tempNode = _tempNode->previousSibling(); 769 _tempNode = _tempNode->previousSibling();
772 return count; 770 return count;
773 } 771 }
774 772
775 NodeListsNodeData* Node::nodeLists() 773 NodeListsNodeData* Node::nodeLists()
776 { 774 {
777 return hasRareData() ? rareData()->nodeLists() : 0; 775 return hasRareData() ? rareData()->nodeLists() : nullptr;
778 } 776 }
779 777
780 void Node::clearNodeLists() 778 void Node::clearNodeLists()
781 { 779 {
782 rareData()->clearNodeLists(); 780 rareData()->clearNodeLists();
783 } 781 }
784 782
785 bool Node::isDescendantOf(const Node *other) const 783 bool Node::isDescendantOf(const Node *other) const
786 { 784 {
787 // Return true if other is an ancestor of this, otherwise false 785 // Return true if other is an ancestor of this, otherwise false
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 current = current->parentOrShadowHostNode(); 842 current = current->parentOrShadowHostNode();
845 } while (current); 843 } while (current);
846 return false; 844 return false;
847 } 845 }
848 846
849 Node* Node::commonAncestor(const Node& other, Node* (*parent)(const Node&)) 847 Node* Node::commonAncestor(const Node& other, Node* (*parent)(const Node&))
850 { 848 {
851 if (this == other) 849 if (this == other)
852 return this; 850 return this;
853 if (document() != other.document()) 851 if (document() != other.document())
854 return 0; 852 return nullptr;
855 int thisDepth = 0; 853 int thisDepth = 0;
856 for (Node* node = this; node; node = parent(*node)) { 854 for (Node* node = this; node; node = parent(*node)) {
857 if (node == &other) 855 if (node == &other)
858 return node; 856 return node;
859 thisDepth++; 857 thisDepth++;
860 } 858 }
861 int otherDepth = 0; 859 int otherDepth = 0;
862 for (const Node* node = &other; node; node = parent(*node)) { 860 for (const Node* node = &other; node; node = parent(*node)) {
863 if (node == this) 861 if (node == this)
864 return this; 862 return this;
865 otherDepth++; 863 otherDepth++;
866 } 864 }
867 Node* thisIterator = this; 865 Node* thisIterator = this;
868 const Node* otherIterator = &other; 866 const Node* otherIterator = &other;
869 if (thisDepth > otherDepth) { 867 if (thisDepth > otherDepth) {
870 for (int i = thisDepth; i > otherDepth; --i) 868 for (int i = thisDepth; i > otherDepth; --i)
871 thisIterator = parent(*thisIterator); 869 thisIterator = parent(*thisIterator);
872 } else if (otherDepth > thisDepth) { 870 } else if (otherDepth > thisDepth) {
873 for (int i = otherDepth; i > thisDepth; --i) 871 for (int i = otherDepth; i > thisDepth; --i)
874 otherIterator = parent(*otherIterator); 872 otherIterator = parent(*otherIterator);
875 } 873 }
876 while (thisIterator) { 874 while (thisIterator) {
877 if (thisIterator == otherIterator) 875 if (thisIterator == otherIterator)
878 return thisIterator; 876 return thisIterator;
879 thisIterator = parent(*thisIterator); 877 thisIterator = parent(*thisIterator);
880 otherIterator = parent(*otherIterator); 878 otherIterator = parent(*otherIterator);
881 } 879 }
882 ASSERT(!otherIterator); 880 ASSERT(!otherIterator);
883 return 0; 881 return nullptr;
884 } 882 }
885 883
886 void Node::reattach(const AttachContext& context) 884 void Node::reattach(const AttachContext& context)
887 { 885 {
888 AttachContext reattachContext(context); 886 AttachContext reattachContext(context);
889 reattachContext.performingReattach = true; 887 reattachContext.performingReattach = true;
890 888
891 // We only need to detach if the node has already been through attach(). 889 // We only need to detach if the node has already been through attach().
892 if (styleChangeType() < NeedsReattachStyleChange) 890 if (styleChangeType() < NeedsReattachStyleChange)
893 detach(reattachContext); 891 detach(reattachContext);
(...skipping 26 matching lines...) Expand all
920 ASSERT(document().lifecycle().stateAllowsDetach()); 918 ASSERT(document().lifecycle().stateAllowsDetach());
921 DocumentLifecycle::DetachScope willDetach(document().lifecycle()); 919 DocumentLifecycle::DetachScope willDetach(document().lifecycle());
922 920
923 #if ENABLE(ASSERT) 921 #if ENABLE(ASSERT)
924 ASSERT(!detachingNode); 922 ASSERT(!detachingNode);
925 detachingNode = this; 923 detachingNode = this;
926 #endif 924 #endif
927 925
928 if (renderer()) 926 if (renderer())
929 renderer()->destroyAndCleanupAnonymousWrappers(); 927 renderer()->destroyAndCleanupAnonymousWrappers();
930 setRenderer(0); 928 setRenderer(nullptr);
931 929
932 // Do not remove the element's hovered and active status 930 // Do not remove the element's hovered and active status
933 // if performing a reattach. 931 // if performing a reattach.
934 if (!context.performingReattach) { 932 if (!context.performingReattach) {
935 Document& doc = document(); 933 Document& doc = document();
936 if (isUserActionElement()) { 934 if (isUserActionElement()) {
937 if (hovered()) 935 if (hovered())
938 doc.hoveredNodeDetached(this); 936 doc.hoveredNodeDetached(this);
939 if (inActiveChain()) 937 if (inActiveChain())
940 doc.activeChainNodeDetached(this); 938 doc.activeChainNodeDetached(this);
941 doc.userActionElements().didDetach(this); 939 doc.userActionElements().didDetach(this);
942 } 940 }
943 } 941 }
944 942
945 setStyleChange(NeedsReattachStyleChange); 943 setStyleChange(NeedsReattachStyleChange);
946 setChildNeedsStyleRecalc(); 944 setChildNeedsStyleRecalc();
947 945
948 if (StyleResolver* resolver = document().styleResolver()) 946 if (StyleResolver* resolver = document().styleResolver())
949 resolver->ruleFeatureSet().styleInvalidator().clearInvalidation(*this); 947 resolver->ruleFeatureSet().styleInvalidator().clearInvalidation(*this);
950 clearChildNeedsStyleInvalidation(); 948 clearChildNeedsStyleInvalidation();
951 clearNeedsStyleInvalidation(); 949 clearNeedsStyleInvalidation();
952 950
953 #if ENABLE(ASSERT) 951 #if ENABLE(ASSERT)
954 detachingNode = 0; 952 detachingNode = nullptr;
955 #endif 953 #endif
956 } 954 }
957 955
958 void Node::reattachWhitespaceSiblings(Text* start) 956 void Node::reattachWhitespaceSiblings(Text* start)
959 { 957 {
960 for (Node* sibling = start; sibling; sibling = sibling->nextSibling()) { 958 for (Node* sibling = start; sibling; sibling = sibling->nextSibling()) {
961 if (sibling->isTextNode() && toText(sibling)->containsOnlyWhitespace()) { 959 if (sibling->isTextNode() && toText(sibling)->containsOnlyWhitespace()) {
962 bool hadRenderer = !!sibling->renderer(); 960 bool hadRenderer = !!sibling->renderer();
963 sibling->reattach(); 961 sibling->reattach();
964 // If the reattach didn't toggle the visibility of the whitespace we don't 962 // If the reattach didn't toggle the visibility of the whitespace we don't
965 // need to continue reattaching siblings since they won't toggle vis ibility 963 // need to continue reattaching siblings since they won't toggle vis ibility
966 // either. 964 // either.
967 if (hadRenderer == !!sibling->renderer()) 965 if (hadRenderer == !!sibling->renderer())
968 return; 966 return;
969 } else if (sibling->renderer()) { 967 } else if (sibling->renderer()) {
970 return; 968 return;
971 } 969 }
972 } 970 }
973 } 971 }
974 972
975 // FIXME: This code is used by editing. Seems like it could move over there and not pollute Node. 973 // FIXME: This code is used by editing. Seems like it could move over there and not pollute Node.
976 Node *Node::previousNodeConsideringAtomicNodes() const 974 Node* Node::previousNodeConsideringAtomicNodes() const
977 { 975 {
978 if (previousSibling()) { 976 if (previousSibling()) {
979 Node *n = previousSibling(); 977 Node* n = previousSibling();
980 while (!isAtomicNode(n) && n->lastChild()) 978 while (!isAtomicNode(n) && n->lastChild())
981 n = n->lastChild(); 979 n = n->lastChild();
982 return n; 980 return n;
983 } 981 }
984 else if (parentNode()) { 982 else if (parentNode()) {
985 return parentNode(); 983 return parentNode();
986 } 984 }
987 else { 985 else {
988 return 0; 986 return nullptr;
989 } 987 }
990 } 988 }
991 989
992 Node *Node::nextNodeConsideringAtomicNodes() const 990 Node* Node::nextNodeConsideringAtomicNodes() const
993 { 991 {
994 if (!isAtomicNode(this) && hasChildren()) 992 if (!isAtomicNode(this) && hasChildren())
995 return firstChild(); 993 return firstChild();
996 if (nextSibling()) 994 if (nextSibling())
997 return nextSibling(); 995 return nextSibling();
998 const Node *n = this; 996 const Node* n = this;
999 while (n && !n->nextSibling()) 997 while (n && !n->nextSibling())
1000 n = n->parentNode(); 998 n = n->parentNode();
1001 if (n) 999 if (n)
1002 return n->nextSibling(); 1000 return n->nextSibling();
1003 return 0; 1001 return nullptr;
1004 } 1002 }
1005 1003
1006 Node *Node::previousLeafNode() const 1004 Node* Node::previousLeafNode() const
1007 { 1005 {
1008 Node *node = previousNodeConsideringAtomicNodes(); 1006 Node* node = previousNodeConsideringAtomicNodes();
1009 while (node) { 1007 while (node) {
1010 if (isAtomicNode(node)) 1008 if (isAtomicNode(node))
1011 return node; 1009 return node;
1012 node = node->previousNodeConsideringAtomicNodes(); 1010 node = node->previousNodeConsideringAtomicNodes();
1013 } 1011 }
1014 return 0; 1012 return nullptr;
1015 } 1013 }
1016 1014
1017 Node *Node::nextLeafNode() const 1015 Node* Node::nextLeafNode() const
1018 { 1016 {
1019 Node *node = nextNodeConsideringAtomicNodes(); 1017 Node* node = nextNodeConsideringAtomicNodes();
1020 while (node) { 1018 while (node) {
1021 if (isAtomicNode(node)) 1019 if (isAtomicNode(node))
1022 return node; 1020 return node;
1023 node = node->nextNodeConsideringAtomicNodes(); 1021 node = node->nextNodeConsideringAtomicNodes();
1024 } 1022 }
1025 return 0; 1023 return nullptr;
1026 } 1024 }
1027 1025
1028 RenderStyle* Node::virtualComputedStyle(PseudoId pseudoElementSpecifier) 1026 RenderStyle* Node::virtualComputedStyle(PseudoId pseudoElementSpecifier)
1029 { 1027 {
1030 return parentOrShadowHostNode() ? parentOrShadowHostNode()->computedStyle(ps eudoElementSpecifier) : 0; 1028 return parentOrShadowHostNode() ? parentOrShadowHostNode()->computedStyle(ps eudoElementSpecifier) : nullptr;
1031 } 1029 }
1032 1030
1033 int Node::maxCharacterOffset() const 1031 int Node::maxCharacterOffset() const
1034 { 1032 {
1035 ASSERT_NOT_REACHED(); 1033 ASSERT_NOT_REACHED();
1036 return 0; 1034 return 0;
1037 } 1035 }
1038 1036
1039 // FIXME: Shouldn't these functions be in the editing code? Code that asks ques tions about HTML in the core DOM class 1037 // FIXME: Shouldn't these functions be in the editing code? Code that asks ques tions about HTML in the core DOM class
1040 // is obviously misplaced. 1038 // is obviously misplaced.
1041 bool Node::canStartSelection() const 1039 bool Node::canStartSelection() const
1042 { 1040 {
1043 if (hasEditableStyle()) 1041 if (hasEditableStyle())
1044 return true; 1042 return true;
1045 1043
1046 if (renderer()) { 1044 if (renderer()) {
1047 RenderStyle* style = renderer()->style(); 1045 RenderStyle* style = renderer()->style();
1048 // We allow selections to begin within an element that has -webkit-user- select: none set, 1046 // We allow selections to begin within an element that has -webkit-user- select: none set,
1049 // but if the element is draggable then dragging should take priority ov er selection. 1047 // but if the element is draggable then dragging should take priority ov er selection.
1050 if (style->userDrag() == DRAG_ELEMENT && style->userSelect() == SELECT_N ONE) 1048 if (style->userDrag() == DRAG_ELEMENT && style->userSelect() == SELECT_N ONE)
1051 return false; 1049 return false;
1052 } 1050 }
1053 return parentOrShadowHostNode() ? parentOrShadowHostNode()->canStartSelectio n() : true; 1051 return parentOrShadowHostNode() ? parentOrShadowHostNode()->canStartSelectio n() : true;
1054 } 1052 }
1055 1053
1056 Element* Node::shadowHost() const 1054 Element* Node::shadowHost() const
1057 { 1055 {
1058 if (ShadowRoot* root = containingShadowRoot()) 1056 if (ShadowRoot* root = containingShadowRoot())
1059 return root->host(); 1057 return root->host();
1060 return 0; 1058 return nullptr;
1061 } 1059 }
1062 1060
1063 ShadowRoot* Node::containingShadowRoot() const 1061 ShadowRoot* Node::containingShadowRoot() const
1064 { 1062 {
1065 Node& root = treeScope().rootNode(); 1063 Node& root = treeScope().rootNode();
1066 return root.isShadowRoot() ? toShadowRoot(&root) : 0; 1064 return root.isShadowRoot() ? toShadowRoot(&root) : nullptr;
1067 } 1065 }
1068 1066
1069 Node* Node::nonBoundaryShadowTreeRootNode() 1067 Node* Node::nonBoundaryShadowTreeRootNode()
1070 { 1068 {
1071 ASSERT(!isShadowRoot()); 1069 ASSERT(!isShadowRoot());
1072 Node* root = this; 1070 Node* root = this;
1073 while (root) { 1071 while (root) {
1074 if (root->isShadowRoot()) 1072 if (root->isShadowRoot())
1075 return root; 1073 return root;
1076 Node* parent = root->parentOrShadowHostNode(); 1074 Node* parent = root->parentOrShadowHostNode();
1077 if (parent && parent->isShadowRoot()) 1075 if (parent && parent->isShadowRoot())
1078 return root; 1076 return root;
1079 root = parent; 1077 root = parent;
1080 } 1078 }
1081 return 0; 1079 return nullptr;
1082 } 1080 }
1083 1081
1084 ContainerNode* Node::nonShadowBoundaryParentNode() const 1082 ContainerNode* Node::nonShadowBoundaryParentNode() const
1085 { 1083 {
1086 ContainerNode* parent = parentNode(); 1084 ContainerNode* parent = parentNode();
1087 return parent && !parent->isShadowRoot() ? parent : 0; 1085 return parent && !parent->isShadowRoot() ? parent : nullptr;
1088 } 1086 }
1089 1087
1090 Element* Node::parentOrShadowHostElement() const 1088 Element* Node::parentOrShadowHostElement() const
1091 { 1089 {
1092 ContainerNode* parent = parentOrShadowHostNode(); 1090 ContainerNode* parent = parentOrShadowHostNode();
1093 if (!parent) 1091 if (!parent)
1094 return 0; 1092 return nullptr;
1095 1093
1096 if (parent->isShadowRoot()) 1094 if (parent->isShadowRoot())
1097 return toShadowRoot(parent)->host(); 1095 return toShadowRoot(parent)->host();
1098 1096
1099 if (!parent->isElementNode()) 1097 if (!parent->isElementNode())
1100 return 0; 1098 return nullptr;
1101 1099
1102 return toElement(parent); 1100 return toElement(parent);
1103 } 1101 }
1104 1102
1105 ContainerNode* Node::parentOrShadowHostOrTemplateHostNode() const 1103 ContainerNode* Node::parentOrShadowHostOrTemplateHostNode() const
1106 { 1104 {
1107 if (isDocumentFragment() && toDocumentFragment(this)->isTemplateContent()) 1105 if (isDocumentFragment() && toDocumentFragment(this)->isTemplateContent())
1108 return static_cast<const TemplateContentDocumentFragment*>(this)->host() ; 1106 return static_cast<const TemplateContentDocumentFragment*>(this)->host() ;
1109 return parentOrShadowHostNode(); 1107 return parentOrShadowHostNode();
1110 } 1108 }
1111 1109
1112 bool Node::isRootEditableElement() const 1110 bool Node::isRootEditableElement() const
1113 { 1111 {
1114 return hasEditableStyle() && isElementNode() && (!parentNode() || !parentNod e()->hasEditableStyle() 1112 return hasEditableStyle() && isElementNode() && (!parentNode() || !parentNod e()->hasEditableStyle()
1115 || !parentNode()->isElementNode() || isHTMLBodyElement((*this))); 1113 || !parentNode()->isElementNode() || isHTMLBodyElement((*this)));
1116 } 1114 }
1117 1115
1118 Element* Node::rootEditableElement(EditableType editableType) const 1116 Element* Node::rootEditableElement(EditableType editableType) const
1119 { 1117 {
1120 if (editableType == HasEditableAXRole) { 1118 if (editableType == HasEditableAXRole) {
1121 if (AXObjectCache* cache = document().existingAXObjectCache()) 1119 if (AXObjectCache* cache = document().existingAXObjectCache())
1122 return const_cast<Element*>(cache->rootAXEditableElement(this)); 1120 return const_cast<Element*>(cache->rootAXEditableElement(this));
1123 } 1121 }
1124 1122
1125 return rootEditableElement(); 1123 return rootEditableElement();
1126 } 1124 }
1127 1125
1128 Element* Node::rootEditableElement() const 1126 Element* Node::rootEditableElement() const
1129 { 1127 {
1130 Element* result = 0; 1128 Element* result = nullptr;
1131 for (Node* n = const_cast<Node*>(this); n && n->hasEditableStyle(); n = n->p arentNode()) { 1129 for (Node* n = const_cast<Node*>(this); n && n->hasEditableStyle(); n = n->p arentNode()) {
1132 if (n->isElementNode()) 1130 if (n->isElementNode())
1133 result = toElement(n); 1131 result = toElement(n);
1134 if (isHTMLBodyElement(*n)) 1132 if (isHTMLBodyElement(*n))
1135 break; 1133 break;
1136 } 1134 }
1137 return result; 1135 return result;
1138 } 1136 }
1139 1137
1140 // FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node. 1138 // FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node.
1141 1139
1142 Document* Node::ownerDocument() const 1140 Document* Node::ownerDocument() const
1143 { 1141 {
1144 Document* doc = &document(); 1142 Document* doc = &document();
1145 return doc == this ? 0 : doc; 1143 return doc == this ? nullptr : doc;
1146 } 1144 }
1147 1145
1148 KURL Node::baseURI() const 1146 KURL Node::baseURI() const
1149 { 1147 {
1150 return parentNode() ? parentNode()->baseURI() : KURL(); 1148 return parentNode() ? parentNode()->baseURI() : KURL();
1151 } 1149 }
1152 1150
1153 bool Node::isEqualNode(Node* other) const 1151 bool Node::isEqualNode(Node* other) const
1154 { 1152 {
1155 if (!other) 1153 if (!other)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 const AtomicString& namespaceURI = namespaceURIMaybeEmpty.isEmpty() ? nullAt om : namespaceURIMaybeEmpty; 1205 const AtomicString& namespaceURI = namespaceURIMaybeEmpty.isEmpty() ? nullAt om : namespaceURIMaybeEmpty;
1208 1206
1209 switch (nodeType()) { 1207 switch (nodeType()) {
1210 case ELEMENT_NODE: { 1208 case ELEMENT_NODE: {
1211 const Element& element = toElement(*this); 1209 const Element& element = toElement(*this);
1212 1210
1213 if (element.prefix().isNull()) 1211 if (element.prefix().isNull())
1214 return element.namespaceURI() == namespaceURI; 1212 return element.namespaceURI() == namespaceURI;
1215 1213
1216 AttributeCollection attributes = element.attributes(); 1214 AttributeCollection attributes = element.attributes();
1217 AttributeCollection::iterator end = attributes.end(); 1215 for (const Attribute& attr : attributes) {
1218 for (AttributeCollection::iterator it = attributes.begin(); it != en d; ++it) { 1216 if (attr.localName() == xmlnsAtom)
1219 if (it->localName() == xmlnsAtom) 1217 return attr.value() == namespaceURI;
1220 return it->value() == namespaceURI;
1221 } 1218 }
1222 1219
1223 if (Element* parent = parentElement()) 1220 if (Element* parent = parentElement())
1224 return parent->isDefaultNamespace(namespaceURI); 1221 return parent->isDefaultNamespace(namespaceURI);
1225 1222
1226 return false; 1223 return false;
1227 } 1224 }
1228 case DOCUMENT_NODE: 1225 case DOCUMENT_NODE:
1229 if (Element* de = toDocument(this)->documentElement()) 1226 if (Element* de = toDocument(this)->documentElement())
1230 return de->isDefaultNamespace(namespaceURI); 1227 return de->isDefaultNamespace(namespaceURI);
(...skipping 26 matching lines...) Expand all
1257 1254
1258 switch (nodeType()) { 1255 switch (nodeType()) {
1259 case ELEMENT_NODE: 1256 case ELEMENT_NODE:
1260 context = toElement(this); 1257 context = toElement(this);
1261 break; 1258 break;
1262 case DOCUMENT_NODE: 1259 case DOCUMENT_NODE:
1263 context = toDocument(this)->documentElement(); 1260 context = toDocument(this)->documentElement();
1264 break; 1261 break;
1265 case DOCUMENT_FRAGMENT_NODE: 1262 case DOCUMENT_FRAGMENT_NODE:
1266 case DOCUMENT_TYPE_NODE: 1263 case DOCUMENT_TYPE_NODE:
1267 context = 0; 1264 context = nullptr;
1268 break; 1265 break;
1269 // FIXME: Remove this when Attr no longer extends Node (CR305105) 1266 // FIXME: Remove this when Attr no longer extends Node (CR305105)
1270 case ATTRIBUTE_NODE: 1267 case ATTRIBUTE_NODE:
1271 context = toAttr(this)->ownerElement(); 1268 context = toAttr(this)->ownerElement();
1272 break; 1269 break;
1273 default: 1270 default:
1274 context = parentElement(); 1271 context = parentElement();
1275 break; 1272 break;
1276 } 1273 }
1277 1274
(...skipping 12 matching lines...) Expand all
1290 return nullAtom; 1287 return nullAtom;
1291 1288
1292 switch (nodeType()) { 1289 switch (nodeType()) {
1293 case ELEMENT_NODE: { 1290 case ELEMENT_NODE: {
1294 const Element& element = toElement(*this); 1291 const Element& element = toElement(*this);
1295 1292
1296 if (!element.namespaceURI().isNull() && element.prefix() == prefix) 1293 if (!element.namespaceURI().isNull() && element.prefix() == prefix)
1297 return element.namespaceURI(); 1294 return element.namespaceURI();
1298 1295
1299 AttributeCollection attributes = element.attributes(); 1296 AttributeCollection attributes = element.attributes();
1300 AttributeCollection::iterator end = attributes.end(); 1297 for (const Attribute& attr : attributes) {
1301 for (AttributeCollection::iterator it = attributes.begin(); it != en d; ++it) { 1298 if (attr.prefix() == xmlnsAtom && attr.localName() == prefix) {
1302 if (it->prefix() == xmlnsAtom && it->localName() == prefix) { 1299 if (!attr.value().isEmpty())
1303 if (!it->value().isEmpty()) 1300 return attr.value();
1304 return it->value();
1305 return nullAtom; 1301 return nullAtom;
1306 } 1302 }
1307 if (it->localName() == xmlnsAtom && prefix.isNull()) { 1303 if (attr.localName() == xmlnsAtom && prefix.isNull()) {
1308 if (!it->value().isEmpty()) 1304 if (!attr.value().isEmpty())
1309 return it->value(); 1305 return attr.value();
1310 return nullAtom; 1306 return nullAtom;
1311 } 1307 }
1312 } 1308 }
1313 1309
1314 if (Element* parent = parentElement()) 1310 if (Element* parent = parentElement())
1315 return parent->lookupNamespaceURI(prefix); 1311 return parent->lookupNamespaceURI(prefix);
1316 return nullAtom; 1312 return nullAtom;
1317 } 1313 }
1318 case DOCUMENT_NODE: 1314 case DOCUMENT_NODE:
1319 if (Element* de = toDocument(this)->documentElement()) 1315 if (Element* de = toDocument(this)->documentElement())
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 ASSERT_NOT_REACHED(); 1416 ASSERT_NOT_REACHED();
1421 } 1417 }
1422 1418
1423 bool Node::offsetInCharacters() const 1419 bool Node::offsetInCharacters() const
1424 { 1420 {
1425 return false; 1421 return false;
1426 } 1422 }
1427 1423
1428 unsigned short Node::compareDocumentPosition(const Node* otherNode, ShadowTreesT reatment treatment) const 1424 unsigned short Node::compareDocumentPosition(const Node* otherNode, ShadowTreesT reatment treatment) const
1429 { 1425 {
1430 // It is not clear what should be done if |otherNode| is 0. 1426 // It is not clear what should be done if |otherNode| is nullptr.
1431 if (!otherNode) 1427 if (!otherNode)
1432 return DOCUMENT_POSITION_DISCONNECTED; 1428 return DOCUMENT_POSITION_DISCONNECTED;
1433 1429
1434 if (otherNode == this) 1430 if (otherNode == this)
1435 return DOCUMENT_POSITION_EQUIVALENT; 1431 return DOCUMENT_POSITION_EQUIVALENT;
1436 1432
1437 const Attr* attr1 = nodeType() == ATTRIBUTE_NODE ? toAttr(this) : 0; 1433 const Attr* attr1 = nodeType() == ATTRIBUTE_NODE ? toAttr(this) : nullptr;
1438 const Attr* attr2 = otherNode->nodeType() == ATTRIBUTE_NODE ? toAttr(otherNo de) : 0; 1434 const Attr* attr2 = otherNode->nodeType() == ATTRIBUTE_NODE ? toAttr(otherNo de) : nullptr;
1439 1435
1440 const Node* start1 = attr1 ? attr1->ownerElement() : this; 1436 const Node* start1 = attr1 ? attr1->ownerElement() : this;
1441 const Node* start2 = attr2 ? attr2->ownerElement() : otherNode; 1437 const Node* start2 = attr2 ? attr2->ownerElement() : otherNode;
1442 1438
1443 // If either of start1 or start2 is null, then we are disconnected, since on e of the nodes is 1439 // If either of start1 or start2 is null, then we are disconnected, since on e of the nodes is
1444 // an orphaned attribute node. 1440 // an orphaned attribute node.
1445 if (!start1 || !start2) { 1441 if (!start1 || !start2) {
1446 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING; 1442 unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECED ING : DOCUMENT_POSITION_FOLLOWING;
1447 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction; 1443 return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION _SPECIFIC | direction;
1448 } 1444 }
1449 1445
1450 Vector<const Node*, 16> chain1; 1446 Vector<const Node*, 16> chain1;
1451 Vector<const Node*, 16> chain2; 1447 Vector<const Node*, 16> chain2;
1452 if (attr1) 1448 if (attr1)
1453 chain1.append(attr1); 1449 chain1.append(attr1);
1454 if (attr2) 1450 if (attr2)
1455 chain2.append(attr2); 1451 chain2.append(attr2);
1456 1452
1457 if (attr1 && attr2 && start1 == start2 && start1) { 1453 if (attr1 && attr2 && start1 == start2 && start1) {
1458 // We are comparing two attributes on the same node. Crawl our attribute map and see which one we hit first. 1454 // We are comparing two attributes on the same node. Crawl our attribute map and see which one we hit first.
1459 const Element* owner1 = attr1->ownerElement(); 1455 const Element* owner1 = attr1->ownerElement();
1460 AttributeCollection attributes = owner1->attributes(); 1456 AttributeCollection attributes = owner1->attributes();
1461 AttributeCollection::iterator end = attributes.end(); 1457 for (const Attribute& attr : attributes) {
1462 for (AttributeCollection::iterator it = attributes.begin(); it != end; + +it) {
1463 // If neither of the two determining nodes is a child node and nodeT ype is the same for both determining nodes, then an 1458 // If neither of the two determining nodes is a child node and nodeT ype is the same for both determining nodes, then an
1464 // implementation-dependent order between the determining nodes is r eturned. This order is stable as long as no nodes of 1459 // implementation-dependent order between the determining nodes is r eturned. This order is stable as long as no nodes of
1465 // the same nodeType are inserted into or removed from the direct co ntainer. This would be the case, for example, 1460 // the same nodeType are inserted into or removed from the direct co ntainer. This would be the case, for example,
1466 // when comparing two attributes of the same element, and inserting or removing additional attributes might change 1461 // when comparing two attributes of the same element, and inserting or removing additional attributes might change
1467 // the order between existing attributes. 1462 // the order between existing attributes.
1468 if (attr1->qualifiedName() == it->name()) 1463 if (attr1->qualifiedName() == attr.name())
1469 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_FOLLOWING; 1464 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_FOLLOWING;
1470 if (attr2->qualifiedName() == it->name()) 1465 if (attr2->qualifiedName() == attr.name())
1471 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_PRECEDING; 1466 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSI TION_PRECEDING;
1472 } 1467 }
1473 1468
1474 ASSERT_NOT_REACHED(); 1469 ASSERT_NOT_REACHED();
1475 return DOCUMENT_POSITION_DISCONNECTED; 1470 return DOCUMENT_POSITION_DISCONNECTED;
1476 } 1471 }
1477 1472
1478 // If one node is in the document and the other is not, we must be disconnec ted. 1473 // If one node is in the document and the other is not, we must be disconnec ted.
1479 // If the nodes have different owning documents, they must be disconnected. Note that we avoid 1474 // If the nodes have different owning documents, they must be disconnected. Note that we avoid
1480 // comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug). 1475 // comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug).
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1771 // For imagemaps, the enclosing link node is the associated area element not the image itself. 1766 // For imagemaps, the enclosing link node is the associated area element not the image itself.
1772 // So we don't let images be the enclosingLinkNode, even though isLink s ometimes returns true 1767 // So we don't let images be the enclosingLinkNode, even though isLink s ometimes returns true
1773 // for them. 1768 // for them.
1774 if (node->isLink() && !isHTMLImageElement(*node)) { 1769 if (node->isLink() && !isHTMLImageElement(*node)) {
1775 // Casting to Element is safe because only HTMLAnchorElement, HTMLIm ageElement and 1770 // Casting to Element is safe because only HTMLAnchorElement, HTMLIm ageElement and
1776 // SVGAElement can return true for isLink(). 1771 // SVGAElement can return true for isLink().
1777 return toElement(node); 1772 return toElement(node);
1778 } 1773 }
1779 } 1774 }
1780 1775
1781 return 0; 1776 return nullptr;
1782 } 1777 }
1783 1778
1784 const AtomicString& Node::interfaceName() const 1779 const AtomicString& Node::interfaceName() const
1785 { 1780 {
1786 return EventTargetNames::Node; 1781 return EventTargetNames::Node;
1787 } 1782 }
1788 1783
1789 ExecutionContext* Node::executionContext() const 1784 ExecutionContext* Node::executionContext() const
1790 { 1785 {
1791 return document().contextDocument().get(); 1786 return document().contextDocument().get();
(...skipping 20 matching lines...) Expand all
1812 1807
1813 oldDocument.markers().removeMarkers(this); 1808 oldDocument.markers().removeMarkers(this);
1814 oldDocument.updateRangesAfterNodeMovedToAnotherDocument(*this); 1809 oldDocument.updateRangesAfterNodeMovedToAnotherDocument(*this);
1815 if (oldDocument.frameHost() && !document().frameHost()) 1810 if (oldDocument.frameHost() && !document().frameHost())
1816 oldDocument.frameHost()->eventHandlerRegistry().didMoveOutOfFrameHost(*t his); 1811 oldDocument.frameHost()->eventHandlerRegistry().didMoveOutOfFrameHost(*t his);
1817 else if (document().frameHost() && !oldDocument.frameHost()) 1812 else if (document().frameHost() && !oldDocument.frameHost())
1818 document().frameHost()->eventHandlerRegistry().didMoveIntoFrameHost(*thi s); 1813 document().frameHost()->eventHandlerRegistry().didMoveIntoFrameHost(*thi s);
1819 else if (oldDocument.frameHost() != document().frameHost()) 1814 else if (oldDocument.frameHost() != document().frameHost())
1820 EventHandlerRegistry::didMoveBetweenFrameHosts(*this, oldDocument.frameH ost(), document().frameHost()); 1815 EventHandlerRegistry::didMoveBetweenFrameHosts(*this, oldDocument.frameH ost(), document().frameHost());
1821 1816
1822 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* reg istry = mutationObserverRegistry()) { 1817 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration>>* regi stry = mutationObserverRegistry()) {
1823 for (size_t i = 0; i < registry->size(); ++i) { 1818 for (size_t i = 0; i < registry->size(); ++i) {
1824 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); 1819 document().addMutationObserverTypes(registry->at(i)->mutationTypes() );
1825 } 1820 }
1826 } 1821 }
1827 1822
1828 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* tr ansientRegistry = transientMutationObserverRegistry()) { 1823 if (transientMutationObserverRegistry()) {
1829 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) { 1824 for (MutationObserverRegistration* registration : *transientMutationObse rverRegistry())
1830 document().addMutationObserverTypes((*iter)->mutationTypes()); 1825 document().addMutationObserverTypes(registration->mutationTypes());
1831 }
1832 } 1826 }
1833 } 1827 }
1834 1828
1835 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) 1829 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture)
1836 { 1830 {
1837 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) 1831 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re))
1838 return false; 1832 return false;
1839 1833
1840 Document& document = targetNode->document(); 1834 Document& document = targetNode->document();
1841 document.addListenerTypeIfNeeded(eventType); 1835 document.addListenerTypeIfNeeded(eventType);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 1872
1879 void Node::removeAllEventListenersRecursively() 1873 void Node::removeAllEventListenersRecursively()
1880 { 1874 {
1881 for (Node& node : NodeTraversal::from(this)) { 1875 for (Node& node : NodeTraversal::from(this)) {
1882 node.removeAllEventListeners(); 1876 node.removeAllEventListeners();
1883 for (ShadowRoot* root = node.youngestShadowRoot(); root; root = root->ol derShadowRoot()) 1877 for (ShadowRoot* root = node.youngestShadowRoot(); root; root = root->ol derShadowRoot())
1884 root->removeAllEventListenersRecursively(); 1878 root->removeAllEventListenersRecursively();
1885 } 1879 }
1886 } 1880 }
1887 1881
1888 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<Node>, OwnPtr<EventTargetData> > EventTargetDataMap; 1882 using EventTargetDataMap = WillBeHeapHashMap<RawPtrWillBeWeakMember<Node>, OwnPt r<EventTargetData>>;
1889
1890 static EventTargetDataMap& eventTargetDataMap() 1883 static EventTargetDataMap& eventTargetDataMap()
1891 { 1884 {
1892 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<EventTargetDataMap>, map, (adoptP trWillBeNoop(new EventTargetDataMap()))); 1885 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<EventTargetDataMap>, map, (adoptP trWillBeNoop(new EventTargetDataMap())));
1893 return *map; 1886 return *map;
1894 } 1887 }
1895 1888
1896 EventTargetData* Node::eventTargetData() 1889 EventTargetData* Node::eventTargetData()
1897 { 1890 {
1898 return hasEventTargetData() ? eventTargetDataMap().get(this) : 0; 1891 return hasEventTargetData() ? eventTargetDataMap().get(this) : nullptr;
1899 } 1892 }
1900 1893
1901 EventTargetData& Node::ensureEventTargetData() 1894 EventTargetData& Node::ensureEventTargetData()
1902 { 1895 {
1903 if (hasEventTargetData()) 1896 if (hasEventTargetData())
1904 return *eventTargetDataMap().get(this); 1897 return *eventTargetDataMap().get(this);
1905 setHasEventTargetData(true); 1898 setHasEventTargetData(true);
1906 EventTargetData* data = new EventTargetData; 1899 EventTargetData* data = new EventTargetData;
1907 eventTargetDataMap().set(this, adoptPtr(data)); 1900 eventTargetDataMap().set(this, adoptPtr(data));
1908 return *data; 1901 return *data;
1909 } 1902 }
1910 1903
1911 #if !ENABLE(OILPAN) 1904 #if !ENABLE(OILPAN)
1912 void Node::clearEventTargetData() 1905 void Node::clearEventTargetData()
1913 { 1906 {
1914 eventTargetDataMap().remove(this); 1907 eventTargetDataMap().remove(this);
1915 } 1908 }
1916 #endif 1909 #endif
1917 1910
1918 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* Node::mutat ionObserverRegistry() 1911 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration>>* Node::mutati onObserverRegistry()
1919 { 1912 {
1920 if (!hasRareData()) 1913 if (!hasRareData())
1921 return 0; 1914 return nullptr;
1922 NodeMutationObserverData* data = rareData()->mutationObserverData(); 1915 NodeMutationObserverData* data = rareData()->mutationObserverData();
1923 if (!data) 1916 if (!data)
1924 return 0; 1917 return nullptr;
1925 return &data->registry; 1918 return &data->registry;
1926 } 1919 }
1927 1920
1928 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* Node::tran sientMutationObserverRegistry() 1921 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration>>* Node::trans ientMutationObserverRegistry()
1929 { 1922 {
1930 if (!hasRareData()) 1923 if (!hasRareData())
1931 return 0; 1924 return nullptr;
1932 NodeMutationObserverData* data = rareData()->mutationObserverData(); 1925 NodeMutationObserverData* data = rareData()->mutationObserverData();
1933 if (!data) 1926 if (!data)
1934 return 0; 1927 return nullptr;
1935 return &data->transientRegistry; 1928 return &data->transientRegistry;
1936 } 1929 }
1937 1930
1938 template<typename Registry> 1931 template<typename Registry>
1939 static inline void collectMatchingObserversForMutation(WillBeHeapHashMap<RawPtrW illBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers, Regist ry* registry, Node& target, MutationObserver::MutationType type, const Qualified Name* attributeName) 1932 static inline void collectMatchingObserversForMutation(WillBeHeapHashMap<RawPtrW illBeMember<MutationObserver>, MutationRecordDeliveryOptions>& observers, Regist ry* registry, Node& target, MutationObserver::MutationType type, const Qualified Name* attributeName)
1940 { 1933 {
1941 if (!registry) 1934 if (!registry)
1942 return; 1935 return;
1943 for (typename Registry::iterator iter = registry->begin(); iter != registry- >end(); ++iter) { 1936
1944 const MutationObserverRegistration& registration = **iter; 1937 for (const auto& registration : *registry) {
1945 if (registration.shouldReceiveMutationFrom(target, type, attributeName)) { 1938 if (registration->shouldReceiveMutationFrom(target, type, attributeName) ) {
1946 MutationRecordDeliveryOptions deliveryOptions = registration.deliver yOptions(); 1939 MutationRecordDeliveryOptions deliveryOptions = registration->delive ryOptions();
1947 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, MutationReco rdDeliveryOptions>::AddResult result = observers.add(&registration.observer(), d eliveryOptions); 1940 WillBeHeapHashMap<RawPtrWillBeMember<MutationObserver>, MutationReco rdDeliveryOptions>::AddResult result = observers.add(&registration->observer(), deliveryOptions);
1948 if (!result.isNewEntry) 1941 if (!result.isNewEntry)
1949 result.storedValue->value |= deliveryOptions; 1942 result.storedValue->value |= deliveryOptions;
1950 } 1943 }
1951 } 1944 }
1952 } 1945 }
1953 1946
1954 void Node::getRegisteredMutationObserversOfType(WillBeHeapHashMap<RawPtrWillBeMe mber<MutationObserver>, MutationRecordDeliveryOptions>& observers, MutationObser ver::MutationType type, const QualifiedName* attributeName) 1947 void Node::getRegisteredMutationObserversOfType(WillBeHeapHashMap<RawPtrWillBeMe mber<MutationObserver>, MutationRecordDeliveryOptions>& observers, MutationObser ver::MutationType type, const QualifiedName* attributeName)
1955 { 1948 {
1956 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name); 1949 ASSERT((type == MutationObserver::Attributes && attributeName) || !attribute Name);
1957 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName); 1950 collectMatchingObserversForMutation(observers, mutationObserverRegistry(), * this, type, attributeName);
1958 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName); 1951 collectMatchingObserversForMutation(observers, transientMutationObserverRegi stry(), *this, type, attributeName);
1959 for (Node* node = parentNode(); node; node = node->parentNode()) { 1952 for (Node* node = parentNode(); node; node = node->parentNode()) {
1960 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName); 1953 collectMatchingObserversForMutation(observers, node->mutationObserverReg istry(), *this, type, attributeName);
1961 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName); 1954 collectMatchingObserversForMutation(observers, node->transientMutationOb serverRegistry(), *this, type, attributeName);
1962 } 1955 }
1963 } 1956 }
1964 1957
1965 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter) 1958 void Node::registerMutationObserver(MutationObserver& observer, MutationObserver Options options, const HashSet<AtomicString>& attributeFilter)
1966 { 1959 {
1967 MutationObserverRegistration* registration = 0; 1960 MutationObserverRegistration* registration = nullptr;
1968 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >& registr y = ensureRareData().ensureMutationObserverData().registry; 1961 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration>>& registry = ensureRareData().ensureMutationObserverData().registry;
1969 for (size_t i = 0; i < registry.size(); ++i) { 1962 for (size_t i = 0; i < registry.size(); ++i) {
1970 if (&registry[i]->observer() == &observer) { 1963 if (&registry[i]->observer() == &observer) {
1971 registration = registry[i].get(); 1964 registration = registry[i].get();
1972 registration->resetObservation(options, attributeFilter); 1965 registration->resetObservation(options, attributeFilter);
1973 } 1966 }
1974 } 1967 }
1975 1968
1976 if (!registration) { 1969 if (!registration) {
1977 registry.append(MutationObserverRegistration::create(observer, this, opt ions, attributeFilter)); 1970 registry.append(MutationObserverRegistration::create(observer, this, opt ions, attributeFilter));
1978 registration = registry.last().get(); 1971 registration = registry.last().get();
1979 } 1972 }
1980 1973
1981 document().addMutationObserverTypes(registration->mutationTypes()); 1974 document().addMutationObserverTypes(registration->mutationTypes());
1982 } 1975 }
1983 1976
1984 void Node::unregisterMutationObserver(MutationObserverRegistration* registration ) 1977 void Node::unregisterMutationObserver(MutationObserverRegistration* registration )
1985 { 1978 {
1986 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registr y = mutationObserverRegistry(); 1979 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration>>* registry = mutationObserverRegistry();
1987 ASSERT(registry); 1980 ASSERT(registry);
1988 if (!registry) 1981 if (!registry)
1989 return; 1982 return;
1990 1983
1991 size_t index = registry->find(registration); 1984 size_t index = registry->find(registration);
1992 ASSERT(index != kNotFound); 1985 ASSERT(index != kNotFound);
1993 if (index == kNotFound) 1986 if (index == kNotFound)
1994 return; 1987 return;
1995 1988
1996 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes 1989 // Deleting the registration may cause this node to be derefed, so we must m ake sure the Vector operation completes
1997 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive). 1990 // before that, in case |this| is destroyed (see MutationObserverRegistratio n::m_registrationNodeKeepAlive).
1998 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans. 1991 // FIXME: Simplify the registration/transient registration logic to make thi s understandable by humans.
1999 RefPtrWillBeRawPtr<Node> protect(this); 1992 RefPtrWillBeRawPtr<Node> protect(this);
2000 #if ENABLE(OILPAN) 1993 #if ENABLE(OILPAN)
2001 // The explicit dispose() is needed to have the registration 1994 // The explicit dispose() is needed to have the registration
2002 // object unregister itself promptly. 1995 // object unregister itself promptly.
2003 registration->dispose(); 1996 registration->dispose();
2004 #endif 1997 #endif
2005 registry->remove(index); 1998 registry->remove(index);
2006 } 1999 }
2007 2000
2008 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration) 2001 void Node::registerTransientMutationObserver(MutationObserverRegistration* regis tration)
2009 { 2002 {
2010 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion); 2003 ensureRareData().ensureMutationObserverData().transientRegistry.add(registra tion);
2011 } 2004 }
2012 2005
2013 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration) 2006 void Node::unregisterTransientMutationObserver(MutationObserverRegistration* reg istration)
2014 { 2007 {
2015 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* transi entRegistry = transientMutationObserverRegistry(); 2008 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration>>* transie ntRegistry = transientMutationObserverRegistry();
2016 ASSERT(transientRegistry); 2009 ASSERT(transientRegistry);
2017 if (!transientRegistry) 2010 if (!transientRegistry)
2018 return; 2011 return;
2019 2012
2020 ASSERT(transientRegistry->contains(registration)); 2013 ASSERT(transientRegistry->contains(registration));
2021 transientRegistry->remove(registration); 2014 transientRegistry->remove(registration);
2022 } 2015 }
2023 2016
2024 void Node::notifyMutationObserversNodeWillDetach() 2017 void Node::notifyMutationObserversNodeWillDetach()
2025 { 2018 {
2026 if (!document().hasMutationObservers()) 2019 if (!document().hasMutationObservers())
2027 return; 2020 return;
2028 2021
2029 for (Node* node = parentNode(); node; node = node->parentNode()) { 2022 for (Node* node = parentNode(); node; node = node->parentNode()) {
2030 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* registry = node->mutationObserverRegistry()) { 2023 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration>>* registry = node->mutationObserverRegistry()) {
2031 const size_t size = registry->size(); 2024 const size_t size = registry->size();
2032 for (size_t i = 0; i < size; ++i) 2025 for (size_t i = 0; i < size; ++i)
2033 registry->at(i)->observedSubtreeNodeWillDetach(*this); 2026 registry->at(i)->observedSubtreeNodeWillDetach(*this);
2034 } 2027 }
2035 2028
2036 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > * transientRegistry = node->transientMutationObserverRegistry()) { 2029 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration>>* transientRegistry = node->transientMutationObserverRegistry()) {
2037 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistrati on> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->en d(); ++iter) 2030 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistrati on>>::iterator iter = transientRegistry->begin(); iter != transientRegistry->end (); ++iter)
2038 (*iter)->observedSubtreeNodeWillDetach(*this); 2031 (*iter)->observedSubtreeNodeWillDetach(*this);
2039 } 2032 }
2040 } 2033 }
2041 } 2034 }
2042 2035
2043 void Node::handleLocalEvents(Event* event) 2036 void Node::handleLocalEvents(Event* event)
2044 { 2037 {
2045 if (!hasEventTargetData()) 2038 if (!hasEventTargetData())
2046 return; 2039 return;
2047 2040
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
2302 2295
2303 for (Node* node = parentOrShadowHostNode(); node; node = node->parentOrShado wHostNode()) 2296 for (Node* node = parentOrShadowHostNode(); node; node = node->parentOrShado wHostNode())
2304 node->incrementConnectedSubframeCount(count); 2297 node->incrementConnectedSubframeCount(count);
2305 } 2298 }
2306 2299
2307 PassRefPtrWillBeRawPtr<StaticNodeList> Node::getDestinationInsertionPoints() 2300 PassRefPtrWillBeRawPtr<StaticNodeList> Node::getDestinationInsertionPoints()
2308 { 2301 {
2309 document().updateDistributionForNodeIfNeeded(this); 2302 document().updateDistributionForNodeIfNeeded(this);
2310 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints; 2303 WillBeHeapVector<RawPtrWillBeMember<InsertionPoint>, 8> insertionPoints;
2311 collectDestinationInsertionPoints(*this, insertionPoints); 2304 collectDestinationInsertionPoints(*this, insertionPoints);
2312 WillBeHeapVector<RefPtrWillBeMember<Node> > filteredInsertionPoints; 2305 WillBeHeapVector<RefPtrWillBeMember<Node>> filteredInsertionPoints;
2313 for (size_t i = 0; i < insertionPoints.size(); ++i) { 2306 for (size_t i = 0; i < insertionPoints.size(); ++i) {
2314 InsertionPoint* insertionPoint = insertionPoints[i]; 2307 InsertionPoint* insertionPoint = insertionPoints[i];
2315 ASSERT(insertionPoint->containingShadowRoot()); 2308 ASSERT(insertionPoint->containingShadowRoot());
2316 if (insertionPoint->containingShadowRoot()->type() != ShadowRoot::UserAg entShadowRoot) 2309 if (insertionPoint->containingShadowRoot()->type() != ShadowRoot::UserAg entShadowRoot)
2317 filteredInsertionPoints.append(insertionPoint); 2310 filteredInsertionPoints.append(insertionPoint);
2318 } 2311 }
2319 return StaticNodeList::adopt(filteredInsertionPoints); 2312 return StaticNodeList::adopt(filteredInsertionPoints);
2320 } 2313 }
2321 2314
2322 void Node::setFocus(bool flag) 2315 void Node::setFocus(bool flag)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 node->showTreeForThis(); 2456 node->showTreeForThis();
2464 } 2457 }
2465 2458
2466 void showNodePath(const blink::Node* node) 2459 void showNodePath(const blink::Node* node)
2467 { 2460 {
2468 if (node) 2461 if (node)
2469 node->showNodePathForThis(); 2462 node->showNodePathForThis();
2470 } 2463 }
2471 2464
2472 #endif 2465 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/PresentationAttributeStyle.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698