OLD | NEW |
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 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 void ContainerNode::setRestyleFlag(DynamicRestyleFlags mask) { | 1282 void ContainerNode::setRestyleFlag(DynamicRestyleFlags mask) { |
1283 DCHECK(isElementNode() || isShadowRoot()); | 1283 DCHECK(isElementNode() || isShadowRoot()); |
1284 ensureRareData().setRestyleFlag(mask); | 1284 ensureRareData().setRestyleFlag(mask); |
1285 } | 1285 } |
1286 | 1286 |
1287 void ContainerNode::recalcDescendantStyles(StyleRecalcChange change) { | 1287 void ContainerNode::recalcDescendantStyles(StyleRecalcChange change) { |
1288 DCHECK(document().inStyleRecalc()); | 1288 DCHECK(document().inStyleRecalc()); |
1289 DCHECK(change >= UpdatePseudoElements || childNeedsStyleRecalc()); | 1289 DCHECK(change >= UpdatePseudoElements || childNeedsStyleRecalc()); |
1290 DCHECK(!needsStyleRecalc()); | 1290 DCHECK(!needsStyleRecalc()); |
1291 | 1291 |
1292 // This loop is deliberately backwards because we use insertBefore in the | |
1293 // layout tree, and want to avoid a potentially n^2 loop to find the insertion | |
1294 // point while resolving style. Having us start from the last child and work | |
1295 // our way back means in the common case, we'll find the insertion point in | |
1296 // O(1) time. See crbug.com/288225 | |
1297 StyleResolver& styleResolver = document().ensureStyleResolver(); | 1292 StyleResolver& styleResolver = document().ensureStyleResolver(); |
1298 Text* lastTextNode = nullptr; | |
1299 for (Node* child = lastChild(); child; child = child->previousSibling()) { | 1293 for (Node* child = lastChild(); child; child = child->previousSibling()) { |
1300 if (child->isTextNode()) { | 1294 if (child->isTextNode()) { |
1301 toText(child)->recalcTextStyle(change, lastTextNode); | 1295 toText(child)->recalcTextStyle(change); |
1302 lastTextNode = toText(child); | |
1303 } else if (child->isElementNode()) { | 1296 } else if (child->isElementNode()) { |
1304 Element* element = toElement(child); | 1297 Element* element = toElement(child); |
1305 if (element->shouldCallRecalcStyle(change)) | 1298 if (element->shouldCallRecalcStyle(change)) |
1306 element->recalcStyle(change, lastTextNode); | 1299 element->recalcStyle(change); |
1307 else if (element->supportsStyleSharing()) | 1300 else if (element->supportsStyleSharing()) |
1308 styleResolver.addToStyleSharingList(*element); | 1301 styleResolver.addToStyleSharingList(*element); |
1309 if (element->layoutObject()) | |
1310 lastTextNode = nullptr; | |
1311 } | 1302 } |
1312 } | 1303 } |
1313 } | 1304 } |
1314 | 1305 |
1315 void ContainerNode::rebuildChildrenLayoutTrees() { | 1306 void ContainerNode::rebuildChildrenLayoutTrees() { |
1316 DCHECK(!needsReattachLayoutTree()); | 1307 DCHECK(!needsReattachLayoutTree()); |
1317 | 1308 |
| 1309 // This loop is deliberately backwards because we use insertBefore in the |
| 1310 // layout tree, and want to avoid a potentially n^2 loop to find the insertion |
| 1311 // point while building the layout tree. Having us start from the last child |
| 1312 // and work our way back means in the common case, we'll find the insertion |
| 1313 // point in O(1) time. See crbug.com/288225 |
| 1314 Text* lastTextNode = nullptr; |
1318 for (Node* child = lastChild(); child; child = child->previousSibling()) { | 1315 for (Node* child = lastChild(); child; child = child->previousSibling()) { |
1319 if (child->needsReattachLayoutTree() || | 1316 bool rebuildChild = child->needsReattachLayoutTree() || |
1320 child->childNeedsReattachLayoutTree()) { | 1317 child->childNeedsReattachLayoutTree(); |
1321 if (child->isTextNode()) | 1318 if (child->isTextNode()) { |
1322 toText(child)->rebuildTextLayoutTree(); | 1319 Text* textNode = toText(child); |
1323 else if (child->isElementNode()) | 1320 if (rebuildChild) |
1324 toElement(child)->rebuildLayoutTree(); | 1321 textNode->rebuildTextLayoutTree(lastTextNode); |
| 1322 lastTextNode = textNode; |
| 1323 } else if (child->isElementNode()) { |
| 1324 Element* element = toElement(child); |
| 1325 if (rebuildChild) |
| 1326 element->rebuildLayoutTree(lastTextNode); |
| 1327 if (element->layoutObject()) |
| 1328 lastTextNode = nullptr; |
1325 } | 1329 } |
1326 } | 1330 } |
1327 // This is done in ContainerNode::attachLayoutTree but will never be cleared | 1331 // This is done in ContainerNode::attachLayoutTree but will never be cleared |
1328 // if we don't enter ContainerNode::attachLayoutTree so we do it here. | 1332 // if we don't enter ContainerNode::attachLayoutTree so we do it here. |
1329 clearChildNeedsStyleRecalc(); | 1333 clearChildNeedsStyleRecalc(); |
1330 clearChildNeedsReattachLayoutTree(); | 1334 clearChildNeedsReattachLayoutTree(); |
1331 } | 1335 } |
1332 | 1336 |
1333 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType, | 1337 void ContainerNode::checkForSiblingStyleChanges(SiblingCheckType changeType, |
1334 Element* changedElement, | 1338 Element* changedElement, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 return true; | 1506 return true; |
1503 | 1507 |
1504 if (node->isElementNode() && toElement(node)->shadow()) | 1508 if (node->isElementNode() && toElement(node)->shadow()) |
1505 return true; | 1509 return true; |
1506 | 1510 |
1507 return false; | 1511 return false; |
1508 } | 1512 } |
1509 #endif | 1513 #endif |
1510 | 1514 |
1511 } // namespace blink | 1515 } // namespace blink |
OLD | NEW |