summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2012-01-24 17:49:29 +0100
committerBenjamin Otte <otte@redhat.com>2012-02-02 03:14:02 +0100
commite84af235ee0d99134f929855cba312e4c5fe7d31 (patch)
tree6595e835dc0895723b819e4d1557579ca5a28e5c /gtk
parentf2352a5f35dea9be25951645c19aeab1553760ce (diff)
downloadgtk+-e84af235ee0d99134f929855cba312e4c5fe7d31.tar.gz
css: Implement padding as numbers
Also remove the now unused border parsing function for shorthands.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtk-default.css4
-rw-r--r--gtk/gtk-win32.css2
-rw-r--r--gtk/gtkcssshorthandpropertyimpl.c58
-rw-r--r--gtk/gtkcssstyleproperty.c10
-rw-r--r--gtk/gtkcssstylepropertyimpl.c73
5 files changed, 86 insertions, 61 deletions
diff --git a/gtk/gtk-default.css b/gtk/gtk-default.css
index 9a7fe4e439..a27239e940 100644
--- a/gtk/gtk-default.css
+++ b/gtk/gtk-default.css
@@ -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;
}
diff --git a/gtk/gtk-win32.css b/gtk/gtk-win32.css
index e1782fc941..e1d604a203 100644
--- a/gtk/gtk-win32.css
+++ b/gtk/gtk-win32.css
@@ -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 {
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 3a012ee2a6..cbff861bbf 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -49,38 +49,6 @@ value_is_done_parsing (GtkCssParser *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,
GtkCssParser *parser,
@@ -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",
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index ad713ec422..6e4f23a2e3 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -28,10 +28,16 @@
#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);
}
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 529483b6d7..74c25bc81d 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -444,6 +444,39 @@ compute_margin (GtkCssStyleProperty *property,
}
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,
GtkCssParser *parser,
@@ -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
*/