]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssshorthandpropertyimpl.c
Change FSF Address
[~andy/gtk] / gtk / gtkcssshorthandpropertyimpl.c
index 33d5335813b239d1a576fb38a51ae1a27aea7ce7..74e75ffd2cd477f8d7a5bfc88a6bfc29b1bafaaf 100644 (file)
@@ -12,8 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Benjamin Otte <otte@gnome.org>
  */
@@ -29,6 +28,9 @@
 #include "gtkcssstylefuncsprivate.h"
 #include "gtkcsstypesprivate.h"
 #include "gtkprivatetypebuiltins.h"
+#include "gtkstylepropertiesprivate.h"
+#include "gtksymboliccolorprivate.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
@@ -46,37 +48,86 @@ value_is_done_parsing (GtkCssParser *parser)
 }
 
 static gboolean
-parse_border (GtkCssShorthandProperty *shorthand,
-              GValue                  *values,
-              GtkCssParser            *parser,
-              GFile                   *base)
+parse_four_numbers (GtkCssShorthandProperty *shorthand,
+                    GValue                  *values,
+                    GtkCssParser            *parser,
+                    GtkCssNumberParseFlags   flags)
 {
-  GValue temp = G_VALUE_INIT;
-  GtkBorder *border;
+  GtkCssNumber numbers[4];
+  guint i;
 
-  g_value_init (&temp, GTK_TYPE_BORDER);
-  if (!_gtk_css_style_parse_value (&temp, parser, base))
+  for (i = 0; i < 4; i++)
     {
-      g_value_unset (&temp);
-      return FALSE;
+      if (!_gtk_css_parser_has_number (parser))
+        break;
+
+      if (!_gtk_css_parser_read_number (parser,
+                                        &numbers[i], 
+                                        flags))
+        return FALSE;
     }
 
-  border = g_value_get_boxed (&temp);
+  if (i == 0)
+    {
+      _gtk_css_parser_error (parser, "Expected a length");
+      return FALSE;
+    }
 
-  g_value_init (&values[0], G_TYPE_INT);
-  g_value_init (&values[1], G_TYPE_INT);
-  g_value_init (&values[2], G_TYPE_INT);
-  g_value_init (&values[3], G_TYPE_INT);
-  g_value_set_int (&values[0], border->top);
-  g_value_set_int (&values[1], border->right);
-  g_value_set_int (&values[2], border->bottom);
-  g_value_set_int (&values[3], border->left);
+  for (; i < 4; i++)
+    {
+      numbers[i] = numbers[(i - 1) >> 1];
+    }
 
-  g_value_unset (&temp);
+  for (i = 0; i < 4; i++)
+    {
+      g_value_init (&values[i], GTK_TYPE_CSS_NUMBER);
+      g_value_set_boxed (&values[i], &numbers[i]);
+    }
 
   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_padding (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_width (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,
@@ -88,13 +139,15 @@ parse_border_radius (GtkCssShorthandProperty *shorthand,
 
   for (i = 0; i < G_N_ELEMENTS (borders); i++)
     {
-      if (!_gtk_css_parser_try_double (parser, &borders[i].horizontal))
+      if (!_gtk_css_parser_has_number (parser))
         break;
-      if (borders[i].horizontal < 0)
-        {
-          _gtk_css_parser_error (parser, "Border radius values cannot be negative");
-          return FALSE;
-        }
+      if (!_gtk_css_parser_read_number (parser,
+                                        &borders[i].horizontal,
+                                        GTK_CSS_POSITIVE_ONLY
+                                        | GTK_CSS_PARSE_PERCENT
+                                        | GTK_CSS_NUMBER_AS_PIXELS
+                                        | GTK_CSS_PARSE_LENGTH))
+        return FALSE;
     }
 
   if (i == 0)
@@ -112,13 +165,15 @@ parse_border_radius (GtkCssShorthandProperty *shorthand,
     {
       for (i = 0; i < G_N_ELEMENTS (borders); i++)
         {
-          if (!_gtk_css_parser_try_double (parser, &borders[i].vertical))
+          if (!_gtk_css_parser_has_number (parser))
             break;
-          if (borders[i].vertical < 0)
-            {
-              _gtk_css_parser_error (parser, "Border radius values cannot be negative");
-              return FALSE;
-            }
+          if (!_gtk_css_parser_read_number (parser,
+                                            &borders[i].vertical,
+                                            GTK_CSS_POSITIVE_ONLY
+                                            | GTK_CSS_PARSE_PERCENT
+                                            | GTK_CSS_NUMBER_AS_PIXELS
+                                            | GTK_CSS_PARSE_LENGTH))
+            return FALSE;
         }
 
       if (i == 0)
@@ -157,9 +212,16 @@ parse_border_color (GtkCssShorthandProperty *shorthand,
 
   for (i = 0; i < 4; i++)
     {
-      symbolic = _gtk_css_parser_read_symbolic_color (parser);
-      if (symbolic == NULL)
-        return FALSE;
+      if (_gtk_css_parser_try (parser, "currentcolor", TRUE))
+        {
+          symbolic = gtk_symbolic_color_ref (_gtk_symbolic_color_get_current_color ());
+        }
+      else
+        {
+          symbolic = _gtk_css_parser_read_symbolic_color (parser);
+          if (symbolic == NULL)
+            return FALSE;
+        }
 
       g_value_init (&values[i], GTK_TYPE_SYMBOLIC_COLOR);
       g_value_set_boxed (&values[i], symbolic);
@@ -170,13 +232,46 @@ parse_border_color (GtkCssShorthandProperty *shorthand,
 
   for (i++; i < 4; i++)
     {
-      g_value_init (&values[i], GTK_TYPE_SYMBOLIC_COLOR);
+      g_value_init (&values[i], G_VALUE_TYPE (&values[(i - 1) >> 1]));
       g_value_copy (&values[(i - 1) >> 1], &values[i]);
     }
 
   return TRUE;
 }
 
+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,
@@ -220,6 +315,135 @@ parse_border_image (GtkCssShorthandProperty *shorthand,
   return TRUE;
 }
 
+static gboolean
+parse_border_side (GtkCssShorthandProperty *shorthand,
+                   GValue                  *values,
+                   GtkCssParser            *parser,
+                   GFile                   *base)
+{
+  int style;
+
+  do
+  {
+    if (!G_IS_VALUE (&values[0]) &&
+         _gtk_css_parser_has_number (parser))
+      {
+        GtkCssNumber number;
+        if (!_gtk_css_parser_read_number (parser,
+                                          &number,
+                                          GTK_CSS_POSITIVE_ONLY
+                                          | GTK_CSS_NUMBER_AS_PIXELS
+                                          | GTK_CSS_PARSE_LENGTH))
+          return FALSE;
+
+        g_value_init (&values[0], GTK_TYPE_CSS_NUMBER);
+        g_value_set_boxed (&values[0], &number);
+      }
+    else if (!G_IS_VALUE (&values[1]) &&
+             _gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, &style))
+      {
+        g_value_init (&values[1], GTK_TYPE_BORDER_STYLE);
+        g_value_set_enum (&values[1], style);
+      }
+    else if (!G_IS_VALUE (&values[2]))
+      {
+        GtkSymbolicColor *symbolic;
+
+        symbolic = _gtk_css_parser_read_symbolic_color (parser);
+        if (symbolic == NULL)
+          return FALSE;
+
+        g_value_init (&values[2], GTK_TYPE_SYMBOLIC_COLOR);
+        g_value_take_boxed (&values[2], symbolic);
+      }
+    else
+      {
+        /* We parsed everything and there's still stuff left?
+         * Pretend we didn't notice and let the normal code produce
+         * a 'junk at end of value' error */
+        break;
+      }
+  }
+  while (!value_is_done_parsing (parser));
+
+  return TRUE;
+}
+
+static gboolean
+parse_border (GtkCssShorthandProperty *shorthand,
+              GValue                  *values,
+              GtkCssParser            *parser,
+              GFile                   *base)
+{
+  int style;
+
+  do
+  {
+    if (!G_IS_VALUE (&values[0]) &&
+         _gtk_css_parser_has_number (parser))
+      {
+        GtkCssNumber number;
+        if (!_gtk_css_parser_read_number (parser,
+                                          &number,
+                                          GTK_CSS_POSITIVE_ONLY
+                                          | GTK_CSS_NUMBER_AS_PIXELS
+                                          | GTK_CSS_PARSE_LENGTH))
+          return FALSE;
+
+        g_value_init (&values[0], GTK_TYPE_CSS_NUMBER);
+        g_value_init (&values[1], GTK_TYPE_CSS_NUMBER);
+        g_value_init (&values[2], GTK_TYPE_CSS_NUMBER);
+        g_value_init (&values[3], GTK_TYPE_CSS_NUMBER);
+        g_value_set_boxed (&values[0], &number);
+        g_value_set_boxed (&values[1], &number);
+        g_value_set_boxed (&values[2], &number);
+        g_value_set_boxed (&values[3], &number);
+      }
+    else if (!G_IS_VALUE (&values[4]) &&
+             _gtk_css_parser_try_enum (parser, GTK_TYPE_BORDER_STYLE, &style))
+      {
+        g_value_init (&values[4], GTK_TYPE_BORDER_STYLE);
+        g_value_init (&values[5], GTK_TYPE_BORDER_STYLE);
+        g_value_init (&values[6], GTK_TYPE_BORDER_STYLE);
+        g_value_init (&values[7], GTK_TYPE_BORDER_STYLE);
+        g_value_set_enum (&values[4], style);
+        g_value_set_enum (&values[5], style);
+        g_value_set_enum (&values[6], style);
+        g_value_set_enum (&values[7], style);
+      }
+    else if (!G_IS_VALUE (&values[8]))
+      {
+        GtkSymbolicColor *symbolic;
+
+        symbolic = _gtk_css_parser_read_symbolic_color (parser);
+        if (symbolic == NULL)
+          return FALSE;
+
+        g_value_init (&values[8], GTK_TYPE_SYMBOLIC_COLOR);
+        g_value_init (&values[9], GTK_TYPE_SYMBOLIC_COLOR);
+        g_value_init (&values[10], GTK_TYPE_SYMBOLIC_COLOR);
+        g_value_init (&values[11], GTK_TYPE_SYMBOLIC_COLOR);
+        g_value_set_boxed (&values[8], symbolic);
+        g_value_set_boxed (&values[9], symbolic);
+        g_value_set_boxed (&values[10], symbolic);
+        g_value_take_boxed (&values[11], symbolic);
+      }
+    else
+      {
+        /* We parsed everything and there's still stuff left?
+         * Pretend we didn't notice and let the normal code produce
+         * a 'junk at end of value' error */
+        break;
+      }
+  }
+  while (!value_is_done_parsing (parser));
+
+  /* Note that border-image values are not set: according to the spec
+     they just need to be reset when using the border shorthand */
+
+  return TRUE;
+}
+
 static gboolean
 parse_font (GtkCssShorthandProperty *shorthand,
             GValue                  *values,
@@ -361,175 +585,110 @@ parse_background (GtkCssShorthandProperty *shorthand,
 
 /*** PACKING ***/
 
-static GParameter *
-unpack_border (const GValue *value,
-               guint        *n_params,
-               const char   *top,
-               const char   *left,
-               const char   *bottom,
-               const char   *right)
-{
-  GParameter *parameter = g_new0 (GParameter, 4);
-  GtkBorder *border = g_value_get_boxed (value);
-
-  parameter[0].name = top;
-  g_value_init (&parameter[0].value, G_TYPE_INT);
-  g_value_set_int (&parameter[0].value, border->top);
-  parameter[1].name = left;
-  g_value_init (&parameter[1].value, G_TYPE_INT);
-  g_value_set_int (&parameter[1].value, border->left);
-  parameter[2].name = bottom;
-  g_value_init (&parameter[2].value, G_TYPE_INT);
-  g_value_set_int (&parameter[2].value, border->bottom);
-  parameter[3].name = right;
-  g_value_init (&parameter[3].value, G_TYPE_INT);
-  g_value_set_int (&parameter[3].value, border->right);
-
-  *n_params = 4;
-  return parameter;
-}
-
 static void
-pack_border (GValue             *value,
-             GtkStyleProperties *props,
-             GtkStateFlags       state,
-             const char         *top,
-             const char         *left,
-             const char         *bottom,
-             const char         *right)
+unpack_border (GtkCssShorthandProperty *shorthand,
+               GtkStyleProperties      *props,
+               GtkStateFlags            state,
+               const GValue            *value)
 {
-  GtkBorder border;
-  int t, l, b, r;
-
-  gtk_style_properties_get (props,
-                            state,
-                            top, &t,
-                            left, &l,
-                            bottom, &b,
-                            right, &r,
-                            NULL);
-
-  border.top = t;
-  border.left = l;
-  border.bottom = b;
-  border.right = r;
-
-  g_value_set_boxed (value, &border);
-}
+  GValue v = G_VALUE_INIT;
+  GtkBorder *border = g_value_get_boxed (value);
 
-static GParameter *
-unpack_border_width (const GValue *value,
-                     guint        *n_params)
-{
-  return unpack_border (value, n_params,
-                        "border-top-width", "border-left-width",
-                        "border-bottom-width", "border-right-width");
-}
+  g_value_init (&v, G_TYPE_INT);
 
-static void
-pack_border_width (GValue             *value,
-                   GtkStyleProperties *props,
-                   GtkStateFlags       state)
-{
-  pack_border (value, props, state,
-               "border-top-width", "border-left-width",
-               "border-bottom-width", "border-right-width");
-}
+  g_value_set_int (&v, border->top);
+  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 0)), props, state, &v);
+  g_value_set_int (&v, border->right);
+  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 1)), props, state, &v);
+  g_value_set_int (&v, border->bottom);
+  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 2)), props, state, &v);
+  g_value_set_int (&v, border->left);
+  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 3)), props, state, &v);
 
