Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: Source/core/dom/Element.cpp

Issue 144963002: Make pseudo element update work with LocalStyleChange. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed review issues and removed always true if-tests. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/rendering/style/RenderStyle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
1658 StyleResolverParentPusher parentPusher(*this); 1662 StyleResolverParentPusher parentPusher(*this);
1659 1663
1660 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { 1664 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
1661 if (root->shouldCallRecalcStyle(change)) { 1665 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderSh adowRoot()) {
1662 parentPusher.push(); 1666 if (root->shouldCallRecalcStyle(change)) {
1663 root->recalcStyle(change); 1667 parentPusher.push();
1668 root->recalcStyle(change);
1669 }
1664 } 1670 }
1665 } 1671 }
1666 1672
1667 if (shouldCallRecalcStyle(change)) 1673 updatePseudoElement(BEFORE, change);
1668 updatePseudoElement(BEFORE, change);
1669 1674
1670 if (change < Force && hasRareData() && childNeedsStyleRecalc()) 1675 if (change < Force && hasRareData() && childNeedsStyleRecalc())
1671 checkForChildrenAdjacentRuleChanges(); 1676 checkForChildrenAdjacentRuleChanges();
1672 1677
1673 // This loop is deliberately backwards because we use insertBefore in the re ndering tree, and want to avoid 1678 if (change > UpdatePseudoElements || childNeedsStyleRecalc()) {
1674 // a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last 1679 // 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. 1680 // 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 1681 // 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(); 1682 // See crbug.com/288225
1678 Text* lastTextNode = 0; 1683 StyleResolver& styleResolver = document().ensureStyleResolver();
1679 for (Node* child = lastChild(); child; child = child->previousSibling()) { 1684 Text* lastTextNode = 0;
1680 if (child->isTextNode()) { 1685 for (Node* child = lastChild(); child; child = child->previousSibling()) {
1681 toText(child)->recalcTextStyle(change, lastTextNode); 1686 if (child->isTextNode()) {
1682 lastTextNode = toText(child); 1687 toText(child)->recalcTextStyle(change, lastTextNode);
1683 } else if (child->isElementNode()) { 1688 lastTextNode = toText(child);
1684 Element* element = toElement(child); 1689 } else if (child->isElementNode()) {
1685 if (element->shouldCallRecalcStyle(change)) { 1690 Element* element = toElement(child);
1686 parentPusher.push(); 1691 if (element->shouldCallRecalcStyle(change)) {
1687 element->recalcStyle(change, lastTextNode); 1692 parentPusher.push();
1688 } else if (element->supportsStyleSharing()) { 1693 element->recalcStyle(change, lastTextNode);
1689 styleResolver.addToStyleSharingList(*element); 1694 } else if (element->supportsStyleSharing()) {
1695 styleResolver.addToStyleSharingList(*element);
1696 }
1697 if (element->renderer())
1698 lastTextNode = 0;
1690 } 1699 }
1691 if (element->renderer())
1692 lastTextNode = 0;
1693 } 1700 }
1694 } 1701 }
1695 1702
1696 if (shouldCallRecalcStyle(change)) { 1703 updatePseudoElement(AFTER, change);
1697 updatePseudoElement(AFTER, change); 1704 updatePseudoElement(BACKDROP, change);
1698 updatePseudoElement(BACKDROP, change);
1699 }
1700 } 1705 }
1701 1706
1702 void Element::checkForChildrenAdjacentRuleChanges() 1707 void Element::checkForChildrenAdjacentRuleChanges()
1703 { 1708 {
1704 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); 1709 bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules();
1705 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); 1710 bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules();
1706 1711
1707 if (!hasDirectAdjacentRules && !hasIndirectAdjacentRules) 1712 if (!hasDirectAdjacentRules && !hasIndirectAdjacentRules)
1708 return; 1713 return;
1709 1714
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 if (!hasAttributes()) 2758 if (!hasAttributes())
2754 return; 2759 return;
2755 for (unsigned i = 0; i < attributeCount(); ++i) { 2760 for (unsigned i = 0; i < attributeCount(); ++i) {
2756 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name())) 2761 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name()))
2757 attr->normalize(); 2762 attr->normalize();
2758 } 2763 }
2759 } 2764 }
2760 2765
2761 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) 2766 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change)
2762 { 2767 {
2768 ASSERT(!needsStyleRecalc());
2763 PseudoElement* element = pseudoElement(pseudoId); 2769 PseudoElement* element = pseudoElement(pseudoId);
2764 if (element && (needsStyleRecalc() || element->shouldCallRecalcStyle(change) )) { 2770 if (element && (change == UpdatePseudoElements || element->shouldCallRecalcS tyle(change))) {
2771
2765 // Need to clear the cached style if the PseudoElement wants a recalc so it 2772 // Need to clear the cached style if the PseudoElement wants a recalc so it
2766 // computes a new style. 2773 // computes a new style.
2767 if (element->needsStyleRecalc()) 2774 if (element->needsStyleRecalc())
2768 renderer()->style()->removeCachedPseudoStyle(pseudoId); 2775 renderer()->style()->removeCachedPseudoStyle(pseudoId);
2769 2776
2770 // PseudoElement styles hang off their parent element's style so if we n eeded 2777 // 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. 2778 // a style recalc we should Force one on the pseudo.
2772 // FIXME: We should figure out the right text sibling to pass. 2779 // FIXME: We should figure out the right text sibling to pass.
2773 element->recalcStyle(needsStyleRecalc() ? Force : change); 2780 element->recalcStyle(change == UpdatePseudoElements ? Force : change);
2774 2781
2775 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed 2782 // Wait until our parent is not displayed or pseudoElementRendererIsNeed ed
2776 // is false, otherwise we could continously create and destroy PseudoEle ments 2783 // is false, otherwise we could continously create and destroy PseudoEle ments
2777 // when RenderObject::isChildAllowed on our parent returns false for the 2784 // when RenderObject::isChildAllowed on our parent returns false for the
2778 // PseudoElement's renderer for each style recalc. 2785 // PseudoElement's renderer for each style recalc.
2779 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId))) 2786 if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedP seudoStyle(pseudoId)))
2780 elementRareData()->setPseudoElement(pseudoId, 0); 2787 elementRareData()->setPseudoElement(pseudoId, 0);
2781 } else if (change >= Inherit || needsStyleRecalc()) 2788 } else if (change >= UpdatePseudoElements) {
2782 createPseudoElementIfNeeded(pseudoId); 2789 createPseudoElementIfNeeded(pseudoId);
2790 }
2783 } 2791 }
2784 2792
2785 void Element::createPseudoElementIfNeeded(PseudoId pseudoId) 2793 void Element::createPseudoElementIfNeeded(PseudoId pseudoId)
2786 { 2794 {
2787 if (isPseudoElement()) 2795 if (isPseudoElement())
2788 return; 2796 return;
2789 2797
2790 RefPtr<PseudoElement> element = document().ensureStyleResolver().createPseud oElementIfNeeded(*this, pseudoId); 2798 RefPtr<PseudoElement> element = document().ensureStyleResolver().createPseud oElementIfNeeded(*this, pseudoId);
2791 if (!element) 2799 if (!element)
2792 return; 2800 return;
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
3620 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3628 // 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 3629 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3622 if (hasTagName(optionTag) || hasTagName(optgroupTag)) 3630 if (hasTagName(optionTag) || hasTagName(optgroupTag))
3623 return false; 3631 return false;
3624 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3632 if (FullscreenElementStack::isActiveFullScreenElement(this))
3625 return false; 3633 return false;
3626 return true; 3634 return true;
3627 } 3635 }
3628 3636
3629 } // namespace WebCore 3637 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/core/rendering/style/RenderStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698