[gtk+] css: Port margin properties to GtkCssNumber



commit 3c4b8a676f1f64b1c413d2822e6f7261b154bbc5
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jan 17 16:41:14 2012 +0100

    css: Port margin properties to GtkCssNumber

 gtk/gtkcssshorthandpropertyimpl.c |   41 ++++++++++++++++----
 gtk/gtkcssstylepropertyimpl.c     |   74 ++++++++++++++++++++++++++----------
 2 files changed, 86 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 3f01074..3a012ee 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -81,10 +81,10 @@ parse_border_width (GtkCssShorthandProperty *shorthand,
 }
 
 static gboolean
-parse_border_width_really (GtkCssShorthandProperty *shorthand,
-                           GValue                  *values,
-                           GtkCssParser            *parser,
-                           GFile                   *base)
+parse_four_numbers (GtkCssShorthandProperty *shorthand,
+                    GValue                  *values,
+                    GtkCssParser            *parser,
+                    GtkCssNumberParseFlags   flags)
 {
   GtkCssNumber numbers[4];
   guint i;
@@ -96,9 +96,7 @@ parse_border_width_really (GtkCssShorthandProperty *shorthand,
 
       if (!_gtk_css_parser_read_number (parser,
                                         &numbers[i], 
-                                        GTK_CSS_POSITIVE_ONLY
-                                        | GTK_CSS_NUMBER_AS_PIXELS
-                                        | GTK_CSS_PARSE_LENGTH))
+                                        flags))
         return FALSE;
     }
 
@@ -122,6 +120,33 @@ parse_border_width_really (GtkCssShorthandProperty *shorthand,
   return TRUE;
 }
 
+static gboolean
+parse_margin (GtkCssShorthandProperty *shorthand,
+              GValue                  *values,
+              GtkCssParser            *parser,
+              GFile                   *base)
+{
+  return parse_four_numbers (shorthand,
+                             values,
+                             parser,
+                             GTK_CSS_NUMBER_AS_PIXELS
+                             | GTK_CSS_PARSE_LENGTH);
+}
+
+static gboolean
+parse_border_width_really (GtkCssShorthandProperty *shorthand,
+                           GValue                  *values,
+                           GtkCssParser            *parser,
+                           GFile                   *base)
+{
+  return parse_four_numbers (shorthand,
+                             values,
+                             parser,
+                             GTK_CSS_POSITIVE_ONLY
+                             | GTK_CSS_NUMBER_AS_PIXELS
+                             | GTK_CSS_PARSE_LENGTH);
+}
+
 static gboolean 
 parse_border_radius (GtkCssShorthandProperty *shorthand,
                      GValue                  *values,
@@ -892,7 +917,7 @@ _gtk_css_shorthand_property_init_properties (void)
   _gtk_css_shorthand_property_register   ("margin",
                                           GTK_TYPE_BORDER,
                                           margin_subproperties,
-                                          parse_border_width,
+                                          parse_margin,
                                           unpack_border,
                                           pack_border);
   _gtk_css_shorthand_property_register   ("padding",
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index b804c31..529483b 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -412,6 +412,38 @@ css_image_value_compute (GtkCssStyleProperty    *property,
 }
 
 static gboolean 
+parse_margin (GtkCssStyleProperty *property,
+              GValue              *value,
+              GtkCssParser        *parser,
+              GFile               *base)
+{
+  GtkCssNumber number;
+
+  if (!_gtk_css_parser_read_number (parser,
+                                    &number, 
+                                    GTK_CSS_NUMBER_AS_PIXELS
+                                    | GTK_CSS_PARSE_LENGTH))
+    return FALSE;
+
+  g_value_set_boxed (value, &number);
+  return TRUE;
+}
+
+static void
+compute_margin (GtkCssStyleProperty *property,
+                GValue              *computed,
+                GtkStyleContext     *context,
+                const GValue        *specified)
+{
+  GtkCssNumber number;
+  
+  _gtk_css_number_compute (&number,
+                           g_value_get_boxed (specified),
+                           context);
+  g_value_set_boxed (computed, &number);
+}
+
+static gboolean 
 parse_border_width (GtkCssStyleProperty *property,
                     GValue              *value,
                     GtkCssParser        *parser,
@@ -745,42 +777,43 @@ _gtk_css_style_property_init_properties (void)
                                           NULL,
                                           NULL);
 
+  _gtk_css_number_init (&number, 0, GTK_CSS_PX);
   gtk_css_style_property_register        ("margin-top",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_margin,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_margin,
+                                          &number);
   gtk_css_style_property_register        ("margin-left",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_margin,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_margin,
+                                          &number);
   gtk_css_style_property_register        ("margin-bottom",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_margin,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_margin,
+                                          &number);
   gtk_css_style_property_register        ("margin-right",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_margin,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_margin,
+                                          &number);
   gtk_css_style_property_register        ("padding-top",
                                           G_TYPE_INT,
                                           G_TYPE_INT,
@@ -817,7 +850,6 @@ _gtk_css_style_property_init_properties (void)
                                           NULL,
                                           NULL,
                                           0);
-  _gtk_css_number_init (&number, 0, GTK_CSS_PX);
   /* IMPORTANT: compute_border_width() requires that the border-width
    * properties be immeditaly followed by the border-style properties
    */



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