-static GParameter *
-unpack_padding (const GValue *value,
-                guint        *n_params)
-{
-  return unpack_border (value, n_params,
-                        "padding-top", "padding-left",
-                        "padding-bottom", "padding-right");
+  g_value_unset (&v);
 }
 
 static void
-pack_padding (GValue             *value,
-              GtkStyleProperties *props,
-              GtkStateFlags       state)
+pack_border (GtkCssShorthandProperty *shorthand,
+             GValue                  *value,
+             GtkStyleQueryFunc        query_func,
+             gpointer                 query_data)
 {
-  pack_border (value, props, state,
-               "padding-top", "padding-left",
-               "padding-bottom", "padding-right");
-}
+  GtkCssStyleProperty *prop;
+  GtkBorder border;
+  const GValue *v;
+
+  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
+  if (v)
+    border.top = g_value_get_int (v);
+  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 1);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
+  if (v)
+    border.right = g_value_get_int (v);
+  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 2);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
+  if (v)
+    border.bottom = g_value_get_int (v);
+  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 3);
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
+  if (v)
+    border.left = g_value_get_int (v);
 
-static GParameter *
-unpack_margin (const GValue *value,
-               guint        *n_params)
-{
-  return unpack_border (value, n_params,
-                        "margin-top", "margin-left",
-                        "margin-bottom", "margin-right");
+  g_value_set_boxed (value, &border);
 }
 
 static void
