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

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

Issue 54273007: Use more references in ContainerNode code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix crashes Created 7 years, 1 month 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 2990 matching lines...) Expand 10 before | Expand all | Expand 10 after
3001 // Documents may contain no more than one of each of these. 3001 // Documents may contain no more than one of each of these.
3002 // (One Element and one DocumentType.) 3002 // (One Element and one DocumentType.)
3003 for (Node* c = firstChild(); c; c = c->nextSibling()) 3003 for (Node* c = firstChild(); c; c = c->nextSibling())
3004 if (c->nodeType() == type) 3004 if (c->nodeType() == type)
3005 return false; 3005 return false;
3006 return true; 3006 return true;
3007 } 3007 }
3008 return false; 3008 return false;
3009 } 3009 }
3010 3010
3011 bool Document::canReplaceChild(Node* newChild, Node* oldChild) 3011 bool Document::canReplaceChild(Node& newChild, Node& oldChild)
3012 { 3012 {
3013 if (!oldChild) 3013 if (oldChild.nodeType() == newChild.nodeType())
3014 // ContainerNode::replaceChild will raise a NotFoundError.
3015 return true;
3016
3017 if (oldChild->nodeType() == newChild->nodeType())
3018 return true; 3014 return true;
3019 3015
3020 int numDoctypes = 0; 3016 int numDoctypes = 0;
3021 int numElements = 0; 3017 int numElements = 0;
3022 3018
3023 // First, check how many doctypes and elements we have, not counting 3019 // First, check how many doctypes and elements we have, not counting
3024 // the child we're about to remove. 3020 // the child we're about to remove.
3025 for (Node* c = firstChild(); c; c = c->nextSibling()) { 3021 for (Node* c = firstChild(); c; c = c->nextSibling()) {
3026 if (c == oldChild) 3022 if (c == oldChild)
3027 continue; 3023 continue;
3028 3024
3029 switch (c->nodeType()) { 3025 switch (c->nodeType()) {
3030 case DOCUMENT_TYPE_NODE: 3026 case DOCUMENT_TYPE_NODE:
3031 numDoctypes++; 3027 numDoctypes++;
3032 break; 3028 break;
3033 case ELEMENT_NODE: 3029 case ELEMENT_NODE:
3034 numElements++; 3030 numElements++;
3035 break; 3031 break;
3036 default: 3032 default:
3037 break; 3033 break;
3038 } 3034 }
3039 } 3035 }
3040 3036
3041 // Then, see how many doctypes and elements might be added by the new child. 3037 // Then, see how many doctypes and elements might be added by the new child.
3042 if (newChild->nodeType() == DOCUMENT_FRAGMENT_NODE) { 3038 if (newChild.nodeType() == DOCUMENT_FRAGMENT_NODE) {
3043 for (Node* c = newChild->firstChild(); c; c = c->nextSibling()) { 3039 for (Node* c = newChild.firstChild(); c; c = c->nextSibling()) {
3044 switch (c->nodeType()) { 3040 switch (c->nodeType()) {
3045 case ATTRIBUTE_NODE: 3041 case ATTRIBUTE_NODE:
3046 case CDATA_SECTION_NODE: 3042 case CDATA_SECTION_NODE:
3047 case DOCUMENT_FRAGMENT_NODE: 3043 case DOCUMENT_FRAGMENT_NODE:
3048 case DOCUMENT_NODE: 3044 case DOCUMENT_NODE:
3049 case ENTITY_NODE: 3045 case ENTITY_NODE:
3050 case NOTATION_NODE: 3046 case NOTATION_NODE:
3051 case TEXT_NODE: 3047 case TEXT_NODE:
3052 case XPATH_NAMESPACE_NODE: 3048 case XPATH_NAMESPACE_NODE:
3053 return false; 3049 return false;
3054 case COMMENT_NODE: 3050 case COMMENT_NODE:
3055 case PROCESSING_INSTRUCTION_NODE: 3051 case PROCESSING_INSTRUCTION_NODE:
3056 break; 3052 break;
3057 case DOCUMENT_TYPE_NODE: 3053 case DOCUMENT_TYPE_NODE:
3058 numDoctypes++; 3054 numDoctypes++;
3059 break; 3055 break;
3060 case ELEMENT_NODE: 3056 case ELEMENT_NODE:
3061 numElements++; 3057 numElements++;
3062 break; 3058 break;
3063 } 3059 }
3064 } 3060 }
3065 } else { 3061 } else {
3066 switch (newChild->nodeType()) { 3062 switch (newChild.nodeType()) {
3067 case ATTRIBUTE_NODE: 3063 case ATTRIBUTE_NODE:
3068 case CDATA_SECTION_NODE: 3064 case CDATA_SECTION_NODE:
3069 case DOCUMENT_FRAGMENT_NODE: 3065 case DOCUMENT_FRAGMENT_NODE:
3070 case DOCUMENT_NODE: 3066 case DOCUMENT_NODE:
3071 case ENTITY_NODE: 3067 case ENTITY_NODE:
3072 case NOTATION_NODE: 3068 case NOTATION_NODE:
3073 case TEXT_NODE: 3069 case TEXT_NODE:
3074 case XPATH_NAMESPACE_NODE: 3070 case XPATH_NAMESPACE_NODE:
3075 return false; 3071 return false;
3076 case COMMENT_NODE: 3072 case COMMENT_NODE:
(...skipping 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after
5213 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode) 5209 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode)
5214 { 5210 {
5215 if (!isActive()) 5211 if (!isActive())
5216 return; 5212 return;
5217 5213
5218 styleEngine()->modifiedStyleSheet(sheet); 5214 styleEngine()->modifiedStyleSheet(sheet);
5219 styleResolverChanged(when, updateMode); 5215 styleResolverChanged(when, updateMode);
5220 } 5216 }
5221 5217
5222 } // namespace WebCore 5218 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Node.h » ('j') | Source/core/dom/Node.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698