css: Update animated styles to resolve used values

The way this works is that we first apply the value changes
from animations, which will trigger recomputation of the regular
style properies if the keyframes contains custom properties.

After that is done, we resolve the used values, base on the
new computed values. This is where currentcolor is resolved.
This commit is contained in:
Matthias Clasen 2024-05-19 18:55:08 -04:00
parent d3c78c8811
commit 1af746e136
5 changed files with 39 additions and 96 deletions

View File

@ -42,36 +42,11 @@
G_DEFINE_TYPE (GtkCssAnimatedStyle, gtk_css_animated_style, GTK_TYPE_CSS_STYLE)
static inline gboolean
property_has_color (guint id)
{
switch (id)
{
case GTK_CSS_PROPERTY_ICON_PALETTE:
case GTK_CSS_PROPERTY_TEXT_DECORATION_COLOR:
case GTK_CSS_PROPERTY_TEXT_SHADOW:
case GTK_CSS_PROPERTY_BOX_SHADOW:
case GTK_CSS_PROPERTY_BORDER_TOP_COLOR:
case GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR:
case GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR:
case GTK_CSS_PROPERTY_BORDER_LEFT_COLOR:
case GTK_CSS_PROPERTY_OUTLINE_COLOR:
case GTK_CSS_PROPERTY_BACKGROUND_COLOR:
case GTK_CSS_PROPERTY_ICON_SOURCE:
case GTK_CSS_PROPERTY_ICON_SHADOW:
case GTK_CSS_PROPERTY_CARET_COLOR:
case GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR:
return TRUE;
default:
return FALSE;
}
}
#define DEFINE_VALUES(ENUM, TYPE, NAME) \
static inline void \
gtk_css_ ## NAME ## _values_recompute (GtkCssAnimatedStyle *animated, \
GtkCssComputeContext *context, \
GtkCssAnimationChange change) \
GtkCssComputeContext *context) \
{ \
GtkCssStyle *style = (GtkCssStyle *)animated; \
int i; \
@ -80,29 +55,12 @@ gtk_css_ ## NAME ## _values_recompute (GtkCssAnimatedStyle *animated, \
{ \
guint id = NAME ## _props[i]; \
GtkCssValue *original, *computed; \
gboolean needs_recompute = FALSE; \
\
original = gtk_css_style_get_original_value (style, id); \
\
if ((change & GTK_CSS_ANIMATION_CHANGE_VARIABLES) && \
original && \
gtk_css_value_contains_variables (original)) \
{ \
needs_recompute = TRUE; \
} \
\
if ((change & GTK_CSS_ANIMATION_CHANGE_COLOR) && \
property_has_color (id)) \
{ \
needs_recompute = TRUE; \
if (original == NULL) \
original = gtk_css_animated_style_get_intrinsic_value (animated, id); \
} \
\
if (!needs_recompute) \
if (original == NULL) \
continue; \
\
if (original == NULL) \
if (!gtk_css_value_contains_variables (original)) \
continue; \
\
computed = gtk_css_value_compute (original, id, context); \
@ -110,9 +68,6 @@ gtk_css_ ## NAME ## _values_recompute (GtkCssAnimatedStyle *animated, \
continue; \
\
gtk_css_animated_style_set_animated_value (animated, id, computed); \
\
if (id == GTK_CSS_PROPERTY_COLOR) \
change |= GTK_CSS_ANIMATION_CHANGE_COLOR; \
} \
}
@ -680,28 +635,28 @@ gtk_css_animated_style_set_animated_custom_value (GtkCssAnimatedStyle *animated,
}
void
gtk_css_animated_style_recompute (GtkCssAnimatedStyle *style,
GtkCssAnimationChange change)
gtk_css_animated_style_recompute (GtkCssAnimatedStyle *style)
{
GtkCssComputeContext context = { NULL, };
GtkCssValue *shorthands[GTK_CSS_SHORTHAND_PROPERTY_N_PROPERTIES] = { NULL, };
context.provider = style->provider;
context.style = style->style;
context.style = (GtkCssStyle *) style;
context.parent_style = style->parent_style;
context.variables = ((GtkCssStyle *) style)->variables;
context.shorthands = shorthands;
gtk_css_core_values_recompute (style, &context, change);
gtk_css_background_values_recompute (style, &context, change);
gtk_css_border_values_recompute (style, &context, change);
gtk_css_icon_values_recompute (style, &context, change);
gtk_css_outline_values_recompute (style, &context, change);
gtk_css_font_values_recompute (style, &context, change);
gtk_css_font_variant_values_recompute (style, &context, change);
gtk_css_animation_values_recompute (style, &context, change);
gtk_css_transition_values_recompute (style, &context, change);
gtk_css_size_values_recompute (style, &context, change);
gtk_css_other_values_recompute (style, &context, change);
gtk_css_core_values_recompute (style, &context);
gtk_css_background_values_recompute (style, &context);
gtk_css_border_values_recompute (style, &context);
gtk_css_icon_values_recompute (style, &context);
gtk_css_outline_values_recompute (style, &context);
gtk_css_font_values_recompute (style, &context);
gtk_css_font_variant_values_recompute (style, &context);
gtk_css_animation_values_recompute (style, &context);
gtk_css_transition_values_recompute (style, &context);
gtk_css_size_values_recompute (style, &context);
gtk_css_other_values_recompute (style, &context);
for (unsigned int i = 0; i < GTK_CSS_SHORTHAND_PROPERTY_N_PROPERTIES; i++)
{
@ -1028,14 +983,22 @@ gtk_css_animated_style_create_css_animations (GPtrArray *animations,
static void
gtk_css_animated_style_apply_animations (GtkCssAnimatedStyle *style)
{
guint i;
GtkCssComputeContext context;
for (i = 0; i < style->n_animations; i ++)
for (guint i = 0; i < style->n_animations; i ++)
{
GtkStyleAnimation *animation = style->animations[i];
_gtk_style_animation_apply_values (animation, style);
}
context.provider = style->provider;
context.style = (GtkCssStyle *) style;
context.parent_style = style->parent_style;
context.variables = NULL;
context.shorthands = NULL;
gtk_css_style_resolve_used_values ((GtkCssStyle *) style, &context);
}
GtkCssStyle *
@ -1088,6 +1051,7 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
style->transition = (GtkCssTransitionValues *)gtk_css_values_ref ((GtkCssValues *)base_style->transition);
style->size = (GtkCssSizeValues *)gtk_css_values_ref ((GtkCssValues *)base_style->size);
style->other = (GtkCssOtherValues *)gtk_css_values_ref ((GtkCssValues *)base_style->other);
style->used = (GtkCssUsedValues *)gtk_css_values_ref ((GtkCssValues *)base_style->used);
if (base_style->variables)
style->variables = gtk_css_variable_set_ref (base_style->variables);
@ -1161,6 +1125,7 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
style->transition = (GtkCssTransitionValues *)gtk_css_values_ref ((GtkCssValues *)base_style->transition);
style->size = (GtkCssSizeValues *)gtk_css_values_ref ((GtkCssValues *)base_style->size);
style->other = (GtkCssOtherValues *)gtk_css_values_ref ((GtkCssValues *)base_style->other);
style->used = (GtkCssUsedValues *)gtk_css_values_ref ((GtkCssValues *)base_style->used);
if (base_style->variables)
style->variables = gtk_css_variable_set_ref (base_style->variables);

View File

@ -74,13 +74,7 @@ gboolean gtk_css_animated_style_set_animated_custom_value (GtkCss
int id,
GtkCssVariableValue *value);
typedef enum {
GTK_CSS_ANIMATION_CHANGE_VARIABLES = 1 << 0,
GTK_CSS_ANIMATION_CHANGE_COLOR = 1 << 1,
} GtkCssAnimationChange;
void gtk_css_animated_style_recompute (GtkCssAnimatedStyle *style,
GtkCssAnimationChange change);
void gtk_css_animated_style_recompute (GtkCssAnimatedStyle *style);
GtkCssVariableValue * gtk_css_animated_style_get_intrinsic_custom_value (GtkCssAnimatedStyle *style,
int id);

View File

@ -95,7 +95,7 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation,
GtkCssKeyframes *resolved_keyframes;
double progress;
guint i;
GtkCssAnimationChange change = 0;
gboolean needs_recompute = FALSE;
if (!gtk_css_animation_is_executing (animation))
return;
@ -127,33 +127,13 @@ gtk_css_animation_apply_values (GtkStyleAnimation *style_animation,
continue;
if (gtk_css_animated_style_set_animated_custom_value (style, variable_id, value))
change |= GTK_CSS_ANIMATION_CHANGE_VARIABLES;
needs_recompute = TRUE;
gtk_css_variable_value_unref (value);
}
/* Now deal with color */
for (i = 0; i < _gtk_css_keyframes_get_n_properties (resolved_keyframes); i++)
{
GtkCssValue *value;
guint property_id;
property_id = _gtk_css_keyframes_get_property_id (resolved_keyframes, i);
if (property_id != GTK_CSS_PROPERTY_COLOR)
continue;
value = _gtk_css_keyframes_get_value (resolved_keyframes,
i,
progress,
gtk_css_animated_style_get_intrinsic_value (style, property_id));
gtk_css_animated_style_set_animated_value (style, property_id, value);
change |= GTK_CSS_ANIMATION_CHANGE_COLOR;
break;
}
if (change != 0)
gtk_css_animated_style_recompute (style, change);
if (needs_recompute)
gtk_css_animated_style_recompute (style);
for (i = 0; i < _gtk_css_keyframes_get_n_properties (resolved_keyframes); i++)
{

View File

@ -991,7 +991,7 @@ gtk_css_style_list_custom_properties (GtkCssStyle *style)
return NULL;
}
static GtkCssValue *
GtkCssValue *
gtk_css_style_resolve_used_value (GtkCssStyle *style,
GtkCssValue *value,
guint id,

View File

@ -328,6 +328,10 @@ GtkCssVariableValue * gtk_css_style_get_custom_property (GtkCssStyle
int id);
GArray * gtk_css_style_list_custom_properties (GtkCssStyle *style);
GtkCssValue * gtk_css_style_resolve_used_value (GtkCssStyle *style,
GtkCssValue *value,
guint property_id,
GtkCssComputeContext *context);
void gtk_css_style_resolve_used_values (GtkCssStyle *style,
GtkCssComputeContext *context);