-pack_margin (GValue             *value,
-             GtkStyleProperties *props,
-             GtkStateFlags       state)
-{
-  pack_border (value, props, state,
-               "margin-top", "margin-left",
-               "margin-bottom", "margin-right");
-}
-
-static GParameter *
-unpack_border_radius (const GValue *value,
-                      guint        *n_params)
+unpack_border_radius (GtkCssShorthandProperty *shorthand,
+                      GtkStyleProperties      *props,
+                      GtkStateFlags            state,
+                      const GValue            *value)
 {
-  GParameter *parameter = g_new0 (GParameter, 4);
   GtkCssBorderCornerRadius border;
+  GValue v = G_VALUE_INIT;
+  guint i;
   
-  border.horizontal = border.vertical = g_value_get_int (value);
-
-  parameter[0].name = "border-top-left-radius";
-  g_value_init (&parameter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
-  g_value_set_boxed (&parameter[0].value, &border);
-  parameter[1].name = "border-top-right-radius";
-  g_value_init (&parameter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
-  g_value_set_boxed (&parameter[1].value, &border);
-  parameter[2].name = "border-bottom-right-radius";
-  g_value_init (&parameter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
-  g_value_set_boxed (&parameter[2].value, &border);
-  parameter[3].name = "border-bottom-left-radius";
-  g_value_init (&parameter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
-  g_value_set_boxed (&parameter[3].value, &border);
-
-  *n_params = 4;
-  return parameter;
+  _gtk_css_number_init (&border.horizontal, g_value_get_int (value), GTK_CSS_PX);
+  border.vertical = border.horizontal;
+  g_value_init (&v, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
+  g_value_set_boxed (&v, &border);
+
+  for (i = 0; i < 4; i++)
+    _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, i)), props, state, &v);
+
+  g_value_unset (&v);
 }
 
 static void
-pack_border_radius (GValue             *value,
-                    GtkStyleProperties *props,
-                    GtkStateFlags       state)
+pack_border_radius (GtkCssShorthandProperty *shorthand,
+                    GValue                  *value,
+                    GtkStyleQueryFunc        query_func,
+                    gpointer                 query_data)
 {
   GtkCssBorderCornerRadius *top_left;
+  GtkCssStyleProperty *prop;
+  const GValue *v;
 
-  /* NB: We are an int property, so we have to resolve to an int here.
-   * So we just resolve to an int. We pick one and stick to it.
-   * Lesson learned: Don't query border-radius shorthand, query the 
-   * real properties instead. */
-  gtk_style_properties_get (props,
-                            state,
-                            "border-top-left-radius", &top_left,
-                            NULL);
-
-  if (top_left)
-    g_value_set_int (value, top_left->horizontal);
-
-  g_free (top_left);
+  prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius"));
+  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
+  if (v)
+    {
+      top_left = g_value_get_boxed (v);
+      if (top_left)
+        g_value_set_int (value, top_left->horizontal.value);
+    }
 }
 
-static GParameter *
-unpack_font_description (const GValue *value,
-                         guint        *n_params)
+static void
+unpack_font_description (GtkCssShorthandProperty *shorthand,
+                         GtkStyleProperties      *props,
+                         GtkStateFlags            state,
+                         const GValue            *value)
 {
-  GParameter *parameter = g_new0 (GParameter, 5);
+  GtkStyleProperty *prop;
   PangoFontDescription *description;
   PangoFontMask mask;
-  guint n;
+  GValue v = G_VALUE_INIT;
   
   /* For backwards compat, we only unpack values that are indeed set.
    * For strict CSS conformance we need to unpack all of them.
@@ -539,7 +698,6 @@ unpack_font_description (const GValue *value,
    */
 
   description = g_value_get_boxed (value);
-  n = 0;
 
   if (description)
     mask = pango_font_description_get_set_fields (description);
@@ -552,143 +710,137 @@ unpack_font_description (const GValue *value,
 
       g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
       g_ptr_array_add (strv, NULL);
-      parameter[n].name = "font-family";
-      g_value_init (&parameter[n].value, G_TYPE_STRV);
-      g_value_take_boxed (&parameter[n].value,
-                          g_ptr_array_free (strv, FALSE));
-      n++;
+      g_value_init (&v, G_TYPE_STRV);
+      g_value_take_boxed (&v, g_ptr_array_free (strv, FALSE));
+
+      prop = _gtk_style_property_lookup ("font-family");
+      _gtk_style_property_assign (prop, props, state, &v);
+      g_value_unset (&v);
     }
 
   if (mask & PANGO_FONT_MASK_STYLE)
     {
-      parameter[n].name = "font-style";
-      g_value_init (&parameter[n].value, PANGO_TYPE_STYLE);
-      g_value_set_enum (&parameter[n].value,
-                        pango_font_description_get_style (description));
-      n++;
+      g_value_init (&v, PANGO_TYPE_STYLE);
+      g_value_set_enum (&v, pango_font_description_get_style (description));
+
+      prop = _gtk_style_property_lookup ("font-style");
+      _gtk_style_property_assign (prop, props, state, &v);
+      g_value_unset (&v);
     }
 
   if (mask & PANGO_FONT_MASK_VARIANT)
     {
-      parameter[n].name = "font-variant";
-      g_value_init (&parameter[n].value, PANGO_TYPE_VARIANT);
-      g_value_set_enum (&parameter[n].value,
-                        pango_font_description_get_variant (description));
-      n++;
+      g_value_init (&v, PANGO_TYPE_VARIANT);
+      g_value_set_enum (&v, pango_font_description_get_variant (description));
+
+      prop = _gtk_style_property_lookup ("font-variant");
+      _gtk_style_property_assign (prop, props, state, &v);
+      g_value_unset (&v);
     }
 
   if (mask & PANGO_FONT_MASK_WEIGHT)
     {
-      parameter[n].name = "font-weight";
-      g_value_init (&parameter[n].value, PANGO_TYPE_WEIGHT);
-      g_value_set_enum (&parameter[n].value,
-                        pango_font_description_get_weight (description));
-      n++;
+      g_value_init (&v, PANGO_TYPE_WEIGHT);
+      g_value_set_enum (&v, pango_font_description_get_weight (description));
+
+      prop = _gtk_style_property_lookup ("font-weight");
+      _gtk_style_property_assign (prop, props, state, &v);
+      g_value_unset (&v);
     }
 
   if (mask & PANGO_FONT_MASK_SIZE)
     {
-      parameter[n].name = "font-size";
-      g_value_init (&parameter[n].value, G_TYPE_DOUBLE);
-      g_value_set_double (&parameter[n].value,
-                          (double) pango_font_description_get_size (description) / PANGO_SCALE);
-      n++;
-    }
+      g_value_init (&v, G_TYPE_DOUBLE);
+      g_value_set_double (&v, (double) pango_font_description_get_size (description) / PANGO_SCALE);
 
-  *n_params = n;
-
-  return parameter;
+      prop = _gtk_style_property_lookup ("font-size");
+      _gtk_style_property_assign (prop, props, state, &v);
+      g_value_unset (&v);
+    }
 }
 
 static void
-pack_font_description (GValue             *value,
-                       GtkStyleProperties *props,
-                       GtkStateFlags       state)
+pack_font_description (GtkCssShorthandProperty *shorthand,
+                       GValue                  *value,
+                       GtkStyleQueryFunc        query_func,
+                       gpointer                 query_data)
 {
   PangoFontDescription *description;
-  char **families;
-  PangoStyle style;
-  PangoVariant variant;
-  PangoWeight weight;
-  double size;
-
-  gtk_style_properties_get (props,
-                            state,
-                            "font-family", &families,
-                            "font-style", &style,
-                            "font-variant", &variant,
-                            "font-weight", &weight,
-                            "font-size", &size,
-                            NULL);
+  const GValue *v;
 
   description = pango_font_description_new ();
-  /* xxx: Can we set all the families here somehow? */
-  if (families)
-    pango_font_description_set_family (description, families[0]);
-  pango_font_description_set_size (description, round (size * PANGO_SCALE));
-  pango_font_description_set_style (description, style);
-  pango_font_description_set_variant (description, variant);
-  pango_font_description_set_weight (description, weight);
 
-  g_strfreev (families);
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data);
+  if (v)
+    {
+      const char **families = g_value_get_boxed (v);
+      /* xxx: Can we set all the families here somehow? */
+      if (families)
+        pango_font_description_set_family (description, families[0]);
+    }
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
+  if (v)
+    pango_font_description_set_size (description, round (g_value_get_double (v) * PANGO_SCALE));
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
+  if (v)
+    pango_font_description_set_style (description, g_value_get_enum (v));
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data);
+  if (v)
+    pango_font_description_set_variant (description, g_value_get_enum (v));
+
+  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data);
+  if (v)
+    pango_font_description_set_weight (description, g_value_get_enum (v));
 
   g_value_take_boxed (value, description);
 }
 
