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 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. |
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
(...skipping 3234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3245 // Documents may contain no more than one of each of these. | 3245 // Documents may contain no more than one of each of these. |
3246 // (One Element and one DocumentType.) | 3246 // (One Element and one DocumentType.) |
3247 for (Node& c : NodeTraversal::childrenOf(*this)) | 3247 for (Node& c : NodeTraversal::childrenOf(*this)) |
3248 if (c.nodeType() == type) | 3248 if (c.nodeType() == type) |
3249 return false; | 3249 return false; |
3250 return true; | 3250 return true; |
3251 } | 3251 } |
3252 return false; | 3252 return false; |
3253 } | 3253 } |
3254 | 3254 |
3255 bool Document::canReplaceChild(const Node& newChild, const Node& oldChild) const | 3255 bool Document::canAcceptChild(const Node& newChild, const Node* oldChild, Except ionState& exceptionState) const |
3256 { | 3256 { |
3257 if (oldChild.nodeType() == newChild.nodeType()) | 3257 if (oldChild && oldChild->nodeType() == newChild.nodeType()) |
3258 return true; | 3258 return true; |
3259 | 3259 |
3260 int numDoctypes = 0; | 3260 int numDoctypes = 0; |
3261 int numElements = 0; | 3261 int numElements = 0; |
3262 | 3262 |
3263 // First, check how many doctypes and elements we have, not counting | 3263 // First, check how many doctypes and elements we have, not counting |
3264 // the child we're about to remove. | 3264 // the child we're about to remove. |
3265 for (Node& c : NodeTraversal::childrenOf(*this)) { | 3265 for (Node& c : NodeTraversal::childrenOf(*this)) { |
3266 if (c == oldChild) | 3266 if (oldChild && *oldChild == c) |
esprehn
2014/12/05 19:18:24
it might be nice to rename "c" to "child" while yo
| |
3267 continue; | 3267 continue; |
3268 | 3268 |
3269 switch (c.nodeType()) { | 3269 switch (c.nodeType()) { |
3270 case DOCUMENT_TYPE_NODE: | 3270 case DOCUMENT_TYPE_NODE: |
3271 numDoctypes++; | 3271 numDoctypes++; |
3272 break; | 3272 break; |
3273 case ELEMENT_NODE: | 3273 case ELEMENT_NODE: |
3274 numElements++; | 3274 numElements++; |
3275 break; | 3275 break; |
3276 default: | 3276 default: |
3277 break; | 3277 break; |
3278 } | 3278 } |
3279 } | 3279 } |
3280 | 3280 |
3281 // Then, see how many doctypes and elements might be added by the new child. | 3281 // Then, see how many doctypes and elements might be added by the new child. |
3282 if (newChild.isDocumentFragment()) { | 3282 if (newChild.isDocumentFragment()) { |
3283 for (Node& c : NodeTraversal::childrenOf(toDocumentFragment(newChild))) { | 3283 for (Node& c : NodeTraversal::childrenOf(toDocumentFragment(newChild))) { |
3284 switch (c.nodeType()) { | 3284 switch (c.nodeType()) { |
3285 case ATTRIBUTE_NODE: | 3285 case ATTRIBUTE_NODE: |
3286 case CDATA_SECTION_NODE: | 3286 case CDATA_SECTION_NODE: |
3287 case DOCUMENT_FRAGMENT_NODE: | 3287 case DOCUMENT_FRAGMENT_NODE: |
3288 case DOCUMENT_NODE: | 3288 case DOCUMENT_NODE: |
3289 case TEXT_NODE: | 3289 case TEXT_NODE: |
3290 exceptionState.throwDOMException(HierarchyRequestError, "Nodes o f type '" + newChild.nodeName() + | |
3291 "' may not be inserted inside nodes of type '#document'."); | |
3290 return false; | 3292 return false; |
3291 case COMMENT_NODE: | 3293 case COMMENT_NODE: |
3292 case PROCESSING_INSTRUCTION_NODE: | 3294 case PROCESSING_INSTRUCTION_NODE: |
3293 break; | 3295 break; |
3294 case DOCUMENT_TYPE_NODE: | 3296 case DOCUMENT_TYPE_NODE: |
3295 numDoctypes++; | 3297 numDoctypes++; |
3296 break; | 3298 break; |
3297 case ELEMENT_NODE: | 3299 case ELEMENT_NODE: |
3298 numElements++; | 3300 numElements++; |
3299 break; | 3301 break; |
3300 } | 3302 } |
3301 } | 3303 } |
3302 } else { | 3304 } else { |
3303 switch (newChild.nodeType()) { | 3305 switch (newChild.nodeType()) { |
3304 case ATTRIBUTE_NODE: | 3306 case ATTRIBUTE_NODE: |
3305 case CDATA_SECTION_NODE: | 3307 case CDATA_SECTION_NODE: |
3306 case DOCUMENT_FRAGMENT_NODE: | 3308 case DOCUMENT_FRAGMENT_NODE: |
3307 case DOCUMENT_NODE: | 3309 case DOCUMENT_NODE: |
3308 case TEXT_NODE: | 3310 case TEXT_NODE: |
3311 exceptionState.throwDOMException(HierarchyRequestError, "Nodes of ty pe '" + newChild.nodeName() + | |
3312 "' may not be inserted inside nodes of type '#document'."); | |
3309 return false; | 3313 return false; |
3310 case COMMENT_NODE: | 3314 case COMMENT_NODE: |
3311 case PROCESSING_INSTRUCTION_NODE: | 3315 case PROCESSING_INSTRUCTION_NODE: |
3312 return true; | 3316 return true; |
3313 case DOCUMENT_TYPE_NODE: | 3317 case DOCUMENT_TYPE_NODE: |
3314 numDoctypes++; | 3318 numDoctypes++; |
3315 break; | 3319 break; |
3316 case ELEMENT_NODE: | 3320 case ELEMENT_NODE: |
3317 numElements++; | 3321 numElements++; |
3318 break; | 3322 break; |
3319 } | 3323 } |
3320 } | 3324 } |
3321 | 3325 |
3322 if (numElements > 1 || numDoctypes > 1) | 3326 if (numElements > 1 || numDoctypes > 1) { |
3327 exceptionState.throwDOMException(HierarchyRequestError, | |
3328 String::format("Only one %s on document allowed.", | |
3329 numElements > 1 ? "element" : "doctype")); | |
3323 return false; | 3330 return false; |
3331 } | |
3324 | 3332 |
3325 return true; | 3333 return true; |
3326 } | 3334 } |
3327 | 3335 |
3328 PassRefPtrWillBeRawPtr<Node> Document::cloneNode(bool deep) | 3336 PassRefPtrWillBeRawPtr<Node> Document::cloneNode(bool deep) |
3329 { | 3337 { |
3330 RefPtrWillBeRawPtr<Document> clone = cloneDocumentWithoutChildren(); | 3338 RefPtrWillBeRawPtr<Document> clone = cloneDocumentWithoutChildren(); |
3331 clone->cloneDataFromDocument(*this); | 3339 clone->cloneDataFromDocument(*this); |
3332 if (deep) | 3340 if (deep) |
3333 cloneChildNodes(clone.get()); | 3341 cloneChildNodes(clone.get()); |
(...skipping 2489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5823 #ifndef NDEBUG | 5831 #ifndef NDEBUG |
5824 using namespace blink; | 5832 using namespace blink; |
5825 void showLiveDocumentInstances() | 5833 void showLiveDocumentInstances() |
5826 { | 5834 { |
5827 WeakDocumentSet& set = liveDocumentSet(); | 5835 WeakDocumentSet& set = liveDocumentSet(); |
5828 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 5836 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
5829 for (Document* document : set) | 5837 for (Document* document : set) |
5830 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); | 5838 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); |
5831 } | 5839 } |
5832 #endif | 5840 #endif |
OLD | NEW |