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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 #include "wtf/text/CString.h" | 102 #include "wtf/text/CString.h" |
103 #include "wtf/text/TextPosition.h" | 103 #include "wtf/text/TextPosition.h" |
104 | 104 |
105 namespace WebCore { | 105 namespace WebCore { |
106 | 106 |
107 using namespace HTMLNames; | 107 using namespace HTMLNames; |
108 using namespace XMLNames; | 108 using namespace XMLNames; |
109 | 109 |
110 class StyleResolverParentPusher { | 110 class StyleResolverParentPusher { |
111 public: | 111 public: |
112 explicit StyleResolverParentPusher(Element& parent) | 112 StyleResolverParentPusher(Element& parent, StyleRecalcChange change = NoChan ge) |
leviw_travelin_and_unemployed
2013/11/11 18:56:15
Since the 2nd argument isn't required, are you sur
| |
113 : m_parent(parent) | 113 : m_parent(parent) |
114 , m_pushedStyleResolver(0) | 114 , m_pushedStyleResolver(0) |
115 { | 115 { |
116 if ((change >= Inherit || parent.childNeedsStyleRecalc()) && (parent.has ChildNodes() || parent.youngestShadowRoot())) { | |
117 m_pushedStyleResolver = m_parent.document().styleResolver(); | |
118 m_pushedStyleResolver->pushParentElement(m_parent); | |
119 } | |
116 } | 120 } |
117 void push() | 121 |
118 { | |
119 if (m_pushedStyleResolver) | |
120 return; | |
121 m_pushedStyleResolver = m_parent.document().styleResolver(); | |
122 m_pushedStyleResolver->pushParentElement(m_parent); | |
123 } | |
124 ~StyleResolverParentPusher() | 122 ~StyleResolverParentPusher() |
125 { | 123 { |
126 | |
127 if (!m_pushedStyleResolver) | 124 if (!m_pushedStyleResolver) |
128 return; | 125 return; |
129 | |
130 // This tells us that our pushed style selector is in a bad state, | |
131 // so we should just bail out in that scenario. | |
132 ASSERT(m_pushedStyleResolver == m_parent.document().styleResolver()); | |
133 if (m_pushedStyleResolver != m_parent.document().styleResolver()) | |
134 return; | |
135 | |
136 m_pushedStyleResolver->popParentElement(m_parent); | 126 m_pushedStyleResolver->popParentElement(m_parent); |
137 } | 127 } |
138 | 128 |
139 private: | 129 private: |
140 Element& m_parent; | 130 Element& m_parent; |
141 StyleResolver* m_pushedStyleResolver; | 131 StyleResolver* m_pushedStyleResolver; |
142 }; | 132 }; |
143 | 133 |
144 typedef Vector<RefPtr<Attr> > AttrNodeList; | 134 typedef Vector<RefPtr<Attr> > AttrNodeList; |
145 typedef HashMap<Element*, OwnPtr<AttrNodeList> > AttrNodeListMap; | 135 typedef HashMap<Element*, OwnPtr<AttrNodeList> > AttrNodeListMap; |
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1352 document().removeFromTopLayer(this); | 1342 document().removeFromTopLayer(this); |
1353 | 1343 |
1354 if (hasRareData()) | 1344 if (hasRareData()) |
1355 elementRareData()->setIsInCanvasSubtree(false); | 1345 elementRareData()->setIsInCanvasSubtree(false); |
1356 } | 1346 } |
1357 | 1347 |
1358 void Element::attach(const AttachContext& context) | 1348 void Element::attach(const AttachContext& context) |
1359 { | 1349 { |
1360 ASSERT(document().inStyleRecalc()); | 1350 ASSERT(document().inStyleRecalc()); |
1361 | 1351 |
1362 StyleResolverParentPusher parentPusher(*this); | |
1363 | |
1364 // We've already been through detach when doing a lazyAttach, but we might | 1352 // We've already been through detach when doing a lazyAttach, but we might |
1365 // need to clear any state that's been added since then. | 1353 // need to clear any state that's been added since then. |
1366 if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) { | 1354 if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) { |
1367 ElementRareData* data = elementRareData(); | 1355 ElementRareData* data = elementRareData(); |
1368 data->clearComputedStyle(); | 1356 data->clearComputedStyle(); |
1369 data->resetDynamicRestyleObservations(); | 1357 data->resetDynamicRestyleObservations(); |
1370 if (!context.resolvedStyle) | 1358 if (!context.resolvedStyle) |
1371 data->resetStyleState(); | 1359 data->resetStyleState(); |
1372 } | 1360 } |
1373 | 1361 |
1374 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf Needed(); | 1362 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf Needed(); |
1375 | 1363 |
1376 if (RenderStyle* style = renderStyle()) | 1364 if (RenderStyle* style = renderStyle()) |
1377 updateCallbackSelectors(0, style); | 1365 updateCallbackSelectors(0, style); |
1378 | 1366 |
1367 StyleResolverParentPusher pushParent(*this); | |
1368 | |
1379 createPseudoElementIfNeeded(BEFORE); | 1369 createPseudoElementIfNeeded(BEFORE); |
1380 | 1370 |
1381 // When a shadow root exists, it does the work of attaching the children. | 1371 // When a shadow root exists, it does the work of attaching the children. |
1382 if (ElementShadow* shadow = this->shadow()) { | 1372 if (ElementShadow* shadow = this->shadow()) |
1383 parentPusher.push(); | |
1384 shadow->attach(context); | 1373 shadow->attach(context); |
1385 } else if (firstChild()) | |
1386 parentPusher.push(); | |
1387 | 1374 |
1388 ContainerNode::attach(context); | 1375 ContainerNode::attach(context); |
1389 | 1376 |
1390 createPseudoElementIfNeeded(AFTER); | 1377 createPseudoElementIfNeeded(AFTER); |
1391 createPseudoElementIfNeeded(BACKDROP); | 1378 createPseudoElementIfNeeded(BACKDROP); |
1392 | 1379 |
1393 if (hasRareData()) { | 1380 if (hasRareData()) { |
1394 ElementRareData* data = elementRareData(); | 1381 ElementRareData* data = elementRareData(); |
1395 if (data->needsFocusAppearanceUpdateSoonAfterAttach()) { | 1382 if (data->needsFocusAppearanceUpdateSoonAfterAttach()) { |
1396 if (isFocusable() && document().focusedElement() == this) | 1383 if (isFocusable() && document().focusedElement() == this) |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1584 | 1571 |
1585 return max(localChange, change); | 1572 return max(localChange, change); |
1586 } | 1573 } |
1587 | 1574 |
1588 void Element::recalcChildStyle(StyleRecalcChange change) | 1575 void Element::recalcChildStyle(StyleRecalcChange change) |
1589 { | 1576 { |
1590 ASSERT(document().inStyleRecalc()); | 1577 ASSERT(document().inStyleRecalc()); |
1591 ASSERT(change >= Inherit || childNeedsStyleRecalc()); | 1578 ASSERT(change >= Inherit || childNeedsStyleRecalc()); |
1592 ASSERT(!needsStyleRecalc()); | 1579 ASSERT(!needsStyleRecalc()); |
1593 | 1580 |
1594 StyleResolverParentPusher parentPusher(*this); | 1581 StyleResolverParentPusher pushParent(*this, change); |
1595 | 1582 |
1596 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { | 1583 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { |
1597 if (shouldRecalcStyle(change, root)) { | 1584 if (shouldRecalcStyle(change, root)) |
1598 parentPusher.push(); | |
1599 root->recalcStyle(change); | 1585 root->recalcStyle(change); |
1600 } | |
1601 } | 1586 } |
1602 | 1587 |
1603 if (shouldRecalcStyle(change, this)) | 1588 if (shouldRecalcStyle(change, this)) |
1604 updatePseudoElement(BEFORE, change); | 1589 updatePseudoElement(BEFORE, change); |
1605 | 1590 |
1606 if (change < Force && hasRareData() && childNeedsStyleRecalc()) | 1591 if (change < Force && hasRareData() && childNeedsStyleRecalc()) |
1607 checkForChildrenAdjacentRuleChanges(); | 1592 checkForChildrenAdjacentRuleChanges(); |
1608 | 1593 |
1609 // This loop is deliberately backwards because we use insertBefore in the re ndering tree, and want to avoid | 1594 // This loop is deliberately backwards because we use insertBefore in the re ndering tree, and want to avoid |
1610 // a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last | 1595 // a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last |
1611 // child and work our way back means in the common case, we'll find the inse rtion point in O(1) time. | 1596 // child and work our way back means in the common case, we'll find the inse rtion point in O(1) time. |
1612 // Reversing this loop can lead to non-deterministic results in our code to optimize out empty whitespace | 1597 // Reversing this loop can lead to non-deterministic results in our code to optimize out empty whitespace |
1613 // RenderTexts. We try to put off recalcing their style until the end to avo id this issue. | 1598 // RenderTexts. We try to put off recalcing their style until the end to avo id this issue. |
1614 // See crbug.com/288225 | 1599 // See crbug.com/288225 |
1615 for (Node* child = lastChild(); child; child = child->previousSibling()) { | 1600 for (Node* child = lastChild(); child; child = child->previousSibling()) { |
1616 bool didReattach = false; | 1601 bool didReattach = false; |
1617 if (child->isTextNode()) { | 1602 if (child->isTextNode()) { |
1618 didReattach = toText(child)->recalcTextStyle(change); | 1603 didReattach = toText(child)->recalcTextStyle(change); |
1619 } else if (child->isElementNode()) { | 1604 } else if (child->isElementNode()) { |
1620 Element* element = toElement(child); | 1605 Element* element = toElement(child); |
1621 if (shouldRecalcStyle(change, element)) { | 1606 if (shouldRecalcStyle(change, element)) |
1622 parentPusher.push(); | |
1623 didReattach = element->recalcStyle(change); | 1607 didReattach = element->recalcStyle(change); |
1624 } else if (element->supportsStyleSharing()) { | 1608 else if (element->supportsStyleSharing()) |
1625 document().styleResolver()->addToStyleSharingList(*element); | 1609 document().styleResolver()->addToStyleSharingList(*element); |
1626 } | |
1627 } | 1610 } |
1628 if (didReattach) | 1611 if (didReattach) |
1629 child->reattachWhitespaceSiblings(); | 1612 child->reattachWhitespaceSiblings(); |
1630 } | 1613 } |
1631 | 1614 |
1632 if (shouldRecalcStyle(change, this)) { | 1615 if (shouldRecalcStyle(change, this)) { |
1633 updatePseudoElement(AFTER, change); | 1616 updatePseudoElement(AFTER, change); |
1634 updatePseudoElement(BACKDROP, change); | 1617 updatePseudoElement(BACKDROP, change); |
1635 } | 1618 } |
1636 } | 1619 } |
(...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3498 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems | 3481 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems |
3499 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 | 3482 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 |
3500 if (hasTagName(optionTag) || hasTagName(optgroupTag)) | 3483 if (hasTagName(optionTag) || hasTagName(optgroupTag)) |
3501 return false; | 3484 return false; |
3502 if (FullscreenElementStack::isActiveFullScreenElement(this)) | 3485 if (FullscreenElementStack::isActiveFullScreenElement(this)) |
3503 return false; | 3486 return false; |
3504 return true; | 3487 return true; |
3505 } | 3488 } |
3506 | 3489 |
3507 } // namespace WebCore | 3490 } // namespace WebCore |
OLD | NEW |