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

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

Issue 16629006: Revert 151996 "Avoid N^2 walk placing renderers when building th..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Update to head Created 7 years, 6 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/Element.h ('k') | Source/core/dom/Text.cpp » ('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 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 // is needed, but for now just assume a layout will be required. The diff code 1355 // is needed, but for now just assume a layout will be required. The diff code
1356 // in RenderObject::setStyle would need to be factored out so th at it could be reused. 1356 // in RenderObject::setStyle would need to be factored out so th at it could be reused.
1357 renderer()->setNeedsLayoutAndPrefWidthsRecalc(); 1357 renderer()->setNeedsLayoutAndPrefWidthsRecalc();
1358 } 1358 }
1359 return true; 1359 return true;
1360 } 1360 }
1361 } 1361 }
1362 return false; 1362 return false;
1363 } 1363 }
1364 1364
1365 PassRefPtr<RenderStyle> Element::styleForRenderer(int childIndex) 1365 PassRefPtr<RenderStyle> Element::styleForRenderer()
1366 { 1366 {
1367 if (hasCustomStyleCallbacks()) { 1367 if (hasCustomStyleCallbacks()) {
1368 if (RefPtr<RenderStyle> style = customStyleForRenderer()) 1368 if (RefPtr<RenderStyle> style = customStyleForRenderer())
1369 return style.release(); 1369 return style.release();
1370 } 1370 }
1371 1371
1372 return originalStyleForRenderer(childIndex); 1372 return originalStyleForRenderer();
1373 } 1373 }
1374 1374
1375 PassRefPtr<RenderStyle> Element::originalStyleForRenderer(int childIndex) 1375 PassRefPtr<RenderStyle> Element::originalStyleForRenderer()
1376 { 1376 {
1377 return document()->styleResolver()->styleForElement(this, childIndex); 1377 return document()->styleResolver()->styleForElement(this);
1378 } 1378 }
1379 1379
1380 void Element::recalcStyle(StyleChange change, int childIndex) 1380 void Element::recalcStyle(StyleChange change)
1381 { 1381 {
1382 ASSERT(document()->inStyleRecalc()); 1382 ASSERT(document()->inStyleRecalc());
1383 1383
1384 if (hasCustomStyleCallbacks()) 1384 if (hasCustomStyleCallbacks())
1385 willRecalcStyle(change); 1385 willRecalcStyle(change);
1386 1386
1387 // Ref currentStyle in case it would otherwise be deleted when setting the n ew style in the renderer. 1387 // Ref currentStyle in case it would otherwise be deleted when setting the n ew style in the renderer.
1388 RefPtr<RenderStyle> currentStyle(renderStyle()); 1388 RefPtr<RenderStyle> currentStyle(renderStyle());
1389 bool hasParentStyle = parentNodeForRenderingAndStyle() ? static_cast<bool>(p arentNodeForRenderingAndStyle()->renderStyle()) : false; 1389 bool hasParentStyle = parentNodeForRenderingAndStyle() ? static_cast<bool>(p arentNodeForRenderingAndStyle()->renderStyle()) : false;
1390 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); 1390 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules();
1391 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); 1391 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules();
1392 1392
1393 if ((change > NoChange || needsStyleRecalc())) { 1393 if ((change > NoChange || needsStyleRecalc())) {
1394 if (hasRareData()) 1394 if (hasRareData())
1395 elementRareData()->resetComputedStyle(); 1395 elementRareData()->resetComputedStyle();
1396 } 1396 }
1397 if (hasParentStyle && (change >= Inherit || needsStyleRecalc())) { 1397 if (hasParentStyle && (change >= Inherit || needsStyleRecalc())) {
1398 StyleChange localChange = Detach; 1398 StyleChange localChange = Detach;
1399 RefPtr<RenderStyle> newStyle; 1399 RefPtr<RenderStyle> newStyle;
1400 if (currentStyle) { 1400 if (currentStyle) {
1401 // FIXME: This still recalcs style twice when changing display types , but saves 1401 // FIXME: This still recalcs style twice when changing display types , but saves
1402 // us from recalcing twice when going from none -> anything else whi ch is more 1402 // us from recalcing twice when going from none -> anything else whi ch is more
1403 // common, especially during lazy attach. 1403 // common, especially during lazy attach.
1404 newStyle = styleForRenderer(childIndex); 1404 newStyle = styleForRenderer();
1405 localChange = Node::diff(currentStyle.get(), newStyle.get(), documen t()); 1405 localChange = Node::diff(currentStyle.get(), newStyle.get(), documen t());
1406 } 1406 }
1407 if (localChange == Detach) { 1407 if (localChange == Detach) {
1408 // FIXME: The style gets computed twice by calling attach. We could do better if we passed the style along. 1408 // FIXME: The style gets computed twice by calling attach. We could do better if we passed the style along.
1409 reattach(); 1409 reattach();
1410 // attach recalculates the style for all children. No need to do it twice. 1410 // attach recalculates the style for all children. No need to do it twice.
1411 clearNeedsStyleRecalc(); 1411 clearNeedsStyleRecalc();
1412 clearChildNeedsStyleRecalc(); 1412 clearChildNeedsStyleRecalc();
1413 1413
1414 if (hasCustomStyleCallbacks()) 1414 if (hasCustomStyleCallbacks())
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 } 1450 }
1451 1451
1452 if (shouldRecalcStyle(change, this)) 1452 if (shouldRecalcStyle(change, this))
1453 updatePseudoElement(BEFORE, change); 1453 updatePseudoElement(BEFORE, change);
1454 1454
1455 // FIXME: This check is good enough for :hover + foo, but it is not good eno ugh for :hover + foo + bar. 1455 // FIXME: This check is good enough for :hover + foo, but it is not good eno ugh for :hover + foo + bar.
1456 // For now we will just worry about the common case, since it's a lot tricki er to get the second case right 1456 // For now we will just worry about the common case, since it's a lot tricki er to get the second case right
1457 // without doing way too much re-resolution. 1457 // without doing way too much re-resolution.
1458 bool forceCheckOfNextElementSibling = false; 1458 bool forceCheckOfNextElementSibling = false;
1459 bool forceCheckOfAnyElementSibling = false; 1459 bool forceCheckOfAnyElementSibling = false;
1460 int indexForChild = 0;
1461 for (Node *n = firstChild(); n; n = n->nextSibling()) { 1460 for (Node *n = firstChild(); n; n = n->nextSibling()) {
1462 ++indexForChild;
1463 if (n->isTextNode()) { 1461 if (n->isTextNode()) {
1464 toText(n)->recalcTextStyle(change); 1462 toText(n)->recalcTextStyle(change);
1465 continue; 1463 continue;
1466 } 1464 }
1467 if (!n->isElementNode()) 1465 if (!n->isElementNode())
1468 continue; 1466 continue;
1469 Element* element = toElement(n); 1467 Element* element = toElement(n);
1470 bool childRulesChanged = element->needsStyleRecalc() && element->styleCh angeType() == FullStyleChange; 1468 bool childRulesChanged = element->needsStyleRecalc() && element->styleCh angeType() == FullStyleChange;
1471 if ((forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling)) 1469 if ((forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling))
1472 element->setNeedsStyleRecalc(); 1470 element->setNeedsStyleRecalc();
1471 if (shouldRecalcStyle(change, element)) {
1472 parentPusher.push();
1473 element->recalcStyle(change);
1474 }
1473 forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjacentR ules; 1475 forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjacentR ules;
1474 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childR ulesChanged && hasIndirectAdjacentRules); 1476 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childR ulesChanged && hasIndirectAdjacentRules);
1475 } 1477 }
1476 // FIXME: Reversing the loop we call recalcStyle avoids an N^2 walk through the DOM to find the next renderer
1477 // to insert before. The logic in NodeRenderingContext should be improved to make this unnecessary.
1478 for (Node *n = lastChild(); n; n = n->previousSibling()) {
1479 if (!n->isElementNode())
1480 continue;
1481 Element* element = toElement(n);
1482 if (shouldRecalcStyle(change, element)) {
1483 parentPusher.push();
1484 element->recalcStyle(change, indexForChild);
1485 }
1486 --indexForChild;
1487 }
1488 1478
1489 if (shouldRecalcStyle(change, this)) 1479 if (shouldRecalcStyle(change, this))
1490 updatePseudoElement(AFTER, change); 1480 updatePseudoElement(AFTER, change);
1491 1481
1492 clearNeedsStyleRecalc(); 1482 clearNeedsStyleRecalc();
1493 clearChildNeedsStyleRecalc(); 1483 clearChildNeedsStyleRecalc();
1494 1484
1495 if (hasCustomStyleCallbacks()) 1485 if (hasCustomStyleCallbacks())
1496 didRecalcStyle(change); 1486 didRecalcStyle(change);
1497 InspectorInstrumentation::didRecalculateStyleForElement(this); 1487 InspectorInstrumentation::didRecalculateStyleForElement(this);
(...skipping 1630 matching lines...) Expand 10 before | Expand all | Expand 10 after
3128 return 0; 3118 return 0;
3129 } 3119 }
3130 3120
3131 Attribute* UniqueElementData::attributeItem(unsigned index) 3121 Attribute* UniqueElementData::attributeItem(unsigned index)
3132 { 3122 {
3133 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); 3123 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
3134 return &m_attributeVector.at(index); 3124 return &m_attributeVector.at(index);
3135 } 3125 }
3136 3126
3137 } // namespace WebCore 3127 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Text.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698