| 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 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "core/dom/ContainerNode.h" | 24 #include "core/dom/ContainerNode.h" |
| 25 | 25 |
| 26 #include "bindings/v8/ExceptionState.h" | 26 #include "bindings/v8/ExceptionState.h" |
| 27 #include "core/dom/ChildListMutationScope.h" | 27 #include "core/dom/ChildListMutationScope.h" |
| 28 #include "core/dom/ClassNodeList.h" |
| 28 #include "core/dom/ContainerNodeAlgorithms.h" | 29 #include "core/dom/ContainerNodeAlgorithms.h" |
| 29 #include "core/dom/ElementTraversal.h" | 30 #include "core/dom/ElementTraversal.h" |
| 30 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
| 31 #include "core/dom/FullscreenElementStack.h" | 32 #include "core/dom/FullscreenElementStack.h" |
| 33 #include "core/dom/NameNodeList.h" |
| 32 #include "core/dom/NodeChildRemovalTracker.h" | 34 #include "core/dom/NodeChildRemovalTracker.h" |
| 33 #include "core/dom/NodeRareData.h" | 35 #include "core/dom/NodeRareData.h" |
| 34 #include "core/dom/NodeRenderStyle.h" | 36 #include "core/dom/NodeRenderStyle.h" |
| 35 #include "core/dom/NodeTraversal.h" | 37 #include "core/dom/NodeTraversal.h" |
| 36 #include "core/events/MutationEvent.h" | 38 #include "core/events/MutationEvent.h" |
| 37 #include "core/events/ThreadLocalEventNames.h" | 39 #include "core/events/ThreadLocalEventNames.h" |
| 38 #include "core/html/HTMLCollection.h" | 40 #include "core/html/HTMLCollection.h" |
| 41 #include "core/html/RadioNodeList.h" |
| 39 #include "core/rendering/InlineTextBox.h" | 42 #include "core/rendering/InlineTextBox.h" |
| 40 #include "core/rendering/RenderText.h" | 43 #include "core/rendering/RenderText.h" |
| 41 #include "core/rendering/RenderTheme.h" | 44 #include "core/rendering/RenderTheme.h" |
| 42 #include "core/rendering/RenderView.h" | 45 #include "core/rendering/RenderView.h" |
| 43 #include "core/rendering/RenderWidget.h" | 46 #include "core/rendering/RenderWidget.h" |
| 44 | 47 |
| 45 using namespace std; | 48 using namespace std; |
| 46 | 49 |
| 47 namespace WebCore { | 50 namespace WebCore { |
| 48 | 51 |
| 52 using namespace HTMLNames; |
| 53 |
| 49 static void dispatchChildInsertionEvents(Node&); | 54 static void dispatchChildInsertionEvents(Node&); |
| 50 static void dispatchChildRemovalEvents(Node&); | 55 static void dispatchChildRemovalEvents(Node&); |
| 51 | 56 |
| 52 ChildNodesLazySnapshot* ChildNodesLazySnapshot::latestSnapshot = 0; | 57 ChildNodesLazySnapshot* ChildNodesLazySnapshot::latestSnapshot = 0; |
| 53 | 58 |
| 54 #ifndef NDEBUG | 59 #ifndef NDEBUG |
| 55 unsigned NoEventDispatchAssertion::s_count = 0; | 60 unsigned NoEventDispatchAssertion::s_count = 0; |
| 56 #endif | 61 #endif |
| 57 | 62 |
| 58 static void collectChildrenAndRemoveFromOldParent(Node& node, NodeVector& nodes,
ExceptionState& exceptionState) | 63 static void collectChildrenAndRemoveFromOldParent(Node& node, NodeVector& nodes,
ExceptionState& exceptionState) |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 newChild.setParentOrShadowHostNode(this); | 260 newChild.setParentOrShadowHostNode(this); |
| 256 newChild.setPreviousSibling(prev); | 261 newChild.setPreviousSibling(prev); |
| 257 newChild.setNextSibling(&nextChild); | 262 newChild.setNextSibling(&nextChild); |
| 258 } | 263 } |
| 259 | 264 |
| 260 void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node& nextChil
d) | 265 void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node& nextChil
d) |
| 261 { | 266 { |
| 262 ASSERT(newChild); | 267 ASSERT(newChild); |
| 263 ASSERT(nextChild.parentNode() == this); | 268 ASSERT(nextChild.parentNode() == this); |
| 264 ASSERT(!newChild->isDocumentFragment()); | 269 ASSERT(!newChild->isDocumentFragment()); |
| 265 ASSERT(!hasTagName(HTMLNames::templateTag)); | 270 ASSERT(!hasTagName(templateTag)); |
| 266 | 271 |
| 267 if (nextChild.previousSibling() == newChild || nextChild == newChild) // not
hing to do | 272 if (nextChild.previousSibling() == newChild || nextChild == newChild) // not
hing to do |
| 268 return; | 273 return; |
| 269 | 274 |
| 270 if (document() != newChild->document()) | 275 if (document() != newChild->document()) |
| 271 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); | 276 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); |
| 272 | 277 |
| 273 insertBeforeCommon(nextChild, *newChild); | 278 insertBeforeCommon(nextChild, *newChild); |
| 274 | 279 |
| 275 newChild->updateAncestorConnectedSubframeCountForInsertion(); | 280 newChild->updateAncestorConnectedSubframeCountForInsertion(); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 603 } |
| 599 | 604 |
| 600 dispatchSubtreeModifiedEvent(); | 605 dispatchSubtreeModifiedEvent(); |
| 601 } | 606 } |
| 602 | 607 |
| 603 void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild) | 608 void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild) |
| 604 { | 609 { |
| 605 ASSERT(newChild); | 610 ASSERT(newChild); |
| 606 ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle re
parenting (and want DOM mutation events). | 611 ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle re
parenting (and want DOM mutation events). |
| 607 ASSERT(!newChild->isDocumentFragment()); | 612 ASSERT(!newChild->isDocumentFragment()); |
| 608 ASSERT(!hasTagName(HTMLNames::templateTag)); | 613 ASSERT(!hasTagName(templateTag)); |
| 609 | 614 |
| 610 if (document() != newChild->document()) | 615 if (document() != newChild->document()) |
| 611 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); | 616 document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION); |
| 612 | 617 |
| 613 Node* last = m_lastChild; | 618 Node* last = m_lastChild; |
| 614 { | 619 { |
| 615 NoEventDispatchAssertion assertNoEventDispatch; | 620 NoEventDispatchAssertion assertNoEventDispatch; |
| 616 // FIXME: This method should take a PassRefPtr. | 621 // FIXME: This method should take a PassRefPtr. |
| 617 appendChildToContainer(*newChild, *this); | 622 appendChildToContainer(*newChild, *this); |
| 618 treeScope().adoptIfNeeded(*newChild); | 623 treeScope().adoptIfNeeded(*newChild); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 | 965 |
| 961 ChildListMutationScope(*this).childAdded(child); | 966 ChildListMutationScope(*this).childAdded(child); |
| 962 | 967 |
| 963 childrenChanged(false, child.previousSibling(), child.nextSibling(), 1); | 968 childrenChanged(false, child.previousSibling(), child.nextSibling(), 1); |
| 964 | 969 |
| 965 ChildNodeInsertionNotifier(*this).notify(child); | 970 ChildNodeInsertionNotifier(*this).notify(child); |
| 966 | 971 |
| 967 dispatchChildInsertionEvents(child); | 972 dispatchChildInsertionEvents(child); |
| 968 } | 973 } |
| 969 | 974 |
| 975 PassRefPtr<NodeList> ContainerNode::getElementsByTagName(const AtomicString& loc
alName) |
| 976 { |
| 977 if (localName.isNull()) |
| 978 return 0; |
| 979 |
| 980 if (document().isHTMLDocument()) |
| 981 return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTag
NodeList>(this, HTMLTagNodeListType, localName); |
| 982 return ensureRareData().ensureNodeLists().addCacheWithAtomicName<TagNodeList
>(this, TagNodeListType, localName); |
| 983 } |
| 984 |
| 985 PassRefPtr<NodeList> ContainerNode::getElementsByTagNameNS(const AtomicString& n
amespaceURI, const AtomicString& localName) |
| 986 { |
| 987 if (localName.isNull()) |
| 988 return 0; |
| 989 |
| 990 if (namespaceURI == starAtom) |
| 991 return getElementsByTagName(localName); |
| 992 |
| 993 return ensureRareData().ensureNodeLists().addCacheWithQualifiedName(this, na
mespaceURI.isEmpty() ? nullAtom : namespaceURI, localName); |
| 994 } |
| 995 |
| 996 // Takes an AtomicString in argument because it is common for elements to share
the same name attribute. |
| 997 // Therefore, the NameNodeList factory function expects an AtomicString type. |
| 998 PassRefPtr<NodeList> ContainerNode::getElementsByName(const AtomicString& elemen
tName) |
| 999 { |
| 1000 return ensureRareData().ensureNodeLists().addCacheWithAtomicName<NameNodeLis
t>(this, NameNodeListType, elementName); |
| 1001 } |
| 1002 |
| 1003 // Takes an AtomicString in argument because it is common for elements to share
the same set of class names. |
| 1004 // Therefore, the ClassNodeList factory function expects an AtomicString type. |
| 1005 PassRefPtr<NodeList> ContainerNode::getElementsByClassName(const AtomicString& c
lassNames) |
| 1006 { |
| 1007 return ensureRareData().ensureNodeLists().addCacheWithAtomicName<ClassNodeLi
st>(this, ClassNodeListType, classNames); |
| 1008 } |
| 1009 |
| 1010 PassRefPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicString& name,
bool onlyMatchImgElements) |
| 1011 { |
| 1012 ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag)); |
| 1013 CollectionType type = onlyMatchImgElements ? RadioImgNodeListType : RadioNod
eListType; |
| 1014 return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeLi
st>(this, type, name); |
| 1015 } |
| 1016 |
| 970 #ifndef NDEBUG | 1017 #ifndef NDEBUG |
| 971 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node) | 1018 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node) |
| 972 { | 1019 { |
| 973 if (node->isShadowRoot()) | 1020 if (node->isShadowRoot()) |
| 974 return true; | 1021 return true; |
| 975 | 1022 |
| 976 if (node->isInsertionPoint()) | 1023 if (node->isInsertionPoint()) |
| 977 return true; | 1024 return true; |
| 978 | 1025 |
| 979 if (node->isElementNode() && toElement(node)->shadow()) | 1026 if (node->isElementNode() && toElement(node)->shadow()) |
| 980 return true; | 1027 return true; |
| 981 | 1028 |
| 982 return false; | 1029 return false; |
| 983 } | 1030 } |
| 984 #endif | 1031 #endif |
| 985 | 1032 |
| 986 } // namespace WebCore | 1033 } // namespace WebCore |
| OLD | NEW |