forked from AuroraMiddleware/gtk
stylecontext: Make static styles static
Instead of keeping an animated style everywhere, we replace it with the static style when nothing gets animated. Apart from making the code cleaner, this gets rid of a bunch of animated style values that do nothing but wrap a static style.
This commit is contained in:
parent
db36ee36a6
commit
79f7392109
@ -117,13 +117,20 @@ gtk_css_animated_style_class_init (GtkCssAnimatedStyleClass *klass)
|
||||
static void
|
||||
gtk_css_animated_style_init (GtkCssAnimatedStyle *style)
|
||||
{
|
||||
style->style = gtk_css_static_style_new ();
|
||||
}
|
||||
|
||||
GtkCssStyle *
|
||||
gtk_css_animated_style_new (void)
|
||||
gtk_css_animated_style_new (GtkCssStyle *style)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
|
||||
GtkCssAnimatedStyle *result;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_CSS_STYLE (style), NULL);
|
||||
|
||||
result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
|
||||
|
||||
result->style = g_object_ref (style);
|
||||
|
||||
return GTK_CSS_STYLE (result);
|
||||
}
|
||||
|
||||
void
|
||||
@ -254,7 +261,7 @@ gtk_css_animated_style_find_transition (GtkCssAnimatedStyle *style,
|
||||
static void
|
||||
gtk_css_animated_style_create_css_transitions (GtkCssAnimatedStyle *style,
|
||||
gint64 timestamp,
|
||||
GtkCssAnimatedStyle *source)
|
||||
GtkCssStyle *source)
|
||||
{
|
||||
TransitionInfo transitions[GTK_CSS_PROPERTY_N_PROPERTIES] = { { 0, } };
|
||||
GtkCssValue *durations, *delays, *timing_functions;
|
||||
@ -280,24 +287,27 @@ gtk_css_animated_style_create_css_transitions (GtkCssAnimatedStyle *style,
|
||||
if (duration + delay == 0.0)
|
||||
continue;
|
||||
|
||||
start = gtk_css_animated_style_get_intrinsic_value (source, i);
|
||||
if (GTK_IS_CSS_ANIMATED_STYLE (source))
|
||||
{
|
||||
start = gtk_css_animated_style_get_intrinsic_value (GTK_CSS_ANIMATED_STYLE (source), i);
|
||||
end = gtk_css_animated_style_get_intrinsic_value (style, i);
|
||||
if (_gtk_css_value_equal (start, end))
|
||||
{
|
||||
animation = gtk_css_animated_style_find_transition (GTK_CSS_ANIMATED_STYLE (source), i);
|
||||
if (animation)
|
||||
style->animations = g_slist_prepend (style->animations, g_object_ref (animation));
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
animation = _gtk_css_transition_new (i,
|
||||
gtk_css_style_get_value (GTK_CSS_STYLE (source), i),
|
||||
gtk_css_style_get_value (source, i),
|
||||
_gtk_css_array_value_get_nth (timing_functions, i),
|
||||
timestamp + delay * G_USEC_PER_SEC,
|
||||
timestamp + (delay + duration) * G_USEC_PER_SEC);
|
||||
style->animations = g_slist_prepend (style->animations, animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GtkStyleAnimation *
|
||||
@ -320,11 +330,11 @@ gtk_css_animated_style_find_animation (GtkCssAnimatedStyle *style,
|
||||
|
||||
static void
|
||||
gtk_css_animated_style_create_css_animations (GtkCssAnimatedStyle *style,
|
||||
GtkCssAnimatedStyle *parent_style,
|
||||
GtkCssStyle *parent_style,
|
||||
gint64 timestamp,
|
||||
GtkStyleProviderPrivate *provider,
|
||||
int scale,
|
||||
GtkCssAnimatedStyle *source)
|
||||
GtkCssStyle *source)
|
||||
{
|
||||
GtkCssValue *durations, *delays, *timing_functions, *animations;
|
||||
GtkCssValue *iteration_counts, *directions, *play_states, *fill_modes;
|
||||
@ -353,8 +363,8 @@ gtk_css_animated_style_create_css_animations (GtkCssAnimatedStyle *style,
|
||||
if (animation)
|
||||
continue;
|
||||
|
||||
if (source)
|
||||
animation = gtk_css_animated_style_find_animation (source, name);
|
||||
if (GTK_IS_CSS_ANIMATED_STYLE (source))
|
||||
animation = gtk_css_animated_style_find_animation (GTK_CSS_ANIMATED_STYLE (source), name);
|
||||
|
||||
if (animation)
|
||||
{
|
||||
@ -368,7 +378,7 @@ gtk_css_animated_style_create_css_animations (GtkCssAnimatedStyle *style,
|
||||
if (keyframes == NULL)
|
||||
continue;
|
||||
|
||||
keyframes = _gtk_css_keyframes_compute (keyframes, provider, scale, GTK_CSS_STYLE (style), GTK_CSS_STYLE (parent_style));
|
||||
keyframes = _gtk_css_keyframes_compute (keyframes, provider, scale, GTK_CSS_STYLE (style), parent_style);
|
||||
|
||||
animation = _gtk_css_animation_new (name,
|
||||
keyframes,
|
||||
@ -390,11 +400,11 @@ gtk_css_animated_style_create_css_animations (GtkCssAnimatedStyle *style,
|
||||
|
||||
void
|
||||
gtk_css_animated_style_create_animations (GtkCssAnimatedStyle *style,
|
||||
GtkCssAnimatedStyle *parent_style,
|
||||
GtkCssStyle *parent_style,
|
||||
gint64 timestamp,
|
||||
GtkStyleProviderPrivate *provider,
|
||||
int scale,
|
||||
GtkCssAnimatedStyle *source)
|
||||
GtkCssStyle *source)
|
||||
{
|
||||
if (source != NULL)
|
||||
gtk_css_animated_style_create_css_transitions (style, timestamp, source);
|
||||
|
@ -52,7 +52,7 @@ struct _GtkCssAnimatedStyleClass
|
||||
|
||||
GType gtk_css_animated_style_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkCssStyle * gtk_css_animated_style_new (void);
|
||||
GtkCssStyle * gtk_css_animated_style_new (GtkCssStyle *style);
|
||||
|
||||
void gtk_css_animated_style_set_animated_value(GtkCssAnimatedStyle *style,
|
||||
guint id,
|
||||
@ -62,11 +62,11 @@ GtkCssValue * gtk_css_animated_style_get_intrinsic_value (GtkCssAnimat
|
||||
guint id);
|
||||
|
||||
void gtk_css_animated_style_create_animations(GtkCssAnimatedStyle *style,
|
||||
GtkCssAnimatedStyle *parent_style,
|
||||
GtkCssStyle *parent_style,
|
||||
gint64 timestamp,
|
||||
GtkStyleProviderPrivate*provider,
|
||||
int scale,
|
||||
GtkCssAnimatedStyle *source);
|
||||
GtkCssStyle *source);
|
||||
GtkBitmask * gtk_css_animated_style_advance (GtkCssAnimatedStyle *style,
|
||||
gint64 timestamp);
|
||||
void gtk_css_animated_style_cancel_animations(GtkCssAnimatedStyle *style);
|
||||
|
@ -505,7 +505,8 @@ gtk_style_context_should_animate (GtkStyleContext *context)
|
||||
return FALSE;
|
||||
|
||||
values = style_values_lookup (context);
|
||||
if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values)))
|
||||
if (!GTK_IS_CSS_ANIMATED_STYLE (values) ||
|
||||
gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values)))
|
||||
return FALSE;
|
||||
|
||||
g_object_get (gtk_widget_get_settings (context->priv->widget),
|
||||
@ -778,9 +779,9 @@ style_values_lookup (GtkStyleContext *context)
|
||||
}
|
||||
else
|
||||
{
|
||||
values = gtk_css_animated_style_new ();
|
||||
values = gtk_css_static_style_new ();
|
||||
|
||||
build_properties (context, GTK_CSS_ANIMATED_STYLE (values)->style, info->decl, &priv->relevant_changes);
|
||||
build_properties (context, values, info->decl, &priv->relevant_changes);
|
||||
/* These flags are always relevant */
|
||||
priv->relevant_changes |= GTK_CSS_CHANGE_SOURCE;
|
||||
}
|
||||
@ -2837,20 +2838,26 @@ _gtk_style_context_validate (GtkStyleContext *context,
|
||||
|
||||
style_info_set_values (info, NULL);
|
||||
values = style_values_lookup (context);
|
||||
values = gtk_css_animated_style_new (values);
|
||||
|
||||
if (values != current)
|
||||
gtk_css_animated_style_create_animations (GTK_CSS_ANIMATED_STYLE (values),
|
||||
priv->parent ? GTK_CSS_ANIMATED_STYLE (style_values_lookup (priv->parent)) : NULL,
|
||||
priv->parent ? style_values_lookup (priv->parent) : NULL,
|
||||
timestamp,
|
||||
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
|
||||
priv->scale,
|
||||
gtk_style_context_should_create_transitions (context)
|
||||
? GTK_CSS_ANIMATED_STYLE (current)
|
||||
? current
|
||||
: NULL);
|
||||
if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values)))
|
||||
{
|
||||
change &= ~GTK_CSS_CHANGE_ANIMATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
change |= GTK_CSS_CHANGE_ANIMATE;
|
||||
style_info_set_values (info, values);
|
||||
}
|
||||
_gtk_style_context_update_animating (context);
|
||||
|
||||
if (current)
|
||||
@ -2862,12 +2869,19 @@ _gtk_style_context_validate (GtkStyleContext *context,
|
||||
changes = _gtk_bitmask_new ();
|
||||
changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
|
||||
}
|
||||
|
||||
g_object_unref (values);
|
||||
}
|
||||
else
|
||||
{
|
||||
changes = gtk_css_style_compute_dependencies (current, parent_changes);
|
||||
if (!_gtk_bitmask_is_empty (changes))
|
||||
{
|
||||
if (GTK_IS_CSS_ANIMATED_STYLE (current))
|
||||
update_properties (context, GTK_CSS_ANIMATED_STYLE (current)->style, info->decl, changes);
|
||||
else
|
||||
update_properties (context, current, info->decl, changes);
|
||||
}
|
||||
|
||||
gtk_style_context_update_cache (context, parent_changes);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user