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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp
diff --git a/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp b/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp
index aa8564f58fe8cc5f24fb795992f4fb3faaf138cd..e3f03d8e6b7799c439c86f772c06740b7bb9b325 100644
--- a/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp
+++ b/third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp
@@ -1132,6 +1132,62 @@ void StyleResolver::CollectPseudoRulesForElement(
}
}
+void StyleResolver::ApplyAnimatedCustomProperties(StyleResolverState& state) {
+ if (!state.IsAnimatingCustomProperties()) {
+ return;
+ }
+ CSSAnimationUpdate& update = state.AnimationUpdate();
+ HashSet<PropertyHandle>& pending = state.AnimationPendingCustomProperties();
+ DCHECK(pending.IsEmpty());
+ for (const auto& interpolations :
+ {update.ActiveInterpolationsForCustomAnimations(),
+ update.ActiveInterpolationsForCustomTransitions()}) {
+ for (const auto& entry : interpolations) {
+ pending.insert(entry.key);
+ }
+ }
+ while (!pending.IsEmpty()) {
+ PropertyHandle property = *pending.begin();
+ CSSVariableResolver variable_resolver(state);
+ ApplyAnimatedCustomProperty(state, variable_resolver, property);
+ DCHECK_EQ(pending.find(property), pending.end());
+ }
+}
+
+static const ActiveInterpolations& ActiveInterpolationsForCustomProperty(
+ const StyleResolverState& state,
+ const PropertyHandle& property) {
+ const ActiveInterpolationsMap& animations_map =
+ state.AnimationUpdate().ActiveInterpolationsForCustomAnimations();
+ const auto& animation = animations_map.find(property);
+ if (animation != animations_map.end()) {
+ return animation->value;
+ }
+ const ActiveInterpolationsMap& transitions_map =
+ state.AnimationUpdate().ActiveInterpolationsForCustomTransitions();
+ const auto& transition = transitions_map.find(property);
+ DCHECK_NE(transition, transitions_map.end());
+ return transition->value;
+}
+
+void StyleResolver::ApplyAnimatedCustomProperty(
+ StyleResolverState& state,
+ CSSVariableResolver& variable_resolver,
+ const PropertyHandle& property) {
+ DCHECK(property.IsCSSCustomProperty());
+ const ActiveInterpolations& interpolations =
+ ActiveInterpolationsForCustomProperty(state, property);
+ const Interpolation& interpolation = *interpolations.front();
+ if (interpolation.IsInvalidatableInterpolation()) {
+ CSSInterpolationTypesMap map(state.GetDocument().GetPropertyRegistry());
+ CSSInterpolationEnvironment environment(map, state, &variable_resolver);
+ InvalidatableInterpolation::ApplyStack(interpolations, environment);
+ } else {
+ ToTransitionInterpolation(interpolation).Apply(state);
+ }
+ state.AnimationPendingCustomProperties().erase(property);
+}
+
bool StyleResolver::ApplyAnimatedStandardProperties(
StyleResolverState& state,
const Element* animating_element) {
@@ -1170,24 +1226,18 @@ bool StyleResolver::ApplyAnimatedStandardProperties(
state.SetApplyPropertyToVisitedLinkStyle(true);
}
- const ActiveInterpolationsMap&
- active_interpolations_map_for_standard_animations =
- state.AnimationUpdate().ActiveInterpolationsForStandardAnimations();
- const ActiveInterpolationsMap&
- active_interpolations_map_for_standard_transitions =
- state.AnimationUpdate().ActiveInterpolationsForStandardTransitions();
- // TODO(crbug.com/644148): Apply animations on custom properties.
- ApplyAnimatedProperties<kHighPropertyPriority>(
- state, active_interpolations_map_for_standard_animations);
- ApplyAnimatedProperties<kHighPropertyPriority>(
- state, active_interpolations_map_for_standard_transitions);
+ const ActiveInterpolationsMap& animations_map =
+ state.AnimationUpdate().ActiveInterpolationsForStandardAnimations();
+ const ActiveInterpolationsMap& transitions_map =
+ state.AnimationUpdate().ActiveInterpolationsForStandardTransitions();
+ ApplyAnimatedStandardProperties<kHighPropertyPriority>(state, animations_map);
+ ApplyAnimatedStandardProperties<kHighPropertyPriority>(state,
+ transitions_map);
UpdateFont(state);
- ApplyAnimatedProperties<kLowPropertyPriority>(
- state, active_interpolations_map_for_standard_animations);
- ApplyAnimatedProperties<kLowPropertyPriority>(
- state, active_interpolations_map_for_standard_transitions);
+ ApplyAnimatedStandardProperties<kLowPropertyPriority>(state, animations_map);
+ ApplyAnimatedStandardProperties<kLowPropertyPriority>(state, transitions_map);
// Start loading resources used by animations.
LoadPendingResources(state);
@@ -1220,9 +1270,12 @@ StyleRuleKeyframes* StyleResolver::FindKeyframesRule(
}
template <CSSPropertyPriority priority>
-void StyleResolver::ApplyAnimatedProperties(
+void StyleResolver::ApplyAnimatedStandardProperties(
StyleResolverState& state,
const ActiveInterpolationsMap& active_interpolations_map) {
+ static_assert(
+ priority != kResolveVariables,
+ "Use applyAnimatedCustomProperty() for custom property animations");
// TODO(alancutter): Don't apply presentation attribute animations here,
// they should instead apply in
// SVGElement::CollectStyleForPresentationAttribute().
@@ -1230,7 +1283,6 @@ void StyleResolver::ApplyAnimatedProperties(
CSSPropertyID property = entry.key.IsCSSProperty()
? entry.key.CssProperty()
: entry.key.PresentationAttribute();
- DCHECK_EQ(entry.key.IsCSSCustomProperty(), priority == kResolveVariables);
if (!CSSPropertyPriorityData<priority>::PropertyHasPriority(property))
continue;
const Interpolation& interpolation = *entry.value.front();
@@ -1752,12 +1804,7 @@ void StyleResolver::ApplyCustomProperties(StyleResolverState& state,
state, match_result.AuthorRules(), true, apply_inherited_only,
needs_apply_pass);
if (apply_animations == kIncludeAnimations) {
- ApplyAnimatedProperties<kResolveVariables>(
- state,
- state.AnimationUpdate().ActiveInterpolationsForCustomAnimations());
- ApplyAnimatedProperties<kResolveVariables>(
- state,
- state.AnimationUpdate().ActiveInterpolationsForCustomTransitions());
+ ApplyAnimatedCustomProperties(state);
}
// TODO(leviw): stop recalculating every time
CSSVariableResolver(state).ResolveVariableDefinitions();
@@ -1772,12 +1819,7 @@ void StyleResolver::ApplyCustomProperties(StyleResolverState& state,
state, match_result.AuthorRules(), true, apply_inherited_only,
needs_apply_pass);
if (apply_animations == kIncludeAnimations) {
- ApplyAnimatedProperties<kResolveVariables>(
- state,
- state.AnimationUpdate().ActiveInterpolationsForCustomAnimations());
- ApplyAnimatedProperties<kResolveVariables>(
- state,
- state.AnimationUpdate().ActiveInterpolationsForCustomTransitions());
+ ApplyAnimatedCustomProperties(state);
}
CSSVariableResolver(state).ResolveVariableDefinitions();
}

Powered by Google App Engine
This is Rietveld 408576698