 Chromium Code Reviews
 Chromium Code Reviews Issue 144963002:
  Make pseudo element update work with LocalStyleChange.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 144963002:
  Make pseudo element update work with LocalStyleChange.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| 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 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1583 if (ActiveAnimations* activeAnimations = data->activeAnimations( )) | 1583 if (ActiveAnimations* activeAnimations = data->activeAnimations( )) | 
| 1584 activeAnimations->setAnimationStyleChange(false); | 1584 activeAnimations->setAnimationStyleChange(false); | 
| 1585 } | 1585 } | 
| 1586 } | 1586 } | 
| 1587 if (parentRenderStyle()) | 1587 if (parentRenderStyle()) | 
| 1588 change = recalcOwnStyle(change); | 1588 change = recalcOwnStyle(change); | 
| 1589 clearNeedsStyleRecalc(); | 1589 clearNeedsStyleRecalc(); | 
| 1590 } | 1590 } | 
| 1591 | 1591 | 
| 1592 // If we reattached we don't need to recalc the style of our descendants any more. | 1592 // If we reattached we don't need to recalc the style of our descendants any more. | 
| 1593 if ((change >= Inherit && change < Reattach) || childNeedsStyleRecalc()) | 1593 if ((change >= UpdatePseudoElements && change < Reattach) || childNeedsStyle Recalc()) { | 
| 1594 recalcChildStyle(change); | 1594 recalcChildStyle(change); | 
| 1595 clearChildNeedsStyleRecalc(); | 1595 clearChildNeedsStyleRecalc(); | 
| 1596 } | |
| 1596 | 1597 | 
| 1597 if (hasCustomStyleCallbacks()) | 1598 if (hasCustomStyleCallbacks()) | 
| 1598 didRecalcStyle(change); | 1599 didRecalcStyle(change); | 
| 1599 | 1600 | 
| 1600 if (change == Reattach) | 1601 if (change == Reattach) | 
| 1601 reattachWhitespaceSiblings(nextTextSibling); | 1602 reattachWhitespaceSiblings(nextTextSibling); | 
| 1602 } | 1603 } | 
| 1603 | 1604 | 
| 1604 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) | 1605 StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) | 
| 1605 { | 1606 { | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1636 // fooled into believing this style is the same. | 1637 // fooled into believing this style is the same. | 
| 1637 // FIXME: We may be able to remove this hack, see discussion in | 1638 // FIXME: We may be able to remove this hack, see discussion in | 
| 1638 // https://codereview.chromium.org/30453002/ | 1639 // https://codereview.chromium.org/30453002/ | 
| 1639 renderer->setStyleInternal(newStyle.get()); | 1640 renderer->setStyleInternal(newStyle.get()); | 
| 1640 } | 1641 } | 
| 1641 } | 1642 } | 
| 1642 | 1643 | 
| 1643 if (styleChangeType() >= SubtreeStyleChange) | 1644 if (styleChangeType() >= SubtreeStyleChange) | 
| 1644 return Force; | 1645 return Force; | 
| 1645 | 1646 | 
| 1646 if (change <= Inherit) | 1647 if (change > Inherit || localChange > Inherit) | 
| 1647 return localChange; | 1648 return max(localChange, change); | 
| 1648 | 1649 | 
| 1649 return max(localChange, change); | 1650 if (localChange < Inherit && (oldStyle->hasPseudoElementStyle() || newStyle- >hasPseudoElementStyle())) | 
| 1651 return UpdatePseudoElements; | |
| 1652 | |
| 1653 return localChange; | |
| 1650 } | 1654 } | 
| 1651 | 1655 | 
| 1652 void Element::recalcChildStyle(StyleRecalcChange change) | 1656 void Element::recalcChildStyle(StyleRecalcChange change) | 
| 1653 { | 1657 { | 
| 1654 ASSERT(document().inStyleRecalc()); | 1658 ASSERT(document().inStyleRecalc()); | 
| 1655 ASSERT(change >= Inherit || childNeedsStyleRecalc()); | 1659 ASSERT(change >= UpdatePseudoElements || childNeedsStyleRecalc()); | 
| 1656 ASSERT(!needsStyleRecalc()); | 1660 ASSERT(!needsStyleRecalc()); | 
| 1657 | 1661 | 
| 1662 bool updatePseudoElements = change == UpdatePseudoElements && !childNeedsSty leRecalc(); | |
| 1658 StyleResolverParentPusher parentPusher(*this); | 1663 StyleResolverParentPusher parentPusher(*this); | 
| 1659 | 1664 | 
| 1660 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { | 1665 if (!updatePseudoElements) | 
| 
esprehn
2014/01/28 18:08:05
Get rid of the bool, you're also missing braces.
 | |
| 1661 if (root->shouldCallRecalcStyle(change)) { | 1666 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderSh adowRoot()) { | 
| 1662 parentPusher.push(); | 1667 if (root->shouldCallRecalcStyle(change)) { | 
| 1663 root->recalcStyle(change); | 1668 parentPusher.push(); | 
| 1669 root->recalcStyle(change); | |
| 1670 } | |
| 1664 } | 1671 } | 
| 1665 } | |
| 1666 | 1672 | 
| 1667 if (shouldCallRecalcStyle(change)) | 1673 if (shouldUpdatePseudoElements(change)) | 
| 1668 updatePseudoElement(BEFORE, change); | 1674 updatePseudoElement(BEFORE, change); | 
| 1669 | 1675 | 
| 1670 if (change < Force && hasRareData() && childNeedsStyleRecalc()) | 1676 if (change < Force && hasRareData() && childNeedsStyleRecalc()) | 
| 1671 checkForChildrenAdjacentRuleChanges(); | 1677 checkForChildrenAdjacentRuleChanges(); | 
| 1672 | 1678 | 
| 1673 // This loop is deliberately backwards because we use insertBefore in the re ndering tree, and want to avoid | 1679 if (!updatePseudoElements) { | 
| 
esprehn
2014/01/28 18:08:05
Same,
if (change > UpdatePseudoElements || childN
 | |
| 1674 // a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last | 1680 // This loop is deliberately backwards because we use insertBefore in th e rendering tree, and want to avoid | 
| 1675 // child and work our way back means in the common case, we'll find the inse rtion point in O(1) time. | 1681 // a potentially n^2 loop to find the insertion point while resolving st yle. Having us start from the last | 
| 1676 // See crbug.com/288225 | 1682 // child and work our way back means in the common case, we'll find the insertion point in O(1) time. | 
| 1677 StyleResolver& styleResolver = document().ensureStyleResolver(); | 1683 // See crbug.com/288225 | 
| 1678 Text* lastTextNode = 0; | 1684 StyleResolver& styleResolver = document().ensureStyleResolver(); | 
| 1679 for (Node* child = lastChild(); child; child = child->previousSibling()) { | 1685 Text* lastTextNode = 0; | 
| 1680 if (child->isTextNode()) { | 1686 for (Node* child = lastChild(); child; child = child->previousSibling()) { | 
| 1681 toText(child)->recalcTextStyle(change, lastTextNode); | 1687 if (child->isTextNode()) { | 
| 1682 lastTextNode = toText(child); | 1688 toText(child)->recalcTextStyle(change, lastTextNode); | 
| 1683 } else if (child->isElementNode()) { | 1689 lastTextNode = toText(child); | 
| 1684 Element* element = toElement(child); | 1690 } else if (child->isElementNode()) { | 
| 1685 if (element->shouldCallRecalcStyle(change)) { | 1691 Element* element = toElement(child); | 
| 1686 parentPusher.push(); | 1692 if (element->shouldCallRecalcStyle(change)) { | 
| 1687 element->recalcStyle(change, lastTextNode); | 1693 parentPusher.push(); | 
| 1688 } else if (element->supportsStyleSharing()) { | 1694 element->recalcStyle(change, lastTextNode); | 
| 1689 styleResolver.addToStyleSharingList(*element); | 1695 } else if (element->supportsStyleSharing()) { | 
| 1696 styleResolver.addToStyleSharingList(*element); | |
| 1697 } | |
| 1698 if (element->renderer()) | |
| 1699 lastTextNode = 0; | |
| 1690 } | 1700 } | 
| 1691 if (element->renderer()) | |
| 1692 lastTextNode = 0; | |
| 1693 } | 1701 } | 
| 1694 } | 1702 } | 
| 1695 | 1703 | 
| 1696 if (shouldCallRecalcStyle(change)) { | 1704 if (shouldUpdatePseudoElements(change)) { | 
| 1697 updatePseudoElement(AFTER, change); | 1705 updatePseudoElement(AFTER, change); | 
| 1698 updatePseudoElement(BACKDROP, change); | 1706 updatePseudoElement(BACKDROP, change); | 
| 1699 } | 1707 } | 
| 1700 } | 1708 } | 
| 1701 | 1709 | 
| 1702 void Element::checkForChildrenAdjacentRuleChanges() | 1710 void Element::checkForChildrenAdjacentRuleChanges() | 
| 1703 { | 1711 { | 
| 1704 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); | 1712 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); | 
| 1705 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); | 1713 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); | 
| 1706 | 1714 | 
| (...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2753 if (!hasAttributes()) | 2761 if (!hasAttributes()) | 
| 2754 return; | 2762 return; | 
| 2755 for (unsigned i = 0; i < attributeCount(); ++i) { | 2763 for (unsigned i = 0; i < attributeCount(); ++i) { | 
| 2756 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name())) | 2764 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name())) | 
| 2757 attr->normalize(); | 2765 attr->normalize(); | 
| 2758 } | 2766 } | 
| 2759 } | 2767 } | 
| 2760 | 2768 | 
| 2761 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) | 2769 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) | 
| 2762 { | 2770 { | 
| 2771 ASSERT(!needsStyleRecalc()); | |
| 2763 PseudoElement* element = pseudoElement(pseudoId); | 2772 PseudoElement* element = pseudoElement(pseudoId); | 
| 2764 if (element && (needsStyleRecalc() || element->shouldCallRecalcStyle(change) )) { | 2773 if (element && (change == UpdatePseudoElements || element->shouldCallRecalcS tyle(change))) { | 
| 2774 | |
| 2765 // Need to clear the cached style if the PseudoElement wants a recalc so it | 2775 // Need to clear the cached style if the PseudoElement wants a recalc so it | 
| 2766 // computes a new style. | 2776 // computes a new style. | 
| 2767 if (element->needsStyleRecalc()) | 2777 if (element->needsStyleRecalc()) | 
| 2768 renderer()->style()->removeCachedPseudoStyle(pseudoId); | 2778 renderer()->style()->removeCachedPseudoStyle(pseudoId); | 
| 2769 | 2779 | 
| 2770 // PseudoElement styles hang off their parent element's style so if we n eeded | 2780 // PseudoElement styles hang off their parent element's style so if we n eeded | 
| 2771 // a style recalc we should Force one on the pseudo. | 2781 // a style recalc we should Force one on the pseudo. | 
| 2772 // FIXME: We should figure out the right text sibling to pass. | 2782 // FIXME: We should figure out the right text sibling to pass. | 
| 2773 element->recalcStyle(needsStyleRecalc() ? Force : change); | 2783 element->recalcStyle(change == UpdatePseudoElements ? Force : change); | 
| 2774 | 2784 | 
| 2775 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed | 2785 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed | 
| 2776 // is false, otherwise we could continously create and destroy PseudoEle ments | 2786 // is false, otherwise we could continously create and destroy PseudoEle ments | 
| 2777 // when RenderObject::isChildAllowed on our parent returns false for the | 2787 // when RenderObject::isChildAllowed on our parent returns false for the | 
| 2778 // PseudoElement's renderer for each style recalc. | 2788 // PseudoElement's renderer for each style recalc. | 
| 2779 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId))) | 2789 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId))) | 
| 2780 elementRareData()->setPseudoElement(pseudoId, 0); | 2790 elementRareData()->setPseudoElement(pseudoId, 0); | 
| 2781 } else if (change >= Inherit || needsStyleRecalc()) | 2791 } else if (change >= UpdatePseudoElements) { | 
| 2782 createPseudoElementIfNeeded(pseudoId); | 2792 createPseudoElementIfNeeded(pseudoId); | 
| 2793 } | |
| 2783 } | 2794 } | 
| 2784 | 2795 | 
| 2785 void Element::createPseudoElementIfNeeded(PseudoId pseudoId) | 2796 void Element::createPseudoElementIfNeeded(PseudoId pseudoId) | 
| 2786 { | 2797 { | 
| 2787 if (isPseudoElement()) | 2798 if (isPseudoElement()) | 
| 2788 return; | 2799 return; | 
| 2789 | 2800 | 
| 2790 RefPtr<PseudoElement> element = document().ensureStyleResolver().createPseud oElementIfNeeded(*this, pseudoId); | 2801 RefPtr<PseudoElement> element = document().ensureStyleResolver().createPseud oElementIfNeeded(*this, pseudoId); | 
| 2791 if (!element) | 2802 if (!element) | 
| 2792 return; | 2803 return; | 
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3620 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems | 3631 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems | 
| 3621 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 | 3632 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 | 
| 3622 if (hasTagName(optionTag) || hasTagName(optgroupTag)) | 3633 if (hasTagName(optionTag) || hasTagName(optgroupTag)) | 
| 3623 return false; | 3634 return false; | 
| 3624 if (FullscreenElementStack::isActiveFullScreenElement(this)) | 3635 if (FullscreenElementStack::isActiveFullScreenElement(this)) | 
| 3625 return false; | 3636 return false; | 
| 3626 return true; | 3637 return true; | 
| 3627 } | 3638 } | 
| 3628 | 3639 | 
| 3629 } // namespace WebCore | 3640 } // namespace WebCore | 
| OLD | NEW |