-static GParameter *
-unpack_border_color (const GValue *value,
-                     guint        *n_params)
+static void
+unpack_to_everything (GtkCssShorthandProperty *shorthand,
+                      GtkStyleProperties      *props,
+                      GtkStateFlags            state,
+                      const GValue            *value)
 {
-  GParameter *parameter = g_new0 (GParameter, 4);
-  GType type;
+  GtkCssStyleProperty *prop;
+  guint i, n;
   
-  type = G_VALUE_TYPE (value);
-  if (type == G_TYPE_PTR_ARRAY)
-    type = GTK_TYPE_SYMBOLIC_COLOR;
-
-  parameter[0].name = "border-top-color";
-  g_value_init (&parameter[0].value, type);
-  parameter[1].name = "border-right-color";
-  g_value_init (&parameter[1].value, type);
-  parameter[2].name = "border-bottom-color";
-  g_value_init (&parameter[2].value, type);
-  parameter[3].name = "border-left-color";
-  g_value_init (&parameter[3].value, type);
-
-  if (G_VALUE_TYPE (value) == G_TYPE_PTR_ARRAY)
-    {
-      GPtrArray *array = g_value_get_boxed (value);
-      guint i;
+  n = _gtk_css_shorthand_property_get_n_subproperties (shorthand);
 
-      for (i = 0; i < 4; i++)
-        g_value_set_boxed (&parameter[i].value, g_ptr_array_index (array, i));
-    }
-  else
+  for (i = 0; i < n; i++)
     {
-      /* can be RGBA or symbolic color */
-      gpointer p = g_value_get_boxed (value);
-
-      g_value_set_boxed (&parameter[0].value, p);
-      g_value_set_boxed (&parameter[1].value, p);
-      g_value_set_boxed (&parameter[2].value, p);
-      g_value_set_boxed (&parameter[3].value, p);
+      prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
+      _gtk_style_property_assign (GTK_STYLE_PROPERTY (prop), props, state, value);
     }
-
-  *n_params = 4;
-  return parameter;
 }
 
 static void
