| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. |
| 6 * All rights reserved. | 6 * All rights reserved. |
| 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 10 * (http://www.torchmobile.com/) | 10 * (http://www.torchmobile.com/) |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 Element* element) { | 630 Element* element) { |
| 631 StyleAdjuster::adjustComputedStyle(state.mutableStyleRef(), | 631 StyleAdjuster::adjustComputedStyle(state.mutableStyleRef(), |
| 632 *state.parentStyle(), element); | 632 *state.parentStyle(), element); |
| 633 } | 633 } |
| 634 | 634 |
| 635 // Start loading resources referenced by this style. | 635 // Start loading resources referenced by this style. |
| 636 void StyleResolver::loadPendingResources(StyleResolverState& state) { | 636 void StyleResolver::loadPendingResources(StyleResolverState& state) { |
| 637 state.elementStyleResources().loadPendingResources(state.style()); | 637 state.elementStyleResources().loadPendingResources(state.style()); |
| 638 } | 638 } |
| 639 | 639 |
| 640 static const ComputedStyle* calculateBaseComputedStyle( |
| 641 StyleResolverState& state, |
| 642 const Element* animatingElement) { |
| 643 if (!animatingElement) |
| 644 return nullptr; |
| 645 |
| 646 ElementAnimations* elementAnimations = animatingElement->elementAnimations(); |
| 647 if (!elementAnimations) |
| 648 return nullptr; |
| 649 |
| 650 if (CSSAnimations::isAnimatingCustomProperties(elementAnimations)) { |
| 651 state.setIsAnimatingCustomProperties(true); |
| 652 // TODO(alancutter): Use the base computed style optimisation in the |
| 653 // presence of custom property animations that don't affect pre-animated |
| 654 // computed values. |
| 655 return nullptr; |
| 656 } |
| 657 |
| 658 return elementAnimations->baseComputedStyle(); |
| 659 } |
| 660 |
| 661 static void updateBaseComputedStyle(StyleResolverState& state, |
| 662 Element* animatingElement) { |
| 663 if (!animatingElement || state.isAnimatingCustomProperties()) |
| 664 return; |
| 665 |
| 666 ElementAnimations* elementAnimations = animatingElement->elementAnimations(); |
| 667 if (elementAnimations) |
| 668 elementAnimations->updateBaseComputedStyle(state.style()); |
| 669 } |
| 670 |
| 640 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( | 671 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( |
| 641 Element* element, | 672 Element* element, |
| 642 const ComputedStyle* defaultParent, | 673 const ComputedStyle* defaultParent, |
| 643 StyleSharingBehavior sharingBehavior, | 674 StyleSharingBehavior sharingBehavior, |
| 644 RuleMatchingBehavior matchingBehavior) { | 675 RuleMatchingBehavior matchingBehavior) { |
| 645 DCHECK(document().frame()); | 676 DCHECK(document().frame()); |
| 646 DCHECK(document().settings()); | 677 DCHECK(document().settings()); |
| 647 DCHECK(!hasPendingAuthorStyleSheets()); | 678 DCHECK(!hasPendingAuthorStyleSheets()); |
| 648 | 679 |
| 649 // Once an element has a layoutObject, we don't try to destroy it, since | 680 // Once an element has a layoutObject, we don't try to destroy it, since |
| (...skipping 22 matching lines...) Expand all Loading... |
| 672 if (RuntimeEnabledFeatures::styleSharingEnabled() && | 703 if (RuntimeEnabledFeatures::styleSharingEnabled() && |
| 673 sharingBehavior == AllowStyleSharing && | 704 sharingBehavior == AllowStyleSharing && |
| 674 (defaultParent || elementContext.parentStyle())) { | 705 (defaultParent || elementContext.parentStyle())) { |
| 675 if (RefPtr<ComputedStyle> sharedStyle = | 706 if (RefPtr<ComputedStyle> sharedStyle = |
| 676 document().styleEngine().findSharedStyle(elementContext)) | 707 document().styleEngine().findSharedStyle(elementContext)) |
| 677 return sharedStyle.release(); | 708 return sharedStyle.release(); |
| 678 } | 709 } |
| 679 | 710 |
| 680 StyleResolverState state(document(), elementContext, defaultParent); | 711 StyleResolverState state(document(), elementContext, defaultParent); |
| 681 | 712 |
| 682 ElementAnimations* elementAnimations = element->elementAnimations(); | |
| 683 const ComputedStyle* baseComputedStyle = | 713 const ComputedStyle* baseComputedStyle = |
| 684 elementAnimations ? elementAnimations->baseComputedStyle() : nullptr; | 714 calculateBaseComputedStyle(state, element); |
| 685 | 715 |
| 686 if (baseComputedStyle) { | 716 if (baseComputedStyle) { |
| 687 state.setStyle(ComputedStyle::clone(*baseComputedStyle)); | 717 state.setStyle(ComputedStyle::clone(*baseComputedStyle)); |
| 688 if (!state.parentStyle()) | 718 if (!state.parentStyle()) |
| 689 state.setParentStyle(initialStyleForElement()); | 719 state.setParentStyle(initialStyleForElement()); |
| 690 } else { | 720 } else { |
| 691 if (state.parentStyle()) { | 721 if (state.parentStyle()) { |
| 692 RefPtr<ComputedStyle> style = ComputedStyle::create(); | 722 RefPtr<ComputedStyle> style = ComputedStyle::create(); |
| 693 style->inheritFrom(*state.parentStyle(), | 723 style->inheritFrom(*state.parentStyle(), |
| 694 isAtShadowBoundary(element) | 724 isAtShadowBoundary(element) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 // NOTE: this must occur before applyMatchedProperties for correct | 787 // NOTE: this must occur before applyMatchedProperties for correct |
| 758 // computation of font-relative lengths. | 788 // computation of font-relative lengths. |
| 759 state.style()->setTextAutosizingMultiplier( | 789 state.style()->setTextAutosizingMultiplier( |
| 760 element->computedStyle()->textAutosizingMultiplier()); | 790 element->computedStyle()->textAutosizingMultiplier()); |
| 761 state.style()->setUnique(); | 791 state.style()->setUnique(); |
| 762 } | 792 } |
| 763 | 793 |
| 764 if (state.hasDirAutoAttribute()) | 794 if (state.hasDirAutoAttribute()) |
| 765 state.style()->setSelfOrAncestorHasDirAutoAttribute(true); | 795 state.style()->setSelfOrAncestorHasDirAutoAttribute(true); |
| 766 | 796 |
| 767 applyMatchedProperties(state, collector.matchedResult()); | 797 applyMatchedPropertiesAndCustomPropertyAnimations( |
| 798 state, collector.matchedResult(), element); |
| 768 applyCallbackSelectors(state); | 799 applyCallbackSelectors(state); |
| 769 | 800 |
| 770 // Cache our original display. | 801 // Cache our original display. |
| 771 state.style()->setOriginalDisplay(state.style()->display()); | 802 state.style()->setOriginalDisplay(state.style()->display()); |
| 772 | 803 |
| 773 adjustComputedStyle(state, element); | 804 adjustComputedStyle(state, element); |
| 774 | 805 |
| 775 if (elementAnimations) | 806 updateBaseComputedStyle(state, element); |
| 776 elementAnimations->updateBaseComputedStyle(state.style()); | |
| 777 } else { | 807 } else { |
| 778 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), baseStylesUsed, 1); | 808 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), baseStylesUsed, 1); |
| 779 } | 809 } |
| 780 | 810 |
| 781 // FIXME: The CSSWG wants to specify that the effects of animations are | 811 // FIXME: The CSSWG wants to specify that the effects of animations are |
| 782 // applied before important rules, but this currently happens here as we | 812 // applied before important rules, but this currently happens here as we |
| 783 // require adjustment to have happened before deciding which properties to | 813 // require adjustment to have happened before deciding which properties to |
| 784 // transition. | 814 // transition. |
| 785 if (applyAnimatedProperties(state, element)) { | 815 if (applyAnimatedStandardProperties(state, element)) { |
| 786 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesAnimated, 1); | 816 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesAnimated, 1); |
| 787 adjustComputedStyle(state, element); | 817 adjustComputedStyle(state, element); |
| 788 } | 818 } |
| 789 | 819 |
| 790 if (isHTMLBodyElement(*element)) | 820 if (isHTMLBodyElement(*element)) |
| 791 document().textLinkColors().setTextColor(state.style()->color()); | 821 document().textLinkColors().setTextColor(state.style()->color()); |
| 792 | 822 |
| 793 setAnimationUpdateIfNeeded(state, *element); | 823 setAnimationUpdateIfNeeded(state, *element); |
| 794 | 824 |
| 795 if (state.style()->hasViewportUnits()) | 825 if (state.style()->hasViewportUnits()) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 StyleResolverState& state) { | 915 StyleResolverState& state) { |
| 886 DCHECK(document().frame()); | 916 DCHECK(document().frame()); |
| 887 DCHECK(document().settings()); | 917 DCHECK(document().settings()); |
| 888 DCHECK(pseudoStyleRequest.pseudoId != PseudoIdFirstLineInherited); | 918 DCHECK(pseudoStyleRequest.pseudoId != PseudoIdFirstLineInherited); |
| 889 DCHECK(state.parentStyle()); | 919 DCHECK(state.parentStyle()); |
| 890 | 920 |
| 891 SelectorFilterParentScope::ensureParentStackIsPushed(); | 921 SelectorFilterParentScope::ensureParentStackIsPushed(); |
| 892 | 922 |
| 893 Element* pseudoElement = element.pseudoElement(pseudoStyleRequest.pseudoId); | 923 Element* pseudoElement = element.pseudoElement(pseudoStyleRequest.pseudoId); |
| 894 | 924 |
| 895 ElementAnimations* elementAnimations = | |
| 896 pseudoElement ? pseudoElement->elementAnimations() : nullptr; | |
| 897 const ComputedStyle* baseComputedStyle = | 925 const ComputedStyle* baseComputedStyle = |
| 898 elementAnimations ? elementAnimations->baseComputedStyle() : nullptr; | 926 calculateBaseComputedStyle(state, pseudoElement); |
| 899 | 927 |
| 900 if (baseComputedStyle) { | 928 if (baseComputedStyle) { |
| 901 state.setStyle(ComputedStyle::clone(*baseComputedStyle)); | 929 state.setStyle(ComputedStyle::clone(*baseComputedStyle)); |
| 902 } else if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { | 930 } else if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { |
| 903 RefPtr<ComputedStyle> style = ComputedStyle::create(); | 931 RefPtr<ComputedStyle> style = ComputedStyle::create(); |
| 904 style->inheritFrom(*state.parentStyle()); | 932 style->inheritFrom(*state.parentStyle()); |
| 905 state.setStyle(style.release()); | 933 state.setStyle(style.release()); |
| 906 } else { | 934 } else { |
| 907 state.setStyle(initialStyleForElement()); | 935 state.setStyle(initialStyleForElement()); |
| 908 state.setParentStyle(ComputedStyle::clone(*state.style())); | 936 state.setParentStyle(ComputedStyle::clone(*state.style())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 922 matchUARules(collector); | 950 matchUARules(collector); |
| 923 matchAuthorRules(*state.element(), collector); | 951 matchAuthorRules(*state.element(), collector); |
| 924 collector.finishAddingAuthorRulesForTreeScope(); | 952 collector.finishAddingAuthorRulesForTreeScope(); |
| 925 | 953 |
| 926 if (m_tracker) | 954 if (m_tracker) |
| 927 addMatchedRulesToTracker(collector); | 955 addMatchedRulesToTracker(collector); |
| 928 | 956 |
| 929 if (!collector.matchedResult().hasMatchedProperties()) | 957 if (!collector.matchedResult().hasMatchedProperties()) |
| 930 return false; | 958 return false; |
| 931 | 959 |
| 932 applyMatchedProperties(state, collector.matchedResult()); | 960 applyMatchedPropertiesAndCustomPropertyAnimations( |
| 961 state, collector.matchedResult(), pseudoElement); |
| 933 applyCallbackSelectors(state); | 962 applyCallbackSelectors(state); |
| 934 | 963 |
| 935 // Cache our original display. | 964 // Cache our original display. |
| 936 state.style()->setOriginalDisplay(state.style()->display()); | 965 state.style()->setOriginalDisplay(state.style()->display()); |
| 937 | 966 |
| 938 // FIXME: Passing 0 as the Element* introduces a lot of complexity | 967 // FIXME: Passing 0 as the Element* introduces a lot of complexity |
| 939 // in the adjustComputedStyle code. | 968 // in the adjustComputedStyle code. |
| 940 adjustComputedStyle(state, 0); | 969 adjustComputedStyle(state, 0); |
| 941 | 970 |
| 942 if (elementAnimations) | 971 updateBaseComputedStyle(state, pseudoElement); |
| 943 elementAnimations->updateBaseComputedStyle(state.style()); | |
| 944 } | 972 } |
| 945 | 973 |
| 946 // FIXME: The CSSWG wants to specify that the effects of animations are | 974 // FIXME: The CSSWG wants to specify that the effects of animations are |
| 947 // applied before important rules, but this currently happens here as we | 975 // applied before important rules, but this currently happens here as we |
| 948 // require adjustment to have happened before deciding which properties to | 976 // require adjustment to have happened before deciding which properties to |
| 949 // transition. | 977 // transition. |
| 950 if (applyAnimatedProperties(state, pseudoElement)) | 978 if (applyAnimatedStandardProperties(state, pseudoElement)) |
| 951 adjustComputedStyle(state, 0); | 979 adjustComputedStyle(state, 0); |
| 952 | 980 |
| 953 document().styleEngine().incStyleForElementCount(); | 981 document().styleEngine().incStyleForElementCount(); |
| 954 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), pseudoElementsStyled, | 982 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), pseudoElementsStyled, |
| 955 1); | 983 1); |
| 956 | 984 |
| 957 if (state.style()->hasViewportUnits()) | 985 if (state.style()->hasViewportUnits()) |
| 958 document().setHasViewportUnits(); | 986 document().setHasViewportUnits(); |
| 959 | 987 |
| 960 return true; | 988 return true; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 if (rulesToInclude & UAAndUserCSSRules) | 1126 if (rulesToInclude & UAAndUserCSSRules) |
| 1099 matchUARules(collector); | 1127 matchUARules(collector); |
| 1100 | 1128 |
| 1101 if (rulesToInclude & AuthorCSSRules) { | 1129 if (rulesToInclude & AuthorCSSRules) { |
| 1102 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); | 1130 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); |
| 1103 collector.setIncludeEmptyRules(rulesToInclude & EmptyCSSRules); | 1131 collector.setIncludeEmptyRules(rulesToInclude & EmptyCSSRules); |
| 1104 matchAuthorRules(element, collector); | 1132 matchAuthorRules(element, collector); |
| 1105 } | 1133 } |
| 1106 } | 1134 } |
| 1107 | 1135 |
| 1108 bool StyleResolver::applyAnimatedProperties(StyleResolverState& state, | 1136 bool StyleResolver::applyAnimatedStandardProperties( |
| 1109 const Element* animatingElement) { | 1137 StyleResolverState& state, |
| 1138 const Element* animatingElement) { |
| 1110 Element* element = state.element(); | 1139 Element* element = state.element(); |
| 1111 DCHECK(element); | 1140 DCHECK(element); |
| 1112 | 1141 |
| 1113 // The animating element may be this element, or its pseudo element. It is | 1142 // The animating element may be this element, or its pseudo element. It is |
| 1114 // null when calculating the style for a potential pseudo element that has | 1143 // null when calculating the style for a potential pseudo element that has |
| 1115 // yet to be created. | 1144 // yet to be created. |
| 1116 DCHECK(animatingElement == element || !animatingElement || | 1145 DCHECK(animatingElement == element || !animatingElement || |
| 1117 animatingElement->parentOrShadowHostElement() == element); | 1146 animatingElement->parentOrShadowHostElement() == element); |
| 1118 | 1147 |
| 1119 if (!(animatingElement && animatingElement->hasAnimations()) && | 1148 if (!(animatingElement && animatingElement->hasAnimations()) && |
| 1120 !state.style()->transitions() && !state.style()->animations()) | 1149 !state.style()->transitions() && !state.style()->animations()) |
| 1121 return false; | 1150 return false; |
| 1122 | 1151 |
| 1123 CSSAnimations::calculateUpdate(animatingElement, *element, *state.style(), | 1152 if (!state.isAnimationInterpolationMapReady()) |
| 1124 state.parentStyle(), state.animationUpdate(), | 1153 calculateAnimationUpdate(state, animatingElement); |
| 1125 this); | 1154 |
| 1155 CSSAnimations::calculateCompositorAndTransitionUpdate( |
| 1156 animatingElement, *element, *state.style(), state.parentStyle(), |
| 1157 state.animationUpdate()); |
| 1126 | 1158 |
| 1127 CSSAnimations::snapshotCompositorKeyframes( | 1159 CSSAnimations::snapshotCompositorKeyframes( |
| 1128 *element, state.animationUpdate(), *state.style(), state.parentStyle()); | 1160 *element, state.animationUpdate(), *state.style(), state.parentStyle()); |
| 1129 | 1161 |
| 1130 if (state.animationUpdate().isEmpty()) | 1162 if (state.animationUpdate().isEmpty()) |
| 1131 return false; | 1163 return false; |
| 1132 | 1164 |
| 1133 if (state.style()->insideLink() != NotInsideLink) { | 1165 if (state.style()->insideLink() != NotInsideLink) { |
| 1134 DCHECK(state.applyPropertyToRegularStyle()); | 1166 DCHECK(state.applyPropertyToRegularStyle()); |
| 1135 state.setApplyPropertyToVisitedLinkStyle(true); | 1167 state.setApplyPropertyToVisitedLinkStyle(true); |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 } | 1615 } |
| 1584 | 1616 |
| 1585 void StyleResolver::invalidateMatchedPropertiesCache() { | 1617 void StyleResolver::invalidateMatchedPropertiesCache() { |
| 1586 m_matchedPropertiesCache.clear(); | 1618 m_matchedPropertiesCache.clear(); |
| 1587 } | 1619 } |
| 1588 | 1620 |
| 1589 void StyleResolver::notifyResizeForViewportUnits() { | 1621 void StyleResolver::notifyResizeForViewportUnits() { |
| 1590 m_matchedPropertiesCache.clearViewportDependent(); | 1622 m_matchedPropertiesCache.clearViewportDependent(); |
| 1591 } | 1623 } |
| 1592 | 1624 |
| 1593 void StyleResolver::applyMatchedProperties(StyleResolverState& state, | 1625 void StyleResolver::applyMatchedPropertiesAndCustomPropertyAnimations( |
| 1594 const MatchResult& matchResult) { | 1626 StyleResolverState& state, |
| 1627 const MatchResult& matchResult, |
| 1628 const Element* animatingElement) { |
| 1629 CacheSuccess cacheSuccess = applyMatchedCache(state, matchResult); |
| 1630 NeedsApplyPass needsApplyPass; |
| 1631 if (!cacheSuccess.isFullCacheHit()) { |
| 1632 applyCustomProperties(state, matchResult, false, cacheSuccess, |
| 1633 needsApplyPass); |
| 1634 applyMatchedAnimationProperties(state, matchResult, cacheSuccess, |
| 1635 needsApplyPass); |
| 1636 } |
| 1637 if (state.style()->animations() || |
| 1638 (state.element() && state.element()->hasAnimations())) { |
| 1639 calculateAnimationUpdate(state, animatingElement); |
| 1640 if (state.isAnimatingCustomProperties()) { |
| 1641 cacheSuccess.setFailed(); |
| 1642 applyCustomProperties(state, matchResult, true, cacheSuccess, |
| 1643 needsApplyPass); |
| 1644 } |
| 1645 } |
| 1646 if (!cacheSuccess.isFullCacheHit()) { |
| 1647 applyMatchedStandardProperties(state, matchResult, cacheSuccess, |
| 1648 needsApplyPass); |
| 1649 } |
| 1650 } |
| 1651 |
| 1652 StyleResolver::CacheSuccess StyleResolver::applyMatchedCache( |
| 1653 StyleResolverState& state, |
| 1654 const MatchResult& matchResult) { |
| 1595 const Element* element = state.element(); | 1655 const Element* element = state.element(); |
| 1596 DCHECK(element); | 1656 DCHECK(element); |
| 1597 | 1657 |
| 1598 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyApply, | |
| 1599 1); | |
| 1600 | |
| 1601 unsigned cacheHash = | 1658 unsigned cacheHash = |
| 1602 matchResult.isCacheable() | 1659 matchResult.isCacheable() |
| 1603 ? computeMatchedPropertiesHash(matchResult.matchedProperties().data(), | 1660 ? computeMatchedPropertiesHash(matchResult.matchedProperties().data(), |
| 1604 matchResult.matchedProperties().size()) | 1661 matchResult.matchedProperties().size()) |
| 1605 : 0; | 1662 : 0; |
| 1606 bool applyInheritedOnly = false; | 1663 bool isInheritedCacheHit = false; |
| 1664 bool isNonInheritedCacheHit = false; |
| 1607 const CachedMatchedProperties* cachedMatchedProperties = | 1665 const CachedMatchedProperties* cachedMatchedProperties = |
| 1608 cacheHash | 1666 cacheHash |
| 1609 ? m_matchedPropertiesCache.find(cacheHash, state, | 1667 ? m_matchedPropertiesCache.find(cacheHash, state, |
| 1610 matchResult.matchedProperties()) | 1668 matchResult.matchedProperties()) |
| 1611 : nullptr; | 1669 : nullptr; |
| 1612 | 1670 |
| 1613 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(state)) { | 1671 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(state)) { |
| 1614 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), | 1672 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), |
| 1615 matchedPropertyCacheHit, 1); | 1673 matchedPropertyCacheHit, 1); |
| 1616 // We can build up the style by copying non-inherited properties from an | 1674 // We can build up the style by copying non-inherited properties from an |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1632 // If the cache item parent style has identical inherited properties to | 1690 // If the cache item parent style has identical inherited properties to |
| 1633 // the current parent style then the resulting style will be identical | 1691 // the current parent style then the resulting style will be identical |
| 1634 // too. We copy the inherited properties over from the cache and are done. | 1692 // too. We copy the inherited properties over from the cache and are done. |
| 1635 state.style()->inheritFrom(*cachedMatchedProperties->computedStyle); | 1693 state.style()->inheritFrom(*cachedMatchedProperties->computedStyle); |
| 1636 | 1694 |
| 1637 // Unfortunately the link status is treated like an inherited property. We | 1695 // Unfortunately the link status is treated like an inherited property. We |
| 1638 // need to explicitly restore it. | 1696 // need to explicitly restore it. |
| 1639 state.style()->setInsideLink(linkStatus); | 1697 state.style()->setInsideLink(linkStatus); |
| 1640 | 1698 |
| 1641 updateFont(state); | 1699 updateFont(state); |
| 1700 isInheritedCacheHit = true; |
| 1701 } |
| 1642 | 1702 |
| 1643 return; | 1703 isNonInheritedCacheHit = true; |
| 1644 } | |
| 1645 applyInheritedOnly = true; | |
| 1646 } | 1704 } |
| 1647 | 1705 |
| 1648 NeedsApplyPass needsApplyPass; | 1706 return CacheSuccess(isInheritedCacheHit, isNonInheritedCacheHit, cacheHash, |
| 1707 cachedMatchedProperties); |
| 1708 } |
| 1649 | 1709 |
| 1650 // TODO(leviw): We need the proper bit for tracking whether we need to do this | 1710 void StyleResolver::applyCustomProperties(StyleResolverState& state, |
| 1651 // work. | 1711 const MatchResult& matchResult, |
| 1712 bool applyAnimations, |
| 1713 const CacheSuccess& cacheSuccess, |
| 1714 NeedsApplyPass& needsApplyPass) { |
| 1715 DCHECK(!cacheSuccess.isFullCacheHit()); |
| 1716 bool applyInheritedOnly = cacheSuccess.shouldApplyInheritedOnly(); |
| 1717 |
| 1718 // TODO(leviw): We need the proper bit for tracking whether we need to do |
| 1719 // this work. |
| 1652 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( | 1720 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( |
| 1653 state, matchResult.authorRules(), false, applyInheritedOnly, | 1721 state, matchResult.authorRules(), false, applyInheritedOnly, |
| 1654 needsApplyPass); | 1722 needsApplyPass); |
| 1655 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( | 1723 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( |
| 1656 state, matchResult.authorRules(), true, applyInheritedOnly, | 1724 state, matchResult.authorRules(), true, applyInheritedOnly, |
| 1657 needsApplyPass); | 1725 needsApplyPass); |
| 1726 if (applyAnimations) { |
| 1727 applyAnimatedProperties<ResolveVariables>( |
| 1728 state, state.animationUpdate().activeInterpolationsForAnimations()); |
| 1729 } |
| 1658 // TODO(leviw): stop recalculating every time | 1730 // TODO(leviw): stop recalculating every time |
| 1659 CSSVariableResolver::resolveVariableDefinitions(state); | 1731 CSSVariableResolver::resolveVariableDefinitions(state); |
| 1660 | 1732 |
| 1661 if (RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { | 1733 if (RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { |
| 1662 if (cacheCustomPropertiesForApplyAtRules(state, | 1734 if (cacheCustomPropertiesForApplyAtRules(state, |
| 1663 matchResult.authorRules())) { | 1735 matchResult.authorRules())) { |
| 1664 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( | 1736 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( |
| 1665 state, matchResult.authorRules(), false, applyInheritedOnly, | 1737 state, matchResult.authorRules(), false, applyInheritedOnly, |
| 1666 needsApplyPass); | 1738 needsApplyPass); |
| 1667 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( | 1739 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( |
| 1668 state, matchResult.authorRules(), true, applyInheritedOnly, | 1740 state, matchResult.authorRules(), true, applyInheritedOnly, |
| 1669 needsApplyPass); | 1741 needsApplyPass); |
| 1742 if (applyAnimations) { |
| 1743 applyAnimatedProperties<ResolveVariables>( |
| 1744 state, state.animationUpdate().activeInterpolationsForAnimations()); |
| 1745 } |
| 1670 CSSVariableResolver::resolveVariableDefinitions(state); | 1746 CSSVariableResolver::resolveVariableDefinitions(state); |
| 1671 } | 1747 } |
| 1672 } | 1748 } |
| 1749 } |
| 1673 | 1750 |
| 1674 // Apply animation affecting properties. | 1751 void StyleResolver::applyMatchedAnimationProperties( |
| 1752 StyleResolverState& state, |
| 1753 const MatchResult& matchResult, |
| 1754 const CacheSuccess& cacheSuccess, |
| 1755 NeedsApplyPass& needsApplyPass) { |
| 1756 DCHECK(!cacheSuccess.isFullCacheHit()); |
| 1757 bool applyInheritedOnly = cacheSuccess.shouldApplyInheritedOnly(); |
| 1758 |
| 1675 applyMatchedProperties<AnimationPropertyPriority, UpdateNeedsApplyPass>( | 1759 applyMatchedProperties<AnimationPropertyPriority, UpdateNeedsApplyPass>( |
| 1676 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); | 1760 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); |
| 1677 applyMatchedProperties<AnimationPropertyPriority, CheckNeedsApplyPass>( | 1761 applyMatchedProperties<AnimationPropertyPriority, CheckNeedsApplyPass>( |
| 1678 state, matchResult.allRules(), true, applyInheritedOnly, needsApplyPass); | 1762 state, matchResult.allRules(), true, applyInheritedOnly, needsApplyPass); |
| 1763 } |
| 1764 |
| 1765 void StyleResolver::calculateAnimationUpdate(StyleResolverState& state, |
| 1766 const Element* animatingElement) { |
| 1767 Element* element = state.element(); |
| 1768 DCHECK(state.style()->animations() || (element && element->hasAnimations())); |
| 1769 DCHECK(!state.isAnimationInterpolationMapReady()); |
| 1770 |
| 1771 CSSAnimations::calculateAnimationUpdate( |
| 1772 state.animationUpdate(), animatingElement, *element, *state.style(), |
| 1773 state.parentStyle(), this); |
| 1774 |
| 1775 state.setIsAnimationInterpolationMapReady(); |
| 1776 |
| 1777 if (state.isAnimatingCustomProperties()) |
| 1778 return; |
| 1779 for (const auto& propertyHandle : |
| 1780 state.animationUpdate().activeInterpolationsForAnimations().keys()) { |
| 1781 if (CSSAnimations::isCustomPropertyHandle(propertyHandle)) { |
| 1782 state.setIsAnimatingCustomProperties(true); |
| 1783 return; |
| 1784 } |
| 1785 } |
| 1786 } |
| 1787 |
| 1788 void StyleResolver::applyMatchedStandardProperties( |
| 1789 StyleResolverState& state, |
| 1790 const MatchResult& matchResult, |
| 1791 const CacheSuccess& cacheSuccess, |
| 1792 NeedsApplyPass& needsApplyPass) { |
| 1793 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyApply, |
| 1794 1); |
| 1795 |
| 1796 DCHECK(!cacheSuccess.isFullCacheHit()); |
| 1797 bool applyInheritedOnly = cacheSuccess.shouldApplyInheritedOnly(); |
| 1679 | 1798 |
| 1680 // Now we have all of the matched rules in the appropriate order. Walk the | 1799 // Now we have all of the matched rules in the appropriate order. Walk the |
| 1681 // rules and apply high-priority properties first, i.e., those properties that | 1800 // rules and apply high-priority properties first, i.e., those properties that |
| 1682 // other properties depend on. The order is (1) high-priority not important, | 1801 // other properties depend on. The order is (1) high-priority not important, |
| 1683 // (2) high-priority important, (3) normal not important and (4) normal | 1802 // (2) high-priority important, (3) normal not important and (4) normal |
| 1684 // important. | 1803 // important. |
| 1685 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( | 1804 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( |
| 1686 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); | 1805 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); |
| 1687 for (auto range : ImportantAuthorRanges(matchResult)) { | 1806 for (auto range : ImportantAuthorRanges(matchResult)) { |
| 1688 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( | 1807 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( |
| 1689 state, range, true, applyInheritedOnly, needsApplyPass); | 1808 state, range, true, applyInheritedOnly, needsApplyPass); |
| 1690 } | 1809 } |
| 1691 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( | 1810 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( |
| 1692 state, matchResult.uaRules(), true, applyInheritedOnly, needsApplyPass); | 1811 state, matchResult.uaRules(), true, applyInheritedOnly, needsApplyPass); |
| 1693 | 1812 |
| 1694 if (UNLIKELY(isSVGForeignObjectElement(element))) { | 1813 if (UNLIKELY(isSVGForeignObjectElement(state.element()))) { |
| 1695 // LayoutSVGRoot handles zooming for the whole SVG subtree, so foreignObject | 1814 // LayoutSVGRoot handles zooming for the whole SVG subtree, so foreignObject |
| 1696 // content should not be scaled again. | 1815 // content should not be scaled again. |
| 1697 // | 1816 // |
| 1698 // FIXME: The following hijacks the zoom property for foreignObject so that | 1817 // FIXME: The following hijacks the zoom property for foreignObject so that |
| 1699 // children of foreignObject get the correct font-size in case of zooming. | 1818 // children of foreignObject get the correct font-size in case of zooming. |
| 1700 // 'zoom' has HighPropertyPriority, along with other font-related properties | 1819 // 'zoom' has HighPropertyPriority, along with other font-related properties |
| 1701 // used as input to the FontBuilder, so resetting it here may cause the | 1820 // used as input to the FontBuilder, so resetting it here may cause the |
| 1702 // FontBuilder to recompute the font used as inheritable font for | 1821 // FontBuilder to recompute the font used as inheritable font for |
| 1703 // foreignObject content. If we want to support zoom on foreignObject we'll | 1822 // foreignObject content. If we want to support zoom on foreignObject we'll |
| 1704 // need to find another way of handling the SVG zoom model. | 1823 // need to find another way of handling the SVG zoom model. |
| 1705 state.setEffectiveZoom(ComputedStyle::initialZoom()); | 1824 state.setEffectiveZoom(ComputedStyle::initialZoom()); |
| 1706 } | 1825 } |
| 1707 | 1826 |
| 1708 if (cachedMatchedProperties && | 1827 if (cacheSuccess.cachedMatchedProperties && |
| 1709 cachedMatchedProperties->computedStyle->effectiveZoom() != | 1828 cacheSuccess.cachedMatchedProperties->computedStyle->effectiveZoom() != |
| 1710 state.style()->effectiveZoom()) { | 1829 state.style()->effectiveZoom()) { |
| 1711 state.fontBuilder().didChangeEffectiveZoom(); | 1830 state.fontBuilder().didChangeEffectiveZoom(); |
| 1712 applyInheritedOnly = false; | 1831 applyInheritedOnly = false; |
| 1713 } | 1832 } |
| 1714 | 1833 |
| 1715 // If our font got dirtied, go ahead and update it now. | 1834 // If our font got dirtied, go ahead and update it now. |
| 1716 updateFont(state); | 1835 updateFont(state); |
| 1717 | 1836 |
| 1718 // Many properties depend on the font. If it changes we just apply all | 1837 // Many properties depend on the font. If it changes we just apply all |
| 1719 // properties. | 1838 // properties. |
| 1720 if (cachedMatchedProperties && | 1839 if (cacheSuccess.cachedMatchedProperties && |
| 1721 cachedMatchedProperties->computedStyle->getFontDescription() != | 1840 cacheSuccess.cachedMatchedProperties->computedStyle |
| 1722 state.style()->getFontDescription()) | 1841 ->getFontDescription() != state.style()->getFontDescription()) |
| 1723 applyInheritedOnly = false; | 1842 applyInheritedOnly = false; |
| 1724 | 1843 |
| 1725 // Registered custom properties are computed after high priority properties. | 1844 // Registered custom properties are computed after high priority properties. |
| 1726 CSSVariableResolver::computeRegisteredVariables(state); | 1845 CSSVariableResolver::computeRegisteredVariables(state); |
| 1727 | 1846 |
| 1728 // Now do the normal priority UA properties. | 1847 // Now do the normal priority UA properties. |
| 1729 applyMatchedProperties<LowPropertyPriority, CheckNeedsApplyPass>( | 1848 applyMatchedProperties<LowPropertyPriority, CheckNeedsApplyPass>( |
| 1730 state, matchResult.uaRules(), false, applyInheritedOnly, needsApplyPass); | 1849 state, matchResult.uaRules(), false, applyInheritedOnly, needsApplyPass); |
| 1731 | 1850 |
| 1732 // Cache the UA properties to pass them to LayoutTheme in adjustComputedStyle. | 1851 // Cache the UA properties to pass them to LayoutTheme in adjustComputedStyle. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1749 // ones. When there is a partial match in the MatchedPropertiesCache, these | 1868 // ones. When there is a partial match in the MatchedPropertiesCache, these |
| 1750 // flags will already be set correctly and the value stored in | 1869 // flags will already be set correctly and the value stored in |
| 1751 // cacheUserAgentBorderAndBackground is incorrect, so doing this check again | 1870 // cacheUserAgentBorderAndBackground is incorrect, so doing this check again |
| 1752 // would give the wrong answer. | 1871 // would give the wrong answer. |
| 1753 state.style()->setHasAuthorBackground(hasAuthorBackground(state)); | 1872 state.style()->setHasAuthorBackground(hasAuthorBackground(state)); |
| 1754 state.style()->setHasAuthorBorder(hasAuthorBorder(state)); | 1873 state.style()->setHasAuthorBorder(hasAuthorBorder(state)); |
| 1755 } | 1874 } |
| 1756 | 1875 |
| 1757 loadPendingResources(state); | 1876 loadPendingResources(state); |
| 1758 | 1877 |
| 1759 if (!cachedMatchedProperties && cacheHash && | 1878 if (!state.isAnimatingCustomProperties() && |
| 1879 !cacheSuccess.cachedMatchedProperties && cacheSuccess.cacheHash && |
| 1760 MatchedPropertiesCache::isCacheable(state)) { | 1880 MatchedPropertiesCache::isCacheable(state)) { |
| 1761 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), | 1881 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), |
| 1762 matchedPropertyCacheAdded, 1); | 1882 matchedPropertyCacheAdded, 1); |
| 1763 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), | 1883 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), |
| 1764 cacheHash, matchResult.matchedProperties()); | 1884 cacheSuccess.cacheHash, |
| 1885 matchResult.matchedProperties()); |
| 1765 } | 1886 } |
| 1766 | 1887 |
| 1767 DCHECK(!state.fontBuilder().fontDirty()); | 1888 DCHECK(!state.fontBuilder().fontDirty()); |
| 1768 } | 1889 } |
| 1769 | 1890 |
| 1770 bool StyleResolver::hasAuthorBackground(const StyleResolverState& state) { | 1891 bool StyleResolver::hasAuthorBackground(const StyleResolverState& state) { |
| 1771 const CachedUAStyle* cachedUAStyle = state.cachedUAStyle(); | 1892 const CachedUAStyle* cachedUAStyle = state.cachedUAStyle(); |
| 1772 if (!cachedUAStyle) | 1893 if (!cachedUAStyle) |
| 1773 return false; | 1894 return false; |
| 1774 | 1895 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 DEFINE_TRACE(StyleResolver) { | 1966 DEFINE_TRACE(StyleResolver) { |
| 1846 visitor->trace(m_matchedPropertiesCache); | 1967 visitor->trace(m_matchedPropertiesCache); |
| 1847 visitor->trace(m_selectorFilter); | 1968 visitor->trace(m_selectorFilter); |
| 1848 visitor->trace(m_styleSharingLists); | 1969 visitor->trace(m_styleSharingLists); |
| 1849 visitor->trace(m_pendingStyleSheets); | 1970 visitor->trace(m_pendingStyleSheets); |
| 1850 visitor->trace(m_document); | 1971 visitor->trace(m_document); |
| 1851 visitor->trace(m_tracker); | 1972 visitor->trace(m_tracker); |
| 1852 } | 1973 } |
| 1853 | 1974 |
| 1854 } // namespace blink | 1975 } // namespace blink |
| OLD | NEW |