]> Pileus Git - ~andy/gtk/commitdiff
css: Implement padding as numbers
authorBenjamin Otte <otte@redhat.com>
Tue, 24 Jan 2012 16:49:29 +0000 (17:49 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 2 Feb 2012 02:14:02 +0000 (03:14 +0100)
Also remove the now unused border parsing function for shorthands.

gtk/gtk-default.css
gtk/gtk-win32.css
gtk/gtkcssshorthandpropertyimpl.c
gtk/gtkcssstyleproperty.c
gtk/gtkcssstylepropertyimpl.c
tests/reftests/background-area.css
tests/reftests/background-origin.css
tests/reftests/css-match-style-property-order.css
tests/reftests/entry-progress-coloring.css

index 9a7fe4e439073b19fabf50072e44fc75d4753375..a27239e940bda4e2e668a5978558f2b1cf033151 100644 (file)
@@ -332,7 +332,7 @@ GtkLabel:selected:focused {
 GtkCalendar.view {
   border-width: 1px;
   border-style: inset;
-  padding: 1;
+  padding: 1px;
 }
 
 GtkCalendar.view:inconsistent {
@@ -360,5 +360,5 @@ GtkCalendar.button:hover {
 
 .menu * {
   border-width: 0;
-  padding: 2;
+  padding: 2px;
 }
index e1782fc94144f46fc3ce34546ae9227eda01bb12..e1d604a203520e8452db7d0834668337c0e1230c 100644 (file)
@@ -607,7 +607,7 @@ GtkComboBox.combobox-entry .button:insensitive {
 
 .notebook tab:active {
     background-image: -gtk-win32-theme-part(tab, 1 3, margins(0 0 -1 0));
-    padding: 4;
+    padding: 4px;
 }
 
 .notebook tab:last-child {
index 3a012ee2a64a5e72798102c2dd143895b56a4f08..cbff861bbf272fa139d57f118546d5c0a38a20c3 100644 (file)
@@ -48,38 +48,6 @@ value_is_done_parsing (GtkCssParser *parser)
          _gtk_css_parser_begins_with (parser, '}');
 }
 
-static gboolean
-parse_border_width (GtkCssShorthandProperty *shorthand,
-                    GValue                  *values,
-                    GtkCssParser            *parser,
-                    GFile                   *base)
-{
-  GValue temp = G_VALUE_INIT;
-  GtkBorder *border;
-
-  g_value_init (&temp, GTK_TYPE_BORDER);
-  if (!_gtk_css_style_parse_value (&temp, parser, base))
-    {
-      g_value_unset (&temp);
-      return FALSE;
-    }
-
-  border = g_value_get_boxed (&temp);
-
-  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);
-
-  g_value_unset (&temp);
-
-  return TRUE;
-}
-
 static gboolean
 parse_four_numbers (GtkCssShorthandProperty *shorthand,
                     GValue                  *values,
@@ -134,10 +102,24 @@ parse_margin (GtkCssShorthandProperty *shorthand,
 }
 
 static gboolean
-parse_border_width_really (GtkCssShorthandProperty *shorthand,
-                           GValue                  *values,
-                           GtkCssParser            *parser,
-                           GFile                   *base)
+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,
@@ -923,13 +905,13 @@ _gtk_css_shorthand_property_init_properties (void)
   _gtk_css_shorthand_property_register   ("padding",
                                           GTK_TYPE_BORDER,
                                           padding_subproperties,
-                                          parse_border_width,
+                                          parse_padding,
                                           unpack_border,
                                           pack_border);
   _gtk_css_shorthand_property_register   ("border-width",
                                           GTK_TYPE_BORDER,
                                           border_width_subproperties,
-                                          parse_border_width_really,
+                                          parse_border_width,
                                           unpack_border,
                                           pack_border);
   _gtk_css_shorthand_property_register   ("border-radius",
index ad713ec422504ffdbe1adf0350924a078248bc8e..6e4f23a2e3121dacc2e3f1f7a941ee4d64e28816 100644 (file)
 #include "gtkprivatetypebuiltins.h"
 #include "gtkstylepropertiesprivate.h"
 
+#include <math.h>
 #include <cairo-gobject.h>
 #include "gtkcssimagegradientprivate.h"
 #include "gtkcssimageprivate.h"
 
+/* this is in case round() is not provided by the compiler, 
+ * such as in the case of C89 compilers, like MSVC
+ */
+#include "fallback-c89.c"
+
 enum {
   PROP_0,
   PROP_ID,
@@ -165,6 +171,10 @@ _gtk_css_style_property_query (GtkStyleProperty   *property,
               g_value_take_boxed (value, pattern);
             }
         }
+      else if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_NUMBER)
+        {
+          g_value_set_int (value, round (_gtk_css_number_get (g_value_get_boxed (val), 100)));
+        }
       else
         g_value_copy (val, value);
     }
index 529483b6d7572ed01b65e67adbec6b364c50a910..74c25bc81d7e36622cb404090f5380671872493c 100644 (file)
@@ -443,6 +443,39 @@ compute_margin (GtkCssStyleProperty *property,
   g_value_set_boxed (computed, &number);
 }
 
+static gboolean 
+parse_padding (GtkCssStyleProperty *property,
+               GValue              *value,
+               GtkCssParser        *parser,
+               GFile               *base)
+{
+  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_set_boxed (value, &number);
+  return TRUE;
+}
+
+static void
+compute_padding (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,
@@ -815,41 +848,41 @@ _gtk_css_style_property_init_properties (void)
                                           compute_margin,
                                           &number);
   gtk_css_style_property_register        ("padding-top",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_padding,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_padding,
+                                          &number);
   gtk_css_style_property_register        ("padding-left",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_padding,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_padding,
+                                          &number);
   gtk_css_style_property_register        ("padding-bottom",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_padding,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_padding,
+                                          &number);
   gtk_css_style_property_register        ("padding-right",
-                                          G_TYPE_INT,
-                                          G_TYPE_INT,
+                                          GTK_TYPE_CSS_NUMBER,
+                                          GTK_TYPE_CSS_NUMBER,
                                           G_TYPE_INT,
                                           0,
+                                          parse_padding,
                                           NULL,
-                                          NULL,
-                                          NULL,
-                                          0);
+                                          compute_padding,
+                                          &number);
   /* IMPORTANT: compute_border_width() requires that the border-width
    * properties be immeditaly followed by the border-style properties
    */
index 73d6bd91ea7321bb08ec20fb21f2f9c1f342863e..8c4e6112748edbee35bc0a707bd7864a78c4d6c6 100644 (file)
@@ -15,7 +15,7 @@ GtkButton {
   border-width: 5px;
   border-style: solid;
   border-color: rgba(255,0,0,0.6);
-  padding: 10;
+  padding: 10px;
   background-color: rgb(0,0,255);
 
   /* Make sure children of button are only offset by padding */
index f665eb93fcb4100bd578c053546ac381ba1e80e6..397f5957b17681ee9b4258a5439926ad4c26c3a8 100644 (file)
@@ -16,7 +16,7 @@ GtkButton {
   border-width: 5px;
   border-style: solid;
   border-color: rgba(255,0,0,0.5);
-  padding: 10;
+  padding: 10px;
   background-color: rgb(0,0,255);
 
   background-image: url("green-20x20.png");
index f41a7255bb7f6342607c7e2017a75d1b545c11bf..bd7a31a58f1b0ba582a8d0032e0bf4380e445eed 100644 (file)
@@ -8,5 +8,5 @@
 }
 
 #reference {
-  padding: 20
+  padding: 20px
 }
index 6359b9f4f350a00e606ecdedc93f71c8c9fcf142..f64340951a1dc3480c8570bdc2615e871a987f98 100644 (file)
@@ -9,7 +9,7 @@
 
 GtkEntry #padded {
   -GtkWidget-interior-focus: true;
-  padding: 10;
+  padding: 10px;
 }
 
 .progressbar {