| 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 explicit StyleResolverParentPusher(Element& parent, StyleRecalcChange change
= NoChange) |
| 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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 document().removeFromTopLayer(this); | 1349 document().removeFromTopLayer(this); |
| 1360 | 1350 |
| 1361 if (hasRareData()) | 1351 if (hasRareData()) |
| 1362 elementRareData()->setIsInCanvasSubtree(false); | 1352 elementRareData()->setIsInCanvasSubtree(false); |
| 1363 } | 1353 } |
| 1364 | 1354 |
| 1365 void Element::attach(const AttachContext& context) | 1355 void Element::attach(const AttachContext& context) |
| 1366 { | 1356 { |
| 1367 ASSERT(document().inStyleRecalc()); | 1357 ASSERT(document().inStyleRecalc()); |
| 1368 | 1358 |
| 1369 StyleResolverParentPusher parentPusher(*this); | |
| 1370 | |
| 1371 // We've already been through detach when doing a lazyAttach, but we might | 1359 // We've already been through detach when doing a lazyAttach, but we might |
| 1372 // need to clear any state that's been added since then. | 1360 // need to clear any state that's been added since then. |
| 1373 if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) { | 1361 if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) { |
| 1374 ElementRareData* data = elementRareData(); | 1362 ElementRareData* data = elementRareData(); |
| 1375 data->clearComputedStyle(); | 1363 data->clearComputedStyle(); |
| 1376 data->resetDynamicRestyleObservations(); | 1364 data->resetDynamicRestyleObservations(); |
| 1377 if (!context.resolvedStyle) | 1365 if (!context.resolvedStyle) |
| 1378 data->resetStyleState(); | 1366 data->resetStyleState(); |
| 1379 } | 1367 } |
| 1380 | 1368 |
| 1381 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf
Needed(); | 1369 NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIf
Needed(); |
| 1382 | 1370 |
| 1383 if (RenderStyle* style = renderStyle()) | 1371 if (RenderStyle* style = renderStyle()) |
| 1384 updateCallbackSelectors(0, style); | 1372 updateCallbackSelectors(0, style); |
| 1385 | 1373 |
| 1374 StyleResolverParentPusher pushParent(*this); |
| 1375 |
| 1386 createPseudoElementIfNeeded(BEFORE); | 1376 createPseudoElementIfNeeded(BEFORE); |
| 1387 | 1377 |
| 1388 // When a shadow root exists, it does the work of attaching the children. | 1378 // When a shadow root exists, it does the work of attaching the children. |
| 1389 if (ElementShadow* shadow = this->shadow()) { | 1379 if (ElementShadow* shadow = this->shadow()) |
| 1390 parentPusher.push(); | |
| 1391 shadow->attach(context); | 1380 shadow->attach(context); |
| 1392 } else if (firstChild()) | |
| 1393 parentPusher.push(); | |
| 1394 | 1381 |
| 1395 ContainerNode::attach(context); | 1382 ContainerNode::attach(context); |
| 1396 | 1383 |
| 1397 createPseudoElementIfNeeded(AFTER); | 1384 createPseudoElementIfNeeded(AFTER); |
| 1398 createPseudoElementIfNeeded(BACKDROP); | 1385 createPseudoElementIfNeeded(BACKDROP); |
| 1399 | 1386 |
| 1400 if (hasRareData()) { | 1387 if (hasRareData()) { |
| 1401 ElementRareData* data = elementRareData(); | 1388 ElementRareData* data = elementRareData(); |
| 1402 if (data->needsFocusAppearanceUpdateSoonAfterAttach()) { | 1389 if (data->needsFocusAppearanceUpdateSoonAfterAttach()) { |
| 1403 if (isFocusable() && document().focusedElement() == this) | 1390 if (isFocusable() && document().focusedElement() == this) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 | 1579 |
| 1593 return max(localChange, change); | 1580 return max(localChange, change); |
| 1594 } | 1581 } |
| 1595 | 1582 |
| 1596 void Element::recalcChildStyle(StyleRecalcChange change) | 1583 void Element::recalcChildStyle(StyleRecalcChange change) |
| 1597 { | 1584 { |
| 1598 ASSERT(document().inStyleRecalc()); | 1585 ASSERT(document().inStyleRecalc()); |
| 1599 ASSERT(change >= Inherit || childNeedsStyleRecalc()); | 1586 ASSERT(change >= Inherit || childNeedsStyleRecalc()); |
| 1600 ASSERT(!needsStyleRecalc()); | 1587 ASSERT(!needsStyleRecalc()); |
| 1601 | 1588 |
| 1602 StyleResolverParentPusher parentPusher(*this); | 1589 StyleResolverParentPusher pushParent(*this, change); |
| 1603 | 1590 |
| 1604 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) { | 1591 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) { |
| 1605 if (shouldRecalcStyle(change, root)) { | 1592 if (shouldRecalcStyle(change, root)) |
| 1606 parentPusher.push(); | |
| 1607 root->recalcStyle(change); | 1593 root->recalcStyle(change); |
| 1608 } | |
| 1609 } | 1594 } |
| 1610 | 1595 |
| 1611 if (shouldRecalcStyle(change, this)) | 1596 if (shouldRecalcStyle(change, this)) |
| 1612 updatePseudoElement(BEFORE, change); | 1597 updatePseudoElement(BEFORE, change); |
| 1613 | 1598 |
| 1614 if (change < Force && hasRareData() && childNeedsStyleRecalc()) | 1599 if (change < Force && hasRareData() && childNeedsStyleRecalc()) |
| 1615 checkForChildrenAdjacentRuleChanges(); | 1600 checkForChildrenAdjacentRuleChanges(); |
| 1616 | 1601 |
| 1617 // This loop is deliberately backwards because we use insertBefore in the re
ndering tree, and want to avoid | 1602 // This loop is deliberately backwards because we use insertBefore in the re
ndering tree, and want to avoid |
| 1618 // a potentially n^2 loop to find the insertion point while resolving style.
Having us start from the last | 1603 // a potentially n^2 loop to find the insertion point while resolving style.
Having us start from the last |
| 1619 // child and work our way back means in the common case, we'll find the inse
rtion point in O(1) time. | 1604 // child and work our way back means in the common case, we'll find the inse
rtion point in O(1) time. |
| 1620 // See crbug.com/288225 | 1605 // See crbug.com/288225 |
| 1621 StyleResolver& styleResolver = *document().styleResolver(); | 1606 StyleResolver& styleResolver = *document().styleResolver(); |
| 1622 for (Node* child = lastChild(); child; child = child->previousSibling()) { | 1607 for (Node* child = lastChild(); child; child = child->previousSibling()) { |
| 1623 if (child->isTextNode()) { | 1608 if (child->isTextNode()) { |
| 1624 toText(child)->recalcTextStyle(change); | 1609 toText(child)->recalcTextStyle(change); |
| 1625 } else if (child->isElementNode()) { | 1610 } else if (child->isElementNode()) { |
| 1626 Element* element = toElement(child); | 1611 Element* element = toElement(child); |
| 1627 if (shouldRecalcStyle(change, element)) { | 1612 if (shouldRecalcStyle(change, element)) |
| 1628 parentPusher.push(); | |
| 1629 element->recalcStyle(change); | 1613 element->recalcStyle(change); |
| 1630 } else if (element->supportsStyleSharing()) { | 1614 else if (element->supportsStyleSharing()) |
| 1631 styleResolver.addToStyleSharingList(*element); | 1615 styleResolver.addToStyleSharingList(*element); |
| 1632 } | |
| 1633 } | 1616 } |
| 1634 } | 1617 } |
| 1635 | 1618 |
| 1636 if (shouldRecalcStyle(change, this)) { | 1619 if (shouldRecalcStyle(change, this)) { |
| 1637 updatePseudoElement(AFTER, change); | 1620 updatePseudoElement(AFTER, change); |
| 1638 updatePseudoElement(BACKDROP, change); | 1621 updatePseudoElement(BACKDROP, change); |
| 1639 } | 1622 } |
| 1640 } | 1623 } |
| 1641 | 1624 |
| 1642 // FIXME: This method and checkForSiblingStyleChanges and checkForEmptyStyleChan
ge | 1625 // FIXME: This method and checkForSiblingStyleChanges and checkForEmptyStyleChan
ge |
| (...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3513 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi
stItems | 3496 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi
stItems |
| 3514 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg
i?id=88405 | 3497 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg
i?id=88405 |
| 3515 if (hasTagName(optionTag) || hasTagName(optgroupTag)) | 3498 if (hasTagName(optionTag) || hasTagName(optgroupTag)) |
| 3516 return false; | 3499 return false; |
| 3517 if (FullscreenElementStack::isActiveFullScreenElement(this)) | 3500 if (FullscreenElementStack::isActiveFullScreenElement(this)) |
| 3518 return false; | 3501 return false; |
| 3519 return true; | 3502 return true; |
| 3520 } | 3503 } |
| 3521 | 3504 |
| 3522 } // namespace WebCore | 3505 } // namespace WebCore |
| OLD | NEW |