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

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp

Issue 2809063002: WIP Support var() references in registered custom property keyframes (Closed)
Patch Set: Rebased Created 3 years, 6 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
OLDNEW
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 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 if (rules_to_include & kUAAndUserCSSRules) 1125 if (rules_to_include & kUAAndUserCSSRules)
1126 MatchUARules(collector); 1126 MatchUARules(collector);
1127 1127
1128 if (rules_to_include & kAuthorCSSRules) { 1128 if (rules_to_include & kAuthorCSSRules) {
1129 collector.SetSameOriginOnly(!(rules_to_include & kCrossOriginCSSRules)); 1129 collector.SetSameOriginOnly(!(rules_to_include & kCrossOriginCSSRules));
1130 collector.SetIncludeEmptyRules(rules_to_include & kEmptyCSSRules); 1130 collector.SetIncludeEmptyRules(rules_to_include & kEmptyCSSRules);
1131 MatchAuthorRules(element, collector); 1131 MatchAuthorRules(element, collector);
1132 } 1132 }
1133 } 1133 }
1134 1134
1135 void StyleResolver::ApplyAnimatedCustomProperties(StyleResolverState& state) {
1136 if (!state.IsAnimatingCustomProperties()) {
1137 return;
1138 }
1139 CSSAnimationUpdate& update = state.AnimationUpdate();
1140 HashSet<PropertyHandle>& pending = state.AnimationPendingCustomProperties();
1141 DCHECK(pending.IsEmpty());
1142 for (const auto& interpolations :
1143 {update.ActiveInterpolationsForCustomAnimations(),
1144 update.ActiveInterpolationsForCustomTransitions()}) {
1145 for (const auto& entry : interpolations) {
1146 pending.insert(entry.key);
1147 }
1148 }
1149 while (!pending.IsEmpty()) {
1150 PropertyHandle property = *pending.begin();
1151 CSSVariableResolver variable_resolver(state);
1152 ApplyAnimatedCustomProperty(state, variable_resolver, property);
1153 DCHECK_EQ(pending.find(property), pending.end());
1154 }
1155 }
1156
1157 static const ActiveInterpolations& ActiveInterpolationsForCustomProperty(
1158 const StyleResolverState& state,
1159 const PropertyHandle& property) {
1160 const ActiveInterpolationsMap& animations_map =
1161 state.AnimationUpdate().ActiveInterpolationsForCustomAnimations();
1162 const auto& animation = animations_map.find(property);
1163 if (animation != animations_map.end()) {
1164 return animation->value;
1165 }
1166 const ActiveInterpolationsMap& transitions_map =
1167 state.AnimationUpdate().ActiveInterpolationsForCustomTransitions();
1168 const auto& transition = transitions_map.find(property);
1169 DCHECK_NE(transition, transitions_map.end());
1170 return transition->value;
1171 }
1172
1173 void StyleResolver::ApplyAnimatedCustomProperty(
1174 StyleResolverState& state,
1175 CSSVariableResolver& variable_resolver,
1176 const PropertyHandle& property) {
1177 DCHECK(property.IsCSSCustomProperty());
1178 const ActiveInterpolations& interpolations =
1179 ActiveInterpolationsForCustomProperty(state, property);
1180 const Interpolation& interpolation = *interpolations.front();
1181 if (interpolation.IsInvalidatableInterpolation()) {
1182 CSSInterpolationTypesMap map(state.GetDocument().GetPropertyRegistry());
1183 CSSInterpolationEnvironment environment(map, state, &variable_resolver);
1184 InvalidatableInterpolation::ApplyStack(interpolations, environment);
1185 } else {
1186 ToTransitionInterpolation(interpolation).Apply(state);
1187 }
1188 state.AnimationPendingCustomProperties().erase(property);
1189 }
1190
1135 bool StyleResolver::ApplyAnimatedStandardProperties( 1191 bool StyleResolver::ApplyAnimatedStandardProperties(
1136 StyleResolverState& state, 1192 StyleResolverState& state,
1137 const Element* animating_element) { 1193 const Element* animating_element) {
1138 Element* element = state.GetElement(); 1194 Element* element = state.GetElement();
1139 DCHECK(element); 1195 DCHECK(element);
1140 1196
1141 // The animating element may be this element, or its pseudo element. It is 1197 // The animating element may be this element, or its pseudo element. It is
1142 // null when calculating the style for a potential pseudo element that has 1198 // null when calculating the style for a potential pseudo element that has
1143 // yet to be created. 1199 // yet to be created.
1144 DCHECK(animating_element == element || !animating_element || 1200 DCHECK(animating_element == element || !animating_element ||
(...skipping 18 matching lines...) Expand all
1163 *element, state.AnimationUpdate(), *state.Style(), state.ParentStyle()); 1219 *element, state.AnimationUpdate(), *state.Style(), state.ParentStyle());
1164 1220
1165 if (state.AnimationUpdate().IsEmpty()) 1221 if (state.AnimationUpdate().IsEmpty())
1166 return false; 1222 return false;
1167 1223
1168 if (state.Style()->InsideLink() != EInsideLink::kNotInsideLink) { 1224 if (state.Style()->InsideLink() != EInsideLink::kNotInsideLink) {
1169 DCHECK(state.ApplyPropertyToRegularStyle()); 1225 DCHECK(state.ApplyPropertyToRegularStyle());
1170 state.SetApplyPropertyToVisitedLinkStyle(true); 1226 state.SetApplyPropertyToVisitedLinkStyle(true);
1171 } 1227 }
1172 1228
1173 const ActiveInterpolationsMap& 1229 const ActiveInterpolationsMap& animations_map =
1174 active_interpolations_map_for_standard_animations = 1230 state.AnimationUpdate().ActiveInterpolationsForStandardAnimations();
1175 state.AnimationUpdate().ActiveInterpolationsForStandardAnimations(); 1231 const ActiveInterpolationsMap& transitions_map =
1176 const ActiveInterpolationsMap& 1232 state.AnimationUpdate().ActiveInterpolationsForStandardTransitions();
1177 active_interpolations_map_for_standard_transitions = 1233 ApplyAnimatedStandardProperties<kHighPropertyPriority>(state, animations_map);
1178 state.AnimationUpdate().ActiveInterpolationsForStandardTransitions(); 1234 ApplyAnimatedStandardProperties<kHighPropertyPriority>(state,
1179 // TODO(crbug.com/644148): Apply animations on custom properties. 1235 transitions_map);
1180 ApplyAnimatedProperties<kHighPropertyPriority>(
1181 state, active_interpolations_map_for_standard_animations);
1182 ApplyAnimatedProperties<kHighPropertyPriority>(
1183 state, active_interpolations_map_for_standard_transitions);
1184 1236
1185 UpdateFont(state); 1237 UpdateFont(state);
1186 1238
1187 ApplyAnimatedProperties<kLowPropertyPriority>( 1239 ApplyAnimatedStandardProperties<kLowPropertyPriority>(state, animations_map);
1188 state, active_interpolations_map_for_standard_animations); 1240 ApplyAnimatedStandardProperties<kLowPropertyPriority>(state, transitions_map);
1189 ApplyAnimatedProperties<kLowPropertyPriority>(
1190 state, active_interpolations_map_for_standard_transitions);
1191 1241
1192 // Start loading resources used by animations. 1242 // Start loading resources used by animations.
1193 LoadPendingResources(state); 1243 LoadPendingResources(state);
1194 1244
1195 DCHECK(!state.GetFontBuilder().FontDirty()); 1245 DCHECK(!state.GetFontBuilder().FontDirty());
1196 1246
1197 state.SetApplyPropertyToVisitedLinkStyle(false); 1247 state.SetApplyPropertyToVisitedLinkStyle(false);
1198 1248
1199 return true; 1249 return true;
1200 } 1250 }
(...skipping 12 matching lines...) Expand all
1213 resolver->KeyframeStylesForAnimation(animation_name.Impl())) 1263 resolver->KeyframeStylesForAnimation(animation_name.Impl()))
1214 return keyframes_rule; 1264 return keyframes_rule;
1215 } 1265 }
1216 1266
1217 for (auto& resolver : resolvers) 1267 for (auto& resolver : resolvers)
1218 resolver->SetHasUnresolvedKeyframesRule(); 1268 resolver->SetHasUnresolvedKeyframesRule();
1219 return nullptr; 1269 return nullptr;
1220 } 1270 }
1221 1271
1222 template <CSSPropertyPriority priority> 1272 template <CSSPropertyPriority priority>
1223 void StyleResolver::ApplyAnimatedProperties( 1273 void StyleResolver::ApplyAnimatedStandardProperties(
1224 StyleResolverState& state, 1274 StyleResolverState& state,
1225 const ActiveInterpolationsMap& active_interpolations_map) { 1275 const ActiveInterpolationsMap& active_interpolations_map) {
1276 static_assert(
1277 priority != kResolveVariables,
1278 "Use applyAnimatedCustomProperty() for custom property animations");
1226 // TODO(alancutter): Don't apply presentation attribute animations here, 1279 // TODO(alancutter): Don't apply presentation attribute animations here,
1227 // they should instead apply in 1280 // they should instead apply in
1228 // SVGElement::CollectStyleForPresentationAttribute(). 1281 // SVGElement::CollectStyleForPresentationAttribute().
1229 for (const auto& entry : active_interpolations_map) { 1282 for (const auto& entry : active_interpolations_map) {
1230 CSSPropertyID property = entry.key.IsCSSProperty() 1283 CSSPropertyID property = entry.key.IsCSSProperty()
1231 ? entry.key.CssProperty() 1284 ? entry.key.CssProperty()
1232 : entry.key.PresentationAttribute(); 1285 : entry.key.PresentationAttribute();
1233 DCHECK_EQ(entry.key.IsCSSCustomProperty(), priority == kResolveVariables);
1234 if (!CSSPropertyPriorityData<priority>::PropertyHasPriority(property)) 1286 if (!CSSPropertyPriorityData<priority>::PropertyHasPriority(property))
1235 continue; 1287 continue;
1236 const Interpolation& interpolation = *entry.value.front(); 1288 const Interpolation& interpolation = *entry.value.front();
1237 if (interpolation.IsInvalidatableInterpolation()) { 1289 if (interpolation.IsInvalidatableInterpolation()) {
1238 CSSInterpolationTypesMap map(state.GetDocument().GetPropertyRegistry()); 1290 CSSInterpolationTypesMap map(state.GetDocument().GetPropertyRegistry());
1239 CSSInterpolationEnvironment environment(map, state); 1291 CSSInterpolationEnvironment environment(map, state);
1240 InvalidatableInterpolation::ApplyStack(entry.value, environment); 1292 InvalidatableInterpolation::ApplyStack(entry.value, environment);
1241 } else if (interpolation.IsTransitionInterpolation()) { 1293 } else if (interpolation.IsTransitionInterpolation()) {
1242 ToTransitionInterpolation(interpolation).Apply(state); 1294 ToTransitionInterpolation(interpolation).Apply(state);
1243 } else { 1295 } else {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 1797
1746 // TODO(leviw): We need the proper bit for tracking whether we need to do 1798 // TODO(leviw): We need the proper bit for tracking whether we need to do
1747 // this work. 1799 // this work.
1748 ApplyMatchedProperties<kResolveVariables, kUpdateNeedsApplyPass>( 1800 ApplyMatchedProperties<kResolveVariables, kUpdateNeedsApplyPass>(
1749 state, match_result.AuthorRules(), false, apply_inherited_only, 1801 state, match_result.AuthorRules(), false, apply_inherited_only,
1750 needs_apply_pass); 1802 needs_apply_pass);
1751 ApplyMatchedProperties<kResolveVariables, kCheckNeedsApplyPass>( 1803 ApplyMatchedProperties<kResolveVariables, kCheckNeedsApplyPass>(
1752 state, match_result.AuthorRules(), true, apply_inherited_only, 1804 state, match_result.AuthorRules(), true, apply_inherited_only,
1753 needs_apply_pass); 1805 needs_apply_pass);
1754 if (apply_animations == kIncludeAnimations) { 1806 if (apply_animations == kIncludeAnimations) {
1755 ApplyAnimatedProperties<kResolveVariables>( 1807 ApplyAnimatedCustomProperties(state);
1756 state,
1757 state.AnimationUpdate().ActiveInterpolationsForCustomAnimations());
1758 ApplyAnimatedProperties<kResolveVariables>(
1759 state,
1760 state.AnimationUpdate().ActiveInterpolationsForCustomTransitions());
1761 } 1808 }
1762 // TODO(leviw): stop recalculating every time 1809 // TODO(leviw): stop recalculating every time
1763 CSSVariableResolver(state).ResolveVariableDefinitions(); 1810 CSSVariableResolver(state).ResolveVariableDefinitions();
1764 1811
1765 if (RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) { 1812 if (RuntimeEnabledFeatures::cssApplyAtRulesEnabled()) {
1766 if (CacheCustomPropertiesForApplyAtRules(state, 1813 if (CacheCustomPropertiesForApplyAtRules(state,
1767 match_result.AuthorRules())) { 1814 match_result.AuthorRules())) {
1768 ApplyMatchedProperties<kResolveVariables, kUpdateNeedsApplyPass>( 1815 ApplyMatchedProperties<kResolveVariables, kUpdateNeedsApplyPass>(
1769 state, match_result.AuthorRules(), false, apply_inherited_only, 1816 state, match_result.AuthorRules(), false, apply_inherited_only,
1770 needs_apply_pass); 1817 needs_apply_pass);
1771 ApplyMatchedProperties<kResolveVariables, kCheckNeedsApplyPass>( 1818 ApplyMatchedProperties<kResolveVariables, kCheckNeedsApplyPass>(
1772 state, match_result.AuthorRules(), true, apply_inherited_only, 1819 state, match_result.AuthorRules(), true, apply_inherited_only,
1773 needs_apply_pass); 1820 needs_apply_pass);
1774 if (apply_animations == kIncludeAnimations) { 1821 if (apply_animations == kIncludeAnimations) {
1775 ApplyAnimatedProperties<kResolveVariables>( 1822 ApplyAnimatedCustomProperties(state);
1776 state,
1777 state.AnimationUpdate().ActiveInterpolationsForCustomAnimations());
1778 ApplyAnimatedProperties<kResolveVariables>(
1779 state,
1780 state.AnimationUpdate().ActiveInterpolationsForCustomTransitions());
1781 } 1823 }
1782 CSSVariableResolver(state).ResolveVariableDefinitions(); 1824 CSSVariableResolver(state).ResolveVariableDefinitions();
1783 } 1825 }
1784 } 1826 }
1785 } 1827 }
1786 1828
1787 void StyleResolver::ApplyMatchedAnimationProperties( 1829 void StyleResolver::ApplyMatchedAnimationProperties(
1788 StyleResolverState& state, 1830 StyleResolverState& state,
1789 const MatchResult& match_result, 1831 const MatchResult& match_result,
1790 const CacheSuccess& cache_success, 1832 const CacheSuccess& cache_success,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2020 2062
2021 DEFINE_TRACE(StyleResolver) { 2063 DEFINE_TRACE(StyleResolver) {
2022 visitor->Trace(matched_properties_cache_); 2064 visitor->Trace(matched_properties_cache_);
2023 visitor->Trace(selector_filter_); 2065 visitor->Trace(selector_filter_);
2024 visitor->Trace(style_sharing_lists_); 2066 visitor->Trace(style_sharing_lists_);
2025 visitor->Trace(document_); 2067 visitor->Trace(document_);
2026 visitor->Trace(tracker_); 2068 visitor->Trace(tracker_);
2027 } 2069 }
2028 2070
2029 } // namespace blink 2071 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698