[gtk+/wip/css: 146/154] Add border-{top|left|bottom|right}-style properties



commit d7a6daedfebeae4e8fac49005f74f5fa806ca6ab
Author: Paolo Borelli <pborelli gnome org>
Date:   Thu Jan 5 16:53:43 2012 +0100

    Add border-{top|left|bottom|right}-style properties
    
    Add all the border-style subproperties and turn border-style itself in a
    shorthand.

 gtk/gtkcssshorthandpropertyimpl.c   |   79 +++++++++++++++++++++++++++++++++++
 gtk/gtkcssstylepropertyimpl.c       |   24 ++++++++++-
 tests/css/parser/value-inherit.css  |    5 ++-
 tests/css/parser/value-initial.css  |    5 ++-
 tests/css/parser/value-none.css     |    7 ++-
 tests/css/parser/value-none.errors  |   16 ++++----
 tests/css/parser/value-none.ref.css |    5 ++-
 7 files changed, 127 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 33d5335..5d93dfd 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -29,6 +29,7 @@
 #include "gtkcssstylefuncsprivate.h"
 #include "gtkcsstypesprivate.h"
 #include "gtkprivatetypebuiltins.h"
+#include "gtktypebuiltins.h"
 
 /* this is in case round() is not provided by the compiler, 
  * such as in the case of C89 compilers, like MSVC
@@ -178,6 +179,39 @@ parse_border_color (GtkCssShorthandProperty *shorthand,
 }
 
 static gboolean
+parse_border_style (GtkCssShorthandProperty *shorthand,
+                    GValue                  *values,
+                    GtkCssParser            *parser,
+                    GFile                   *base)
+{
+  GtkBorderStyle styles[4];
+  guint i;
+
+  for (i = 0; i < 4; i++)
+    {
+      if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, (int *)&styles[i]))
+        break;
+    }
+
+  if (i == 0)
+    {
+      _gtk_css_parser_error (parser, "Expected a border style");
+      return FALSE;
+    }
+
+  for (; i < G_N_ELEMENTS (styles); i++)
+    styles[i] = styles[(i - 1) >> 1];
+
+  for (i = 0; i < G_N_ELEMENTS (styles); i++)
+    {
+      g_value_init (&values[i], GTK_TYPE_BORDER_STYLE);
+      g_value_set_enum (&values[i], styles[i]);
+    }
+
+  return TRUE;
+}
+
+static gboolean
 parse_border_image (GtkCssShorthandProperty *shorthand,
                     GValue                  *values,
                     GtkCssParser            *parser,
@@ -691,6 +725,44 @@ pack_border_color (GValue             *value,
   gtk_style_properties_get_property (props, "border-top-color", state, value);
 }
 
+static GParameter *
+unpack_border_style (const GValue *value,
+                     guint        *n_params)
+{
+  GParameter *parameter = g_new0 (GParameter, 4);
+  GtkBorderStyle style;
+
+  style = g_value_get_enum (value);
+
+  parameter[0].name = "border-top-style";
+  g_value_init (&parameter[0].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[0].value, style);
+  parameter[1].name = "border-right-style";
+  g_value_init (&parameter[1].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[1].value, style);
+  parameter[2].name = "border-bottom-style";
+  g_value_init (&parameter[2].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[2].value, style);
+  parameter[3].name = "border-left-style";
+  g_value_init (&parameter[3].value, GTK_TYPE_BORDER_STYLE);
+  g_value_set_enum (&parameter[3].value, style);
+
+  *n_params = 4;
+  return parameter;
+}
+
+static void
+pack_border_style (GValue             *value,
+                   GtkStyleProperties *props,
+                   GtkStateFlags       state)
+{
+  /* NB: We can just resolve to a style. We pick one and stick to it.
+   * Lesson learned: Don't query border-style shorthand, query the
+   * real properties instead. */
+  g_value_unset (value);
+  gtk_style_properties_get_property (props, "border-top-style", state, value);
+}
+
 static void
 _gtk_css_shorthand_property_register (const char                        *name,
                                       GType                              value_type,
@@ -723,6 +795,7 @@ _gtk_css_shorthand_property_init_properties (void)
   const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
                                                 "border-bottom-right-radius", "border-bottom-left-radius", NULL };
   const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
+  const char *border_style_subproperties[] = { "border-top-style", "border-right-style", "border-bottom-style", "border-left-style", NULL };
   const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
   const char *background_subproperties[] = { "background-image", "background-repeat", "background-clip", "background-origin",
                                              "background-color", NULL };
@@ -763,6 +836,12 @@ _gtk_css_shorthand_property_init_properties (void)
                                           parse_border_color,
                                           unpack_border_color,
                                           pack_border_color);