-pack_border_color (GValue             *value,
-                   GtkStyleProperties *props,
-                   GtkStateFlags       state)
+pack_first_element (GtkCssShorthandProperty *shorthand,
+                    GValue                  *value,
+                    GtkStyleQueryFunc        query_func,
+                    gpointer                 query_data)
 {
-  /* NB: We are a color property, so we have to resolve to a color here.
-   * So we just resolve to a color. We pick one and stick to it.
-   * Lesson learned: Don't query border-color shorthand, query the 
+  GtkCssStyleProperty *prop;
+  const GValue *v;
+  guint i;
+
+  /* NB: This is a fallback for properties that originally were
+   * not used as shorthand. We just pick the first subproperty
+   * as a representative.
+   * Lesson learned: Don't query the shorthand, query the 
    * real properties instead. */
-  g_value_unset (value);
-  gtk_style_properties_get_property (props, "border-top-color", state, value);
+  for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
+    {
+      prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
+      v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
+      if (v)
+        {
+          g_value_copy (v, value);
+          return;
+        }
+    }
 }
 
 static void
@@ -696,10 +848,10 @@ _gtk_css_shorthand_property_register (const char                        *name,
                                       GType                              value_type,
                                       const char                       **subproperties,
                                       GtkCssShorthandPropertyParseFunc   parse_func,
-                                      GtkStyleUnpackFunc                 unpack_func,
-                                      GtkStylePackFunc                   pack_func)
+                                      GtkCssShorthandPropertyAssignFunc  assign_func,
+                                      GtkCssShorthandPropertyQueryFunc   query_func)
 {
-  GtkStyleProperty *node;
+  GtkCssShorthandProperty *node;
 
   node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
                        "name", name,
@@ -707,9 +859,9 @@ _gtk_css_shorthand_property_register (const char                        *name,
                        "subproperties", subproperties,
                        NULL);
 
-  GTK_CSS_SHORTHAND_PROPERTY (node)->parse = parse_func;
-  node->pack_func = pack_func;
-  node->unpack_func = unpack_func;
+  node->parse = parse_func;
+  node->assign = assign_func;
+  node->query = query_func;
 }
 
 void
