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

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

Issue 758523002: Store :last/first-child state as restyle flags. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed assert Created 6 years 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
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | Source/core/rendering/style/RenderStyle.h » ('j') | 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 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 return; 1282 return;
1283 } 1283 }
1284 1284
1285 // :first-child. In the parser callback case, we don't have to check anythin g, since we were right the first time. 1285 // :first-child. In the parser callback case, we don't have to check anythin g, since we were right the first time.
1286 // In the DOM case, we only need to do something if |afterChange| is not 0. 1286 // In the DOM case, we only need to do something if |afterChange| is not 0.
1287 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block. 1287 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block.
1288 if (childrenAffectedByFirstChildRules() && nodeAfterChange) { 1288 if (childrenAffectedByFirstChildRules() && nodeAfterChange) {
1289 ASSERT(changeType != FinishedParsingChildren); 1289 ASSERT(changeType != FinishedParsingChildren);
1290 // Find our new first child element. 1290 // Find our new first child element.
1291 Element* firstChildElement = ElementTraversal::firstChild(*this); 1291 Element* firstChildElement = ElementTraversal::firstChild(*this);
1292 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem ent->renderStyle() : nullptr;
1293 1292
1294 // Find the first element after the change. 1293 // Find the first element after the change.
1295 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange); 1294 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange);
1296 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter Change->renderStyle() : nullptr;
1297 1295
1298 // This is the element insertion as first child element case. 1296 // This is the element insertion as first child element case.
1299 if (firstChildElement != elementAfterChange && elementAfterChangeStyle & & elementAfterChangeStyle->firstChildState()) { 1297 if (changeType == SiblingElementInserted && elementAfterChange && firstC hildElement != elementAfterChange
1300 ASSERT(changeType == SiblingElementInserted); 1298 && (!nodeBeforeChange || !nodeBeforeChange->isElementNode()) && elem entAfterChange->affectedByFirstChildRules()) {
1301 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCha ngeReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1299 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCha ngeReasonForTracing::create(StyleChangeReason::SiblingSelector));
rune 2014/11/26 15:14:05 Since the flag is not cleared for every recalc, fa
1302 } 1300 }
1303 1301
1304 // This is the first child element removal case. 1302 // This is the first child element removal case.
1305 if (changeType == SiblingElementRemoved && firstChildElement == elementA fterChange && firstChildElement && (!firstChildElementStyle || !firstChildElemen tStyle->firstChildState())) 1303 if (changeType == SiblingElementRemoved && firstChildElement == elementA fterChange && firstChildElement && firstChildElement->affectedByFirstChildRules( ))
1306 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChan geReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1304 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChan geReasonForTracing::create(StyleChangeReason::SiblingSelector));
1307 } 1305 }
1308 1306
1309 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time. 1307 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time.
1310 // In the DOM case, we only need to do something if |afterChange| is not 0. 1308 // In the DOM case, we only need to do something if |afterChange| is not 0.
1311 if (childrenAffectedByLastChildRules() && nodeBeforeChange) { 1309 if (childrenAffectedByLastChildRules() && nodeBeforeChange) {
1312 // Find our new last child element. 1310 // Find our new last child element.
1313 Element* lastChildElement = ElementTraversal::lastChild(*this); 1311 Element* lastChildElement = ElementTraversal::lastChild(*this);
1314 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement ->renderStyle() : nullptr;
1315 1312
1316 // Find the last element before the change. 1313 // Find the last element before the change.
1317 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange); 1314 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange);
1318 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef oreChange->renderStyle() : nullptr;
1319 1315
1320 // This is the element insertion as last child element case. 1316 // This is the element insertion as last child element case.
1321 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle && elementBeforeChangeStyle->lastChildState()) { 1317 if (changeType == SiblingElementInserted && elementBeforeChange && lastC hildElement != elementBeforeChange
1322 ASSERT(SiblingElementInserted); 1318 && (!nodeAfterChange || !nodeAfterChange->isElementNode()) && elemen tBeforeChange->affectedByLastChildRules()) {
rune 2014/11/26 15:14:05 Analogue to the other change, only for :last-child
1323 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCh angeReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1319 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCh angeReasonForTracing::create(StyleChangeReason::SiblingSelector));
1324 } 1320 }
1325 1321
1326 // 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 1322 // 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
1327 // to match now. 1323 // to match now.
1328 if ((changeType == SiblingElementRemoved || changeType == FinishedParsin gChildren) && lastChildElement == elementBeforeChange && lastChildElement && (!l astChildElementStyle || !lastChildElementStyle->lastChildState())) 1324 if ((changeType == SiblingElementRemoved || changeType == FinishedParsin gChildren) && lastChildElement == elementBeforeChange && lastChildElement && las tChildElement->affectedByLastChildRules())
1329 lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChang eReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1325 lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChang eReasonForTracing::create(StyleChangeReason::SiblingSelector));
1330 } 1326 }
1331 1327
1332 // The + selector. We need to invalidate the first element following the cha nge. It is the only possible element 1328 // The + selector. We need to invalidate the first element following the cha nge. It is the only possible element
1333 // that could be affected by this DOM change. 1329 // that could be affected by this DOM change.
1334 if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) { 1330 if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) {
1335 if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toE lement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange)) 1331 if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toE lement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange))
1336 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCha ngeReasonForTracing::create(StyleChangeReason::SiblingSelector)); 1332 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleCha ngeReasonForTracing::create(StyleChangeReason::SiblingSelector));
1337 } 1333 }
1338 } 1334 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 return true; 1434 return true;
1439 1435
1440 if (node->isElementNode() && toElement(node)->shadow()) 1436 if (node->isElementNode() && toElement(node)->shadow())
1441 return true; 1437 return true;
1442 1438
1443 return false; 1439 return false;
1444 } 1440 }
1445 #endif 1441 #endif
1446 1442
1447 } // namespace blink 1443 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | Source/core/rendering/style/RenderStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698