summaryrefslogtreecommitdiff
path: root/gtk/gtkcssstylepropertyimpl.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2012-04-04 16:15:41 +0200
committerBenjamin Otte <otte@redhat.com>2012-04-17 08:59:18 +0200
commit56f79fecce885e05b7fe1677a70b98c64ea4a85c (patch)
tree7b2e19ed13500e3c7075873a0326b3b29e510bf8 /gtk/gtkcssstylepropertyimpl.c
parentcfc64627304916e1a1848230dbb426e7dc22251f (diff)
downloadgtk+-56f79fecce885e05b7fe1677a70b98c64ea4a85c.tar.gz
cssvalue: Add a border value
.. and parse border-image-slice with it.
Diffstat (limited to 'gtk/gtkcssstylepropertyimpl.c')
-rw-r--r--gtk/gtkcssstylepropertyimpl.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index e5b3461c8d..530a85ec3c 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -42,6 +42,7 @@
#include "gtkbindings.h"
#include "gtkcssarrayvalueprivate.h"
#include "gtkcssbgsizevalueprivate.h"
+#include "gtkcssbordervalueprivate.h"
#include "gtkcsscornervalueprivate.h"
#include "gtkcsseasevalueprivate.h"
#include "gtkcssenginevalueprivate.h"
@@ -159,6 +160,38 @@ assign_length_from_double (GtkCssStyleProperty *property,
return _gtk_css_number_value_new (g_value_get_double (value), GTK_CSS_PX);
}
+static void
+query_border (GtkCssStyleProperty *property,
+ const GtkCssValue *css_value,
+ GValue *value)
+{
+ GtkBorder border;
+
+ g_value_init (value, GTK_TYPE_BORDER);
+
+ border.top = round (_gtk_css_number_value_get (_gtk_css_border_value_get_top (css_value), 100));
+ border.right = round (_gtk_css_number_value_get (_gtk_css_border_value_get_right (css_value), 100));
+ border.bottom = round (_gtk_css_number_value_get (_gtk_css_border_value_get_bottom (css_value), 100));
+ border.left = round (_gtk_css_number_value_get (_gtk_css_border_value_get_left (css_value), 100));
+
+ g_value_set_boxed (value, &border);
+}
+
+static GtkCssValue *
+assign_border (GtkCssStyleProperty *property,
+ const GValue *value)
+{
+ const GtkBorder *border = g_value_get_boxed (value);
+
+ if (border == NULL)
+ return _gtk_css_value_ref (_gtk_css_style_property_get_initial_value (property));
+ else
+ return _gtk_css_border_value_new (_gtk_css_number_value_new (border->top, GTK_CSS_PX),
+ _gtk_css_number_value_new (border->right, GTK_CSS_PX),
+ _gtk_css_number_value_new (border->bottom, GTK_CSS_PX),
+ _gtk_css_number_value_new (border->left, GTK_CSS_PX));
+}
+
static GtkCssValue *
color_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
@@ -683,20 +716,12 @@ border_image_slice_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
- GValue value = G_VALUE_INIT;
- GtkCssValue *result;
-
- g_value_init (&value, GTK_TYPE_BORDER);
- if (!_gtk_css_style_parse_value (&value, parser, base))
- {
- g_value_unset (&value);
- return NULL;
- }
-
- result = _gtk_css_value_new_from_gvalue (&value);
- g_value_unset (&value);
-
- return result;
+ return _gtk_css_border_value_parse (parser,
+ GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_PARSE_NUMBER
+ | GTK_CSS_POSITIVE_ONLY,
+ FALSE,
+ TRUE);
}
static GtkCssValue *
@@ -721,6 +746,14 @@ border_image_width_parse (GtkCssStyleProperty *property,
}
static GtkCssValue *
+compute_border (GtkCssStyleProperty *property,
+ GtkStyleContext *context,
+ GtkCssValue *specified)
+{
+ return _gtk_css_border_value_compute (specified, context);
+}
+
+static GtkCssValue *
transition_property_parse_one (GtkCssParser *parser)
{
GtkCssValue *value;
@@ -942,8 +975,6 @@ gtk_symbolic_color_new_rgba (double red,
void
_gtk_css_style_property_init_properties (void)
{
- GtkBorder border_of_ones = { 1, 1, 1, 1 };
-
/* Initialize "color" and "font-size" first,
* so that when computing values later they are
* done first. That way, 'currentColor' and font
@@ -1492,18 +1523,20 @@ _gtk_css_style_property_init_properties (void)
_gtk_css_border_repeat_value_new (GTK_CSS_REPEAT_STYLE_STRETCH,
GTK_CSS_REPEAT_STYLE_STRETCH));
- /* XXX: The initial value is wrong, it should be 100% */
gtk_css_style_property_register ("border-image-slice",
GTK_CSS_PROPERTY_BORDER_IMAGE_SLICE,
GTK_TYPE_BORDER,
0,
border_image_slice_parse,
NULL,
+ compute_border,
+ query_border,
+ assign_border,
NULL,
- query_simple,
- assign_simple,
- NULL,
- _gtk_css_value_new_from_boxed (GTK_TYPE_BORDER, &border_of_ones));
+ _gtk_css_border_value_new (_gtk_css_number_value_new (100, GTK_CSS_PERCENT),
+ _gtk_css_number_value_new (100, GTK_CSS_PERCENT),
+ _gtk_css_number_value_new (100, GTK_CSS_PERCENT),
+ _gtk_css_number_value_new (100, GTK_CSS_PERCENT)));
gtk_css_style_property_register ("border-image-width",
GTK_CSS_PROPERTY_BORDER_IMAGE_WIDTH,
GTK_TYPE_BORDER,