+  _gtk_css_shorthand_property_register   ("border-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          border_style_subproperties,
+                                          parse_border_style,
+                                          unpack_border_style,
+                                          pack_border_style);
   _gtk_css_shorthand_property_register   ("border-image",
                                           G_TYPE_NONE,
                                           border_image_subproperties,
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 447e1df..3354e16 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -715,13 +715,35 @@ _gtk_css_style_property_init_properties (void)
                                           NULL,
                                           &no_corner_radius);
 
-  gtk_style_property_register            ("border-style",
+  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/tests/css/parser/value-inherit.css b/tests/css/parser/value-inherit.css
index c58106b..777bbac 100644
--- a/tests/css/parser/value-inherit.css
+++ b/tests/css/parser/value-inherit.css
@@ -7,19 +7,22 @@
   border-bottom-color: inherit;
   border-bottom-left-radius: inherit;
   border-bottom-right-radius: inherit;
+  border-bottom-style: inherit;
   border-bottom-width: inherit;
   border-image-repeat: inherit;
   border-image-slice: inherit;
   border-image-source: inherit;
   border-image-width: inherit;
   border-left-color: inherit;
+  border-left-style: inherit;
   border-left-width: inherit;
   border-right-color: inherit;
+  border-right-style: inherit;
   border-right-width: inherit;
-  border-style: inherit;
   border-top-color: inherit;
   border-top-left-radius: inherit;
   border-top-right-radius: inherit;
+  border-top-style: inherit;
   border-top-width: inherit;
   box-shadow: inherit;
   color: inherit;
diff --git a/tests/css/parser/value-initial.css b/tests/css/parser/value-initial.css
index 5abcd7e..7e72166 100644
--- a/tests/css/parser/value-initial.css
+++ b/tests/css/parser/value-initial.css
@@ -7,19 +7,22 @@
   border-bottom-color: initial;
   border-bottom-left-radius: initial;
   border-bottom-right-radius: initial;
+  border-bottom-style: initial;
   border-bottom-width: initial;
   border-image-repeat: initial;
   border-image-slice: initial;
   border-image-source: initial;
   border-image-width: initial;
   border-left-color: initial;
+  border-left-style: initial;
   border-left-width: initial;
   border-right-color: initial;
+  border-right-style: initial;
   border-right-width: initial;
-  border-style: initial;
   border-top-color: initial;
   border-top-left-radius: initial;
   border-top-right-radius: initial;
+  border-top-style: initial;
   border-top-width: initial;
   box-shadow: initial;
   color: initial;
diff --git a/tests/css/parser/value-none.css b/tests/css/parser/value-none.css
index 738d684..928f5a2 100644
--- a/tests/css/parser/value-none.css
+++ b/tests/css/parser/value-none.css
@@ -7,24 +7,27 @@
   border-bottom-color: none;
   border-bottom-left-radius: none;
   border-bottom-right-radius: none;
+    border-bottom-style: none;
   border-bottom-width: none;
   border-image-repeat: none;
   border-image-slice: none;
     border-image-source: none;
   border-image-width: none;
   border-left-color: none;
+    border-left-style: none;
   border-left-width: none;
   border-right-color: none;
+    border-right-style: none;
   border-right-width: none;
-    border-style: none;
   border-top-color: none;
   border-top-left-radius: none;
   border-top-right-radius: none;
+    border-top-style: none;
   border-top-width: none;
     box-shadow: none;
   color: none;
     engine: none;
-  font-family: none;
+    font-family: none;
   font-size: none;
   font-style: none;
   font-variant: none;
diff --git a/tests/css/parser/value-none.errors b/tests/css/parser/value-none.errors
index f4c3de6..9e17c29 100644
--- a/tests/css/parser/value-none.errors
+++ b/tests/css/parser/value-none.errors
@@ -5,28 +5,28 @@ value-none.css:6: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:7: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:8: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:9: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:10: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:11: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:12: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:14: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:13: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:15: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:16: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:17: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:18: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:20: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:19: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:21: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:22: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:23: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:25: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:24: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:26: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:28: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:29: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:30: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:31: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:32: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:33: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:34: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
-value-none.css:35: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:36: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:37: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:38: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:39: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
 value-none.css:40: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:41: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:42: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
+value-none.css:43: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
diff --git a/tests/css/parser/value-none.ref.css b/tests/css/parser/value-none.ref.css
index deadc14..660cd52 100644
--- a/tests/css/parser/value-none.ref.css
+++ b/tests/css/parser/value-none.ref.css
@@ -1,7 +1,10 @@
 * {
   background-image: none;
+  border-bottom-style: none;
   border-image-source: none;
-  border-style: none;
+  border-left-style: none;
+  border-right-style: none;
+  border-top-style: none;
   box-shadow: none;
   engine: none;
   font-family: "none";



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