css: Implement dynamic values for array values
authorBenjamin Otte <otte@redhat.com>
Sat, 17 Feb 2018 23:14:48 +0000 (00:14 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 16 Mar 2018 05:04:44 +0000 (06:04 +0100)
This makes animated background-images work.

gtk/gtkcssarrayvalue.c

index 221632e0591cd51cb869d6210f926be98f5d534c..d294d90892c04b2989a2c2dc1eede33f0cb7702c 100644 (file)
@@ -298,6 +298,56 @@ gtk_css_value_array_transition (GtkCssValue *start,
     }
 }
 
+static gboolean
+gtk_css_value_array_is_dynamic (GtkCssValue *value)
+{
+  guint i;
+
+  for (i = 0; i < value->n_values; i++)
+    {
+      if (gtk_css_value_is_dynamic (value->values[i]))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static GtkCssValue *
+gtk_css_value_array_get_dynamic_value (GtkCssValue *value,
+                                       gint64       monotonic_time)
+{
+  GtkCssValue *result;
+  GtkCssValue *i_value;
+  guint i, j;
+
+  if (!gtk_css_value_is_dynamic (value))
+    return gtk_css_value_ref (value);
+
+  result = NULL;
+  for (i = 0; i < value->n_values; i++)
+    {
+      i_value = gtk_css_value_get_dynamic_value (value->values[i], monotonic_time);
+
+      if (result == NULL &&
+         i_value != value->values[i])
+       {
+         result = _gtk_css_array_value_new_from_array (value->values, value->n_values);
+         for (j = 0; j < i; j++)
+           _gtk_css_value_ref (result->values[j]);
+       }
+
+      if (result != NULL)
+       result->values[i] = i_value;
+      else
+       _gtk_css_value_unref (i_value);
+    }
+
+  if (result == NULL)
+    return _gtk_css_value_ref (value);
+
+  return result;
+}
+
 static void
 gtk_css_value_array_print (const GtkCssValue *value,
                            GString           *string)
@@ -323,8 +373,8 @@ static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
   gtk_css_value_array_compute,
   gtk_css_value_array_equal,
   gtk_css_value_array_transition,
-  NULL,
-  NULL,
+  gtk_css_value_array_is_dynamic,
+  gtk_css_value_array_get_dynamic_value,
   gtk_css_value_array_print
 };