[gtk+/wip/cssstyle: 16/27] cssanimatedstyle: Make advancing the style return a new style



commit 5e0332bcc53bffbea64bdf43e21ce7ececb5f86e
Author: Benjamin Otte <otte redhat com>
Date:   Tue Dec 16 04:15:25 2014 +0100

    cssanimatedstyle: Make advancing the style return a new style
    
    This is another step towards making CssStyles immutable.

 gtk/gtkcssanimatedstyle.c        |   79 ++++++++++++++++++-------------------
 gtk/gtkcssanimatedstyleprivate.h |    4 +-
 gtk/gtkstylecontext.c            |    9 +++-
 3 files changed, 47 insertions(+), 45 deletions(-)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index c36cfe3..efdbe12 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -391,6 +391,22 @@ gtk_css_animated_style_create_css_animations (GSList                  *animation
 
 /* PUBLIC API */
 
+static void
+gtk_css_animated_style_apply_animations (GtkCssAnimatedStyle *style,
+                                         gint64               timestamp)
+{
+  GSList *l;
+
+  for (l = style->animations; l; l = l->next)
+    {
+      GtkStyleAnimation *animation = l->data;
+      
+      _gtk_style_animation_set_values (animation,
+                                       timestamp,
+                                       GTK_CSS_ANIMATED_STYLE (style));
+    }
+}
+
 GtkCssStyle *
 gtk_css_animated_style_new (GtkCssStyle             *base_style,
                             GtkCssStyle             *parent_style,
@@ -424,58 +440,39 @@ gtk_css_animated_style_new (GtkCssStyle             *base_style,
   return GTK_CSS_STYLE (result);
 }
 
-GtkBitmask *
-gtk_css_animated_style_advance (GtkCssAnimatedStyle *style,
-                                gint64               timestamp)
+GtkCssStyle *
+gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
+                                    gint64               timestamp)
 {
-  GtkBitmask *changed;
-  GPtrArray *old_computed_values;
-  GSList *list;
-  guint i;
-
-  gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), NULL);
-  gtk_internal_return_val_if_fail (timestamp >= style->current_time, NULL);
-
-  style->current_time = timestamp;
-  old_computed_values = style->animated_values;
-  style->animated_values = NULL;
+  GtkCssAnimatedStyle *result;
+  GSList *l, *animations;
 
-  list = style->animations;
-  while (list)
+  gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (source), NULL);
+  
+  animations = NULL;
+  for (l = source->animations; l; l = l->next)
     {
-      GtkStyleAnimation *animation = list->data;
-      
-      list = list->next;
-
-      _gtk_style_animation_set_values (animation,
-                                       timestamp,
-                                       GTK_CSS_ANIMATED_STYLE (style));
+      GtkStyleAnimation *animation = l->data;
       
       if (_gtk_style_animation_is_finished (animation, timestamp))
-        {
-          style->animations = g_slist_remove (style->animations, animation);
-          g_object_unref (animation);
-        }
-    }
+        continue;
 
-  /* figure out changes */
-  changed = _gtk_bitmask_new ();
+      animations = g_slist_prepend (animations, g_object_ref (animation));
+    }
+  animations = g_slist_reverse (animations);
 
-  for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++)
-    {
-      GtkCssValue *old_animated, *new_animated;
+  if (animations == NULL)
+    return g_object_ref (source->style);
 
-      old_animated = old_computed_values && i < old_computed_values->len ? g_ptr_array_index 
(old_computed_values, i) : NULL;
-      new_animated = style->animated_values && i < style->animated_values->len ? g_ptr_array_index 
(style->animated_values, i) : NULL;
+  result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
 
-      if (!_gtk_css_value_equal0 (old_animated, new_animated))
-        changed = _gtk_bitmask_set (changed, i, TRUE);
-    }
+  result->style = g_object_ref (source->style);
+  result->current_time = timestamp;
+  result->animations = animations;
 
-  if (old_computed_values)
-    g_ptr_array_unref (old_computed_values);
+  gtk_css_animated_style_apply_animations (result, timestamp);
 
-  return changed;
+  return GTK_CSS_STYLE (result);
 }
 
 gboolean
diff --git a/gtk/gtkcssanimatedstyleprivate.h b/gtk/gtkcssanimatedstyleprivate.h
index c61ebe8..3bd49d7 100644
--- a/gtk/gtkcssanimatedstyleprivate.h
+++ b/gtk/gtkcssanimatedstyleprivate.h
@@ -58,6 +58,8 @@ GtkCssStyle *           gtk_css_animated_style_new              (GtkCssStyle
                                                                  GtkStyleProviderPrivate *provider,
                                                                  int                     scale,
                                                                  GtkCssStyle            *previous_style);
+GtkCssStyle *           gtk_css_animated_style_new_advance      (GtkCssAnimatedStyle    *source,
+                                                                 gint64                  timestamp);
 
 void                    gtk_css_animated_style_set_animated_value(GtkCssAnimatedStyle   *style,
                                                                  guint                   id,
@@ -66,8 +68,6 @@ void                    gtk_css_animated_style_set_animated_value(GtkCssAnimated
 GtkCssValue *           gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style,
                                                                  guint                   id);
 
-GtkBitmask *            gtk_css_animated_style_advance          (GtkCssAnimatedStyle    *style,
-                                                                 gint64                  timestamp);
 gboolean                gtk_css_animated_style_is_static        (GtkCssAnimatedStyle    *style);
 
 G_END_DECLS
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 5fe3ff4..bc35928 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -2865,14 +2865,19 @@ _gtk_style_context_validate (GtkStyleContext  *context,
   if (change & GTK_CSS_CHANGE_ANIMATE &&
       gtk_style_context_is_animating (context))
     {
+      GtkCssStyle *new_values;
       GtkBitmask *animation_changes;
 
-      animation_changes = gtk_css_animated_style_advance (GTK_CSS_ANIMATED_STYLE (info->values), timestamp);
+      new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (info->values), timestamp);
+      animation_changes = gtk_css_style_get_difference (new_values, info->values);
+      style_info_set_values (info, new_values);
+      g_object_unref (new_values);
 
       changes = _gtk_bitmask_union (changes, animation_changes);
       _gtk_bitmask_free (animation_changes);
 
-      if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (info->values)))
+      if (!GTK_IS_CSS_ANIMATED_STYLE (info->values) ||
+          gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (info->values)))
         _gtk_style_context_update_animating (context);
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]