@@ -723,7 +875,17 @@ _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 *border_top_subproperties[] = { "border-top-width", "border-top-style", "border-top-color", NULL };
+  const char *border_right_subproperties[] = { "border-right-width", "border-right-style", "border-right-color", NULL };
+  const char *border_bottom_subproperties[] = { "border-bottom-width", "border-bottom-style", "border-bottom-color", NULL };
+  const char *border_left_subproperties[] = { "border-left-width", "border-left-style", "border-left-color", NULL };
+  const char *border_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width",
+                                         "border-top-style", "border-right-style", "border-bottom-style", "border-left-style",
+                                         "border-top-color", "border-right-color", "border-bottom-color", "border-left-color",
+                                         "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
+  const char *outline_subproperties[] = { "outline-width", "outline-style", "outline-color", NULL };
   const char *background_subproperties[] = { "background-image", "background-repeat", "background-clip", "background-origin",
                                              "background-color", NULL };
 
@@ -736,21 +898,21 @@ _gtk_css_shorthand_property_init_properties (void)
   _gtk_css_shorthand_property_register   ("margin",
                                           GTK_TYPE_BORDER,
                                           margin_subproperties,
-                                          parse_border,
-                                          unpack_margin,
-                                          pack_margin);
+                                          parse_margin,
+                                          unpack_border,
+                                          pack_border);
   _gtk_css_shorthand_property_register   ("padding",
                                           GTK_TYPE_BORDER,
                                           padding_subproperties,
-                                          parse_border,
-                                          unpack_padding,
-                                          pack_padding);
+                                          parse_padding,
+                                          unpack_border,
+                                          pack_border);
   _gtk_css_shorthand_property_register   ("border-width",
                                           GTK_TYPE_BORDER,
                                           border_width_subproperties,
-                                          parse_border,
-                                          unpack_border_width,
-                                          pack_border_width);
+                                          parse_border_width,
+                                          unpack_border,
+                                          pack_border);
   _gtk_css_shorthand_property_register   ("border-radius",
                                           G_TYPE_INT,
                                           border_radius_subproperties,
@@ -761,14 +923,56 @@ _gtk_css_shorthand_property_init_properties (void)
                                           GDK_TYPE_RGBA,
                                           border_color_subproperties,
                                           parse_border_color,
-                                          unpack_border_color,
-                                          pack_border_color);
+                                          unpack_to_everything,
+                                          pack_first_element);
+  _gtk_css_shorthand_property_register   ("border-style",
+                                          GTK_TYPE_BORDER_STYLE,
+                                          border_style_subproperties,
+                                          parse_border_style,
+                                          unpack_to_everything,
+                                          pack_first_element);
   _gtk_css_shorthand_property_register   ("border-image",
                                           G_TYPE_NONE,
                                           border_image_subproperties,
                                           parse_border_image,
                                           NULL,
                                           NULL);
