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

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

Issue 380073002: Rename variables in ContainerNode::checkForSiblingStyleChanges() for clarity (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
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 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 1144
1145 if (childRulesChanged && hasDirectAdjacentRules) 1145 if (childRulesChanged && hasDirectAdjacentRules)
1146 forceCheckOfNextElementCount = document.styleEngine()->maxDirectAdja centSelectors(); 1146 forceCheckOfNextElementCount = document.styleEngine()->maxDirectAdja centSelectors();
1147 else if (forceCheckOfNextElementCount) 1147 else if (forceCheckOfNextElementCount)
1148 --forceCheckOfNextElementCount; 1148 --forceCheckOfNextElementCount;
1149 1149
1150 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childR ulesChanged && hasIndirectAdjacentRules); 1150 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childR ulesChanged && hasIndirectAdjacentRules);
1151 } 1151 }
1152 } 1152 }
1153 1153
1154 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType, Nod e* beforeChange, Node* afterChange) 1154 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType, Nod e* nodeBeforeChange, Node* nodeAfterChange)
Inactive 2014/07/10 01:05:11 Possible improvement idea: it seems like we are ca
1155 { 1155 {
1156 if (!inActiveDocument() || document().hasPendingForcedStyleRecalc() || style ChangeType() >= SubtreeStyleChange) 1156 if (!inActiveDocument() || document().hasPendingForcedStyleRecalc() || style ChangeType() >= SubtreeStyleChange)
1157 return; 1157 return;
1158 1158
1159 if (needsStyleRecalc() && childrenAffectedByPositionalRules()) 1159 if (needsStyleRecalc() && childrenAffectedByPositionalRules())
1160 return; 1160 return;
1161 1161
1162 // Forward positional selectors include nth-child, nth-of-type, first-of-typ e and only-of-type. 1162 // Forward positional selectors include nth-child, nth-of-type, first-of-typ e and only-of-type.
1163 // The indirect adjacent selector is the ~ selector. 1163 // The indirect adjacent selector is the ~ selector.
1164 // Backward positional selectors include nth-last-child, nth-last-of-type, l ast-of-type and only-of-type. 1164 // Backward positional selectors include nth-last-child, nth-last-of-type, l ast-of-type and only-of-type.
1165 // We have to invalidate everything following the insertion point in the for ward and indirect adjacent case, 1165 // We have to invalidate everything following the insertion point in the for ward and indirect adjacent case,
1166 // and everything before the insertion point in the backward case. 1166 // and everything before the insertion point in the backward case.
1167 // |afterChange| is 0 in the parser callback case, so we won't do any work f or the forward case if we don't have to. 1167 // |afterChange| is 0 in the parser callback case, so we won't do any work f or the forward case if we don't have to.
1168 // For performance reasons we just mark the parent node as changed, since we don't want to make childrenChanged O(n^2) by crawling all our kids 1168 // For performance reasons we just mark the parent node as changed, since we don't want to make childrenChanged O(n^2) by crawling all our kids
1169 // here. recalcStyle will then force a walk of the children when it sees tha t this has happened. 1169 // here. recalcStyle will then force a walk of the children when it sees tha t this has happened.
1170 if (((childrenAffectedByForwardPositionalRules() || childrenAffectedByIndire ctAdjacentRules()) && afterChange) 1170 if (((childrenAffectedByForwardPositionalRules() || childrenAffectedByIndire ctAdjacentRules()) && nodeAfterChange)
Inactive 2014/07/10 01:05:11 Possible improvement idea: it seems like we may be
1171 || (childrenAffectedByBackwardPositionalRules() && beforeChange)) { 1171 || (childrenAffectedByBackwardPositionalRules() && nodeBeforeChange)) {
Inactive 2014/07/10 01:05:11 Possible improvement idea: it seems like we may be
1172 setNeedsStyleRecalc(SubtreeStyleChange); 1172 setNeedsStyleRecalc(SubtreeStyleChange);
1173 return; 1173 return;
1174 } 1174 }
1175 1175
1176 // :first-child. In the parser callback case, we don't have to check anythin g, since we were right the first time. 1176 // :first-child. In the parser callback case, we don't have to check anythin g, since we were right the first time.
1177 // In the DOM case, we only need to do something if |afterChange| is not 0. 1177 // In the DOM case, we only need to do something if |afterChange| is not 0.
1178 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block. 1178 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block.
1179 if (childrenAffectedByFirstChildRules() && afterChange) { 1179 if (childrenAffectedByFirstChildRules() && nodeAfterChange) {
1180 // Find our new first child. 1180 ASSERT(changeType != FinishedParsingChildren);
1181 Element* newFirstChild = ElementTraversal::firstWithin(*this); 1181 // Find our new first child element.
1182 RenderStyle* newFirstChildStyle = newFirstChild ? newFirstChild->renderS tyle() : 0; 1182 Element* firstChildElement = ElementTraversal::firstChild(*this);
1183 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem ent->renderStyle() : 0;
1183 1184
1184 // Find the first element node following |afterChange| 1185 // Find the first element after the change.
1185 Node* firstElementAfterInsertion = afterChange->isElementNode() ? afterC hange : ElementTraversal::nextSibling(*afterChange); 1186 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange);
1186 RenderStyle* firstElementAfterInsertionStyle = firstElementAfterInsertio n ? firstElementAfterInsertion->renderStyle() : 0; 1187 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter Change->renderStyle() : 0;
1187 1188
1188 // This is the insert/append case. 1189 // This is the element insertion as first child element case.
1189 if (newFirstChild != firstElementAfterInsertion && firstElementAfterInse rtionStyle && firstElementAfterInsertionStyle->firstChildState()) 1190 if (firstChildElement != elementAfterChange && elementAfterChangeStyle & & elementAfterChangeStyle->firstChildState())
1190 firstElementAfterInsertion->setNeedsStyleRecalc(SubtreeStyleChange); 1191 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange);
1191 1192
1192 // We also have to handle node removal. 1193 // This is the first child element removal case.
1193 if (changeType == SiblingRemoved && newFirstChild == firstElementAfterIn sertion && newFirstChild && (!newFirstChildStyle || !newFirstChildStyle->firstCh ildState())) 1194 if (changeType == SiblingRemoved && firstChildElement == elementAfterCha nge && firstChildElement && (!firstChildElementStyle || !firstChildElementStyle- >firstChildState()))
Inactive 2014/07/10 01:05:11 Possible improvement idea: Seems like this could b
1194 newFirstChild->setNeedsStyleRecalc(SubtreeStyleChange); 1195 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange);
1195 } 1196 }
1196 1197
1197 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time. 1198 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time.
1198 // In the DOM case, we only need to do something if |afterChange| is not 0. 1199 // In the DOM case, we only need to do something if |afterChange| is not 0.
1199 if (childrenAffectedByLastChildRules() && beforeChange) { 1200 if (childrenAffectedByLastChildRules() && nodeBeforeChange) {
1200 // Find our new last child. 1201 // Find our new last child element.
1201 Node* newLastChild = ElementTraversal::lastChild(*this); 1202 Element* lastChildElement = ElementTraversal::lastChild(*this);
1202 RenderStyle* newLastChildStyle = newLastChild ? newLastChild->renderStyl e() : 0; 1203 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement ->renderStyle() : 0;
1203 1204
1204 // Find the last element node going backwards from |beforeChange| 1205 // Find the last element before the change.
1205 Node* lastElementBeforeInsertion = beforeChange->isElementNode() ? befor eChange : ElementTraversal::previousSibling(*beforeChange); 1206 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange);
1206 RenderStyle* lastElementBeforeInsertionStyle = lastElementBeforeInsertio n ? lastElementBeforeInsertion->renderStyle() : 0; 1207 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef oreChange->renderStyle() : 0;
1207 1208
1208 if (newLastChild != lastElementBeforeInsertion && lastElementBeforeInser tionStyle && lastElementBeforeInsertionStyle->lastChildState()) 1209 // This is the element insertion as last child element case.
1209 lastElementBeforeInsertion->setNeedsStyleRecalc(SubtreeStyleChange); 1210 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle && elementBeforeChangeStyle->lastChildState())
1211 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange);
1210 1212
1211 // We also have to handle node removal. The parser callback case is simi lar to node removal as well in that we need to change the last child 1213 // This is the last child element removal case. The parser callback case is similar to node removal as well in that we need to change the last child
1212 // to match now. 1214 // to match now.
1213 if ((changeType == SiblingRemoved || changeType == FinishedParsingChildr en) && newLastChild == lastElementBeforeInsertion && newLastChild && (!newLastCh ildStyle || !newLastChildStyle->lastChildState())) 1215 if ((changeType == SiblingRemoved || changeType == FinishedParsingChildr en) && lastChildElement == elementBeforeChange && lastChildElement && (!lastChil dElementStyle || !lastChildElementStyle->lastChildState()))
Inactive 2014/07/10 01:05:11 Possible improvement idea: Seems like this could b
1214 newLastChild->setNeedsStyleRecalc(SubtreeStyleChange); 1216 lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange);
1215 } 1217 }
1216 1218
1217 // The + selector. We need to invalidate the first element following the ins ertion point. It is the only possible element 1219 // The + selector. We need to invalidate the first element following the cha nge. It is the only possible element
1218 // that could be affected by this DOM change. 1220 // that could be affected by this DOM change.
1219 if (childrenAffectedByDirectAdjacentRules() && afterChange) { 1221 if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) {
1220 if (Node* firstElementAfterInsertion = afterChange->isElementNode() ? af terChange : ElementTraversal::nextSibling(*afterChange)) 1222 if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toE lement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange))
1221 firstElementAfterInsertion->setNeedsStyleRecalc(SubtreeStyleChange); 1223 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange);
1222 } 1224 }
1223 } 1225 }
1224 1226
1225 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagName(const AtomicString& localName) 1227 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagName(const AtomicString& localName)
1226 { 1228 {
1227 if (localName.isNull()) 1229 if (localName.isNull())
1228 return nullptr; 1230 return nullptr;
1229 1231
1230 if (document().isHTMLDocument()) 1232 if (document().isHTMLDocument())
1231 return ensureRareData().ensureNodeLists().addCache<HTMLTagCollection>(*t his, HTMLTagCollectionType, localName); 1233 return ensureRareData().ensureNodeLists().addCache<HTMLTagCollection>(*t his, HTMLTagCollectionType, localName);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 return true; 1296 return true;
1295 1297
1296 if (node->isElementNode() && toElement(node)->shadow()) 1298 if (node->isElementNode() && toElement(node)->shadow())
1297 return true; 1299 return true;
1298 1300
1299 return false; 1301 return false;
1300 } 1302 }
1301 #endif 1303 #endif
1302 1304
1303 } // namespace WebCore 1305 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698