| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 { | 137 { |
| 138 return (newParent->isInShadowTree() || isInTemplateContent(newParent)) | 138 return (newParent->isInShadowTree() || isInTemplateContent(newParent)) |
| 139 ? newChild->containsIncludingHostElements(newParent) | 139 ? newChild->containsIncludingHostElements(newParent) |
| 140 : newChild->contains(newParent); | 140 : newChild->contains(newParent); |
| 141 } | 141 } |
| 142 | 142 |
| 143 static inline bool checkAcceptChild(ContainerNode* newParent, Node* newChild, No
de* oldChild, ExceptionState& es) | 143 static inline bool checkAcceptChild(ContainerNode* newParent, Node* newChild, No
de* oldChild, ExceptionState& es) |
| 144 { | 144 { |
| 145 // Not mentioned in spec: throw NotFoundError if newChild is null | 145 // Not mentioned in spec: throw NotFoundError if newChild is null |
| 146 if (!newChild) { | 146 if (!newChild) { |
| 147 es.throwDOMException(NotFoundError); | 147 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Use common case fast path if possible. | 151 // Use common case fast path if possible. |
| 152 if ((newChild->isElementNode() || newChild->isTextNode()) && newParent->isEl
ementNode()) { | 152 if ((newChild->isElementNode() || newChild->isTextNode()) && newParent->isEl
ementNode()) { |
| 153 ASSERT(!newParent->isDocumentTypeNode()); | 153 ASSERT(!newParent->isDocumentTypeNode()); |
| 154 ASSERT(isChildTypeAllowed(newParent, newChild)); | 154 ASSERT(isChildTypeAllowed(newParent, newChild)); |
| 155 if (containsConsideringHostElements(newChild, newParent)) { | 155 if (containsConsideringHostElements(newChild, newParent)) { |
| 156 es.throwDOMException(HierarchyRequestError); | 156 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 return true; | 159 return true; |
| 160 } | 160 } |
| 161 | 161 |
| 162 // This should never happen, but also protect release builds from tree corru
ption. | 162 // This should never happen, but also protect release builds from tree corru
ption. |
| 163 ASSERT(!newChild->isPseudoElement()); | 163 ASSERT(!newChild->isPseudoElement()); |
| 164 if (newChild->isPseudoElement()) { | 164 if (newChild->isPseudoElement()) { |
| 165 es.throwDOMException(HierarchyRequestError); | 165 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 166 return false; | 166 return false; |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (containsConsideringHostElements(newChild, newParent)) { | 169 if (containsConsideringHostElements(newChild, newParent)) { |
| 170 es.throwDOMException(HierarchyRequestError); | 170 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| 173 | 173 |
| 174 if (oldChild && newParent->isDocumentNode()) { | 174 if (oldChild && newParent->isDocumentNode()) { |
| 175 if (!toDocument(newParent)->canReplaceChild(newChild, oldChild)) { | 175 if (!toDocument(newParent)->canReplaceChild(newChild, oldChild)) { |
| 176 es.throwDOMException(HierarchyRequestError); | 176 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 177 return false; | 177 return false; |
| 178 } | 178 } |
| 179 } else if (!isChildTypeAllowed(newParent, newChild)) { | 179 } else if (!isChildTypeAllowed(newParent, newChild)) { |
| 180 es.throwDOMException(HierarchyRequestError); | 180 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 181 return false; | 181 return false; |
| 182 } | 182 } |
| 183 | 183 |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent,
Node* newChild, ExceptionState& es) | 187 static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent,
Node* newChild, ExceptionState& es) |
| 188 { | 188 { |
| 189 ASSERT(!newParent->isDocumentTypeNode()); | 189 ASSERT(!newParent->isDocumentTypeNode()); |
| 190 ASSERT(isChildTypeAllowed(newParent, newChild)); | 190 ASSERT(isChildTypeAllowed(newParent, newChild)); |
| 191 if (newChild->contains(newParent)) { | 191 if (newChild->contains(newParent)) { |
| 192 es.throwDOMException(HierarchyRequestError); | 192 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
| 193 return false; | 193 return false; |
| 194 } | 194 } |
| 195 | 195 |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| 198 | 198 |
| 199 static inline bool checkAddChild(ContainerNode* newParent, Node* newChild, Excep
tionState& es) | 199 static inline bool checkAddChild(ContainerNode* newParent, Node* newChild, Excep
tionState& es) |
| 200 { | 200 { |
| 201 return checkAcceptChild(newParent, newChild, 0, es); | 201 return checkAcceptChild(newParent, newChild, 0, es); |
| 202 } | 202 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 219 appendChild(newChild, es); | 219 appendChild(newChild, es); |
| 220 return; | 220 return; |
| 221 } | 221 } |
| 222 | 222 |
| 223 // Make sure adding the new child is OK. | 223 // Make sure adding the new child is OK. |
| 224 if (!checkAddChild(this, newChild.get(), es)) | 224 if (!checkAddChild(this, newChild.get(), es)) |
| 225 return; | 225 return; |
| 226 | 226 |
| 227 // NotFoundError: Raised if refChild is not a child of this node | 227 // NotFoundError: Raised if refChild is not a child of this node |
| 228 if (refChild->parentNode() != this) { | 228 if (refChild->parentNode() != this) { |
| 229 es.throwDOMException(NotFoundError); | 229 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 | 232 |
| 233 if (refChild->previousSibling() == newChild || refChild == newChild) // noth
ing to do | 233 if (refChild->previousSibling() == newChild || refChild == newChild) // noth
ing to do |
| 234 return; | 234 return; |
| 235 | 235 |
| 236 RefPtr<Node> next = refChild; | 236 RefPtr<Node> next = refChild; |
| 237 | 237 |
| 238 NodeVector targets; | 238 NodeVector targets; |
| 239 collectChildrenAndRemoveFromOldParent(newChild.get(), targets, es); | 239 collectChildrenAndRemoveFromOldParent(newChild.get(), targets, es); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // Check that this node is not "floating". | 327 // Check that this node is not "floating". |
| 328 // If it is, it can be deleted as a side effect of sending mutation events. | 328 // If it is, it can be deleted as a side effect of sending mutation events. |
| 329 ASSERT(refCount() || parentOrShadowHostNode()); | 329 ASSERT(refCount() || parentOrShadowHostNode()); |
| 330 | 330 |
| 331 RefPtr<Node> protect(this); | 331 RefPtr<Node> protect(this); |
| 332 | 332 |
| 333 if (oldChild == newChild) // nothing to do | 333 if (oldChild == newChild) // nothing to do |
| 334 return; | 334 return; |
| 335 | 335 |
| 336 if (!oldChild) { | 336 if (!oldChild) { |
| 337 es.throwDOMException(NotFoundError); | 337 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 338 return; | 338 return; |
| 339 } | 339 } |
| 340 | 340 |
| 341 // Make sure replacing the old child with the new is ok | 341 // Make sure replacing the old child with the new is ok |
| 342 if (!checkReplaceChild(this, newChild.get(), oldChild, es)) | 342 if (!checkReplaceChild(this, newChild.get(), oldChild, es)) |
| 343 return; | 343 return; |
| 344 | 344 |
| 345 // NotFoundError: Raised if oldChild is not a child of this node. | 345 // NotFoundError: Raised if oldChild is not a child of this node. |
| 346 if (oldChild->parentNode() != this) { | 346 if (oldChild->parentNode() != this) { |
| 347 es.throwDOMException(NotFoundError); | 347 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 348 return; | 348 return; |
| 349 } | 349 } |
| 350 | 350 |
| 351 ChildListMutationScope mutation(this); | 351 ChildListMutationScope mutation(this); |
| 352 | 352 |
| 353 RefPtr<Node> next = oldChild->nextSibling(); | 353 RefPtr<Node> next = oldChild->nextSibling(); |
| 354 | 354 |
| 355 // Remove the node we're replacing | 355 // Remove the node we're replacing |
| 356 RefPtr<Node> removedChild = oldChild; | 356 RefPtr<Node> removedChild = oldChild; |
| 357 removeChild(oldChild, es); | 357 removeChild(oldChild, es); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 void ContainerNode::removeChild(Node* oldChild, ExceptionState& es) | 444 void ContainerNode::removeChild(Node* oldChild, ExceptionState& es) |
| 445 { | 445 { |
| 446 // Check that this node is not "floating". | 446 // Check that this node is not "floating". |
| 447 // If it is, it can be deleted as a side effect of sending mutation events. | 447 // If it is, it can be deleted as a side effect of sending mutation events. |
| 448 ASSERT(refCount() || parentOrShadowHostNode()); | 448 ASSERT(refCount() || parentOrShadowHostNode()); |
| 449 | 449 |
| 450 RefPtr<Node> protect(this); | 450 RefPtr<Node> protect(this); |
| 451 | 451 |
| 452 // NotFoundError: Raised if oldChild is not a child of this node. | 452 // NotFoundError: Raised if oldChild is not a child of this node. |
| 453 if (!oldChild || oldChild->parentNode() != this) { | 453 if (!oldChild || oldChild->parentNode() != this) { |
| 454 es.throwDOMException(NotFoundError); | 454 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 455 return; | 455 return; |
| 456 } | 456 } |
| 457 | 457 |
| 458 RefPtr<Node> child = oldChild; | 458 RefPtr<Node> child = oldChild; |
| 459 | 459 |
| 460 document().removeFocusedElementOfSubtree(child.get()); | 460 document().removeFocusedElementOfSubtree(child.get()); |
| 461 | 461 |
| 462 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(&document())) | 462 if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExist
s(&document())) |
| 463 fullscreen->removeFullScreenElementOfSubtree(child.get()); | 463 fullscreen->removeFullScreenElementOfSubtree(child.get()); |
| 464 | 464 |
| 465 // Events fired when blurring currently focused node might have moved this | 465 // Events fired when blurring currently focused node might have moved this |
| 466 // child into a different parent. | 466 // child into a different parent. |
| 467 if (child->parentNode() != this) { | 467 if (child->parentNode() != this) { |
| 468 es.throwDOMException(NotFoundError); | 468 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 469 return; | 469 return; |
| 470 } | 470 } |
| 471 | 471 |
| 472 willRemoveChild(child.get()); | 472 willRemoveChild(child.get()); |
| 473 | 473 |
| 474 // Mutation events might have moved this child into a different parent. | 474 // Mutation events might have moved this child into a different parent. |
| 475 if (child->parentNode() != this) { | 475 if (child->parentNode() != this) { |
| 476 es.throwDOMException(NotFoundError); | 476 es.throwUninformativeAndGenericDOMException(NotFoundError); |
| 477 return; | 477 return; |
| 478 } | 478 } |
| 479 | 479 |
| 480 { | 480 { |
| 481 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; | 481 WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; |
| 482 | 482 |
| 483 Node* prev = child->previousSibling(); | 483 Node* prev = child->previousSibling(); |
| 484 Node* next = child->nextSibling(); | 484 Node* next = child->nextSibling(); |
| 485 removeBetween(prev, next, child.get()); | 485 removeBetween(prev, next, child.get()); |
| 486 childrenChanged(false, prev, next, -1); | 486 childrenChanged(false, prev, next, -1); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 return true; | 999 return true; |
| 1000 | 1000 |
| 1001 if (node->isElementNode() && toElement(node)->shadow()) | 1001 if (node->isElementNode() && toElement(node)->shadow()) |
| 1002 return true; | 1002 return true; |
| 1003 | 1003 |
| 1004 return false; | 1004 return false; |
| 1005 } | 1005 } |
| 1006 #endif | 1006 #endif |
| 1007 | 1007 |
| 1008 } // namespace WebCore | 1008 } // namespace WebCore |
| OLD | NEW |