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 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 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 // is needed, but for now just assume a layout will be required.
The diff code | 1435 // is needed, but for now just assume a layout will be required.
The diff code |
1436 // in RenderObject::setStyle would need to be factored out so th
at it could be reused. | 1436 // in RenderObject::setStyle would need to be factored out so th
at it could be reused. |
1437 renderer()->setNeedsLayoutAndPrefWidthsRecalc(); | 1437 renderer()->setNeedsLayoutAndPrefWidthsRecalc(); |
1438 } | 1438 } |
1439 return true; | 1439 return true; |
1440 } | 1440 } |
1441 } | 1441 } |
1442 return false; | 1442 return false; |
1443 } | 1443 } |
1444 | 1444 |
1445 PassRefPtr<RenderStyle> Element::styleForRenderer() | 1445 PassRefPtr<RenderStyle> Element::styleForRenderer(int childIndex) |
1446 { | 1446 { |
1447 if (hasCustomStyleCallbacks()) { | 1447 if (hasCustomStyleCallbacks()) { |
1448 if (RefPtr<RenderStyle> style = customStyleForRenderer()) | 1448 if (RefPtr<RenderStyle> style = customStyleForRenderer()) |
1449 return style.release(); | 1449 return style.release(); |
1450 } | 1450 } |
1451 | 1451 |
1452 return originalStyleForRenderer(); | 1452 return originalStyleForRenderer(childIndex); |
1453 } | 1453 } |
1454 | 1454 |
1455 PassRefPtr<RenderStyle> Element::originalStyleForRenderer() | 1455 PassRefPtr<RenderStyle> Element::originalStyleForRenderer(int childIndex) |
1456 { | 1456 { |
1457 return document()->styleResolver()->styleForElement(this); | 1457 return document()->styleResolver()->styleForElement(this, childIndex); |
1458 } | 1458 } |
1459 | 1459 |
1460 bool Element::recalcStyle(StyleChange change) | 1460 bool Element::recalcStyle(StyleChange change, int childIndex) |
1461 { | 1461 { |
1462 ASSERT(document()->inStyleRecalc()); | 1462 ASSERT(document()->inStyleRecalc()); |
1463 | 1463 |
1464 if (hasCustomStyleCallbacks()) | 1464 if (hasCustomStyleCallbacks()) |
1465 willRecalcStyle(change); | 1465 willRecalcStyle(change); |
1466 | 1466 |
1467 // Ref currentStyle in case it would otherwise be deleted when setting the n
ew style in the renderer. | 1467 // Ref currentStyle in case it would otherwise be deleted when setting the n
ew style in the renderer. |
1468 RefPtr<RenderStyle> currentStyle(renderStyle()); | 1468 RefPtr<RenderStyle> currentStyle(renderStyle()); |
1469 bool hasParentStyle = parentNodeForRenderingAndStyle() ? static_cast<bool>(p
arentNodeForRenderingAndStyle()->renderStyle()) : false; | 1469 bool hasParentStyle = parentNodeForRenderingAndStyle() ? static_cast<bool>(p
arentNodeForRenderingAndStyle()->renderStyle()) : false; |
1470 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); | 1470 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); |
1471 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); | 1471 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); |
1472 | 1472 |
1473 if ((change > NoChange || needsStyleRecalc())) { | 1473 if ((change > NoChange || needsStyleRecalc())) { |
1474 if (hasRareData()) | 1474 if (hasRareData()) |
1475 elementRareData()->resetComputedStyle(); | 1475 elementRareData()->resetComputedStyle(); |
1476 } | 1476 } |
1477 if (hasParentStyle && (change >= Inherit || needsStyleRecalc())) { | 1477 if (hasParentStyle && (change >= Inherit || needsStyleRecalc())) { |
1478 StyleChange localChange = Detach; | 1478 StyleChange localChange = Detach; |
1479 RefPtr<RenderStyle> newStyle; | 1479 RefPtr<RenderStyle> newStyle; |
1480 if (currentStyle) { | 1480 if (currentStyle) { |
1481 // FIXME: This still recalcs style twice when changing display types
, but saves | 1481 // FIXME: This still recalcs style twice when changing display types
, but saves |
1482 // us from recalcing twice when going from none -> anything else whi
ch is more | 1482 // us from recalcing twice when going from none -> anything else whi
ch is more |
1483 // common, especially during lazy attach. | 1483 // common, especially during lazy attach. |
1484 newStyle = styleForRenderer(); | 1484 newStyle = styleForRenderer(childIndex); |
1485 localChange = Node::diff(currentStyle.get(), newStyle.get(), documen
t()); | 1485 localChange = Node::diff(currentStyle.get(), newStyle.get(), documen
t()); |
1486 } else if (attached() && isActiveInsertionPoint(this)) { | 1486 } else if (attached() && isActiveInsertionPoint(this)) { |
1487 // Active InsertionPoints will never have renderers so there's no re
ason to | 1487 // Active InsertionPoints will never have renderers so there's no re
ason to |
1488 // reattach them repeatedly once they're already attached. | 1488 // reattach them repeatedly once they're already attached. |
1489 localChange = change; | 1489 localChange = change; |
1490 } | 1490 } |
1491 if (localChange == Detach) { | 1491 if (localChange == Detach) { |
1492 AttachContext reattachContext; | 1492 AttachContext reattachContext; |
1493 reattachContext.resolvedStyle = newStyle.get(); | 1493 reattachContext.resolvedStyle = newStyle.get(); |
1494 reattach(reattachContext); | 1494 reattach(reattachContext); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 } | 1538 } |
1539 | 1539 |
1540 if (shouldRecalcStyle(change, this)) | 1540 if (shouldRecalcStyle(change, this)) |
1541 updatePseudoElement(BEFORE, change); | 1541 updatePseudoElement(BEFORE, change); |
1542 | 1542 |
1543 // FIXME: This check is good enough for :hover + foo, but it is not good eno
ugh for :hover + foo + bar. | 1543 // FIXME: This check is good enough for :hover + foo, but it is not good eno
ugh for :hover + foo + bar. |
1544 // For now we will just worry about the common case, since it's a lot tricki
er to get the second case right | 1544 // For now we will just worry about the common case, since it's a lot tricki
er to get the second case right |
1545 // without doing way too much re-resolution. | 1545 // without doing way too much re-resolution. |
1546 bool forceCheckOfNextElementSibling = false; | 1546 bool forceCheckOfNextElementSibling = false; |
1547 bool forceCheckOfAnyElementSibling = false; | 1547 bool forceCheckOfAnyElementSibling = false; |
1548 bool forceReattachOfAnyWhitespaceSibling = false; | 1548 int indexForChild = 1; |
1549 for (Node* child = firstChild(); child; child = child->nextSibling()) { | 1549 if (hasDirectAdjacentRules || hasIndirectAdjacentRules) { |
| 1550 for (Node *child = firstChild(); child; child = child->nextSibling()) { |
| 1551 ++indexForChild; |
| 1552 if (!child->isElementNode()) |
| 1553 continue; |
| 1554 Element* element = toElement(child); |
| 1555 bool childRulesChanged = element->needsStyleRecalc() && element->sty
leChangeType() == SubtreeStyleChange; |
| 1556 if (forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling) |
| 1557 element->setNeedsStyleRecalc(); |
| 1558 forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjac
entRules; |
| 1559 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (ch
ildRulesChanged && hasIndirectAdjacentRules); |
| 1560 } |
| 1561 } |
| 1562 // FIXME: Reversing the loop we call recalcStyle avoids an N^2 walk through
the DOM to find the next renderer |
| 1563 // to insert before. The logic in NodeRenderingContext should be improved to
make this unnecessary. |
| 1564 for (Node *child = lastChild(); child; child = child->previousSibling()) { |
| 1565 indexForChild = max(--indexForChild, 0); |
1550 bool didReattach = false; | 1566 bool didReattach = false; |
1551 | 1567 |
1552 if (child->renderer()) | |
1553 forceReattachOfAnyWhitespaceSibling = false; | |
1554 | |
1555 if (child->isTextNode()) { | 1568 if (child->isTextNode()) { |
1556 if (forceReattachOfAnyWhitespaceSibling && toText(child)->containsOn
lyWhitespace()) | 1569 didReattach = toText(child)->recalcTextStyle(change); |
1557 child->reattach(); | |
1558 else | |
1559 didReattach = toText(child)->recalcTextStyle(change); | |
1560 } else if (child->isElementNode()) { | 1570 } else if (child->isElementNode()) { |
1561 Element* element = toElement(child); | 1571 Element* element = toElement(child); |
1562 | 1572 |
1563 if (forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling) | |
1564 element->setNeedsStyleRecalc(); | |
1565 | |
1566 bool childRulesChanged = element->needsStyleRecalc() && element->sty
leChangeType() == SubtreeStyleChange; | |
1567 forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjac
entRules; | |
1568 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (ch
ildRulesChanged && hasIndirectAdjacentRules); | |
1569 | |
1570 if (shouldRecalcStyle(change, element)) { | 1573 if (shouldRecalcStyle(change, element)) { |
1571 parentPusher.push(); | 1574 parentPusher.push(); |
1572 didReattach = element->recalcStyle(change); | 1575 didReattach = element->recalcStyle(change, indexForChild); |
1573 } | 1576 } |
1574 } | 1577 } |
1575 | 1578 |
1576 forceReattachOfAnyWhitespaceSibling = didReattach || forceReattachOfAnyW
hitespaceSibling; | 1579 if (didReattach) |
| 1580 child->reattachWhitespaceSiblings(); |
1577 } | 1581 } |
1578 | 1582 |
1579 if (shouldRecalcStyle(change, this)) | 1583 if (shouldRecalcStyle(change, this)) |
1580 updatePseudoElement(AFTER, change); | 1584 updatePseudoElement(AFTER, change); |
1581 | 1585 |
1582 clearNeedsStyleRecalc(); | 1586 clearNeedsStyleRecalc(); |
1583 clearChildNeedsStyleRecalc(); | 1587 clearChildNeedsStyleRecalc(); |
1584 | 1588 |
1585 if (hasCustomStyleCallbacks()) | 1589 if (hasCustomStyleCallbacks()) |
1586 didRecalcStyle(change); | 1590 didRecalcStyle(change); |
(...skipping 2062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3649 return 0; | 3653 return 0; |
3650 } | 3654 } |
3651 | 3655 |
3652 Attribute* UniqueElementData::attributeItem(unsigned index) | 3656 Attribute* UniqueElementData::attributeItem(unsigned index) |
3653 { | 3657 { |
3654 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); | 3658 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); |
3655 return &m_attributeVector.at(index); | 3659 return &m_attributeVector.at(index); |
3656 } | 3660 } |
3657 | 3661 |
3658 } // namespace WebCore | 3662 } // namespace WebCore |
OLD | NEW |