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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include "core/dom/MutationObserverInterestGroup.h" | 59 #include "core/dom/MutationObserverInterestGroup.h" |
60 #include "core/dom/MutationRecord.h" | 60 #include "core/dom/MutationRecord.h" |
61 #include "core/dom/NamedNodeMap.h" | 61 #include "core/dom/NamedNodeMap.h" |
62 #include "core/dom/NodeRenderStyle.h" | 62 #include "core/dom/NodeRenderStyle.h" |
63 #include "core/dom/NodeRenderingContext.h" | 63 #include "core/dom/NodeRenderingContext.h" |
64 #include "core/dom/PostAttachCallbacks.h" | 64 #include "core/dom/PostAttachCallbacks.h" |
65 #include "core/dom/PseudoElement.h" | 65 #include "core/dom/PseudoElement.h" |
66 #include "core/dom/ScriptableDocumentParser.h" | 66 #include "core/dom/ScriptableDocumentParser.h" |
67 #include "core/dom/SelectorQuery.h" | 67 #include "core/dom/SelectorQuery.h" |
68 #include "core/dom/Text.h" | 68 #include "core/dom/Text.h" |
| 69 #include "core/dom/WhitespaceChildList.h" |
69 #include "core/dom/shadow/InsertionPoint.h" | 70 #include "core/dom/shadow/InsertionPoint.h" |
70 #include "core/dom/shadow/ShadowRoot.h" | 71 #include "core/dom/shadow/ShadowRoot.h" |
71 #include "core/editing/FrameSelection.h" | 72 #include "core/editing/FrameSelection.h" |
72 #include "core/editing/TextIterator.h" | 73 #include "core/editing/TextIterator.h" |
73 #include "core/editing/htmlediting.h" | 74 #include "core/editing/htmlediting.h" |
74 #include "core/html/ClassList.h" | 75 #include "core/html/ClassList.h" |
75 #include "core/html/HTMLCollection.h" | 76 #include "core/html/HTMLCollection.h" |
76 #include "core/html/HTMLDocument.h" | 77 #include "core/html/HTMLDocument.h" |
77 #include "core/html/HTMLElement.h" | 78 #include "core/html/HTMLElement.h" |
78 #include "core/html/HTMLFormControlsCollection.h" | 79 #include "core/html/HTMLFormControlsCollection.h" |
(...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 if (shouldRecalcStyle(change, this)) | 1531 if (shouldRecalcStyle(change, this)) |
1531 updatePseudoElement(BEFORE, change); | 1532 updatePseudoElement(BEFORE, change); |
1532 | 1533 |
1533 // FIXME: This check is good enough for :hover + foo, but it is not good eno
ugh for :hover + foo + bar. | 1534 // FIXME: This check is good enough for :hover + foo, but it is not good eno
ugh for :hover + foo + bar. |
1534 // For now we will just worry about the common case, since it's a lot tricki
er to get the second case right | 1535 // For now we will just worry about the common case, since it's a lot tricki
er to get the second case right |
1535 // without doing way too much re-resolution. | 1536 // without doing way too much re-resolution. |
1536 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); | 1537 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); |
1537 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); | 1538 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); |
1538 bool forceCheckOfNextElementSibling = false; | 1539 bool forceCheckOfNextElementSibling = false; |
1539 bool forceCheckOfAnyElementSibling = false; | 1540 bool forceCheckOfAnyElementSibling = false; |
1540 bool forceReattachOfAnyWhitespaceSibling = false; | 1541 if (hasDirectAdjacentRules || hasIndirectAdjacentRules) { |
1541 for (Node* child = firstChild(); child; child = child->nextSibling()) { | 1542 for (Node* child = firstChild(); child; child = child->nextSibling()) { |
1542 bool didReattach = false; | 1543 if (!child->isElementNode()) |
1543 | 1544 continue; |
1544 if (child->renderer()) | 1545 Element* element = toElement(child); |
1545 forceReattachOfAnyWhitespaceSibling = false; | 1546 bool childRulesChanged = element->needsStyleRecalc() && element->sty
leChangeType() >= SubtreeStyleChange; |
1546 | 1547 if (forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling) |
| 1548 element->setNeedsStyleRecalc(); |
| 1549 forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjac
entRules; |
| 1550 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (ch
ildRulesChanged && hasIndirectAdjacentRules); |
| 1551 } |
| 1552 } |
| 1553 // This loop is deliberately backwards because we use insertBefore in the re
ndering tree, and want to avoid |
| 1554 // a potentially n^2 loop to find the insertion point while resolving style.
Having us start from the last |
| 1555 // child and work our way back means in the common case, we'll find the inse
rtion point in O(1) time. |
| 1556 // Reversing this loop can lead to non-deterministic results in our code to
optimize out empty whitespace |
| 1557 // RenderTexts. We try to put off recalcing their style until the end to avo
id this issue. |
| 1558 // See crbug.com/288225 |
| 1559 WhitespaceChildList whitespaceChildList(change); |
| 1560 for (Node* child = lastChild(); child; child = child->previousSibling()) { |
1547 if (child->isTextNode()) { | 1561 if (child->isTextNode()) { |
1548 if (forceReattachOfAnyWhitespaceSibling && toText(child)->containsOn
lyWhitespace()) | 1562 Text* textChild = toText(child); |
1549 child->reattach(); | 1563 // FIXME: This check is expensive and may negate the performance gai
ned by the optimization of |
| 1564 // avoiding whitespace renderers. |
| 1565 if (textChild->containsOnlyWhitespace()) |
| 1566 whitespaceChildList.append(textChild); |
1550 else | 1567 else |
1551 didReattach = toText(child)->recalcTextStyle(change); | 1568 textChild->recalcTextStyle(change); |
1552 } else if (child->isElementNode()) { | 1569 } else if (child->isElementNode()) { |
1553 Element* element = toElement(child); | 1570 Element* element = toElement(child); |
1554 | |
1555 bool childRulesChanged = element->needsStyleRecalc() && element->sty
leChangeType() >= SubtreeStyleChange; | |
1556 | |
1557 if (forceCheckOfNextElementSibling || forceCheckOfAnyElementSibling) | |
1558 element->setNeedsStyleRecalc(); | |
1559 | |
1560 forceCheckOfNextElementSibling = childRulesChanged && hasDirectAdjac
entRules; | |
1561 forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (ch
ildRulesChanged && hasIndirectAdjacentRules); | |
1562 | |
1563 if (shouldRecalcStyle(change, element)) { | 1571 if (shouldRecalcStyle(change, element)) { |
1564 parentPusher.push(); | 1572 parentPusher.push(); |
1565 didReattach = element->recalcStyle(change); | 1573 element->recalcStyle(change); |
1566 } else if (document().styleResolver()->supportsStyleSharing(element)
) { | 1574 } else if (document().styleResolver()->supportsStyleSharing(element)
) { |
1567 document().styleResolver()->addToStyleSharingList(element); | 1575 document().styleResolver()->addToStyleSharingList(element); |
1568 } | 1576 } |
1569 } | 1577 } |
| 1578 } |
1570 | 1579 |
1571 forceReattachOfAnyWhitespaceSibling = didReattach || forceReattachOfAnyW
hitespaceSibling; | 1580 whitespaceChildList.recalcStyle(); |
1572 } | |
1573 | 1581 |
1574 if (shouldRecalcStyle(change, this)) { | 1582 if (shouldRecalcStyle(change, this)) { |
1575 updatePseudoElement(AFTER, change); | 1583 updatePseudoElement(AFTER, change); |
1576 updatePseudoElement(BACKDROP, change); | 1584 updatePseudoElement(BACKDROP, change); |
1577 } | 1585 } |
1578 } | 1586 } |
1579 | 1587 |
1580 ElementShadow* Element::shadow() const | 1588 ElementShadow* Element::shadow() const |
1581 { | 1589 { |
1582 return hasRareData() ? elementRareData()->shadow() : 0; | 1590 return hasRareData() ? elementRareData()->shadow() : 0; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 | 1741 |
1734 // We also have to handle node removal. The parser callback case is sim
ilar to node removal as well in that we need to change the last child | 1742 // We also have to handle node removal. The parser callback case is sim
ilar to node removal as well in that we need to change the last child |
1735 // to match now. | 1743 // to match now. |
1736 if ((childCountDelta < 0 || finishedParsingCallback) && newLastChild ==
lastElementBeforeInsertion && newLastChild && (!newLastChildStyle || !newLastChi
ldStyle->lastChildState())) | 1744 if ((childCountDelta < 0 || finishedParsingCallback) && newLastChild ==
lastElementBeforeInsertion && newLastChild && (!newLastChildStyle || !newLastChi
ldStyle->lastChildState())) |
1737 newLastChild->setNeedsStyleRecalc(); | 1745 newLastChild->setNeedsStyleRecalc(); |
1738 } | 1746 } |
1739 | 1747 |
1740 // The + selector. We need to invalidate the first element following the in
sertion point. It is the only possible element | 1748 // The + selector. We need to invalidate the first element following the in
sertion point. It is the only possible element |
1741 // that could be affected by this DOM change. | 1749 // that could be affected by this DOM change. |
1742 if (e->childrenAffectedByDirectAdjacentRules() && afterChange) { | 1750 if (e->childrenAffectedByDirectAdjacentRules() && afterChange) { |
1743 if (Node* firstElementAfterInsertion = afterChange->nextElementSibling()
) | 1751 if (Node* firstElementAfterInsertion = afterChange->isElementNode() ? af
terChange : afterChange->nextElementSibling()) |
1744 firstElementAfterInsertion->setNeedsStyleRecalc(); | 1752 firstElementAfterInsertion->setNeedsStyleRecalc(); |
1745 } | 1753 } |
1746 } | 1754 } |
1747 | 1755 |
1748 void Element::childrenChanged(bool changedByParser, Node* beforeChange, Node* af
terChange, int childCountDelta) | 1756 void Element::childrenChanged(bool changedByParser, Node* beforeChange, Node* af
terChange, int childCountDelta) |
1749 { | 1757 { |
1750 ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, c
hildCountDelta); | 1758 ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, c
hildCountDelta); |
1751 if (changedByParser) | 1759 if (changedByParser) |
1752 checkForEmptyStyleChange(this, renderStyle()); | 1760 checkForEmptyStyleChange(this, renderStyle()); |
1753 else | 1761 else |
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3642 return 0; | 3650 return 0; |
3643 } | 3651 } |
3644 | 3652 |
3645 Attribute* UniqueElementData::attributeItem(unsigned index) | 3653 Attribute* UniqueElementData::attributeItem(unsigned index) |
3646 { | 3654 { |
3647 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); | 3655 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); |
3648 return &m_attributeVector.at(index); | 3656 return &m_attributeVector.at(index); |
3649 } | 3657 } |
3650 | 3658 |
3651 } // namespace WebCore | 3659 } // namespace WebCore |
OLD | NEW |