+  _gtk_css_shorthand_property_register   ("border-top",
+                                          G_TYPE_NONE,
+                                          border_top_subproperties,
+                                          parse_border_side,
+                                          NULL,
+                                          NULL);
+  _gtk_css_shorthand_property_register   ("border-right",
+                                          G_TYPE_NONE,
+                                          border_right_subproperties,
+                                          parse_border_side,
+                                          NULL,
+                                          NULL);
+  _gtk_css_shorthand_property_register   ("border-bottom",
+                                          G_TYPE_NONE,
+                                          border_bottom_subproperties,
+                                          parse_border_side,
+                                          NULL,
+                                          NULL);
+  _gtk_css_shorthand_property_register   ("border-left",
+                                          G_TYPE_NONE,
+                                          border_left_subproperties,
+                                          parse_border_side,
+                                          NULL,
+                                          NULL);
+  _gtk_css_shorthand_property_register   ("border",
+                                          G_TYPE_NONE,
+                                          border_subproperties,
+                                          parse_border,
+                                          NULL,
+                                          NULL);
+  _gtk_css_shorthand_property_register   ("outline",
+                                          G_TYPE_NONE,
+                                          outline_subproperties,
+                                          parse_border_side,
+                                          NULL,
+                                          NULL);
   _gtk_css_shorthand_property_register   ("background",
                                           G_TYPE_NONE,
                                           background_subproperties,