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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void ContainerNode::removeDetachedChildren() | 80 void ContainerNode::removeDetachedChildren() |
81 { | 81 { |
82 ASSERT(!connectedSubframeCount()); | 82 ASSERT(!connectedSubframeCount()); |
83 ASSERT(needsAttach()); | 83 ASSERT(needsAttach()); |
84 removeDetachedChildrenInContainer<Node, ContainerNode>(*this); | 84 removeDetachedChildrenInContainer<Node, ContainerNode>(*this); |
85 } | 85 } |
86 #endif | 86 #endif |
87 | 87 |
88 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent) | 88 void ContainerNode::parserTakeAllChildrenFrom(ContainerNode& oldParent) |
89 { | 89 { |
90 while (RefPtr<Node> child = oldParent.firstChild()) { | 90 while (RefPtrWillBeRawPtr<Node> child = oldParent.firstChild()) { |
91 oldParent.parserRemoveChild(*child); | 91 oldParent.parserRemoveChild(*child); |
92 treeScope().adoptIfNeeded(*child); | 92 treeScope().adoptIfNeeded(*child); |
93 parserAppendChild(child.get()); | 93 parserAppendChild(child.get()); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 ContainerNode::~ContainerNode() | 97 ContainerNode::~ContainerNode() |
98 { | 98 { |
99 ASSERT(needsAttach()); | 99 ASSERT(needsAttach()); |
100 #if !ENABLE(OILPAN) | 100 #if !ENABLE(OILPAN) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 | 178 |
179 void ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
ptionState& exceptionState) | 179 void ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* refChild, Exce
ptionState& exceptionState) |
180 { | 180 { |
181 #if !ENABLE(OILPAN) | 181 #if !ENABLE(OILPAN) |
182 // Check that this node is not "floating". | 182 // Check that this node is not "floating". |
183 // If it is, it can be deleted as a side effect of sending mutation events. | 183 // If it is, it can be deleted as a side effect of sending mutation events. |
184 ASSERT(refCount() || parentOrShadowHostNode()); | 184 ASSERT(refCount() || parentOrShadowHostNode()); |
185 #endif | 185 #endif |
186 | 186 |
187 RefPtr<Node> protect(this); | 187 RefPtrWillBeRawPtr<Node> protect(this); |
188 | 188 |
189 // insertBefore(node, 0) is equivalent to appendChild(node) | 189 // insertBefore(node, 0) is equivalent to appendChild(node) |
190 if (!refChild) { | 190 if (!refChild) { |
191 appendChild(newChild, exceptionState); | 191 appendChild(newChild, exceptionState); |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 // Make sure adding the new child is OK. | 195 // Make sure adding the new child is OK. |
196 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) | 196 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) |
197 return; | 197 return; |
198 ASSERT(newChild); | 198 ASSERT(newChild); |
199 | 199 |
200 // NotFoundError: Raised if refChild is not a child of this node | 200 // NotFoundError: Raised if refChild is not a child of this node |
201 if (refChild->parentNode() != this) { | 201 if (refChild->parentNode() != this) { |
202 exceptionState.throwDOMException(NotFoundError, "The node before which t
he new node is to be inserted is not a child of this node."); | 202 exceptionState.throwDOMException(NotFoundError, "The node before which t
he new node is to be inserted is not a child of this node."); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 if (refChild->previousSibling() == newChild || refChild == newChild) // noth
ing to do | 206 if (refChild->previousSibling() == newChild || refChild == newChild) // noth
ing to do |
207 return; | 207 return; |
208 | 208 |
209 RefPtr<Node> next = refChild; | 209 RefPtrWillBeRawPtr<Node> next = refChild; |
210 | 210 |
211 NodeVector targets; | 211 NodeVector targets; |
212 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); | 212 collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); |
213 if (exceptionState.hadException()) | 213 if (exceptionState.hadException()) |
214 return; | 214 return; |
215 if (targets.isEmpty()) | 215 if (targets.isEmpty()) |
216 return; | 216 return; |
217 | 217 |
218 // We need this extra check because collectChildrenAndRemoveFromOldParent()
can fire mutation events. | 218 // We need this extra check because collectChildrenAndRemoveFromOldParent()
can fire mutation events. |
219 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) | 219 if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 296 } |
297 | 297 |
298 void ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
ptionState& exceptionState) | 298 void ContainerNode::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, Exce
ptionState& exceptionState) |
299 { | 299 { |
300 #if !ENABLE(OILPAN) | 300 #if !ENABLE(OILPAN) |
301 // Check that this node is not "floating". | 301 // Check that this node is not "floating". |
302 // If it is, it can be deleted as a side effect of sending mutation events. | 302 // If it is, it can be deleted as a side effect of sending mutation events. |
303 ASSERT(refCount() || parentOrShadowHostNode()); | 303 ASSERT(refCount() || parentOrShadowHostNode()); |
304 #endif | 304 #endif |
305 | 305 |
306 RefPtr<Node> protect(this); | 306 RefPtrWillBeRawPtr<Node> protect(this); |
307 | 307 |
308 if (oldChild == newChild) // nothing to do | 308 if (oldChild == newChild) // nothing to do |
309 return; | 309 return; |
310 | 310 |
311 if (!oldChild) { | 311 if (!oldChild) { |
312 exceptionState.throwDOMException(NotFoundError, "The node to be replaced
is null."); | 312 exceptionState.throwDOMException(NotFoundError, "The node to be replaced
is null."); |
313 return; | 313 return; |
314 } | 314 } |
315 | 315 |
316 // Make sure replacing the old child with the new is ok | 316 // Make sure replacing the old child with the new is ok |
317 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState)) | 317 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState)) |
318 return; | 318 return; |
319 | 319 |
320 // NotFoundError: Raised if oldChild is not a child of this node. | 320 // NotFoundError: Raised if oldChild is not a child of this node. |
321 if (oldChild->parentNode() != this) { | 321 if (oldChild->parentNode() != this) { |
322 exceptionState.throwDOMException(NotFoundError, "The node to be replaced
is not a child of this node."); | 322 exceptionState.throwDOMException(NotFoundError, "The node to be replaced
is not a child of this node."); |
323 return; | 323 return; |
324 } | 324 } |
325 | 325 |
326 ChildListMutationScope mutation(*this); | 326 ChildListMutationScope mutation(*this); |
327 | 327 |
328 RefPtr<Node> next = oldChild->nextSibling(); | 328 RefPtrWillBeRawPtr<Node> next = oldChild->nextSibling(); |
329 | 329 |
330 // Remove the node we're replacing | 330 // Remove the node we're replacing |
331 RefPtr<Node> removedChild = oldChild; | 331 RefPtrWillBeRawPtr<Node> protectRemovedChild = oldChild; |
| 332 ASSERT_UNUSED(protectRemovedChild, protectRemovedChild); |
332 removeChild(oldChild, exceptionState); | 333 removeChild(oldChild, exceptionState); |
333 if (exceptionState.hadException()) | 334 if (exceptionState.hadException()) |
334 return; | 335 return; |
335 | 336 |
336 if (next && (next->previousSibling() == newChild || next == newChild)) // no
thing to do | 337 if (next && (next->previousSibling() == newChild || next == newChild)) // no
thing to do |
337 return; | 338 return; |
338 | 339 |
339 // Does this one more time because removeChild() fires a MutationEvent. | 340 // Does this one more time because removeChild() fires a MutationEvent. |
340 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState)) | 341 if (!checkAcceptChild(newChild.get(), oldChild, exceptionState)) |
341 return; | 342 return; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 423 } |
423 | 424 |
424 void ContainerNode::removeChild(Node* oldChild, ExceptionState& exceptionState) | 425 void ContainerNode::removeChild(Node* oldChild, ExceptionState& exceptionState) |
425 { | 426 { |
426 #if !ENABLE(OILPAN) | 427 #if !ENABLE(OILPAN) |
427 // Check that this node is not "floating". | 428 // Check that this node is not "floating". |
428 // If it is, it can be deleted as a side effect of sending mutation events. | 429 // If it is, it can be deleted as a side effect of sending mutation events. |
429 ASSERT(refCount() || parentOrShadowHostNode()); | 430 ASSERT(refCount() || parentOrShadowHostNode()); |
430 #endif | 431 #endif |
431 | 432 |
432 RefPtr<Node> protect(this); | 433 RefPtrWillBeRawPtr<Node> protect(this); |
433 | 434 |
434 // NotFoundError: Raised if oldChild is not a child of this node. | 435 // NotFoundError: Raised if oldChild is not a child of this node. |
435 // FIXME: We should never really get PseudoElements in here, but editing wil
l sometimes | 436 // FIXME: We should never really get PseudoElements in here, but editing wil
l sometimes |
436 // attempt to remove them still. We should fix that and enable this ASSERT. | 437 // attempt to remove them still. We should fix that and enable this ASSERT. |
437 // ASSERT(!oldChild->isPseudoElement()) | 438 // ASSERT(!oldChild->isPseudoElement()) |
438 if (!oldChild || oldChild->parentNode() != this || oldChild->isPseudoElement
()) { | 439 if (!oldChild || oldChild->parentNode() != this || oldChild->isPseudoElement
()) { |
439 exceptionState.throwDOMException(NotFoundError, "The node to be removed
is not a child of this node."); | 440 exceptionState.throwDOMException(NotFoundError, "The node to be removed
is not a child of this node."); |
440 return; | 441 return; |
441 } | 442 } |
442 | 443 |
443 RefPtr<Node> child = oldChild; | 444 RefPtrWillBeRawPtr<Node> child = oldChild; |
444 | 445 |
445 document().removeFocusedElementOfSubtree(child.get()); | 446 document().removeFocusedElementOfSubtree(child.get()); |
446 | 447 |
447 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(document())) | 448 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(document())) |
448 fullscreen->removeFullScreenElementOfSubtree(child.get()); | 449 fullscreen->removeFullScreenElementOfSubtree(child.get()); |
449 | 450 |
450 // Events fired when blurring currently focused node might have moved this | 451 // Events fired when blurring currently focused node might have moved this |
451 // child into a different parent. | 452 // child into a different parent. |
452 if (child->parentNode() != this) { | 453 if (child->parentNode() != this) { |
453 exceptionState.throwDOMException(NotFoundError, "The node to be removed
is no longer a child of this node. Perhaps it was moved in a 'blur' event handle
r?"); | 454 exceptionState.throwDOMException(NotFoundError, "The node to be removed
is no longer a child of this node. Perhaps it was moved in a 'blur' event handle
r?"); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 520 } |
520 | 521 |
521 // this differs from other remove functions because it forcibly removes all the
children, | 522 // this differs from other remove functions because it forcibly removes all the
children, |
522 // regardless of read-only status or event exceptions, e.g. | 523 // regardless of read-only status or event exceptions, e.g. |
523 void ContainerNode::removeChildren() | 524 void ContainerNode::removeChildren() |
524 { | 525 { |
525 if (!m_firstChild) | 526 if (!m_firstChild) |
526 return; | 527 return; |
527 | 528 |
528 // The container node can be removed from event handlers. | 529 // The container node can be removed from event handlers. |
529 RefPtr<ContainerNode> protect(this); | 530 RefPtrWillBeRawPtr<ContainerNode> protect(this); |
530 | 531 |
531 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(document())) | 532 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(document())) |
532 fullscreen->removeFullScreenElementOfSubtree(this, true); | 533 fullscreen->removeFullScreenElementOfSubtree(this, true); |
533 | 534 |
534 // Do any prep work needed before actually starting to detach | 535 // Do any prep work needed before actually starting to detach |
535 // and remove... e.g. stop loading frames, fire unload events. | 536 // and remove... e.g. stop loading frames, fire unload events. |
536 willRemoveChildren(); | 537 willRemoveChildren(); |
537 | 538 |
538 { | 539 { |
539 // Removing focus can cause frames to load, either via events (focusout,
blur) | 540 // Removing focus can cause frames to load, either via events (focusout,
blur) |
(...skipping 27 matching lines...) Expand all Loading... |
567 | 568 |
568 for (size_t i = 0; i < removedChildren.size(); ++i) | 569 for (size_t i = 0; i < removedChildren.size(); ++i) |
569 notifyNodeRemoved(*removedChildren[i]); | 570 notifyNodeRemoved(*removedChildren[i]); |
570 } | 571 } |
571 | 572 |
572 dispatchSubtreeModifiedEvent(); | 573 dispatchSubtreeModifiedEvent(); |
573 } | 574 } |
574 | 575 |
575 void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& excep
tionState) | 576 void ContainerNode::appendChild(PassRefPtr<Node> newChild, ExceptionState& excep
tionState) |
576 { | 577 { |
577 RefPtr<ContainerNode> protect(this); | 578 RefPtrWillBeRawPtr<ContainerNode> protect(this); |
578 | 579 |
579 #if !ENABLE(OILPAN) | 580 #if !ENABLE(OILPAN) |
580 // Check that this node is not "floating". | 581 // Check that this node is not "floating". |
581 // If it is, it can be deleted as a side effect of sending mutation events. | 582 // If it is, it can be deleted as a side effect of sending mutation events. |
582 ASSERT(refCount() || parentOrShadowHostNode()); | 583 ASSERT(refCount() || parentOrShadowHostNode()); |
583 #endif | 584 #endif |
584 | 585 |
585 // Make sure adding the new child is ok | 586 // Make sure adding the new child is ok |
586 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) | 587 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) |
587 return; | 588 return; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 childrenChanged(true, last, 0, 1); | 657 childrenChanged(true, last, 0, 1); |
657 notifyNodeInserted(*newChild); | 658 notifyNodeInserted(*newChild); |
658 } | 659 } |
659 | 660 |
660 void ContainerNode::notifyNodeInserted(Node& root) | 661 void ContainerNode::notifyNodeInserted(Node& root) |
661 { | 662 { |
662 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); | 663 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); |
663 | 664 |
664 InspectorInstrumentation::didInsertDOMNode(&root); | 665 InspectorInstrumentation::didInsertDOMNode(&root); |
665 | 666 |
666 RefPtr<Node> protect(this); | 667 RefPtrWillBeRawPtr<Node> protect(this); |
667 RefPtr<Node> protectNode(root); | 668 RefPtrWillBeRawPtr<Node> protectNode(root); |
668 | 669 |
669 NodeVector postInsertionNotificationTargets; | 670 NodeVector postInsertionNotificationTargets; |
670 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); | 671 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); |
671 | 672 |
672 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { | 673 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { |
673 Node* targetNode = postInsertionNotificationTargets[i].get(); | 674 Node* targetNode = postInsertionNotificationTargets[i].get(); |
674 if (targetNode->inDocument()) | 675 if (targetNode->inDocument()) |
675 targetNode->didNotifySubtreeInsertionsToDocument(); | 676 targetNode->didNotifySubtreeInsertionsToDocument(); |
676 } | 677 } |
677 } | 678 } |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 return true; | 1278 return true; |
1278 | 1279 |
1279 if (node->isElementNode() && toElement(node)->shadow()) | 1280 if (node->isElementNode() && toElement(node)->shadow()) |
1280 return true; | 1281 return true; |
1281 | 1282 |
1282 return false; | 1283 return false; |
1283 } | 1284 } |
1284 #endif | 1285 #endif |
1285 | 1286 |
1286 } // namespace WebCore | 1287 } // namespace WebCore |
OLD | NEW |