[gtk+/wip/matthiasc/node-dump] style context: Don't print initial values by default



commit 46cb8dcb0c2b1f4c72c2ba2aedaf731d740a422c
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 28 14:40:11 2015 -0500

    style context: Don't print initial values by default
    
    This just clutters up the output of the css tests.

 gtk/gtkcssnode.c      |   39 ++++++++++++++++++++++++++-------------
 gtk/gtkstylecontext.c |    4 ++++
 gtk/gtkstylecontext.h |    7 ++++---
 3 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index baa293a..ca74721 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -1598,36 +1598,50 @@ append_classes (GtkCssNode *cssnode,
 }
 
 static void
-append_style (GtkCssNode *cssnode,
-              GString    *string,
-              guint       indent)
+append_style (GtkCssNode                *cssnode,
+              GtkStyleContextPrintFlags  flags,
+              GString                   *string,
+              guint                      indent)
 {
   int i;
   GtkCssStyle *style;
 
+  if (!(flags & GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE))
+    return;
+
   style = gtk_css_node_get_style (cssnode);
 
   for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
     {
       GtkCssStyleProperty *prop;
+      GtkCssValue *value;
       GtkCssSection *section;
       const char *name;
-      char *value;
-      char *location;
+      char *str;
 
       prop = _gtk_css_style_property_lookup_by_id (i);
       name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
-      value = _gtk_css_value_to_string (gtk_css_style_get_value (style, i));
+      value = gtk_css_style_get_value (style, i);
+
+      if (!(flags & GTK_STYLE_CONTEXT_PRINT_SHOW_INITIAL))
+        {
+          GtkCssValue *initial;
+
+          initial = _gtk_css_style_property_get_initial_value (prop);
+          if (_gtk_css_value_equal (value, initial))
+            continue;
+        }
 
-      g_string_append_printf (string, "%*s%s: %s", indent, "", name, value);
-      g_free (value);
+      str = _gtk_css_value_to_string (value);
+      g_string_append_printf (string, "%*s%s: %s", indent, "", name, str);
+      g_free (str);
 
       section = gtk_css_style_get_section (style, i);
       if (section)
         {
-          location = _gtk_css_section_to_string (section);
-          g_string_append_printf (string, " (%s)", location);
-          g_free (location);
+          str = _gtk_css_section_to_string (section);
+          g_string_append_printf (string, " (%s)", str);
+          g_free (str);
         }
       g_string_append_c (string, '\n');
     }
@@ -1652,8 +1666,7 @@ gtk_css_node_print (GtkCssNode                *cssnode,
   append_classes (cssnode, string);
   g_string_append_c (string, '\n');
 
-  if (flags & GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE)
-    append_style (cssnode, string, indent + 2);
+  append_style (cssnode, flags, string, indent + 2);
 
   if (flags & GTK_STYLE_CONTEXT_PRINT_RECURSE)
     {
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index b1de3c8..a6b5295 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -3226,6 +3226,10 @@ _gtk_style_context_is_background_opaque (GtkStyleContext *context)
  *     CSS nodes starting at the style context's node
  * @GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE: Show the values of the
  *     CSS properties for each node
+ * @GTK_STYLE_CONTEXT_PRINT_SHOW_INITIAL: Show the values of the
+ *     CSS properties even if they match the initial value. By default,
+ *     values are only shown if they are different from the initial
+ *     value.
  *
  * Flags that modify the behavior of gtk_style_context_to_string().
  */
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 81f1df9..d6fe575 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -1209,9 +1209,10 @@ void   gtk_draw_insertion_cursor    (GtkWidget          *widget,
                                      gboolean            draw_arrow);
 
 typedef enum {
-  GTK_STYLE_CONTEXT_PRINT_NONE       = 0,
-  GTK_STYLE_CONTEXT_PRINT_RECURSE    = 1 << 0,
-  GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE = 1 << 1
+  GTK_STYLE_CONTEXT_PRINT_NONE         = 0,
+  GTK_STYLE_CONTEXT_PRINT_RECURSE      = 1 << 0,
+  GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE   = 1 << 1,
+  GTK_STYLE_CONTEXT_PRINT_SHOW_INITIAL = 1 << 2
 } GtkStyleContextPrintFlags;
 
 GDK_AVAILABLE_IN_3_20


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