Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

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

Powered by Google App Engine
This is Rietveld 408576698