[gtk+/wip/css: 146/154] Set border-width to 0 in compute function



commit 176f6eae8159d5f512883b6401dbb5f883e5b505
Author: Benjamin Otte <otte redhat com>
Date:   Fri Jan 6 22:25:05 2012 +0100

    Set border-width to 0 in compute function
    
    This reverts commit c276f53796158d2ed025861f9d9e10eaeee3a279 and
    implements the same feature using the compute function.
    A nice side effect is that gtk_style_property_get_border() and
    gtk_style_property_get("border") to the same thing now.

 gtk/gtkcssstylepropertyimpl.c |   92 ++++++++++++++++++++++++++---------------
 gtk/gtkstylecontext.c         |   22 ++--------
 2 files changed, 63 insertions(+), 51 deletions(-)
---
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 3354e16..4ec3c8e 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -103,7 +103,7 @@ _gtk_style_property_register (const char *                   name,
                        "name", name,
                        "value-type", value_type,
                        NULL);
-
+  
   if (parse_value)
     node->parse_value = parse_value;
   if (print_value)
@@ -432,6 +432,28 @@ css_image_value_compute (GtkCssStyleProperty    *property,
   g_value_take_object (computed, image);
 }
 
+static void
+compute_border_width (GtkCssStyleProperty    *property,
+                      GValue                 *computed,
+                      GtkStyleContext        *context,
+                      const GValue           *specified)
+{
+  GtkCssStyleProperty *style;
+  GtkBorderStyle border_style;
+  
+  /* The -1 is magic that is only true because we register the style
+   * properties directly after the width properties.
+   */
+  style = _gtk_css_style_property_lookup_by_id (_gtk_css_style_property_get_id (property) - 1);
+  border_style = g_value_get_enum (_gtk_style_context_peek_property (context, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (style))));
+
+  g_value_init (computed, G_TYPE_INT);
+  if (border_style == GTK_BORDER_STYLE_NONE)
+    g_value_set_int (computed, 0);
+  else
+    g_value_copy (specified, computed);
+}
+
 static gboolean
 background_repeat_value_parse (GtkCssStyleProperty *property,
                                GValue              *value,
@@ -657,33 +679,64 @@ _gtk_css_style_property_init_properties (void)
                                           NULL,
                                           NULL,
                                           0);
+  /* IMPORTANT: compute_border_width() requires that the border-width
+   * properties be immeditaly followed by the border-style properties
+   */
+  gtk_style_property_register            ("border-top-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GTK_BORDER_STYLE_NONE);
   gtk_style_property_register            ("border-top-width",
                                           G_TYPE_INT,
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          compute_border_width,
                                           0);
+  gtk_style_property_register            ("border-left-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GTK_BORDER_STYLE_NONE);
   gtk_style_property_register            ("border-left-width",
                                           G_TYPE_INT,
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          compute_border_width,
                                           0);
+  gtk_style_property_register            ("border-bottom-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GTK_BORDER_STYLE_NONE);
   gtk_style_property_register            ("border-bottom-width",
                                           G_TYPE_INT,
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          compute_border_width,
                                           0);
+  gtk_style_property_register            ("border-right-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          0,
+                                          NULL,
+                                          NULL,
+                                          NULL,
+                                          GTK_BORDER_STYLE_NONE);
   gtk_style_property_register            ("border-right-width",
                                           G_TYPE_INT,
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          compute_border_width,
                                           0);
 
   gtk_style_property_register            ("border-top-left-radius",
@@ -715,35 +768,6 @@ _gtk_css_style_property_init_properties (void)
                                           NULL,
                                           &no_corner_radius);
 
-  gtk_style_property_register            ("border-top-style",
-                                          GTK_TYPE_BORDER_STYLE,
-                                          0,
-                                          NULL,
-                                          NULL,
-                                          NULL,
-                                          GTK_BORDER_STYLE_NONE);
-  gtk_style_property_register            ("border-left-style",
-                                          GTK_TYPE_BORDER_STYLE,
-                                          0,
-                                          NULL,
-                                          NULL,
-                                          NULL,
-                                          GTK_BORDER_STYLE_NONE);
-  gtk_style_property_register            ("border-bottom-style",
-                                          GTK_TYPE_BORDER_STYLE,
-                                          0,
-                                          NULL,
-                                          NULL,
-                                          NULL,
-                                          GTK_BORDER_STYLE_NONE);
-  gtk_style_property_register            ("border-right-style",
-                                          GTK_TYPE_BORDER_STYLE,
-                                          0,
-                                          NULL,
-                                          NULL,
-                                          NULL,
-                                          GTK_BORDER_STYLE_NONE);
-
   gtk_style_property_register            ("background-clip",
                                           GTK_TYPE_CSS_AREA,
                                           0,
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index b53f82c..993f8f6 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -3533,7 +3533,6 @@ gtk_style_context_get_border (GtkStyleContext *context,
   GtkStyleContextPrivate *priv;
   StyleData *data;
   int top, left, bottom, right;
-  GtkBorderStyle border_style;
 
   g_return_if_fail (border != NULL);
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
@@ -3544,27 +3543,16 @@ gtk_style_context_get_border (GtkStyleContext *context,
   data = style_data_lookup (context, state);
   gtk_style_properties_get (data->store,
                             0,
-			    "border-style", &border_style,
-                            "border-top-width", &top,
                             "border-top-width", &top,
                             "border-left-width", &left,
                             "border-bottom-width", &bottom,
                             "border-right-width", &right,
                             NULL);
-  if (border_style == GTK_BORDER_STYLE_NONE)
-    {
-      border->top = 0;
-      border->left = 0;
-      border->bottom = 0;
-      border->right = 0;
-    }
-  else
-    {
-      border->top = top;
-      border->left = left;
-      border->bottom = bottom;
-      border->right = right;
-    }
+
+  border->top = top;
+  border->left = left;
+  border->bottom = bottom;
+  border->right = right;
 }
 
 /**



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