Commit 4168e038 authored by Benjamin Otte's avatar Benjamin Otte

cssstyle: Split into GtkCssStyle and GtkCssAnimatedStyle

GtkCssStyle is the base class to be used for all types of styles that do
exist.

GtkCssAnimatedStyle is the only implementation so far, that is exactly a
copy/paste of the old GtkCssStyle code.
parent 572f4606
...@@ -368,6 +368,7 @@ gtk_private_h_sources = \ ...@@ -368,6 +368,7 @@ gtk_private_h_sources = \
gtkcomboboxprivate.h \ gtkcomboboxprivate.h \
gtkcontainerprivate.h \ gtkcontainerprivate.h \
gtkcssanimationprivate.h \ gtkcssanimationprivate.h \
gtkcssanimatedstyleprivate.h \
gtkcssarrayvalueprivate.h \ gtkcssarrayvalueprivate.h \
gtkcssbgsizevalueprivate.h \ gtkcssbgsizevalueprivate.h \
gtkcssbordervalueprivate.h \ gtkcssbordervalueprivate.h \
...@@ -592,6 +593,7 @@ gtk_base_c_sources = \ ...@@ -592,6 +593,7 @@ gtk_base_c_sources = \
gtkcomboboxtext.c \ gtkcomboboxtext.c \
gtkcontainer.c \ gtkcontainer.c \
gtkcssanimation.c \ gtkcssanimation.c \
gtkcssanimatedstyle.c \
gtkcssarrayvalue.c \ gtkcssarrayvalue.c \
gtkcssbgsizevalue.c \ gtkcssbgsizevalue.c \
gtkcssbordervalue.c \ gtkcssbordervalue.c \
......
This diff is collapsed.
/*
* Copyright © 2012 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GTK_CSS_ANIMATED_STYLE_PRIVATE_H__
#define __GTK_CSS_ANIMATED_STYLE_PRIVATE_H__
#include "gtk/gtkcssstyleprivate.h"
G_BEGIN_DECLS
#define GTK_TYPE_CSS_ANIMATED_STYLE (gtk_css_animated_style_get_type ())
#define GTK_CSS_ANIMATED_STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_ANIMATED_STYLE, GtkCssAnimatedStyle))
#define GTK_CSS_ANIMATED_STYLE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_ANIMATED_STYLE, GtkCssAnimatedStyleClass))
#define GTK_IS_CSS_ANIMATED_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_ANIMATED_STYLE))
#define GTK_IS_CSS_ANIMATED_STYLE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_ANIMATED_STYLE))
#define GTK_CSS_ANIMATED_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_ANIMATED_STYLE, GtkCssAnimatedStyleClass))
typedef struct _GtkCssAnimatedStyle GtkCssAnimatedStyle;
typedef struct _GtkCssAnimatedStyleClass GtkCssAnimatedStyleClass;
struct _GtkCssAnimatedStyle
{
GtkCssStyle parent;
GPtrArray *values; /* the unanimated (aka intrinsic) values */
GPtrArray *sections; /* sections the values are defined in */
GPtrArray *animated_values; /* NULL or array of animated values/NULL if not animated */
gint64 current_time; /* the current time in our world */
GSList *animations; /* the running animations, least important one first */
GtkBitmask *depends_on_parent; /* for intrinsic values */
GtkBitmask *equals_parent; /* dito */
GtkBitmask *depends_on_color; /* dito */
GtkBitmask *depends_on_font_size; /* dito */
};
struct _GtkCssAnimatedStyleClass
{
GtkCssStyleClass parent_class;
};
GType gtk_css_animated_style_get_type (void) G_GNUC_CONST;
GtkCssStyle * gtk_css_animated_style_new (void);
void gtk_css_animated_style_compute_value (GtkCssAnimatedStyle *style,
GtkStyleProviderPrivate*provider,
int scale,
GtkCssStyle *parent_style,
guint id,
GtkCssValue *specified,
GtkCssSection *section);
void gtk_css_animated_style_set_animated_value(GtkCssAnimatedStyle *style,
guint id,
GtkCssValue *value);
GtkCssValue * gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style,
guint id);
void gtk_css_animated_style_create_animations(GtkCssAnimatedStyle *style,
GtkCssAnimatedStyle *parent_style,
gint64 timestamp,
GtkStyleProviderPrivate*provider,
int scale,
GtkCssAnimatedStyle *source);
GtkBitmask * gtk_css_animated_style_advance (GtkCssAnimatedStyle *style,
gint64 timestamp);
void gtk_css_animated_style_cancel_animations(GtkCssAnimatedStyle *style);
gboolean gtk_css_animated_style_is_static (GtkCssAnimatedStyle *style);
G_END_DECLS
#endif /* __GTK_CSS_ANIMATED_STYLE_PRIVATE_H__ */
...@@ -104,7 +104,7 @@ gtk_css_animation_get_progress_from_iteration (GtkCssAnimation *animation, ...@@ -104,7 +104,7 @@ gtk_css_animation_get_progress_from_iteration (GtkCssAnimation *animation,
static void static void
gtk_css_animation_set_values (GtkStyleAnimation *style_animation, gtk_css_animation_set_values (GtkStyleAnimation *style_animation,
gint64 for_time_us, gint64 for_time_us,
GtkCssStyle *values) GtkCssAnimatedStyle *style)
{ {
GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation); GtkCssAnimation *animation = GTK_CSS_ANIMATION (style_animation);
double iteration, progress; double iteration, progress;
...@@ -128,8 +128,8 @@ gtk_css_animation_set_values (GtkStyleAnimation *style_animation, ...@@ -128,8 +128,8 @@ gtk_css_animation_set_values (GtkStyleAnimation *style_animation,
value = _gtk_css_keyframes_get_value (animation->keyframes, value = _gtk_css_keyframes_get_value (animation->keyframes,
i, i,
progress, progress,
gtk_css_style_get_intrinsic_value (values, property_id)); gtk_css_animated_style_get_intrinsic_value (style, property_id));
gtk_css_style_set_animated_value (values, property_id, value); gtk_css_animated_style_set_animated_value (style, property_id, value);
_gtk_css_value_unref (value); _gtk_css_value_unref (value);
} }
} }
......
...@@ -106,15 +106,15 @@ void ...@@ -106,15 +106,15 @@ void
_gtk_css_lookup_resolve (GtkCssLookup *lookup, _gtk_css_lookup_resolve (GtkCssLookup *lookup,
GtkStyleProviderPrivate *provider, GtkStyleProviderPrivate *provider,
int scale, int scale,
GtkCssStyle *values, GtkCssAnimatedStyle *style,
GtkCssStyle *parent_values) GtkCssStyle *parent_style)
{ {
guint i, n; guint i, n;
g_return_if_fail (lookup != NULL); g_return_if_fail (lookup != NULL);
g_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider)); g_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
g_return_if_fail (GTK_IS_CSS_STYLE (values)); g_return_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style));
g_return_if_fail (parent_values == NULL || GTK_IS_CSS_STYLE (parent_values)); g_return_if_fail (parent_style == NULL || GTK_IS_CSS_ANIMATED_STYLE (parent_style));
n = _gtk_css_style_property_get_n_properties (); n = _gtk_css_style_property_get_n_properties ();
...@@ -122,13 +122,13 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup, ...@@ -122,13 +122,13 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup,
{ {
if (lookup->values[i].value || if (lookup->values[i].value ||
_gtk_bitmask_get (lookup->missing, i)) _gtk_bitmask_get (lookup->missing, i))
gtk_css_style_compute_value (values, gtk_css_animated_style_compute_value (style,
provider, provider,
scale, scale,
parent_values, parent_style,
i, i,
lookup->values[i].value, lookup->values[i].value,
lookup->values[i].section); lookup->values[i].section);
/* else not a relevant property */ /* else not a relevant property */
} }
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <glib-object.h> #include <glib-object.h>
#include "gtk/gtkbitmaskprivate.h" #include "gtk/gtkbitmaskprivate.h"
#include "gtk/gtkcssstyleprivate.h" #include "gtk/gtkcssanimatedstyleprivate.h"
#include "gtk/gtkcsssection.h" #include "gtk/gtkcsssection.h"
...@@ -51,8 +51,8 @@ void _gtk_css_lookup_set (GtkCssLookup ...@@ -51,8 +51,8 @@ void _gtk_css_lookup_set (GtkCssLookup
void _gtk_css_lookup_resolve (GtkCssLookup *lookup, void _gtk_css_lookup_resolve (GtkCssLookup *lookup,
GtkStyleProviderPrivate *provider, GtkStyleProviderPrivate *provider,
int scale, int scale,
GtkCssStyle *values, GtkCssAnimatedStyle *style,
GtkCssStyle *parent_values); GtkCssStyle *parent_style);
static inline const GtkBitmask * static inline const GtkBitmask *
_gtk_css_lookup_get_missing (const GtkCssLookup *lookup) _gtk_css_lookup_get_missing (const GtkCssLookup *lookup)
......
This diff is collapsed.
...@@ -41,62 +41,39 @@ typedef struct _GtkCssStyleClass GtkCssStyleClass; ...@@ -41,62 +41,39 @@ typedef struct _GtkCssStyleClass GtkCssStyleClass;
struct _GtkCssStyle struct _GtkCssStyle
{ {
GObject parent; GObject parent;
GPtrArray *values; /* the unanimated (aka intrinsic) values */
GPtrArray *sections; /* sections the values are defined in */
GPtrArray *animated_values; /* NULL or array of animated values/NULL if not animated */
gint64 current_time; /* the current time in our world */
GSList *animations; /* the running animations, least important one first */
GtkBitmask *depends_on_parent; /* for intrinsic values */
GtkBitmask *equals_parent; /* dito */
GtkBitmask *depends_on_color; /* dito */
GtkBitmask *depends_on_font_size; /* dito */
}; };
struct _GtkCssStyleClass struct _GtkCssStyleClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
/* Get the value for the given property id. This needs to be FAST. */
GtkCssValue * (* get_value) (GtkCssStyle *style,
guint id);
/* Get the section the value at the given id was declared at or NULL if unavailable.
* Optional: default impl will just return NULL */
GtkCssSection * (* get_section) (GtkCssStyle *style,
guint id);
/* Compute the bitmask of potentially changed properties if the parent has changed
* the passed in ones.
* This is for example needed when changes in the "color" property will affect
* all properties using "currentColor" as a color.
* Optional: The default impl just returns the parent changes unchanged */
GtkBitmask * (* compute_dependencies) (GtkCssStyle *style,
const GtkBitmask *parent_changes);
}; };
GType gtk_css_style_get_type (void) G_GNUC_CONST; GType gtk_css_style_get_type (void) G_GNUC_CONST;
GtkCssStyle * gtk_css_style_new (void);
void gtk_css_style_compute_value (GtkCssStyle *style,
GtkStyleProviderPrivate*provider,
int scale,
GtkCssStyle *parent_style,
guint id,
GtkCssValue *specified,
GtkCssSection *section);
void gtk_css_style_set_animated_value (GtkCssStyle *style,
guint id,
GtkCssValue *value);
GtkCssValue * gtk_css_style_get_value (GtkCssStyle *style, GtkCssValue * gtk_css_style_get_value (GtkCssStyle *style,
guint id); guint id);
GtkCssSection * gtk_css_style_get_section (GtkCssStyle *style, GtkCssSection * gtk_css_style_get_section (GtkCssStyle *style,
guint id); guint id);
GtkCssValue * gtk_css_style_get_intrinsic_value (GtkCssStyle *style,
guint id);
GtkBitmask * gtk_css_style_get_difference (GtkCssStyle *style, GtkBitmask * gtk_css_style_get_difference (GtkCssStyle *style,
GtkCssStyle *other); GtkCssStyle *other);
GtkBitmask * gtk_css_style_compute_dependencies (GtkCssStyle *style, GtkBitmask * gtk_css_style_compute_dependencies (GtkCssStyle *style,
const GtkBitmask *parent_changes); const GtkBitmask *parent_changes);
void gtk_css_style_create_animations (GtkCssStyle *style,
GtkCssStyle *parent_style,
gint64 timestamp,
GtkStyleProviderPrivate*provider,
int scale,
GtkCssStyle *source);
GtkBitmask * gtk_css_style_advance (GtkCssStyle *style,
gint64 timestamp);
void gtk_css_style_cancel_animations (GtkCssStyle *style);
gboolean gtk_css_style_is_static (GtkCssStyle *style);
char * gtk_css_style_to_string (GtkCssStyle *style); char * gtk_css_style_to_string (GtkCssStyle *style);
void gtk_css_style_print (GtkCssStyle *style, void gtk_css_style_print (GtkCssStyle *style,
GString *string); GString *string);
......
...@@ -26,15 +26,15 @@ ...@@ -26,15 +26,15 @@
G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION) G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION)
static void static void
gtk_css_transition_set_values (GtkStyleAnimation *animation, gtk_css_transition_set_values (GtkStyleAnimation *animation,
gint64 for_time_us, gint64 for_time_us,
GtkCssStyle *style) GtkCssAnimatedStyle *style)
{ {
GtkCssTransition *transition = GTK_CSS_TRANSITION (animation); GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
GtkCssValue *value, *end; GtkCssValue *value, *end;
double progress; double progress;
end = gtk_css_style_get_intrinsic_value (style, transition->property); end = gtk_css_animated_style_get_intrinsic_value (style, transition->property);
if (transition->start_time >= for_time_us) if (transition->start_time >= for_time_us)
value = _gtk_css_value_ref (transition->start); value = _gtk_css_value_ref (transition->start);
...@@ -55,7 +55,7 @@ gtk_css_transition_set_values (GtkStyleAnimation *animation, ...@@ -55,7 +55,7 @@ gtk_css_transition_set_values (GtkStyleAnimation *animation,
if (value) if (value)
{ {
gtk_css_style_set_animated_value (style, transition->property, value); gtk_css_animated_style_set_animated_value (style, transition->property, value);
_gtk_css_value_unref (value); _gtk_css_value_unref (value);
} }
} }
......
...@@ -26,7 +26,7 @@ G_DEFINE_ABSTRACT_TYPE (GtkStyleAnimation, _gtk_style_animation, G_TYPE_OBJECT) ...@@ -26,7 +26,7 @@ G_DEFINE_ABSTRACT_TYPE (GtkStyleAnimation, _gtk_style_animation, G_TYPE_OBJECT)
static void static void
gtk_style_animation_real_set_values (GtkStyleAnimation *animation, gtk_style_animation_real_set_values (GtkStyleAnimation *animation,
gint64 for_time_us, gint64 for_time_us,
GtkCssStyle *values) GtkCssAnimatedStyle *style)
{ {
} }
...@@ -60,16 +60,16 @@ _gtk_style_animation_init (GtkStyleAnimation *animation) ...@@ -60,16 +60,16 @@ _gtk_style_animation_init (GtkStyleAnimation *animation)
void void
_gtk_style_animation_set_values (GtkStyleAnimation *animation, _gtk_style_animation_set_values (GtkStyleAnimation *animation,
gint64 for_time_us, gint64 for_time_us,
GtkCssStyle *values) GtkCssAnimatedStyle *style)
{ {
GtkStyleAnimationClass *klass; GtkStyleAnimationClass *klass;
g_return_if_fail (GTK_IS_STYLE_ANIMATION (animation)); g_return_if_fail (GTK_IS_STYLE_ANIMATION (animation));
g_return_if_fail (GTK_IS_CSS_STYLE (values)); g_return_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style));
klass = GTK_STYLE_ANIMATION_GET_CLASS (animation); klass = GTK_STYLE_ANIMATION_GET_CLASS (animation);
return klass->set_values (animation, for_time_us, values); klass->set_values (animation, for_time_us, style);
} }
gboolean gboolean
......
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
#ifndef __GTK_STYLE_ANIMATION_PRIVATE_H__ #ifndef __GTK_STYLE_ANIMATION_PRIVATE_H__
#define __GTK_STYLE_ANIMATION_PRIVATE_H__ #define __GTK_STYLE_ANIMATION_PRIVATE_H__
#include <glib-object.h> #include "gtkcssanimatedstyleprivate.h"
#include "gtkcssstyleprivate.h"
G_BEGIN_DECLS G_BEGIN_DECLS
...@@ -50,14 +49,14 @@ struct _GtkStyleAnimationClass ...@@ -50,14 +49,14 @@ struct _GtkStyleAnimationClass
gint64 at_time_us); gint64 at_time_us);
void (* set_values) (GtkStyleAnimation *animation, void (* set_values) (GtkStyleAnimation *animation,
gint64 for_time_us, gint64 for_time_us,
GtkCssStyle *values); GtkCssAnimatedStyle *style);
}; };
GType _gtk_style_animation_get_type (void) G_GNUC_CONST; GType _gtk_style_animation_get_type (void) G_GNUC_CONST;
void _gtk_style_animation_set_values (GtkStyleAnimation *animation, void _gtk_style_animation_set_values (GtkStyleAnimation *animation,
gint64 for_time_us, gint64 for_time_us,
GtkCssStyle *values); GtkCssAnimatedStyle *style);
gboolean _gtk_style_animation_is_finished (GtkStyleAnimation *animation, gboolean _gtk_style_animation_is_finished (GtkStyleAnimation *animation,
gint64 at_time_us); gint64 at_time_us);
gboolean _gtk_style_animation_is_static (GtkStyleAnimation *animation, gboolean _gtk_style_animation_is_static (GtkStyleAnimation *animation,
......
...@@ -503,7 +503,7 @@ gtk_style_context_should_animate (GtkStyleContext *context) ...@@ -503,7 +503,7 @@ gtk_style_context_should_animate (GtkStyleContext *context)
return FALSE; return FALSE;
values = style_values_lookup (context); values = style_values_lookup (context);
if (gtk_css_style_is_static (values)) if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values)))
return FALSE; return FALSE;
g_object_get (gtk_widget_get_settings (context->priv->widget), g_object_get (gtk_widget_get_settings (context->priv->widget),
...@@ -704,7 +704,7 @@ build_properties (GtkStyleContext *context, ...@@ -704,7 +704,7 @@ build_properties (GtkStyleContext *context,
_gtk_css_lookup_resolve (lookup, _gtk_css_lookup_resolve (lookup,
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade), GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
priv->scale, priv->scale,
values, GTK_CSS_ANIMATED_STYLE (values),
priv->parent ? style_values_lookup (priv->parent) : NULL); priv->parent ? style_values_lookup (priv->parent) : NULL);
_gtk_css_lookup_free (lookup); _gtk_css_lookup_free (lookup);
...@@ -734,7 +734,7 @@ style_values_lookup (GtkStyleContext *context) ...@@ -734,7 +734,7 @@ style_values_lookup (GtkStyleContext *context)
return values; return values;
} }
values = gtk_css_style_new (); values = gtk_css_animated_style_new ();
style_info_set_values (info, values); style_info_set_values (info, values);
if (gtk_style_context_is_saved (context)) if (gtk_style_context_is_saved (context))
...@@ -772,7 +772,7 @@ style_values_lookup_for_state (GtkStyleContext *context, ...@@ -772,7 +772,7 @@ style_values_lookup_for_state (GtkStyleContext *context,
decl = gtk_css_node_declaration_ref (context->priv->info->decl); decl = gtk_css_node_declaration_ref (context->priv->info->decl);
gtk_css_node_declaration_set_state (&decl, state); gtk_css_node_declaration_set_state (&decl, state);
values = gtk_css_style_new (); values = gtk_css_animated_style_new ();
build_properties (context, values, decl, NULL, NULL); build_properties (context, values, decl, NULL, NULL);
gtk_css_node_declaration_unref (decl); gtk_css_node_declaration_unref (decl);
...@@ -2696,9 +2696,9 @@ gtk_style_context_update_animations (GtkStyleContext *context, ...@@ -2696,9 +2696,9 @@ gtk_style_context_update_animations (GtkStyleContext *context,
values = style_values_lookup (context); values = style_values_lookup (context);
differences = gtk_css_style_advance (values, timestamp); differences = gtk_css_animated_style_advance (GTK_CSS_ANIMATED_STYLE (values), timestamp);
if (gtk_css_style_is_static (values)) if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values)))
_gtk_style_context_update_animating (context); _gtk_style_context_update_animating (context);
return differences; return differences;
...@@ -2805,13 +2805,15 @@ _gtk_style_context_validate (GtkStyleContext *context, ...@@ -2805,13 +2805,15 @@ _gtk_style_context_validate (GtkStyleContext *context,
values = style_values_lookup (context); values = style_values_lookup (context);
if (values != current) if (values != current)
gtk_css_style_create_animations (values, gtk_css_animated_style_create_animations (GTK_CSS_ANIMATED_STYLE (values),
priv->parent ? style_values_lookup (priv->parent) : NULL, priv->parent ? GTK_CSS_ANIMATED_STYLE (style_values_lookup (priv->parent)) : NULL,
timestamp, timestamp,
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade), GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
priv->scale, priv->scale,
gtk_style_context_should_create_transitions (context) ? current : NULL); gtk_style_context_should_create_transitions (context)
if (gtk_css_style_is_static (values)) ? GTK_CSS_ANIMATED_STYLE (current)
: NULL);
if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (values)))
change &= ~GTK_CSS_CHANGE_ANIMATE; change &= ~GTK_CSS_CHANGE_ANIMATE;
else else
change |= GTK_CSS_CHANGE_ANIMATE; change |= GTK_CSS_CHANGE_ANIMATE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment