| 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 (state.style()->animations() || |
| 1120 !state.style()->transitions() && !state.style()->animations()) | 1149 (animatingElement && animatingElement->hasAnimations())) { |
| 1150 if (!state.isAnimationInterpolationMapReady()) |
| 1151 calculateAnimationUpdate(state, animatingElement); |
| 1152 } else if (!state.style()->transitions()) { |
| 1121 return false; | 1153 return false; |
| 1154 } |
| 1122 | 1155 |
| 1123 CSSAnimations::calculateUpdate(animatingElement, *element, *state.style(), | 1156 CSSAnimations::calculateCompositorAndTransitionUpdate( |
| 1124 state.parentStyle(), state.animationUpdate(), | 1157 animatingElement, *element, *state.style(), state.parentStyle(), |
| 1125 this); | 1158 state.animationUpdate()); |
| 1126 | 1159 |
| 1127 CSSAnimations::snapshotCompositorKeyframes( | 1160 CSSAnimations::snapshotCompositorKeyframes( |
| 1128 *element, state.animationUpdate(), *state.style(), state.parentStyle()); | 1161 *element, state.animationUpdate(), *state.style(), state.parentStyle()); |
| 1129 | 1162 |
| 1130 if (state.animationUpdate().isEmpty()) | 1163 if (state.animationUpdate().isEmpty()) |
| 1131 return false; | 1164 return false; |
| 1132 | 1165 |
| 1133 if (state.style()->insideLink() != NotInsideLink) { | 1166 if (state.style()->insideLink() != NotInsideLink) { |
| 1134 DCHECK(state.applyPropertyToRegularStyle()); | 1167 DCHECK(state.applyPropertyToRegularStyle()); |
| 1135 state.setApplyPropertyToVisitedLinkStyle(true); | 1168 state.setApplyPropertyToVisitedLinkStyle(true); |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 } | 1616 } |
| 1584 | 1617 |
| 1585 void StyleResolver::invalidateMatchedPropertiesCache() { | 1618 void StyleResolver::invalidateMatchedPropertiesCache() { |
| 1586 m_matchedPropertiesCache.clear(); | 1619 m_matchedPropertiesCache.clear(); |
| 1587 } | 1620 } |
| 1588 | 1621 |
| 1589 void StyleResolver::notifyResizeForViewportUnits() { | 1622 void StyleResolver::notifyResizeForViewportUnits() { |
| 1590 m_matchedPropertiesCache.clearViewportDependent(); | 1623 m_matchedPropertiesCache.clearViewportDependent(); |
| 1591 } | 1624 } |
| 1592 | 1625 |
| 1593 void StyleResolver::applyMatchedProperties(StyleResolverState& state, | 1626 void StyleResolver::applyMatchedPropertiesAndCustomPropertyAnimations( |
| 1594 const MatchResult& matchResult) { | 1627 StyleResolverState& state, |
| 1628 const MatchResult& matchResult, |
| 1629 const Element* animatingElement) { |
| 1630 CacheSuccess cacheSuccess = applyMatchedCache(state, matchResult); |
| 1631 NeedsApplyPass needsApplyPass; |
| 1632 if (!cacheSuccess.isFullCacheHit()) { |
| 1633 applyCustomProperties(state, matchResult, false, cacheSuccess, |
| 1634 needsApplyPass); |
| 1635 applyMatchedAnimationProperties(state, matchResult, cacheSuccess, |
| 1636 needsApplyPass); |
| 1637 } |
| 1638 if (state.style()->animations() || |
| 1639 (animatingElement && animatingElement->hasAnimations())) { |
| 1640 calculateAnimationUpdate(state, animatingElement); |
| 1641 if (state.isAnimatingCustomProperties()) { |
| 1642 cacheSuccess.setFailed(); |
| 1643 applyCustomProperties(state, matchResult, true, cacheSuccess, |
| 1644 needsApplyPass); |
| 1645 } |
| 1646 } |
| 1647 if (!cacheSuccess.isFullCacheHit()) { |
| 1648 applyMatchedStandardProperties(state, matchResult, cacheSuccess, |
| 1649 needsApplyPass); |
| 1650 } |
| 1651 } |
| 1652 |
| 1653 StyleResolver::CacheSuccess StyleResolver::applyMatchedCache( |
| 1654 StyleResolverState& state, |
| 1655 const MatchResult& matchResult) { |
| 1595 const Element* element = state.element(); | 1656 const Element* element = state.element(); |
| 1596 DCHECK(element); | 1657 DCHECK(element); |
| 1597 | 1658 |
| 1598 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyApply, | |
| 1599 1); | |
| 1600 | |
| 1601 unsigned cacheHash = | 1659 unsigned cacheHash = |
| 1602 matchResult.isCacheable() | 1660 matchResult.isCacheable() |
| 1603 ? computeMatchedPropertiesHash(matchResult.matchedProperties().data(), | 1661 ? computeMatchedPropertiesHash(matchResult.matchedProperties().data(), |
| 1604 matchResult.matchedProperties().size()) | 1662 matchResult.matchedProperties().size()) |
| 1605 : 0; | 1663 : 0; |
| 1606 bool applyInheritedOnly = false; | 1664 bool isInheritedCacheHit = false; |
| 1665 bool isNonInheritedCacheHit = false; |
| 1607 const CachedMatchedProperties* cachedMatchedProperties = | 1666 const CachedMatchedProperties* cachedMatchedProperties = |
| 1608 cacheHash | 1667 cacheHash |
| 1609 ? m_matchedPropertiesCache.find(cacheHash, state, | 1668 ? m_matchedPropertiesCache.find(cacheHash, state, |
| 1610 matchResult.matchedProperties()) | 1669 matchResult.matchedProperties()) |
| 1611 : nullptr; | 1670 : nullptr; |
| 1612 | 1671 |
| 1613 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(state)) { | 1672 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(state)) { |
| 1614 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), | 1673 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), |
| 1615 matchedPropertyCacheHit, 1); | 1674 matchedPropertyCacheHit, 1); |
| 1616 // We can build up the style by copying non-inherited properties from an | 1675 // 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 | 1691 // If the cache item parent style has identical inherited properties to |
| 1633 // the current parent style then the resulting style will be identical | 1692 // 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. | 1693 // too. We copy the inherited properties over from the cache and are done. |
| 1635 state.style()->inheritFrom(*cachedMatchedProperties->computedStyle); | 1694 state.style()->inheritFrom(*cachedMatchedProperties->computedStyle); |
| 1636 | 1695 |
| 1637 // Unfortunately the link status is treated like an inherited property. We | 1696 // Unfortunately the link status is treated like an inherited property. We |
| 1638 // need to explicitly restore it. | 1697 // need to explicitly restore it. |
| 1639 state.style()->setInsideLink(linkStatus); | 1698 state.style()->setInsideLink(linkStatus); |
| 1640 | 1699 |
| 1641 updateFont(state); | 1700 updateFont(state); |
| 1701 isInheritedCacheHit = true; |
| 1702 } |
| 1642 | 1703 |
| 1643 return; | 1704 isNonInheritedCacheHit = true; |
| 1644 } | |
| 1645 applyInheritedOnly = true; | |
| 1646 } | 1705 } |
| 1647 | 1706 |
| 1648 NeedsApplyPass needsApplyPass; | 1707 return CacheSuccess(isInheritedCacheHit, isNonInheritedCacheHit, cacheHash, |
| 1708 cachedMatchedProperties); |
| 1709 } |
| 1649 | 1710 |
| 1650 // TODO(leviw): We need the proper bit for tracking whether we need to do this | 1711 void StyleResolver::applyCustomProperties(StyleResolverState& state, |
| 1651 // work. | 1712 const MatchResult& matchResult, |
| 1713 bool applyAnimations, |
| 1714 const CacheSuccess& cacheSuccess, |
| 1715 NeedsApplyPass& needsApplyPass) { |
| 1716 DCHECK(!cacheSuccess.isFullCacheHit()); |
| 1717 bool applyInheritedOnly = cacheSuccess.shouldApplyInheritedOnly(); |
| 1718 |
| 1719 // TODO(leviw): We need the proper bit for tracking whether we need to do |
| 1720 // this work. |
| 1652 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( | 1721 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( |
| 1653 state, matchResult.authorRules(), false, applyInheritedOnly, | 1722 state, matchResult.authorRules(), false, applyInheritedOnly, |
| 1654 needsApplyPass); | 1723 needsApplyPass); |
| 1655 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( | 1724 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( |
| 1656 state, matchResult.authorRules(), true, applyInheritedOnly, | 1725 state, matchResult.authorRules(), true, applyInheritedOnly, |
| 1657 needsApplyPass); | 1726 needsApplyPass); |
| 1727 if (applyAnimations) { |
| 1728 applyAnimatedProperties<ResolveVariables>( |
| 1729 state, state.animationUpdate().activeInterpolationsForAnimations()); |
| 1730 } |
| 1658 // TODO(leviw): stop recalculating every time | 1731 // TODO(leviw): stop recalculating every time |
| 1659 CSSVariableResolver::resolveVariableDefinitions(state); | 1732 CSSVariableResolver::resolveVariableDefinitions(state); |
| 1660 | 1733 |
| 1661 if (RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { | 1734 if (RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { |
| 1662 if (cacheCustomPropertiesForApplyAtRules(state, | 1735 if (cacheCustomPropertiesForApplyAtRules(state, |
| 1663 matchResult.authorRules())) { | 1736 matchResult.authorRules())) { |
| 1664 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( | 1737 applyMatchedProperties<ResolveVariables, UpdateNeedsApplyPass>( |
| 1665 state, matchResult.authorRules(), false, applyInheritedOnly, | 1738 state, matchResult.authorRules(), false, applyInheritedOnly, |
| 1666 needsApplyPass); | 1739 needsApplyPass); |
| 1667 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( | 1740 applyMatchedProperties<ResolveVariables, CheckNeedsApplyPass>( |
| 1668 state, matchResult.authorRules(), true, applyInheritedOnly, | 1741 state, matchResult.authorRules(), true, applyInheritedOnly, |
| 1669 needsApplyPass); | 1742 needsApplyPass); |
| 1743 if (applyAnimations) { |
| 1744 applyAnimatedProperties<ResolveVariables>( |
| 1745 state, state.animationUpdate().activeInterpolationsForAnimations()); |
| 1746 } |
| 1670 CSSVariableResolver::resolveVariableDefinitions(state); | 1747 CSSVariableResolver::resolveVariableDefinitions(state); |
| 1671 } | 1748 } |
| 1672 } | 1749 } |
| 1750 } |
| 1673 | 1751 |
| 1674 // Apply animation affecting properties. | 1752 void StyleResolver::applyMatchedAnimationProperties( |
| 1753 StyleResolverState& state, |
| 1754 const MatchResult& matchResult, |
| 1755 const CacheSuccess& cacheSuccess, |
| 1756 NeedsApplyPass& needsApplyPass) { |
| 1757 DCHECK(!cacheSuccess.isFullCacheHit()); |
| 1758 bool applyInheritedOnly = cacheSuccess.shouldApplyInheritedOnly(); |
| 1759 |
| 1675 applyMatchedProperties<AnimationPropertyPriority, UpdateNeedsApplyPass>( | 1760 applyMatchedProperties<AnimationPropertyPriority, UpdateNeedsApplyPass>( |
| 1676 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); | 1761 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); |
| 1677 applyMatchedProperties<AnimationPropertyPriority, CheckNeedsApplyPass>( | 1762 applyMatchedProperties<AnimationPropertyPriority, CheckNeedsApplyPass>( |
| 1678 state, matchResult.allRules(), true, applyInheritedOnly, needsApplyPass); | 1763 state, matchResult.allRules(), true, applyInheritedOnly, needsApplyPass); |
| 1764 } |
| 1765 |
| 1766 void StyleResolver::calculateAnimationUpdate(StyleResolverState& state, |
| 1767 const Element* animatingElement) { |
| 1768 DCHECK(state.style()->animations() || |
| 1769 (animatingElement && animatingElement->hasAnimations())); |
| 1770 DCHECK(!state.isAnimationInterpolationMapReady()); |
| 1771 |
| 1772 CSSAnimations::calculateAnimationUpdate( |
| 1773 state.animationUpdate(), animatingElement, *state.element(), |
| 1774 *state.style(), state.parentStyle(), this); |
| 1775 |
| 1776 state.setIsAnimationInterpolationMapReady(); |
| 1777 |
| 1778 if (state.isAnimatingCustomProperties()) |
| 1779 return; |
| 1780 for (const auto& propertyHandle : |
| 1781 state.animationUpdate().activeInterpolationsForAnimations().keys()) { |
| 1782 if (CSSAnimations::isCustomPropertyHandle(propertyHandle)) { |
| 1783 state.setIsAnimatingCustomProperties(true); |
| 1784 return; |
| 1785 } |
| 1786 } |
| 1787 } |
| 1788 |
| 1789 void StyleResolver::applyMatchedStandardProperties( |
| 1790 StyleResolverState& state, |
| 1791 const MatchResult& matchResult, |
| 1792 const CacheSuccess& cacheSuccess, |
| 1793 NeedsApplyPass& needsApplyPass) { |
| 1794 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyApply, |
| 1795 1); |
| 1796 |
| 1797 DCHECK(!cacheSuccess.isFullCacheHit()); |
| 1798 bool applyInheritedOnly = cacheSuccess.shouldApplyInheritedOnly(); |
| 1679 | 1799 |
| 1680 // Now we have all of the matched rules in the appropriate order. Walk the | 1800 // 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 | 1801 // 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, | 1802 // other properties depend on. The order is (1) high-priority not important, |
| 1683 // (2) high-priority important, (3) normal not important and (4) normal | 1803 // (2) high-priority important, (3) normal not important and (4) normal |
| 1684 // important. | 1804 // important. |
| 1685 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( | 1805 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( |
| 1686 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); | 1806 state, matchResult.allRules(), false, applyInheritedOnly, needsApplyPass); |
| 1687 for (auto range : ImportantAuthorRanges(matchResult)) { | 1807 for (auto range : ImportantAuthorRanges(matchResult)) { |
| 1688 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( | 1808 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( |
| 1689 state, range, true, applyInheritedOnly, needsApplyPass); | 1809 state, range, true, applyInheritedOnly, needsApplyPass); |
| 1690 } | 1810 } |
| 1691 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( | 1811 applyMatchedProperties<HighPropertyPriority, CheckNeedsApplyPass>( |
| 1692 state, matchResult.uaRules(), true, applyInheritedOnly, needsApplyPass); | 1812 state, matchResult.uaRules(), true, applyInheritedOnly, needsApplyPass); |
| 1693 | 1813 |
| 1694 if (UNLIKELY(isSVGForeignObjectElement(element))) { | 1814 if (UNLIKELY(isSVGForeignObjectElement(state.element()))) { |
| 1695 // LayoutSVGRoot handles zooming for the whole SVG subtree, so foreignObject | 1815 // LayoutSVGRoot handles zooming for the whole SVG subtree, so foreignObject |
| 1696 // content should not be scaled again. | 1816 // content should not be scaled again. |
| 1697 // | 1817 // |
| 1698 // FIXME: The following hijacks the zoom property for foreignObject so that | 1818 // FIXME: The following hijacks the zoom property for foreignObject so that |
| 1699 // children of foreignObject get the correct font-size in case of zooming. | 1819 // children of foreignObject get the correct font-size in case of zooming. |
| 1700 // 'zoom' has HighPropertyPriority, along with other font-related properties | 1820 // 'zoom' has HighPropertyPriority, along with other font-related properties |
| 1701 // used as input to the FontBuilder, so resetting it here may cause the | 1821 // used as input to the FontBuilder, so resetting it here may cause the |
| 1702 // FontBuilder to recompute the font used as inheritable font for | 1822 // FontBuilder to recompute the font used as inheritable font for |
| 1703 // foreignObject content. If we want to support zoom on foreignObject we'll | 1823 // foreignObject content. If we want to support zoom on foreignObject we'll |
| 1704 // need to find another way of handling the SVG zoom model. | 1824 // need to find another way of handling the SVG zoom model. |
| 1705 state.setEffectiveZoom(ComputedStyle::initialZoom()); | 1825 state.setEffectiveZoom(ComputedStyle::initialZoom()); |
| 1706 } | 1826 } |
| 1707 | 1827 |
| 1708 if (cachedMatchedProperties && | 1828 if (cacheSuccess.cachedMatchedProperties && |
| 1709 cachedMatchedProperties->computedStyle->effectiveZoom() != | 1829 cacheSuccess.cachedMatchedProperties->computedStyle->effectiveZoom() != |
| 1710 state.style()->effectiveZoom()) { | 1830 state.style()->effectiveZoom()) { |
| 1711 state.fontBuilder().didChangeEffectiveZoom(); | 1831 state.fontBuilder().didChangeEffectiveZoom(); |
| 1712 applyInheritedOnly = false; | 1832 applyInheritedOnly = false; |
| 1713 } | 1833 } |
| 1714 | 1834 |
| 1715 // If our font got dirtied, go ahead and update it now. | 1835 // If our font got dirtied, go ahead and update it now. |
| 1716 updateFont(state); | 1836 updateFont(state); |
| 1717 | 1837 |
| 1718 // Many properties depend on the font. If it changes we just apply all | 1838 // Many properties depend on the font. If it changes we just apply all |
| 1719 // properties. | 1839 // properties. |
| 1720 if (cachedMatchedProperties && | 1840 if (cacheSuccess.cachedMatchedProperties && |
| 1721 cachedMatchedProperties->computedStyle->getFontDescription() != | 1841 cacheSuccess.cachedMatchedProperties->computedStyle |
| 1722 state.style()->getFontDescription()) | 1842 ->getFontDescription() != state.style()->getFontDescription()) |
| 1723 applyInheritedOnly = false; | 1843 applyInheritedOnly = false; |
| 1724 | 1844 |
| 1725 // Registered custom properties are computed after high priority properties. | 1845 // Registered custom properties are computed after high priority properties. |
| 1726 CSSVariableResolver::computeRegisteredVariables(state); | 1846 CSSVariableResolver::computeRegisteredVariables(state); |
| 1727 | 1847 |
| 1728 // Now do the normal priority UA properties. | 1848 // Now do the normal priority UA properties. |
| 1729 applyMatchedProperties<LowPropertyPriority, CheckNeedsApplyPass>( | 1849 applyMatchedProperties<LowPropertyPriority, CheckNeedsApplyPass>( |
| 1730 state, matchResult.uaRules(), false, applyInheritedOnly, needsApplyPass); | 1850 state, matchResult.uaRules(), false, applyInheritedOnly, needsApplyPass); |
| 1731 | 1851 |
| 1732 // Cache the UA properties to pass them to LayoutTheme in adjustComputedStyle. | 1852 // 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 | 1869 // ones. When there is a partial match in the MatchedPropertiesCache, these |
| 1750 // flags will already be set correctly and the value stored in | 1870 // flags will already be set correctly and the value stored in |
| 1751 // cacheUserAgentBorderAndBackground is incorrect, so doing this check again | 1871 // cacheUserAgentBorderAndBackground is incorrect, so doing this check again |
| 1752 // would give the wrong answer. | 1872 // would give the wrong answer. |
| 1753 state.style()->setHasAuthorBackground(hasAuthorBackground(state)); | 1873 state.style()->setHasAuthorBackground(hasAuthorBackground(state)); |
| 1754 state.style()->setHasAuthorBorder(hasAuthorBorder(state)); | 1874 state.style()->setHasAuthorBorder(hasAuthorBorder(state)); |
| 1755 } | 1875 } |
| 1756 | 1876 |
| 1757 loadPendingResources(state); | 1877 loadPendingResources(state); |
| 1758 | 1878 |
| 1759 if (!cachedMatchedProperties && cacheHash && | 1879 if (!state.isAnimatingCustomProperties() && |
| 1880 !cacheSuccess.cachedMatchedProperties && cacheSuccess.cacheHash && |
| 1760 MatchedPropertiesCache::isCacheable(state)) { | 1881 MatchedPropertiesCache::isCacheable(state)) { |
| 1761 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), | 1882 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), |
| 1762 matchedPropertyCacheAdded, 1); | 1883 matchedPropertyCacheAdded, 1); |
| 1763 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), | 1884 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), |
| 1764 cacheHash, matchResult.matchedProperties()); | 1885 cacheSuccess.cacheHash, |
| 1886 matchResult.matchedProperties()); |
| 1765 } | 1887 } |
| 1766 | 1888 |
| 1767 DCHECK(!state.fontBuilder().fontDirty()); | 1889 DCHECK(!state.fontBuilder().fontDirty()); |
| 1768 } | 1890 } |
| 1769 | 1891 |
| 1770 bool StyleResolver::hasAuthorBackground(const StyleResolverState& state) { | 1892 bool StyleResolver::hasAuthorBackground(const StyleResolverState& state) { |
| 1771 const CachedUAStyle* cachedUAStyle = state.cachedUAStyle(); | 1893 const CachedUAStyle* cachedUAStyle = state.cachedUAStyle(); |
| 1772 if (!cachedUAStyle) | 1894 if (!cachedUAStyle) |
| 1773 return false; | 1895 return false; |
| 1774 | 1896 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 DEFINE_TRACE(StyleResolver) { | 1967 DEFINE_TRACE(StyleResolver) { |
| 1846 visitor->trace(m_matchedPropertiesCache); | 1968 visitor->trace(m_matchedPropertiesCache); |
| 1847 visitor->trace(m_selectorFilter); | 1969 visitor->trace(m_selectorFilter); |
| 1848 visitor->trace(m_styleSharingLists); | 1970 visitor->trace(m_styleSharingLists); |
| 1849 visitor->trace(m_pendingStyleSheets); | 1971 visitor->trace(m_pendingStyleSheets); |
| 1850 visitor->trace(m_document); | 1972 visitor->trace(m_document); |
| 1851 visitor->trace(m_tracker); | 1973 visitor->trace(m_tracker); |
| 1852 } | 1974 } |
| 1853 | 1975 |
| 1854 } // namespace blink | 1976 } // namespace blink |
| OLD | NEW |