| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 { | 118 { |
| 119 return (newParent->isInShadowTree() || isInTemplateContent(newParent)) | 119 return (newParent->isInShadowTree() || isInTemplateContent(newParent)) |
| 120 ? newChild->containsIncludingHostElements(newParent) | 120 ? newChild->containsIncludingHostElements(newParent) |
| 121 : newChild->contains(newParent); | 121 : newChild->contains(newParent); |
| 122 } | 122 } |
| 123 | 123 |
| 124 static inline bool checkAcceptChild(ContainerNode* newParent, Node* newChild, No
de* oldChild, const String& method, ExceptionState& es) | 124 static inline bool checkAcceptChild(ContainerNode* newParent, Node* newChild, No
de* oldChild, const String& method, ExceptionState& es) |
| 125 { | 125 { |
| 126 // Not mentioned in spec: throw NotFoundError if newChild is null | 126 // Not mentioned in spec: throw NotFoundError if newChild is null |
| 127 if (!newChild) { | 127 if (!newChild) { |
| 128 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute(m
ethod, "ContainerNode", "The new child element is null.")); | 128 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute(m
ethod, "Node", "The new child element is null.")); |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Use common case fast path if possible. | 132 // Use common case fast path if possible. |
| 133 if ((newChild->isElementNode() || newChild->isTextNode()) && newParent->isEl
ementNode()) { | 133 if ((newChild->isElementNode() || newChild->isTextNode()) && newParent->isEl
ementNode()) { |
| 134 ASSERT(!newParent->isDocumentTypeNode()); | 134 ASSERT(!newParent->isDocumentTypeNode()); |
| 135 ASSERT(isChildTypeAllowed(newParent, newChild)); | 135 ASSERT(isChildTypeAllowed(newParent, newChild)); |
| 136 if (containsConsideringHostElements(newChild, newParent)) { | 136 if (containsConsideringHostElements(newChild, newParent)) { |
| 137 es.throwDOMException(HierarchyRequestError, ExceptionMessages::faile
dToExecute(method, "ContainerNode", "The new child element contains the parent."
)); | 137 es.throwDOMException(HierarchyRequestError, ExceptionMessages::faile
dToExecute(method, "Node", "The new child element contains the parent.")); |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 return true; | 140 return true; |
| 141 } | 141 } |
| 142 | 142 |
| 143 // This should never happen, but also protect release builds from tree corru
ption. | 143 // This should never happen, but also protect release builds from tree corru
ption. |
| 144 ASSERT(!newChild->isPseudoElement()); | 144 ASSERT(!newChild->isPseudoElement()); |
| 145 if (newChild->isPseudoElement()) { | 145 if (newChild->isPseudoElement()) { |
| 146 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "ContainerNode", "The new child element is a pseudo-element.")); | 146 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "Node", "The new child element is a pseudo-element.")); |
| 147 return false; | 147 return false; |
| 148 } | 148 } |
| 149 | 149 |
| 150 if (containsConsideringHostElements(newChild, newParent)) { | 150 if (containsConsideringHostElements(newChild, newParent)) { |
| 151 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "ContainerNode", "The new child element contains the parent.")); | 151 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "Node", "The new child element contains the parent.")); |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (oldChild && newParent->isDocumentNode()) { | 155 if (oldChild && newParent->isDocumentNode()) { |
| 156 if (!toDocument(newParent)->canReplaceChild(newChild, oldChild)) { | 156 if (!toDocument(newParent)->canReplaceChild(newChild, oldChild)) { |
| 157 // FIXME: Adjust 'Document::canReplaceChild' to return some addition
al detail (or an error message). | 157 // FIXME: Adjust 'Document::canReplaceChild' to return some addition
al detail (or an error message). |
| 158 es.throwDOMException(HierarchyRequestError, ExceptionMessages::faile
dToExecute(method, "ContainerNode")); | 158 es.throwDOMException(HierarchyRequestError, ExceptionMessages::faile
dToExecute(method, "ContainerNode")); |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 } else if (!isChildTypeAllowed(newParent, newChild)) { | 161 } else if (!isChildTypeAllowed(newParent, newChild)) { |
| 162 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "ContainerNode", "Nodes of type '" + newChild->nodeName() + "' ma
y not be inserted inside nodes of type '" + newParent->nodeName() + "'.")); | 162 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "Node", "Nodes of type '" + newChild->nodeName() + "' may not be
inserted inside nodes of type '" + newParent->nodeName() + "'.")); |
| 163 return false; | 163 return false; |
| 164 } | 164 } |
| 165 | 165 |
| 166 return true; | 166 return true; |
| 167 } | 167 } |
| 168 | 168 |
| 169 static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent,
Node* newChild, const String& method, ExceptionState& es) | 169 static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent,
Node* newChild, const String& method, ExceptionState& es) |
| 170 { | 170 { |
| 171 ASSERT(!newParent->isDocumentTypeNode()); | 171 ASSERT(!newParent->isDocumentTypeNode()); |
| 172 ASSERT(isChildTypeAllowed(newParent, newChild)); | 172 ASSERT(isChildTypeAllowed(newParent, newChild)); |
| 173 if (newChild->contains(newParent)) { | 173 if (newChild->contains(newParent)) { |
| 174 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "ContainerNode", "The new child element contains the parent.")); | 174 es.throwDOMException(HierarchyRequestError, ExceptionMessages::failedToE
xecute(method, "Node", "The new child element contains the parent.")); |
| 175 return false; | 175 return false; |
| 176 } | 176 } |
| 177 | 177 |
| 178 return true; | 178 return true; |
| 179 } | 179 } |
| 180 | 180 |
| 181 static inline bool checkAddChild(ContainerNode* newParent, Node* newChild, const
String& method, ExceptionState& es) | 181 static inline bool checkAddChild(ContainerNode* newParent, Node* newChild, const
String& method, ExceptionState& es) |
| 182 { | 182 { |
| 183 return checkAcceptChild(newParent, newChild, 0, method, es); | 183 return checkAcceptChild(newParent, newChild, 0, method, es); |
| 184 } | 184 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 201 appendChild(newChild, es); | 201 appendChild(newChild, es); |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 | 204 |
| 205 // Make sure adding the new child is OK. | 205 // Make sure adding the new child is OK. |
| 206 if (!checkAddChild(this, newChild.get(), "insertBefore", es)) | 206 if (!checkAddChild(this, newChild.get(), "insertBefore", es)) |
| 207 return; | 207 return; |
| 208 | 208 |
| 209 // NotFoundError: Raised if refChild is not a child of this node | 209 // NotFoundError: Raised if refChild is not a child of this node |
| 210 if (refChild->parentNode() != this) { | 210 if (refChild->parentNode() != this) { |
| 211 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
insertBefore", "ContainerNode", "The node before which the new node is to be ins
erted is not a child of this node.")); | 211 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
insertBefore", "Node", "The node before which the new node is to be inserted is
not a child of this node.")); |
| 212 return; | 212 return; |
| 213 } | 213 } |
| 214 | 214 |
| 215 if (refChild->previousSibling() == newChild || refChild == newChild) // noth
ing to do | 215 if (refChild->previousSibling() == newChild || refChild == newChild) // noth
ing to do |
| 216 return; | 216 return; |
| 217 | 217 |
| 218 RefPtr<Node> next = refChild; | 218 RefPtr<Node> next = refChild; |
| 219 | 219 |
| 220 NodeVector targets; | 220 NodeVector targets; |
| 221 collectChildrenAndRemoveFromOldParent(newChild.get(), targets, es); | 221 collectChildrenAndRemoveFromOldParent(newChild.get(), targets, es); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // Check that this node is not "floating". | 309 // Check that this node is not "floating". |
| 310 // If it is, it can be deleted as a side effect of sending mutation events. | 310 // If it is, it can be deleted as a side effect of sending mutation events. |
| 311 ASSERT(refCount() || parentOrShadowHostNode()); | 311 ASSERT(refCount() || parentOrShadowHostNode()); |
| 312 | 312 |
| 313 RefPtr<Node> protect(this); | 313 RefPtr<Node> protect(this); |
| 314 | 314 |
| 315 if (oldChild == newChild) // nothing to do | 315 if (oldChild == newChild) // nothing to do |
| 316 return; | 316 return; |
| 317 | 317 |
| 318 if (!oldChild) { | 318 if (!oldChild) { |
| 319 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
replaceChild", "ContainerNode", "The node to be replaced is null.")); | 319 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
replaceChild", "Node", "The node to be replaced is null.")); |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 | 322 |
| 323 // Make sure replacing the old child with the new is ok | 323 // Make sure replacing the old child with the new is ok |
| 324 if (!checkReplaceChild(this, newChild.get(), oldChild, "replaceChild", es)) | 324 if (!checkReplaceChild(this, newChild.get(), oldChild, "replaceChild", es)) |
| 325 return; | 325 return; |
| 326 | 326 |
| 327 // NotFoundError: Raised if oldChild is not a child of this node. | 327 // NotFoundError: Raised if oldChild is not a child of this node. |
| 328 if (oldChild->parentNode() != this) { | 328 if (oldChild->parentNode() != this) { |
| 329 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
replaceChild", "ContainerNode", "The node to be replaced is not a child of this
node.")); | 329 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
replaceChild", "Node", "The node to be replaced is not a child of this node.")); |
| 330 return; | 330 return; |
| 331 } | 331 } |
| 332 | 332 |
| 333 ChildListMutationScope mutation(this); | 333 ChildListMutationScope mutation(this); |
| 334 | 334 |
| 335 RefPtr<Node> next = oldChild->nextSibling(); | 335 RefPtr<Node> next = oldChild->nextSibling(); |
| 336 | 336 |
| 337 // Remove the node we're replacing | 337 // Remove the node we're replacing |
| 338 RefPtr<Node> removedChild = oldChild; | 338 RefPtr<Node> removedChild = oldChild; |
| 339 removeChild(oldChild, es); | 339 removeChild(oldChild, es); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 void ContainerNode::removeChild(Node* oldChild, ExceptionState& es) | 426 void ContainerNode::removeChild(Node* oldChild, ExceptionState& es) |
| 427 { | 427 { |
| 428 // Check that this node is not "floating". | 428 // Check that this node is not "floating". |
| 429 // 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. |
| 430 ASSERT(refCount() || parentOrShadowHostNode()); | 430 ASSERT(refCount() || parentOrShadowHostNode()); |
| 431 | 431 |
| 432 RefPtr<Node> protect(this); | 432 RefPtr<Node> protect(this); |
| 433 | 433 |
| 434 // NotFoundError: Raised if oldChild is not a child of this node. | 434 // NotFoundError: Raised if oldChild is not a child of this node. |
| 435 if (!oldChild || oldChild->parentNode() != this) { | 435 if (!oldChild || oldChild->parentNode() != this) { |
| 436 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
removeChild", "ContainerNode", "The node to be removed is not a child of this no
de.")); | 436 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
removeChild", "Node", "The node to be removed is not a child of this node.")); |
| 437 return; | 437 return; |
| 438 } | 438 } |
| 439 | 439 |
| 440 RefPtr<Node> child = oldChild; | 440 RefPtr<Node> child = oldChild; |
| 441 | 441 |
| 442 document().removeFocusedElementOfSubtree(child.get()); | 442 document().removeFocusedElementOfSubtree(child.get()); |
| 443 | 443 |
| 444 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(&document())) | 444 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(&document())) |
| 445 fullscreen->removeFullScreenElementOfSubtree(child.get()); | 445 fullscreen->removeFullScreenElementOfSubtree(child.get()); |
| 446 | 446 |
| 447 // Events fired when blurring currently focused node might have moved this | 447 // Events fired when blurring currently focused node might have moved this |
| 448 // child into a different parent. | 448 // child into a different parent. |
| 449 if (child->parentNode() != this) { | 449 if (child->parentNode() != this) { |
| 450 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
removeChild", "ContainerNode", "The node to be removed is no longer a child of t
his node. Perhaps it was moved in a 'blur' event handler?")); | 450 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
removeChild", "Node", "The node to be removed is no longer a child of this node.
Perhaps it was moved in a 'blur' event handler?")); |
| 451 return; | 451 return; |
| 452 } | 452 } |
| 453 | 453 |
| 454 willRemoveChild(child.get()); | 454 willRemoveChild(child.get()); |
| 455 | 455 |
| 456 // Mutation events might have moved this child into a different parent. | 456 // Mutation events might have moved this child into a different parent. |
| 457 if (child->parentNode() != this) { | 457 if (child->parentNode() != this) { |
| 458 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
removeChild", "ContainerNode", "The node to be removed is no longer a child of t
his node. Perhaps it was moved in response to a mutation?")); | 458 es.throwDOMException(NotFoundError, ExceptionMessages::failedToExecute("
removeChild", "Node", "The node to be removed is no longer a child of this node.
Perhaps it was moved in response to a mutation?")); |
| 459 return; | 459 return; |
| 460 } | 460 } |
| 461 | 461 |
| 462 { | 462 { |
| 463 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; | 463 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; |
| 464 | 464 |
| 465 Node* prev = child->previousSibling(); | 465 Node* prev = child->previousSibling(); |
| 466 Node* next = child->nextSibling(); | 466 Node* next = child->nextSibling(); |
| 467 removeBetween(prev, next, child.get()); | 467 removeBetween(prev, next, child.get()); |
| 468 childrenChanged(false, prev, next, -1); | 468 childrenChanged(false, prev, next, -1); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 return true; | 981 return true; |
| 982 | 982 |
| 983 if (node->isElementNode() && toElement(node)->shadow()) | 983 if (node->isElementNode() && toElement(node)->shadow()) |
| 984 return true; | 984 return true; |
| 985 | 985 |
| 986 return false; | 986 return false; |
| 987 } | 987 } |
| 988 #endif | 988 #endif |
| 989 | 989 |
| 990 } // namespace WebCore | 990 } // namespace WebCore |
| OLD | NEW |