summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2016-01-03 17:05:16 -0500
committerMatthias Clasen <mclasen@redhat.com>2016-01-03 17:05:16 -0500
commitcfa0884165d306e64cca74213c6fbc20ad071c7e (patch)
tree3d4db21a65dab55be0196dbf939a0ab604aec852
parent12be432df7c40473ea8bfa8e1c738f7dec1433ff (diff)
downloadgtk+-cfa0884165d306e64cca74213c6fbc20ad071c7e.tar.gz
Improve formatting of CSS style prints
Add a newline after CSS properties, so things don't run into each other.
-rw-r--r--gtk/gtkcssnode.c9
-rw-r--r--gtk/gtkcssstyle.c21
-rw-r--r--gtk/gtkcssstyleprivate.h2
3 files changed, 28 insertions, 4 deletions
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 676d0b27a8..a5dda31a5c 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -1529,7 +1529,7 @@ gtk_css_node_print (GtkCssNode *cssnode,
GString *string,
guint indent)
{
- GtkCssNode *node;
+ gboolean need_newline = FALSE;
g_string_append_printf (string, "%*s", indent, "");
@@ -1544,10 +1544,15 @@ gtk_css_node_print (GtkCssNode *cssnode,
g_string_append_c (string, '\n');
if (flags & GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE)
- gtk_css_style_print (gtk_css_node_get_style (cssnode), string, indent + 2, TRUE);
+ need_newline = gtk_css_style_print (gtk_css_node_get_style (cssnode), string, indent + 2, TRUE);
if (flags & GTK_STYLE_CONTEXT_PRINT_RECURSE)
{
+ GtkCssNode *node;
+
+ if (need_newline && gtk_css_node_get_first_child (cssnode))
+ g_string_append_c (string, '\n');
+
for (node = gtk_css_node_get_first_child (cssnode); node; node = gtk_css_node_get_next_sibling (node))
gtk_css_node_print (node, flags, string, indent + 2);
}
diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c
index 812c8dc75a..794a20ae5e 100644
--- a/gtk/gtkcssstyle.c
+++ b/gtk/gtkcssstyle.c
@@ -114,13 +114,28 @@ gtk_css_style_is_static (GtkCssStyle *style)
return GTK_CSS_STYLE_GET_CLASS (style)->is_static (style);
}
-void
+/*
+ * gtk_css_style_print:
+ * @style: a #GtkCssStyle
+ * @string: the #GString to print to
+ * @indent: level of indentation to use
+ * @skip_initial: %TRUE to skip properties that have their initial value
+ *
+ * Print the @style to @string, in CSS format. Every property is printed
+ * on a line by itself, indented by @indent spaces. If @skip_initial is
+ * %TRUE, properties are only printed if their value in @style is different
+ * from the initial value of the property.
+ *
+ * Returns: %TRUE is any properties have been printed
+ */
+gboolean
gtk_css_style_print (GtkCssStyle *style,
GString *string,
guint indent,
gboolean skip_initial)
{
guint i;
+ gboolean retval = FALSE;
g_return_if_fail (GTK_IS_CSS_STYLE (style));
g_return_if_fail (string != NULL);
@@ -152,7 +167,11 @@ gtk_css_style_print (GtkCssStyle *style,
}
g_string_append_c (string, '\n');
+
+ retval = TRUE;
}
+
+ return retval;
}
char *
diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h
index d5cd40526b..f1d165f8df 100644
--- a/gtk/gtkcssstyleprivate.h
+++ b/gtk/gtkcssstyleprivate.h
@@ -70,7 +70,7 @@ GtkBitmask * gtk_css_style_add_difference (GtkBitmask
gboolean gtk_css_style_is_static (GtkCssStyle *style);
char * gtk_css_style_to_string (GtkCssStyle *style);
-void gtk_css_style_print (GtkCssStyle *style,
+gboolean gtk_css_style_print (GtkCssStyle *style,
GString *string,
guint indent,
gboolean skip_initial);