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. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
51 static void notifyChildInserted(Node*); | 51 static void notifyChildInserted(Node*); |
52 static void dispatchChildInsertionEvents(Node*); | 52 static void dispatchChildInsertionEvents(Node*); |
53 static void dispatchChildRemovalEvents(Node*); | 53 static void dispatchChildRemovalEvents(Node*); |
54 | 54 |
55 typedef pair<RefPtr<Node>, unsigned> CallbackParameters; | 55 typedef pair<RefPtr<Node>, unsigned> CallbackParameters; |
56 typedef pair<NodeCallback, CallbackParameters> CallbackInfo; | 56 typedef pair<NodeCallback, CallbackParameters> CallbackInfo; |
57 typedef Vector<CallbackInfo> NodeCallbackQueue; | 57 typedef Vector<CallbackInfo> NodeCallbackQueue; |
58 | 58 |
59 typedef Vector<RefPtr<Node>, 1> NodeVector; | |
60 static NodeCallbackQueue* s_postAttachCallbackQueue; | 59 static NodeCallbackQueue* s_postAttachCallbackQueue; |
61 | 60 |
62 static size_t s_attachDepth; | 61 static size_t s_attachDepth; |
63 static bool s_shouldReEnableMemoryCacheCallsAfterAttach; | 62 static bool s_shouldReEnableMemoryCacheCallsAfterAttach; |
64 | 63 |
65 static inline void collectNodes(Node* node, NodeVector& nodes) | |
66 { | |
67 for (Node* child = node->firstChild(); child; child = child->nextSibling()) | |
68 nodes.append(child); | |
69 } | |
70 | |
71 static void collectTargetNodes(Node* node, NodeVector& nodes) | 64 static void collectTargetNodes(Node* node, NodeVector& nodes) |
72 { | 65 { |
73 if (node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE) { | 66 if (node->nodeType() != Node::DOCUMENT_FRAGMENT_NODE) { |
74 nodes.append(node); | 67 nodes.append(node); |
75 return; | 68 return; |
76 } | 69 } |
77 collectNodes(node, nodes); | 70 getChildNodes(node, nodes); |
78 } | 71 } |
79 | 72 |
80 void ContainerNode::removeAllChildren() | 73 void ContainerNode::removeAllChildren() |
81 { | 74 { |
82 removeAllChildrenInContainer<Node, ContainerNode>(this); | 75 removeAllChildrenInContainer<Node, ContainerNode>(this); |
83 } | 76 } |
84 | 77 |
85 void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent) | 78 void ContainerNode::takeAllChildrenFrom(ContainerNode* oldParent) |
86 { | 79 { |
87 NodeVector children; | 80 NodeVector children; |
88 collectNodes(oldParent, children); | 81 getChildNodes(oldParent, children); |
89 oldParent->removeAllChildren(); | 82 oldParent->removeAllChildren(); |
90 | 83 |
91 for (unsigned i = 0; i < children.size(); ++i) { | 84 for (unsigned i = 0; i < children.size(); ++i) { |
92 ExceptionCode ec = 0; | 85 ExceptionCode ec = 0; |
93 if (children[i]->attached()) | 86 if (children[i]->attached()) |
94 children[i]->detach(); | 87 children[i]->detach(); |
95 // FIXME: We need a no mutation event version of adoptNode. | 88 // FIXME: We need a no mutation event version of adoptNode. |
96 RefPtr<Node> child = document()->adoptNode(children[i].release(), ec); | 89 RefPtr<Node> child = document()->adoptNode(children[i].release(), ec); |
97 ASSERT(!ec); | 90 ASSERT(!ec); |
98 parserAddChild(child.get()); | 91 parserAddChild(child.get()); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 373 |
381 dispatchSubtreeModifiedEvent(); | 374 dispatchSubtreeModifiedEvent(); |
382 return true; | 375 return true; |
383 } | 376 } |
384 | 377 |
385 void ContainerNode::willRemove() | 378 void ContainerNode::willRemove() |
386 { | 379 { |
387 RefPtr<Node> protect(this); | 380 RefPtr<Node> protect(this); |
388 | 381 |
389 NodeVector children; | 382 NodeVector children; |
390 collectNodes(this, children); | 383 getChildNodes(this, children); |
391 for (size_t i = 0; i < children.size(); ++i) { | 384 for (size_t i = 0; i < children.size(); ++i) { |
392 if (children[i]->parentNode() != this) // Check for child being removed
from subtree while removing. | 385 if (children[i]->parentNode() != this) // Check for child being removed
from subtree while removing. |
393 continue; | 386 continue; |
394 children[i]->willRemove(); | 387 children[i]->willRemove(); |
395 } | 388 } |
396 | 389 |
397 Node::willRemove(); | 390 Node::willRemove(); |
398 } | 391 } |
399 | 392 |
400 static void willRemoveChild(Node* child) | 393 static void willRemoveChild(Node* child) |
401 { | 394 { |
402 // update auxiliary doc info (e.g. iterators) to note that node is being rem
oved | 395 // update auxiliary doc info (e.g. iterators) to note that node is being rem
oved |
403 child->document()->nodeWillBeRemoved(child); | 396 child->document()->nodeWillBeRemoved(child); |
404 child->document()->incDOMTreeVersion(); | 397 child->document()->incDOMTreeVersion(); |
405 | 398 |
406 // fire removed from document mutation events. | 399 // fire removed from document mutation events. |
407 dispatchChildRemovalEvents(child); | 400 dispatchChildRemovalEvents(child); |
408 child->willRemove(); | 401 child->willRemove(); |
409 } | 402 } |
410 | 403 |
411 static void willRemoveChildren(ContainerNode* container) | 404 static void willRemoveChildren(ContainerNode* container) |
412 { | 405 { |
413 container->document()->nodeChildrenWillBeRemoved(container); | 406 container->document()->nodeChildrenWillBeRemoved(container); |
414 container->document()->incDOMTreeVersion(); | 407 container->document()->incDOMTreeVersion(); |
415 | 408 |
416 NodeVector children; | 409 NodeVector children; |
417 collectNodes(container, children); | 410 getChildNodes(container, children); |
418 | 411 |
419 #if ENABLE(MUTATION_OBSERVERS) | 412 #if ENABLE(MUTATION_OBSERVERS) |
420 ChildListMutationScope mutation(container); | 413 ChildListMutationScope mutation(container); |
421 #endif | 414 #endif |
422 | 415 |
423 for (NodeVector::const_iterator it = children.begin(); it != children.end();
it++) { | 416 for (NodeVector::const_iterator it = children.begin(); it != children.end();
it++) { |
424 Node* child = it->get(); | 417 Node* child = it->get(); |
425 // fire removed from document mutation events. | 418 // fire removed from document mutation events. |
426 dispatchChildRemovalEvents(child); | 419 dispatchChildRemovalEvents(child); |
427 child->willRemove(); | 420 child->willRemove(); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 } | 800 } |
808 | 801 |
809 void ContainerNode::insertedIntoDocument() | 802 void ContainerNode::insertedIntoDocument() |
810 { | 803 { |
811 RefPtr<Node> protect(this); | 804 RefPtr<Node> protect(this); |
812 | 805 |
813 Node::insertedIntoDocument(); | 806 Node::insertedIntoDocument(); |
814 insertedIntoTree(false); | 807 insertedIntoTree(false); |
815 | 808 |
816 NodeVector children; | 809 NodeVector children; |
817 collectNodes(this, children); | 810 getChildNodes(this, children); |
818 for (size_t i = 0; i < children.size(); ++i) { | 811 for (size_t i = 0; i < children.size(); ++i) { |
819 // If we have been removed from the document during this loop, then | 812 // If we have been removed from the document during this loop, then |
820 // we don't want to tell the rest of our children that they've been | 813 // we don't want to tell the rest of our children that they've been |
821 // inserted into the document because they haven't. | 814 // inserted into the document because they haven't. |
822 if (!inDocument()) | 815 if (!inDocument()) |
823 break; | 816 break; |
824 if (children[i]->parentNode() != this) | 817 if (children[i]->parentNode() != this) |
825 continue; | 818 continue; |
826 children[i]->insertedIntoDocument(); | 819 children[i]->insertedIntoDocument(); |
827 } | 820 } |
828 } | 821 } |
829 | 822 |
830 void ContainerNode::removedFromDocument() | 823 void ContainerNode::removedFromDocument() |
831 { | 824 { |
832 Node::removedFromDocument(); | 825 Node::removedFromDocument(); |
833 if (document()->cssTarget() == this) | 826 if (document()->cssTarget() == this) |
834 document()->setCSSTarget(0); | 827 document()->setCSSTarget(0); |
835 clearInDocument(); | 828 clearInDocument(); |
836 removedFromTree(false); | 829 removedFromTree(false); |
837 | 830 |
838 NodeVector children; | 831 NodeVector children; |
839 collectNodes(this, children); | 832 getChildNodes(this, children); |
840 for (size_t i = 0; i < children.size(); ++i) { | 833 for (size_t i = 0; i < children.size(); ++i) { |
841 // If we have been added to the document during this loop, then we | 834 // If we have been added to the document during this loop, then we |
842 // don't want to tell the rest of our children that they've been | 835 // don't want to tell the rest of our children that they've been |
843 // removed from the document because they haven't. | 836 // removed from the document because they haven't. |
844 if (inDocument()) | 837 if (inDocument()) |
845 break; | 838 break; |
846 if (children[i]->parentNode() != this) | 839 if (children[i]->parentNode() != this) |
847 continue; | 840 continue; |
848 children[i]->removedFromDocument(); | 841 children[i]->removedFromDocument(); |
849 } | 842 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 if (!document()->hasListenerType(Document::BEFORELOAD_LISTENER)) | 1188 if (!document()->hasListenerType(Document::BEFORELOAD_LISTENER)) |
1196 return true; | 1189 return true; |
1197 | 1190 |
1198 RefPtr<ContainerNode> protector(this); | 1191 RefPtr<ContainerNode> protector(this); |
1199 RefPtr<BeforeLoadEvent> beforeLoadEvent = BeforeLoadEvent::create(sourceURL)
; | 1192 RefPtr<BeforeLoadEvent> beforeLoadEvent = BeforeLoadEvent::create(sourceURL)
; |
1200 dispatchEvent(beforeLoadEvent.get()); | 1193 dispatchEvent(beforeLoadEvent.get()); |
1201 return !beforeLoadEvent->defaultPrevented(); | 1194 return !beforeLoadEvent->defaultPrevented(); |
1202 } | 1195 } |
1203 | 1196 |
1204 } // namespace WebCore | 1197 } // namespace WebCore |
OLD | NEW |