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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Fix unconditional ShadowRoot::rebuildLayoutTree() and retain needsStyleRecalc information for cases… Created 3 years, 10 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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 } 1273 }
1274 1274
1275 void ContainerNode::setRestyleFlag(DynamicRestyleFlags mask) { 1275 void ContainerNode::setRestyleFlag(DynamicRestyleFlags mask) {
1276 DCHECK(isElementNode() || isShadowRoot()); 1276 DCHECK(isElementNode() || isShadowRoot());
1277 ensureRareData().setRestyleFlag(mask); 1277 ensureRareData().setRestyleFlag(mask);
1278 } 1278 }
1279 1279
1280 void ContainerNode::recalcDescendantStyles(StyleRecalcChange change) { 1280 void ContainerNode::recalcDescendantStyles(StyleRecalcChange change) {
1281 DCHECK(document().inStyleRecalc()); 1281 DCHECK(document().inStyleRecalc());
1282 DCHECK(change >= UpdatePseudoElements || childNeedsStyleRecalc()); 1282 DCHECK(change >= UpdatePseudoElements || childNeedsStyleRecalc());
1283 DCHECK(!needsStyleRecalc());
1284 1283
1285 // This loop is deliberately backwards because we use insertBefore in the 1284 // This loop is deliberately backwards because we use insertBefore in the
1286 // layout tree, and want to avoid a potentially n^2 loop to find the insertion 1285 // layout tree, and want to avoid a potentially n^2 loop to find the insertion
1287 // point while resolving style. Having us start from the last child and work 1286 // point while resolving style. Having us start from the last child and work
1288 // our way back means in the common case, we'll find the insertion point in 1287 // our way back means in the common case, we'll find the insertion point in
1289 // O(1) time. See crbug.com/288225 1288 // O(1) time. See crbug.com/288225
1290 StyleResolver& styleResolver = document().ensureStyleResolver(); 1289 StyleResolver& styleResolver = document().ensureStyleResolver();
1291 Text* lastTextNode = nullptr; 1290 Text* lastTextNode = nullptr;
1292 for (Node* child = lastChild(); child; child = child->previousSibling()) { 1291 for (Node* child = lastChild(); child; child = child->previousSibling()) {
1293 if (child->isTextNode()) { 1292 if (child->isTextNode()) {
1294 toText(child)->recalcTextStyle(change, lastTextNode); 1293 toText(child)->recalcTextStyle(change, lastTextNode);
1295 lastTextNode = toText(child); 1294 lastTextNode = toText(child);
1296 } else if (child->isElementNode()) { 1295 } else if (child->isElementNode()) {
1297 Element* element = toElement(child); 1296 Element* element = toElement(child);
1298 if (element->shouldCallRecalcStyle(change)) 1297 if (element->shouldCallRecalcStyle(change))
1299 element->recalcStyle(change, lastTextNode); 1298 element->recalcStyle(change, lastTextNode);
1300 else if (element->supportsStyleSharing()) 1299 else if (element->supportsStyleSharing())
1301 styleResolver.addToStyleSharingList(*element); 1300 styleResolver.addToStyleSharingList(*element);
1302 if (element->layoutObject()) 1301 if (element->layoutObject())
1303 lastTextNode = nullptr; 1302 lastTextNode = nullptr;
1304 } 1303 }
1305 } 1304 }
1306 } 1305 }
1307 1306
1307 void ContainerNode::rebuildChildrenLayoutTrees() {
1308 DCHECK(!needsReattachLayoutTree());
1309
1310 for (Node* child = lastChild(); child; child = child->previousSibling()) {
1311 if (child->needsReattachLayoutTree() ||
1312 child->childNeedsReattachLayoutTree()) {
1313 if (child->isTextNode())
1314 toText(child)->rebuildTextLayoutTree();
1315 else if (child->isElementNode())
1316 toElement(child)->rebuildLayoutTree();
1317 }
1318 }
1319 clearNeedsStyleRecalc();
1320 // This is done in ContainerNode::attachLayoutTree but will never be cleared
1321 // if we don't enter ContainerNode::attachLayoutTree so we do it here.
1322 clearChildNeedsStyleRecalc();
1323 clearChildNeedsReattachLayoutTree();
1324 }
1325
1308 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType, 1326 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType,
1309 Element* changedElement, 1327 Element* changedElement,
1310 Node* nodeBeforeChange, 1328 Node* nodeBeforeChange,
1311 Node* nodeAfterChange) { 1329 Node* nodeAfterChange) {
1312 if (!inActiveDocument() || document().hasPendingForcedStyleRecalc() || 1330 if (!inActiveDocument() || document().hasPendingForcedStyleRecalc() ||
1313 getStyleChangeType() >= SubtreeStyleChange) 1331 getStyleChangeType() >= SubtreeStyleChange)
1314 return; 1332 return;
1315 1333
1316 if (!hasRestyleFlag(ChildrenAffectedByStructuralRules)) 1334 if (!hasRestyleFlag(ChildrenAffectedByStructuralRules))
1317 return; 1335 return;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 return true; 1495 return true;
1478 1496
1479 if (node->isElementNode() && toElement(node)->shadow()) 1497 if (node->isElementNode() && toElement(node)->shadow())
1480 return true; 1498 return true;
1481 1499
1482 return false; 1500 return false;
1483 } 1501 }
1484 #endif 1502 #endif
1485 1503
1486 } // namespace blink 1504 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698