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

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

Issue 2473743003: Call Element::rebuildLayoutTree from Document::updateStyle directly (Closed)
Patch Set: Final patch - make sure to retain information needed to determine whether to call detachLayoutTree() 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 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 } 1266 }
1267 1267
1268 void ContainerNode::setRestyleFlag(DynamicRestyleFlags mask) { 1268 void ContainerNode::setRestyleFlag(DynamicRestyleFlags mask) {
1269 DCHECK(isElementNode() || isShadowRoot()); 1269 DCHECK(isElementNode() || isShadowRoot());
1270 ensureRareData().setRestyleFlag(mask); 1270 ensureRareData().setRestyleFlag(mask);
1271 } 1271 }
1272 1272
1273 void ContainerNode::recalcDescendantStyles(StyleRecalcChange change) { 1273 void ContainerNode::recalcDescendantStyles(StyleRecalcChange change) {
1274 DCHECK(document().inStyleRecalc()); 1274 DCHECK(document().inStyleRecalc());
1275 DCHECK(change >= UpdatePseudoElements || childNeedsStyleRecalc()); 1275 DCHECK(change >= UpdatePseudoElements || childNeedsStyleRecalc());
1276 DCHECK(!needsStyleRecalc());
1277 1276
1278 // This loop is deliberately backwards because we use insertBefore in the 1277 // This loop is deliberately backwards because we use insertBefore in the
1279 // layout tree, and want to avoid a potentially n^2 loop to find the insertion 1278 // layout tree, and want to avoid a potentially n^2 loop to find the insertion
1280 // point while resolving style. Having us start from the last child and work 1279 // point while resolving style. Having us start from the last child and work
1281 // our way back means in the common case, we'll find the insertion point in 1280 // our way back means in the common case, we'll find the insertion point in
1282 // O(1) time. See crbug.com/288225 1281 // O(1) time. See crbug.com/288225
1283 StyleResolver& styleResolver = document().ensureStyleResolver(); 1282 StyleResolver& styleResolver = document().ensureStyleResolver();
1284 Text* lastTextNode = nullptr; 1283 Text* lastTextNode = nullptr;
1285 for (Node* child = lastChild(); child; child = child->previousSibling()) { 1284 for (Node* child = lastChild(); child; child = child->previousSibling()) {
1286 if (child->isTextNode()) { 1285 if (child->isTextNode()) {
1287 toText(child)->recalcTextStyle(change, lastTextNode); 1286 toText(child)->recalcTextStyle(change, lastTextNode);
1288 lastTextNode = toText(child); 1287 lastTextNode = toText(child);
1289 } else if (child->isElementNode()) { 1288 } else if (child->isElementNode()) {
1290 Element* element = toElement(child); 1289 Element* element = toElement(child);
1291 if (element->shouldCallRecalcStyle(change)) 1290 if (element->shouldCallRecalcStyle(change))
1292 element->recalcStyle(change, lastTextNode); 1291 element->recalcStyle(change, lastTextNode);
1293 else if (element->supportsStyleSharing()) 1292 else if (element->supportsStyleSharing())
1294 styleResolver.addToStyleSharingList(*element); 1293 styleResolver.addToStyleSharingList(*element);
1295 if (element->layoutObject()) 1294 if (element->layoutObject())
1296 lastTextNode = nullptr; 1295 lastTextNode = nullptr;
1297 } 1296 }
1298 } 1297 }
1299 } 1298 }
1300 1299
1300 void ContainerNode::rebuildChildrenLayoutTrees() {
1301 DCHECK(!needsReattachLayoutTree());
1302
1303 for (Node* child = lastChild(); child; child = child->previousSibling()) {
1304 if (child->needsReattachLayoutTree() ||
1305 child->childNeedsReattachLayoutTree()) {
1306 if (child->isTextNode())
1307 toText(child)->rebuildTextLayoutTree();
1308 else if (child->isElementNode())
1309 toElement(child)->rebuildLayoutTree();
1310 }
1311 }
1312 clearNeedsStyleRecalc();
1313 // This is done in ContainerNode::attachLayoutTree but will never be cleared
1314 // if we don't enter ContainerNode::attachLayoutTree so we do it here.
1315 clearChildNeedsStyleRecalc();
1316 clearChildNeedsReattachLayoutTree();
1317 }
1318
1301 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType, 1319 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType,
1302 Element* changedElement, 1320 Element* changedElement,
1303 Node* nodeBeforeChange, 1321 Node* nodeBeforeChange,
1304 Node* nodeAfterChange) { 1322 Node* nodeAfterChange) {
1305 if (!inActiveDocument() || document().hasPendingForcedStyleRecalc() || 1323 if (!inActiveDocument() || document().hasPendingForcedStyleRecalc() ||
1306 getStyleChangeType() >= SubtreeStyleChange) 1324 getStyleChangeType() >= SubtreeStyleChange)
1307 return; 1325 return;
1308 1326
1309 if (!hasRestyleFlag(ChildrenAffectedByStructuralRules)) 1327 if (!hasRestyleFlag(ChildrenAffectedByStructuralRules))
1310 return; 1328 return;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 return true; 1488 return true;
1471 1489
1472 if (node->isElementNode() && toElement(node)->shadow()) 1490 if (node->isElementNode() && toElement(node)->shadow())
1473 return true; 1491 return true;
1474 1492
1475 return false; 1493 return false;
1476 } 1494 }
1477 #endif 1495 #endif
1478 1496
1479 } // namespace blink 1497 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698