[gtk+/wip/cssnode3: 69/102] cssnode: Create animated styles by default



commit 5bdc1909672dd43604d43c29be7c6ae8918c77c6
Author: Benjamin Otte <otte redhat com>
Date:   Sun Feb 22 08:23:04 2015 +0100

    cssnode: Create animated styles by default
    
    ... and hardcode transient and path nodes to never create animated
    styles.

 gtk/gtkcssnode.c          |   55 ++++++++++++++++++++++++++++++++++++++++----
 gtk/gtkcsspathnode.c      |   11 +++++++++
 gtk/gtkcsstransientnode.c |   11 +++++++++
 3 files changed, 72 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index d6c2c40..2c032ed 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -207,6 +207,12 @@ gtk_css_node_create_style (GtkCssNode *cssnode)
 }
 
 static gboolean
+should_create_transitions (GtkCssChange change)
+{
+  return (change & GTK_CSS_CHANGE_ANIMATIONS) == 0;
+}
+
+static gboolean
 gtk_css_style_needs_recreation (GtkCssStyle  *style,
                                 GtkCssChange  change)
 {
@@ -225,14 +231,53 @@ gtk_css_style_needs_recreation (GtkCssStyle  *style,
 
 static GtkCssStyle *
 gtk_css_node_real_update_style (GtkCssNode   *cssnode,
-                                GtkCssChange  pending_change,
+                                GtkCssChange  change,
                                 gint64        timestamp,
-                                GtkCssStyle  *old_style)
+                                GtkCssStyle  *style)
 {
-  if (!gtk_css_style_needs_recreation (old_style, pending_change))
-    return g_object_ref (old_style);
+  GtkCssStyle *static_style, *new_static_style, *new_style;
+
+  if (GTK_IS_CSS_ANIMATED_STYLE (style))
+    {
+      static_style = GTK_CSS_ANIMATED_STYLE (style)->style;
+    }
+  else
+    {
+      static_style = style;
+    }
+
+  if (gtk_css_style_needs_recreation (static_style, change))
+    new_static_style = gtk_css_node_create_style (cssnode);
+  else
+    new_static_style = g_object_ref (static_style);
+
+  if (new_static_style != static_style || (change & GTK_CSS_CHANGE_ANIMATIONS))
+    {
+      GtkCssNode *parent = gtk_css_node_get_parent (cssnode);
+      new_style = gtk_css_animated_style_new (new_static_style,
+                                              parent ? gtk_css_node_get_style (parent) : NULL,
+                                              timestamp,
+                                              gtk_css_node_get_style_provider (cssnode),
+                                              should_create_transitions (change) ? style : NULL);
+    }
+  else if (GTK_IS_CSS_ANIMATED_STYLE (style) && (change & GTK_CSS_CHANGE_TIMESTAMP))
+    {
+      new_style = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (style),
+                                                      static_style,
+                                                      timestamp);
+    }
+  else
+    {
+      new_style = g_object_ref (style);
+    }
+
+  if (GTK_IS_CSS_ANIMATED_STYLE (new_style) &&
+      !gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (new_style)))
+    gtk_css_node_set_invalid (cssnode, TRUE);
+
+  g_object_unref (new_static_style);
 
-  return gtk_css_node_create_style (cssnode);
+  return new_style;
 }
 
 static void
diff --git a/gtk/gtkcsspathnode.c b/gtk/gtkcsspathnode.c
index 50a1cc3..e9b5298 100644
--- a/gtk/gtkcsspathnode.c
+++ b/gtk/gtkcsspathnode.c
@@ -101,6 +101,16 @@ gtk_css_path_node_real_get_widget_path (GtkCssNode *node)
   return path_node->path;
 }
 
+static GtkCssStyle *
+gtk_css_path_node_update_style (GtkCssNode   *cssnode,
+                                GtkCssChange  change,
+                                gint64        timestamp,
+                                GtkCssStyle  *style)
+{
+  /* This should get rid of animations */
+  return GTK_CSS_NODE_CLASS (gtk_css_path_node_parent_class)->update_style (cssnode, change, 0, style);
+}
+
 static GtkStyleProviderPrivate *
 gtk_css_path_node_get_style_provider (GtkCssNode *node)
 {
@@ -121,6 +131,7 @@ gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
   object_class->finalize = gtk_css_path_node_finalize;
 
   node_class->invalidate = gtk_css_path_node_invalidate;
+  node_class->update_style = gtk_css_path_node_update_style;
   node_class->init_matcher = gtk_css_path_node_real_init_matcher;
   node_class->create_widget_path = gtk_css_path_node_real_create_widget_path;
   node_class->get_widget_path = gtk_css_path_node_real_get_widget_path;
diff --git a/gtk/gtkcsstransientnode.c b/gtk/gtkcsstransientnode.c
index e3d68b4..a8485f0 100644
--- a/gtk/gtkcsstransientnode.c
+++ b/gtk/gtkcsstransientnode.c
@@ -52,6 +52,16 @@ gtk_css_transient_node_get_widget_path (GtkCssNode *node)
   return gtk_css_node_get_widget_path (parent);
 }
 
+static GtkCssStyle *
+gtk_css_transient_node_update_style (GtkCssNode   *cssnode,
+                                     GtkCssChange  change,
+                                     gint64        timestamp,
+                                     GtkCssStyle  *style)
+{
+  /* This should get rid of animations */
+  return GTK_CSS_NODE_CLASS (gtk_css_transient_node_parent_class)->update_style (cssnode, change, 0, style);
+}
+
 static void
 gtk_css_transient_node_class_init (GtkCssTransientNodeClass *klass)
 {
@@ -59,6 +69,7 @@ gtk_css_transient_node_class_init (GtkCssTransientNodeClass *klass)
 
   node_class->create_widget_path = gtk_css_transient_node_create_widget_path;
   node_class->get_widget_path = gtk_css_transient_node_get_widget_path;
+  node_class->update_style = gtk_css_transient_node_update_style;
 }
 
 static void


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