| 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, 2013 Apple Inc. All rights
reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights
reserved. |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 void ContainerNode::removeDetachedChildren() | 63 void ContainerNode::removeDetachedChildren() |
| 64 { | 64 { |
| 65 ASSERT(needsAttach()); | 65 ASSERT(needsAttach()); |
| 66 removeDetachedChildrenInContainer(*this); | 66 removeDetachedChildrenInContainer(*this); |
| 67 } | 67 } |
| 68 | 68 |
| 69 ContainerNode::~ContainerNode() | 69 ContainerNode::~ContainerNode() |
| 70 { | 70 { |
| 71 ASSERT(needsAttach()); | 71 ASSERT(needsAttach()); |
| 72 #if !ENABLE(OILPAN) | |
| 73 willBeDeletedFromDocument(); | 72 willBeDeletedFromDocument(); |
| 74 removeDetachedChildren(); | 73 removeDetachedChildren(); |
| 75 #endif | |
| 76 } | 74 } |
| 77 | 75 |
| 78 bool ContainerNode::isChildTypeAllowed(const Node& child) const | 76 bool ContainerNode::isChildTypeAllowed(const Node& child) const |
| 79 { | 77 { |
| 80 if (!child.isDocumentFragment()) | 78 if (!child.isDocumentFragment()) |
| 81 return childTypeAllowed(child.nodeType()); | 79 return childTypeAllowed(child.nodeType()); |
| 82 | 80 |
| 83 for (Node* node = toDocumentFragment(child).firstChild(); node; node = node-
>nextSibling()) { | 81 for (Node* node = toDocumentFragment(child).firstChild(); node; node = node-
>nextSibling()) { |
| 84 if (!childTypeAllowed(node->nodeType())) | 82 if (!childTypeAllowed(node->nodeType())) |
| 85 return false; | 83 return false; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 ASSERT(isChildTypeAllowed(newChild)); | 134 ASSERT(isChildTypeAllowed(newChild)); |
| 137 if (newChild.contains(this)) { | 135 if (newChild.contains(this)) { |
| 138 exceptionState.throwDOMException(HierarchyRequestError, "The new child e
lement contains the parent."); | 136 exceptionState.throwDOMException(HierarchyRequestError, "The new child e
lement contains the parent."); |
| 139 return false; | 137 return false; |
| 140 } | 138 } |
| 141 return true; | 139 return true; |
| 142 } | 140 } |
| 143 | 141 |
| 144 PassRefPtr<Node> ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* re
fChild, ExceptionState& exceptionState) | 142 PassRefPtr<Node> ContainerNode::insertBefore(PassRefPtr<Node> newChild, Node* re
fChild, ExceptionState& exceptionState) |
| 145 { | 143 { |
| 146 #if !ENABLE(OILPAN) | |
| 147 // Check that this node is not "floating". | 144 // Check that this node is not "floating". |
| 148 // If it is, it can be deleted as a side effect of sending mutation events. | 145 // If it is, it can be deleted as a side effect of sending mutation events. |
| 149 ASSERT(refCount() || parentOrShadowHostNode()); | 146 ASSERT(refCount() || parentOrShadowHostNode()); |
| 150 #endif | |
| 151 | 147 |
| 152 RefPtr<Node> protect(this); | 148 RefPtr<Node> protect(this); |
| 153 | 149 |
| 154 // insertBefore(node, 0) is equivalent to appendChild(node) | 150 // insertBefore(node, 0) is equivalent to appendChild(node) |
| 155 if (!refChild) { | 151 if (!refChild) { |
| 156 return appendChild(newChild, exceptionState); | 152 return appendChild(newChild, exceptionState); |
| 157 } | 153 } |
| 158 | 154 |
| 159 // Make sure adding the new child is OK. | 155 // Make sure adding the new child is OK. |
| 160 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) { | 156 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 m_lastChild->setNextSibling(&child); | 245 m_lastChild->setNextSibling(&child); |
| 250 } else { | 246 } else { |
| 251 setFirstChild(&child); | 247 setFirstChild(&child); |
| 252 } | 248 } |
| 253 | 249 |
| 254 setLastChild(&child); | 250 setLastChild(&child); |
| 255 } | 251 } |
| 256 | 252 |
| 257 PassRefPtr<Node> ContainerNode::replaceChild(PassRefPtr<Node> newChild, PassRefP
tr<Node> oldChild, ExceptionState& exceptionState) | 253 PassRefPtr<Node> ContainerNode::replaceChild(PassRefPtr<Node> newChild, PassRefP
tr<Node> oldChild, ExceptionState& exceptionState) |
| 258 { | 254 { |
| 259 #if !ENABLE(OILPAN) | |
| 260 // Check that this node is not "floating". | 255 // Check that this node is not "floating". |
| 261 // If it is, it can be deleted as a side effect of sending mutation events. | 256 // If it is, it can be deleted as a side effect of sending mutation events. |
| 262 ASSERT(refCount() || parentOrShadowHostNode()); | 257 ASSERT(refCount() || parentOrShadowHostNode()); |
| 263 #endif | |
| 264 | 258 |
| 265 RefPtr<Node> protect(this); | 259 RefPtr<Node> protect(this); |
| 266 | 260 |
| 267 if (oldChild == newChild) // nothing to do | 261 if (oldChild == newChild) // nothing to do |
| 268 return oldChild; | 262 return oldChild; |
| 269 | 263 |
| 270 if (!oldChild) { | 264 if (!oldChild) { |
| 271 exceptionState.throwDOMException(NotFoundError, "The node to be replaced
is null."); | 265 exceptionState.throwDOMException(NotFoundError, "The node to be replaced
is null."); |
| 272 return nullptr; | 266 return nullptr; |
| 273 } | 267 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 358 |
| 365 ChildListMutationScope mutation(*this); | 359 ChildListMutationScope mutation(*this); |
| 366 for (NodeVector::const_iterator it = children.begin(); it != children.end();
++it) { | 360 for (NodeVector::const_iterator it = children.begin(); it != children.end();
++it) { |
| 367 ASSERT(*it); | 361 ASSERT(*it); |
| 368 Node& child = **it; | 362 Node& child = **it; |
| 369 mutation.willRemoveChild(child); | 363 mutation.willRemoveChild(child); |
| 370 child.notifyMutationObserversNodeWillDetach(); | 364 child.notifyMutationObserversNodeWillDetach(); |
| 371 } | 365 } |
| 372 } | 366 } |
| 373 | 367 |
| 374 #if !ENABLE(OILPAN) | |
| 375 void ContainerNode::removeDetachedChildrenInContainer(ContainerNode& container) | 368 void ContainerNode::removeDetachedChildrenInContainer(ContainerNode& container) |
| 376 { | 369 { |
| 377 // List of nodes to be deleted. | 370 // List of nodes to be deleted. |
| 378 Node* head = 0; | 371 Node* head = 0; |
| 379 Node* tail = 0; | 372 Node* tail = 0; |
| 380 | 373 |
| 381 addChildNodesToDeletionQueue(head, tail, container); | 374 addChildNodesToDeletionQueue(head, tail, container); |
| 382 | 375 |
| 383 Node* n; | 376 Node* n; |
| 384 Node* next; | 377 Node* next; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } else { | 421 } else { |
| 429 RefPtr<Node> protect(n); // removedFromDocument may remove all refer
ences to this node. | 422 RefPtr<Node> protect(n); // removedFromDocument may remove all refer
ences to this node. |
| 430 container.document().adoptIfNeeded(*n); | 423 container.document().adoptIfNeeded(*n); |
| 431 if (n->inDocument()) | 424 if (n->inDocument()) |
| 432 container.notifyNodeRemoved(*n); | 425 container.notifyNodeRemoved(*n); |
| 433 } | 426 } |
| 434 } | 427 } |
| 435 | 428 |
| 436 container.setLastChild(0); | 429 container.setLastChild(0); |
| 437 } | 430 } |
| 438 #endif | |
| 439 | 431 |
| 440 PassRefPtr<Node> ContainerNode::removeChild(PassRefPtr<Node> oldChild, Exception
State& exceptionState) | 432 PassRefPtr<Node> ContainerNode::removeChild(PassRefPtr<Node> oldChild, Exception
State& exceptionState) |
| 441 { | 433 { |
| 442 #if !ENABLE(OILPAN) | |
| 443 // Check that this node is not "floating". | 434 // Check that this node is not "floating". |
| 444 // If it is, it can be deleted as a side effect of sending mutation events. | 435 // If it is, it can be deleted as a side effect of sending mutation events. |
| 445 ASSERT(refCount() || parentOrShadowHostNode()); | 436 ASSERT(refCount() || parentOrShadowHostNode()); |
| 446 #endif | |
| 447 | 437 |
| 448 RefPtr<Node> protect(this); | 438 RefPtr<Node> protect(this); |
| 449 RefPtr<Node> child = oldChild; | 439 RefPtr<Node> child = oldChild; |
| 450 | 440 |
| 451 document().removeFocusedElementOfSubtree(child.get()); | 441 document().removeFocusedElementOfSubtree(child.get()); |
| 452 | 442 |
| 453 // Events fired when blurring currently focused node might have moved this | 443 // Events fired when blurring currently focused node might have moved this |
| 454 // child into a different parent. | 444 // child into a different parent. |
| 455 if (child->parentNode() != this) { | 445 if (child->parentNode() != this) { |
| 456 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?"); | 446 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 534 |
| 545 ChildrenChange change = {AllChildrenRemoved, ChildrenChangeSourceAPI}; | 535 ChildrenChange change = {AllChildrenRemoved, ChildrenChangeSourceAPI}; |
| 546 childrenChanged(change); | 536 childrenChanged(change); |
| 547 } | 537 } |
| 548 } | 538 } |
| 549 | 539 |
| 550 PassRefPtr<Node> ContainerNode::appendChild(PassRefPtr<Node> newChild, Exception
State& exceptionState) | 540 PassRefPtr<Node> ContainerNode::appendChild(PassRefPtr<Node> newChild, Exception
State& exceptionState) |
| 551 { | 541 { |
| 552 RefPtr<ContainerNode> protect(this); | 542 RefPtr<ContainerNode> protect(this); |
| 553 | 543 |
| 554 #if !ENABLE(OILPAN) | |
| 555 // Check that this node is not "floating". | 544 // Check that this node is not "floating". |
| 556 // If it is, it can be deleted as a side effect of sending mutation events. | 545 // If it is, it can be deleted as a side effect of sending mutation events. |
| 557 ASSERT(refCount() || parentOrShadowHostNode()); | 546 ASSERT(refCount() || parentOrShadowHostNode()); |
| 558 #endif | |
| 559 | 547 |
| 560 // Make sure adding the new child is ok | 548 // Make sure adding the new child is ok |
| 561 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) { | 549 if (!checkAcceptChild(newChild.get(), 0, exceptionState)) { |
| 562 if (exceptionState.hadException()) | 550 if (exceptionState.hadException()) |
| 563 return nullptr; | 551 return nullptr; |
| 564 return newChild; | 552 return newChild; |
| 565 } | 553 } |
| 566 ASSERT(newChild); | 554 ASSERT(newChild); |
| 567 | 555 |
| 568 if (newChild == m_lastChild) // nothing to do | 556 if (newChild == m_lastChild) // nothing to do |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 | 936 |
| 949 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors
, document(), exceptionState); | 937 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors
, document(), exceptionState); |
| 950 if (!selectorQuery) | 938 if (!selectorQuery) |
| 951 return nullptr; | 939 return nullptr; |
| 952 | 940 |
| 953 return selectorQuery->queryAll(*this); | 941 return selectorQuery->queryAll(*this); |
| 954 } | 942 } |
| 955 | 943 |
| 956 void ContainerNode::updateTreeAfterInsertion(Node& child) | 944 void ContainerNode::updateTreeAfterInsertion(Node& child) |
| 957 { | 945 { |
| 958 #if !ENABLE(OILPAN) | |
| 959 ASSERT(refCount()); | 946 ASSERT(refCount()); |
| 960 ASSERT(child.refCount()); | 947 ASSERT(child.refCount()); |
| 961 #endif | |
| 962 | 948 |
| 963 ChildListMutationScope(*this).childAdded(child); | 949 ChildListMutationScope(*this).childAdded(child); |
| 964 | 950 |
| 965 notifyNodeInserted(child); | 951 notifyNodeInserted(child); |
| 966 } | 952 } |
| 967 | 953 |
| 968 Element* ContainerNode::getElementById(const AtomicString& id) const | 954 Element* ContainerNode::getElementById(const AtomicString& id) const |
| 969 { | 955 { |
| 970 if (isInTreeScope()) { | 956 if (isInTreeScope()) { |
| 971 // Fast path if we are in a tree scope: call getElementById() on tree sc
ope | 957 // Fast path if we are in a tree scope: call getElementById() on tree sc
ope |
| (...skipping 23 matching lines...) Expand all Loading... |
| 995 return true; | 981 return true; |
| 996 | 982 |
| 997 if (node->isElementNode() && toElement(node)->shadow()) | 983 if (node->isElementNode() && toElement(node)->shadow()) |
| 998 return true; | 984 return true; |
| 999 | 985 |
| 1000 return false; | 986 return false; |
| 1001 } | 987 } |
| 1002 #endif | 988 #endif |
| 1003 | 989 |
| 1004 } // namespace blink | 990 } // namespace blink |
| OLD | NEW |