| 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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 if (exceptionState.hadException()) | 827 if (exceptionState.hadException()) |
| 828 return false; | 828 return false; |
| 829 } | 829 } |
| 830 | 830 |
| 831 return true; | 831 return true; |
| 832 } | 832 } |
| 833 | 833 |
| 834 Node* Document::importNode(Node* importedNode, bool deep, ExceptionState& except
ionState) | 834 Node* Document::importNode(Node* importedNode, bool deep, ExceptionState& except
ionState) |
| 835 { | 835 { |
| 836 switch (importedNode->getNodeType()) { | 836 switch (importedNode->getNodeType()) { |
| 837 case TEXT_NODE: | 837 case kTextNode: |
| 838 return createTextNode(importedNode->nodeValue()); | 838 return createTextNode(importedNode->nodeValue()); |
| 839 case CDATA_SECTION_NODE: | 839 case kCdataSectionNode: |
| 840 return CDATASection::create(*this, importedNode->nodeValue()); | 840 return CDATASection::create(*this, importedNode->nodeValue()); |
| 841 case PROCESSING_INSTRUCTION_NODE: | 841 case kProcessingInstructionNode: |
| 842 return createProcessingInstruction(importedNode->nodeName(), importedNod
e->nodeValue(), exceptionState); | 842 return createProcessingInstruction(importedNode->nodeName(), importedNod
e->nodeValue(), exceptionState); |
| 843 case COMMENT_NODE: | 843 case kCommentNode: |
| 844 return createComment(importedNode->nodeValue()); | 844 return createComment(importedNode->nodeValue()); |
| 845 case DOCUMENT_TYPE_NODE: { | 845 case kDocumentTypeNode: { |
| 846 DocumentType* doctype = toDocumentType(importedNode); | 846 DocumentType* doctype = toDocumentType(importedNode); |
| 847 return DocumentType::create(this, doctype->name(), doctype->publicId(),
doctype->systemId()); | 847 return DocumentType::create(this, doctype->name(), doctype->publicId(),
doctype->systemId()); |
| 848 } | 848 } |
| 849 case ELEMENT_NODE: { | 849 case kElementNode: { |
| 850 Element* oldElement = toElement(importedNode); | 850 Element* oldElement = toElement(importedNode); |
| 851 // FIXME: The following check might be unnecessary. Is it possible that | 851 // FIXME: The following check might be unnecessary. Is it possible that |
| 852 // oldElement has mismatched prefix/namespace? | 852 // oldElement has mismatched prefix/namespace? |
| 853 if (!hasValidNamespaceForElements(oldElement->tagQName())) { | 853 if (!hasValidNamespaceForElements(oldElement->tagQName())) { |
| 854 exceptionState.throwDOMException(NamespaceError, "The imported node
has an invalid namespace."); | 854 exceptionState.throwDOMException(NamespaceError, "The imported node
has an invalid namespace."); |
| 855 return nullptr; | 855 return nullptr; |
| 856 } | 856 } |
| 857 Element* newElement = createElement(oldElement->tagQName(), CreatedByImp
ortNode); | 857 Element* newElement = createElement(oldElement->tagQName(), CreatedByImp
ortNode); |
| 858 | 858 |
| 859 newElement->cloneDataFromElement(*oldElement); | 859 newElement->cloneDataFromElement(*oldElement); |
| 860 | 860 |
| 861 if (deep) { | 861 if (deep) { |
| 862 if (!importContainerNodeChildren(oldElement, newElement, exceptionSt
ate)) | 862 if (!importContainerNodeChildren(oldElement, newElement, exceptionSt
ate)) |
| 863 return nullptr; | 863 return nullptr; |
| 864 if (isHTMLTemplateElement(*oldElement) | 864 if (isHTMLTemplateElement(*oldElement) |
| 865 && !ensureTemplateDocument().importContainerNodeChildren( | 865 && !ensureTemplateDocument().importContainerNodeChildren( |
| 866 toHTMLTemplateElement(oldElement)->content(), | 866 toHTMLTemplateElement(oldElement)->content(), |
| 867 toHTMLTemplateElement(newElement)->content(), exceptionState
)) | 867 toHTMLTemplateElement(newElement)->content(), exceptionState
)) |
| 868 return nullptr; | 868 return nullptr; |
| 869 } | 869 } |
| 870 | 870 |
| 871 return newElement; | 871 return newElement; |
| 872 } | 872 } |
| 873 case ATTRIBUTE_NODE: | 873 case kAttributeNode: |
| 874 return Attr::create(*this, QualifiedName(nullAtom, AtomicString(toAttr(i
mportedNode)->name()), nullAtom), toAttr(importedNode)->value()); | 874 return Attr::create(*this, QualifiedName(nullAtom, AtomicString(toAttr(i
mportedNode)->name()), nullAtom), toAttr(importedNode)->value()); |
| 875 case DOCUMENT_FRAGMENT_NODE: { | 875 case kDocumentFragmentNode: { |
| 876 if (importedNode->isShadowRoot()) { | 876 if (importedNode->isShadowRoot()) { |
| 877 // ShadowRoot nodes should not be explicitly importable. | 877 // ShadowRoot nodes should not be explicitly importable. |
| 878 // Either they are imported along with their host node, or created i
mplicitly. | 878 // Either they are imported along with their host node, or created i
mplicitly. |
| 879 exceptionState.throwDOMException(NotSupportedError, "The node provid
ed is a shadow root, which may not be imported."); | 879 exceptionState.throwDOMException(NotSupportedError, "The node provid
ed is a shadow root, which may not be imported."); |
| 880 return nullptr; | 880 return nullptr; |
| 881 } | 881 } |
| 882 DocumentFragment* oldFragment = toDocumentFragment(importedNode); | 882 DocumentFragment* oldFragment = toDocumentFragment(importedNode); |
| 883 DocumentFragment* newFragment = createDocumentFragment(); | 883 DocumentFragment* newFragment = createDocumentFragment(); |
| 884 if (deep && !importContainerNodeChildren(oldFragment, newFragment, excep
tionState)) | 884 if (deep && !importContainerNodeChildren(oldFragment, newFragment, excep
tionState)) |
| 885 return nullptr; | 885 return nullptr; |
| 886 | 886 |
| 887 return newFragment; | 887 return newFragment; |
| 888 } | 888 } |
| 889 case DOCUMENT_NODE: | 889 case kDocumentNode: |
| 890 exceptionState.throwDOMException(NotSupportedError, "The node provided i
s a document, which may not be imported."); | 890 exceptionState.throwDOMException(NotSupportedError, "The node provided i
s a document, which may not be imported."); |
| 891 return nullptr; | 891 return nullptr; |
| 892 } | 892 } |
| 893 | 893 |
| 894 ASSERT_NOT_REACHED(); | 894 ASSERT_NOT_REACHED(); |
| 895 return nullptr; | 895 return nullptr; |
| 896 } | 896 } |
| 897 | 897 |
| 898 Node* Document::adoptNode(Node* source, ExceptionState& exceptionState) | 898 Node* Document::adoptNode(Node* source, ExceptionState& exceptionState) |
| 899 { | 899 { |
| 900 EventQueueScope scope; | 900 EventQueueScope scope; |
| 901 | 901 |
| 902 switch (source->getNodeType()) { | 902 switch (source->getNodeType()) { |
| 903 case DOCUMENT_NODE: | 903 case kDocumentNode: |
| 904 exceptionState.throwDOMException(NotSupportedError, "The node provided i
s of type '" + source->nodeName() + "', which may not be adopted."); | 904 exceptionState.throwDOMException(NotSupportedError, "The node provided i
s of type '" + source->nodeName() + "', which may not be adopted."); |
| 905 return nullptr; | 905 return nullptr; |
| 906 case ATTRIBUTE_NODE: { | 906 case kAttributeNode: { |
| 907 Attr* attr = toAttr(source); | 907 Attr* attr = toAttr(source); |
| 908 if (Element* ownerElement = attr->ownerElement()) | 908 if (Element* ownerElement = attr->ownerElement()) |
| 909 ownerElement->removeAttributeNode(attr, exceptionState); | 909 ownerElement->removeAttributeNode(attr, exceptionState); |
| 910 break; | 910 break; |
| 911 } | 911 } |
| 912 default: | 912 default: |
| 913 if (source->isShadowRoot()) { | 913 if (source->isShadowRoot()) { |
| 914 // ShadowRoot cannot disconnect itself from the host node. | 914 // ShadowRoot cannot disconnect itself from the host node. |
| 915 exceptionState.throwDOMException(HierarchyRequestError, "The node pr
ovided is a shadow root, which may not be adopted."); | 915 exceptionState.throwDOMException(HierarchyRequestError, "The node pr
ovided is a shadow root, which may not be adopted."); |
| 916 return nullptr; | 916 return nullptr; |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 m_canvasFontCache->pruneAll(); | 1342 m_canvasFontCache->pruneAll(); |
| 1343 } | 1343 } |
| 1344 | 1344 |
| 1345 String Document::nodeName() const | 1345 String Document::nodeName() const |
| 1346 { | 1346 { |
| 1347 return "#document"; | 1347 return "#document"; |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 Node::NodeType Document::getNodeType() const | 1350 Node::NodeType Document::getNodeType() const |
| 1351 { | 1351 { |
| 1352 return DOCUMENT_NODE; | 1352 return kDocumentNode; |
| 1353 } | 1353 } |
| 1354 | 1354 |
| 1355 FormController& Document::formController() | 1355 FormController& Document::formController() |
| 1356 { | 1356 { |
| 1357 if (!m_formController) { | 1357 if (!m_formController) { |
| 1358 m_formController = FormController::create(); | 1358 m_formController = FormController::create(); |
| 1359 if (m_frame && m_frame->loader().currentItem() && m_frame->loader().curr
entItem()->isCurrentDocument(this)) | 1359 if (m_frame && m_frame->loader().currentItem() && m_frame->loader().curr
entItem()->isCurrentDocument(this)) |
| 1360 m_frame->loader().currentItem()->setDocumentState(m_formController->
formElementsState()); | 1360 m_frame->loader().currentItem()->setDocumentState(m_formController->
formElementsState()); |
| 1361 } | 1361 } |
| 1362 return *m_formController; | 1362 return *m_formController; |
| (...skipping 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3181 return MouseEventWithHitTestResults(eventWithRegion, result); | 3181 return MouseEventWithHitTestResults(eventWithRegion, result); |
| 3182 } | 3182 } |
| 3183 | 3183 |
| 3184 return MouseEventWithHitTestResults(event, result); | 3184 return MouseEventWithHitTestResults(event, result); |
| 3185 } | 3185 } |
| 3186 | 3186 |
| 3187 // DOM Section 1.1.1 | 3187 // DOM Section 1.1.1 |
| 3188 bool Document::childTypeAllowed(NodeType type) const | 3188 bool Document::childTypeAllowed(NodeType type) const |
| 3189 { | 3189 { |
| 3190 switch (type) { | 3190 switch (type) { |
| 3191 case ATTRIBUTE_NODE: | 3191 case kAttributeNode: |
| 3192 case CDATA_SECTION_NODE: | 3192 case kCdataSectionNode: |
| 3193 case DOCUMENT_FRAGMENT_NODE: | 3193 case kDocumentFragmentNode: |
| 3194 case DOCUMENT_NODE: | 3194 case kDocumentNode: |
| 3195 case TEXT_NODE: | 3195 case kTextNode: |
| 3196 return false; | 3196 return false; |
| 3197 case COMMENT_NODE: | 3197 case kCommentNode: |
| 3198 case PROCESSING_INSTRUCTION_NODE: | 3198 case kProcessingInstructionNode: |
| 3199 return true; | 3199 return true; |
| 3200 case DOCUMENT_TYPE_NODE: | 3200 case kDocumentTypeNode: |
| 3201 case ELEMENT_NODE: | 3201 case kElementNode: |
| 3202 // Documents may contain no more than one of each of these. | 3202 // Documents may contain no more than one of each of these. |
| 3203 // (One Element and one DocumentType.) | 3203 // (One Element and one DocumentType.) |
| 3204 for (Node& c : NodeTraversal::childrenOf(*this)) { | 3204 for (Node& c : NodeTraversal::childrenOf(*this)) { |
| 3205 if (c.getNodeType() == type) | 3205 if (c.getNodeType() == type) |
| 3206 return false; | 3206 return false; |
| 3207 } | 3207 } |
| 3208 return true; | 3208 return true; |
| 3209 } | 3209 } |
| 3210 return false; | 3210 return false; |
| 3211 } | 3211 } |
| 3212 | 3212 |
| 3213 bool Document::canAcceptChild(const Node& newChild, const Node* oldChild, Except
ionState& exceptionState) const | 3213 bool Document::canAcceptChild(const Node& newChild, const Node* oldChild, Except
ionState& exceptionState) const |
| 3214 { | 3214 { |
| 3215 if (oldChild && oldChild->getNodeType() == newChild.getNodeType()) | 3215 if (oldChild && oldChild->getNodeType() == newChild.getNodeType()) |
| 3216 return true; | 3216 return true; |
| 3217 | 3217 |
| 3218 int numDoctypes = 0; | 3218 int numDoctypes = 0; |
| 3219 int numElements = 0; | 3219 int numElements = 0; |
| 3220 | 3220 |
| 3221 // First, check how many doctypes and elements we have, not counting | 3221 // First, check how many doctypes and elements we have, not counting |
| 3222 // the child we're about to remove. | 3222 // the child we're about to remove. |
| 3223 for (Node& child : NodeTraversal::childrenOf(*this)) { | 3223 for (Node& child : NodeTraversal::childrenOf(*this)) { |
| 3224 if (oldChild && *oldChild == child) | 3224 if (oldChild && *oldChild == child) |
| 3225 continue; | 3225 continue; |
| 3226 | 3226 |
| 3227 switch (child.getNodeType()) { | 3227 switch (child.getNodeType()) { |
| 3228 case DOCUMENT_TYPE_NODE: | 3228 case kDocumentTypeNode: |
| 3229 numDoctypes++; | 3229 numDoctypes++; |
| 3230 break; | 3230 break; |
| 3231 case ELEMENT_NODE: | 3231 case kElementNode: |
| 3232 numElements++; | 3232 numElements++; |
| 3233 break; | 3233 break; |
| 3234 default: | 3234 default: |
| 3235 break; | 3235 break; |
| 3236 } | 3236 } |
| 3237 } | 3237 } |
| 3238 | 3238 |
| 3239 // Then, see how many doctypes and elements might be added by the new child. | 3239 // Then, see how many doctypes and elements might be added by the new child. |
| 3240 if (newChild.isDocumentFragment()) { | 3240 if (newChild.isDocumentFragment()) { |
| 3241 for (Node& child : NodeTraversal::childrenOf(toDocumentFragment(newChild
))) { | 3241 for (Node& child : NodeTraversal::childrenOf(toDocumentFragment(newChild
))) { |
| 3242 switch (child.getNodeType()) { | 3242 switch (child.getNodeType()) { |
| 3243 case ATTRIBUTE_NODE: | 3243 case kAttributeNode: |
| 3244 case CDATA_SECTION_NODE: | 3244 case kCdataSectionNode: |
| 3245 case DOCUMENT_FRAGMENT_NODE: | 3245 case kDocumentFragmentNode: |
| 3246 case DOCUMENT_NODE: | 3246 case kDocumentNode: |
| 3247 case TEXT_NODE: | 3247 case kTextNode: |
| 3248 exceptionState.throwDOMException(HierarchyRequestError, "Nodes o
f type '" + newChild.nodeName() + | 3248 exceptionState.throwDOMException(HierarchyRequestError, "Nodes o
f type '" + newChild.nodeName() + |
| 3249 "' may not be inserted inside nodes of type '#document'."); | 3249 "' may not be inserted inside nodes of type '#document'."); |
| 3250 return false; | 3250 return false; |
| 3251 case COMMENT_NODE: | 3251 case kCommentNode: |
| 3252 case PROCESSING_INSTRUCTION_NODE: | 3252 case kProcessingInstructionNode: |
| 3253 break; | 3253 break; |
| 3254 case DOCUMENT_TYPE_NODE: | 3254 case kDocumentTypeNode: |
| 3255 numDoctypes++; | 3255 numDoctypes++; |
| 3256 break; | 3256 break; |
| 3257 case ELEMENT_NODE: | 3257 case kElementNode: |
| 3258 numElements++; | 3258 numElements++; |
| 3259 break; | 3259 break; |
| 3260 } | 3260 } |
| 3261 } | 3261 } |
| 3262 } else { | 3262 } else { |
| 3263 switch (newChild.getNodeType()) { | 3263 switch (newChild.getNodeType()) { |
| 3264 case ATTRIBUTE_NODE: | 3264 case kAttributeNode: |
| 3265 case CDATA_SECTION_NODE: | 3265 case kCdataSectionNode: |
| 3266 case DOCUMENT_FRAGMENT_NODE: | 3266 case kDocumentFragmentNode: |
| 3267 case DOCUMENT_NODE: | 3267 case kDocumentNode: |
| 3268 case TEXT_NODE: | 3268 case kTextNode: |
| 3269 exceptionState.throwDOMException(HierarchyRequestError, "Nodes of ty
pe '" + newChild.nodeName() + | 3269 exceptionState.throwDOMException(HierarchyRequestError, "Nodes of ty
pe '" + newChild.nodeName() + |
| 3270 "' may not be inserted inside nodes of type '#document'."); | 3270 "' may not be inserted inside nodes of type '#document'."); |
| 3271 return false; | 3271 return false; |
| 3272 case COMMENT_NODE: | 3272 case kCommentNode: |
| 3273 case PROCESSING_INSTRUCTION_NODE: | 3273 case kProcessingInstructionNode: |
| 3274 return true; | 3274 return true; |
| 3275 case DOCUMENT_TYPE_NODE: | 3275 case kDocumentTypeNode: |
| 3276 numDoctypes++; | 3276 numDoctypes++; |
| 3277 break; | 3277 break; |
| 3278 case ELEMENT_NODE: | 3278 case kElementNode: |
| 3279 numElements++; | 3279 numElements++; |
| 3280 break; | 3280 break; |
| 3281 } | 3281 } |
| 3282 } | 3282 } |
| 3283 | 3283 |
| 3284 if (numElements > 1 || numDoctypes > 1) { | 3284 if (numElements > 1 || numDoctypes > 1) { |
| 3285 exceptionState.throwDOMException(HierarchyRequestError, | 3285 exceptionState.throwDOMException(HierarchyRequestError, |
| 3286 String::format("Only one %s on document allowed.", | 3286 String::format("Only one %s on document allowed.", |
| 3287 numElements > 1 ? "element" : "doctype")); | 3287 numElements > 1 ? "element" : "doctype")); |
| 3288 return false; | 3288 return false; |
| (...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6047 } | 6047 } |
| 6048 | 6048 |
| 6049 void showLiveDocumentInstances() | 6049 void showLiveDocumentInstances() |
| 6050 { | 6050 { |
| 6051 WeakDocumentSet& set = liveDocumentSet(); | 6051 WeakDocumentSet& set = liveDocumentSet(); |
| 6052 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6052 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
| 6053 for (Document* document : set) | 6053 for (Document* document : set) |
| 6054 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get
String().utf8().data()); | 6054 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get
String().utf8().data()); |
| 6055 } | 6055 } |
| 6056 #endif | 6056 #endif |
| OLD | NEW |