summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2012-01-15 06:26:08 +0100
committerBenjamin Otte <otte@redhat.com>2012-02-02 03:14:00 +0100
commita63ff724060c0a9ff9299d294e17b59aab46f81f (patch)
tree04a26d5c42745d63f05381da2bee291c1222c91b /gtk
parent82c2dad178b918699372a1d2942753af25908438 (diff)
downloadgtk+-a63ff724060c0a9ff9299d294e17b59aab46f81f.tar.gz
css: Convert border-radius to GtkCssNumber
We can do % now, wohoo!
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkcssshorthandpropertyimpl.c33
-rw-r--r--gtk/gtkcssstylepropertyimpl.c52
-rw-r--r--gtk/gtkcsstypes.c18
-rw-r--r--gtk/gtkcsstypesprivate.h8
-rw-r--r--gtk/gtkroundedbox.c34
-rw-r--r--gtk/gtkroundedboxprivate.h8
-rw-r--r--gtk/gtkstylecontext.c7
-rw-r--r--gtk/gtkthemingengine.c16
8 files changed, 105 insertions, 71 deletions
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index d0aa8acd0f..3f01074239 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -133,13 +133,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)
@@ -157,13 +159,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)
@@ -638,7 +642,8 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand,
GValue v = G_VALUE_INIT;
guint i;
- border.horizontal = border.vertical = g_value_get_int (value);
+ _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);
@@ -664,7 +669,7 @@ pack_border_radius (GtkCssShorthandProperty *shorthand,
{
top_left = g_value_get_boxed (v);
if (top_left)
- g_value_set_int (value, top_left->horizontal);
+ g_value_set_int (value, top_left->horizontal.value);
}
}
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 7f01fe4584..66dc005e4c 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -101,16 +101,6 @@ gtk_css_style_property_register (const char * name,
/*** HELPERS ***/
static void
-string_append_double (GString *string,
- double d)
-{
- char buf[G_ASCII_DTOSTR_BUF_SIZE];
-
- g_ascii_dtostr (buf, sizeof (buf), d);
- g_string_append (string, buf);
-}
-
-static void
string_append_string (GString *str,
const char *string)
{
@@ -333,25 +323,26 @@ border_corner_radius_value_parse (GtkCssStyleProperty *property,
{
GtkCssBorderCornerRadius corner;
- if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
- {
- _gtk_css_parser_error (parser, "Expected a number");
- return FALSE;
- }
- else if (corner.horizontal < 0)
- goto negative;
+ if (!_gtk_css_parser_read_number (parser,
+ &corner.horizontal,
+ GTK_CSS_POSITIVE_ONLY
+ | GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_NUMBER_AS_PIXELS
+ | GTK_CSS_PARSE_LENGTH))
+ return FALSE;
- if (!_gtk_css_parser_try_double (parser, &corner.vertical))
+ if (!_gtk_css_parser_has_number (parser))
corner.vertical = corner.horizontal;
- else if (corner.vertical < 0)
- goto negative;
+ else if (!_gtk_css_parser_read_number (parser,
+ &corner.vertical,
+ GTK_CSS_POSITIVE_ONLY
+ | GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_NUMBER_AS_PIXELS
+ | GTK_CSS_PARSE_LENGTH))
+ return FALSE;
g_value_set_boxed (value, &corner);
return TRUE;
-
-negative:
- _gtk_css_parser_error (parser, "Border radius values cannot be negative");
- return FALSE;
}
static void
@@ -363,17 +354,12 @@ border_corner_radius_value_print (GtkCssStyleProperty *property,
corner = g_value_get_boxed (value);
- if (corner == NULL)
- {
- g_string_append (string, "none");
- return;
- }
+ _gtk_css_number_print (&corner->horizontal, string);
- string_append_double (string, corner->horizontal);
- if (corner->horizontal != corner->vertical)
+ if (!_gtk_css_number_equal (&corner->horizontal, &corner->vertical))
{
g_string_append_c (string, ' ');
- string_append_double (string, corner->vertical);
+ _gtk_css_number_print (&corner->vertical, string);
}
}
@@ -558,7 +544,7 @@ _gtk_css_style_property_init_properties (void)
char *default_font_family[] = { "Sans", NULL };
GtkCssNumber number;
GtkSymbolicColor *symbolic;
- GtkCssBorderCornerRadius no_corner_radius = { 0, };
+ GtkCssBorderCornerRadius no_corner_radius = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX) };
GtkBorder border_of_ones = { 1, 1, 1, 1 };
GtkCssBorderImageRepeat border_image_repeat = { GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_STRETCH };
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index c2929d6266..2cb883354e 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -45,6 +45,24 @@ _gtk_css_number_init (GtkCssNumber *number,
number->unit = unit;
}
+gboolean
+_gtk_css_number_equal (const GtkCssNumber *one,
+ const GtkCssNumber *two)
+{
+ return one->unit == two->unit &&
+ one->value == two->value;
+}
+
+double
+_gtk_css_number_get (const GtkCssNumber *number,
+ double one_hundred_percent)
+{
+ if (number->unit == GTK_CSS_PERCENT)
+ return number->value * one_hundred_percent * 0.01;
+ else
+ return number->value;
+}
+
void
_gtk_css_number_compute (GtkCssNumber *dest,
const GtkCssNumber *src,
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 6422d9a02c..493978f1b8 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -104,8 +104,8 @@ struct _GtkCssNumber {
};
struct _GtkCssBorderCornerRadius {
- double horizontal;
- double vertical;
+ GtkCssNumber horizontal;
+ GtkCssNumber vertical;
};
struct _GtkCssBorderImageRepeat {
@@ -125,6 +125,10 @@ GType _gtk_css_number_get_type (void);
void _gtk_css_number_init (GtkCssNumber *number,
double value,
GtkCssUnit unit);
+gboolean _gtk_css_number_equal (const GtkCssNumber *one,
+ const GtkCssNumber *two);
+double _gtk_css_number_get (const GtkCssNumber *number,
+ double one_hundred_percent);
void _gtk_css_number_compute (GtkCssNumber *dest,
const GtkCssNumber *src,
GtkStyleContext *context);
diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c
index 1aea2eeaae..94451e8158 100644
--- a/gtk/gtkroundedbox.c
+++ b/gtk/gtkroundedbox.c
@@ -94,13 +94,33 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
NULL);
if (corner[GTK_CSS_TOP_LEFT] && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0)
- box->corner[GTK_CSS_TOP_LEFT] = *corner[GTK_CSS_TOP_LEFT];
+ {
+ box->corner[GTK_CSS_TOP_LEFT].horizontal = _gtk_css_number_get (&corner[GTK_CSS_TOP_LEFT]->horizontal,
+ box->box.width);
+ box->corner[GTK_CSS_TOP_LEFT].vertical = _gtk_css_number_get (&corner[GTK_CSS_TOP_LEFT]->vertical,
+ box->box.height);
+ }
if (corner[GTK_CSS_TOP_RIGHT] && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0)
- box->corner[GTK_CSS_TOP_RIGHT] = *corner[GTK_CSS_TOP_RIGHT];
+ {
+ box->corner[GTK_CSS_TOP_RIGHT].horizontal = _gtk_css_number_get (&corner[GTK_CSS_TOP_RIGHT]->horizontal,
+ box->box.width);
+ box->corner[GTK_CSS_TOP_RIGHT].vertical = _gtk_css_number_get (&corner[GTK_CSS_TOP_RIGHT]->vertical,
+ box->box.height);
+ }
if (corner[GTK_CSS_BOTTOM_RIGHT] && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0)
- box->corner[GTK_CSS_BOTTOM_RIGHT] = *corner[GTK_CSS_BOTTOM_RIGHT];
+ {
+ box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal = _gtk_css_number_get (&corner[GTK_CSS_BOTTOM_RIGHT]->horizontal,
+ box->box.width);
+ box->corner[GTK_CSS_BOTTOM_RIGHT].vertical = _gtk_css_number_get (&corner[GTK_CSS_BOTTOM_RIGHT]->vertical,
+ box->box.height);
+ }
if (corner[GTK_CSS_BOTTOM_LEFT] && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0)
- box->corner[GTK_CSS_BOTTOM_LEFT] = *corner[GTK_CSS_BOTTOM_LEFT];
+ {
+ box->corner[GTK_CSS_BOTTOM_LEFT].horizontal = _gtk_css_number_get (&corner[GTK_CSS_BOTTOM_LEFT]->horizontal,
+ box->box.width);
+ box->corner[GTK_CSS_BOTTOM_LEFT].vertical = _gtk_css_number_get (&corner[GTK_CSS_BOTTOM_LEFT]->vertical,
+ box->box.height);
+ }
gtk_rounded_box_clamp_border_radius (box);
@@ -109,9 +129,9 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
}
static void
-gtk_css_border_radius_grow (GtkCssBorderCornerRadius *corner,
- double horizontal,
- double vertical)
+gtk_css_border_radius_grow (GtkRoundedBoxCorner *corner,
+ double horizontal,
+ double vertical)
{
corner->horizontal += horizontal;
corner->vertical += vertical;
diff --git a/gtk/gtkroundedboxprivate.h b/gtk/gtkroundedboxprivate.h
index 98309e7f36..07987c4dda 100644
--- a/gtk/gtkroundedboxprivate.h
+++ b/gtk/gtkroundedboxprivate.h
@@ -30,11 +30,17 @@
G_BEGIN_DECLS
typedef struct _GtkRoundedBox GtkRoundedBox;
+typedef struct _GtkRoundedBoxCorner GtkRoundedBoxCorner;
+
+struct _GtkRoundedBoxCorner {
+ double horizontal;
+ double vertical;
+};
struct _GtkRoundedBox {
/*< private >*/
cairo_rectangle_t box;
- GtkCssBorderCornerRadius corner[4];
+ GtkRoundedBoxCorner corner[4];
};
void _gtk_rounded_box_init_rect (GtkRoundedBox *box,
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index c4669eb586..e497d1f249 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -2378,14 +2378,9 @@ _gtk_style_context_get_number (GtkStyleContext *context,
double one_hundred_percent)
{
const GValue *value;
- const GtkCssNumber *number;
value = _gtk_style_context_peek_property (context, property_name);
- number = g_value_get_boxed (value);
- if (number->unit == GTK_CSS_PERCENT)
- return number->value * one_hundred_percent * 0.01;
- else
- return number->value;
+ return _gtk_css_number_get (g_value_get_boxed (value), one_hundred_percent);
}
const GValue *
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index ce90769ed6..21bcdb80c6 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -2223,10 +2223,10 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
hc = border_width;
- if (xy0_gap < top_left_radius->horizontal)
+ if (xy0_gap < _gtk_css_number_get (&top_left_radius->horizontal, width))
junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- if (xy1_gap > width - top_right_radius->horizontal)
+ if (xy1_gap > width - _gtk_css_number_get (&top_right_radius->horizontal, width))
junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
break;
case GTK_POS_BOTTOM:
@@ -2235,10 +2235,10 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
wc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
hc = border_width;
- if (xy0_gap < bottom_left_radius->horizontal)
+ if (xy0_gap < _gtk_css_number_get (&bottom_left_radius->horizontal, width))
junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
- if (xy1_gap > width - bottom_right_radius->horizontal)
+ if (xy1_gap > width - _gtk_css_number_get (&bottom_right_radius->horizontal, width))
junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
break;
@@ -2248,10 +2248,10 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
wc = border_width;
hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
- if (xy0_gap < top_left_radius->vertical)
+ if (xy0_gap < _gtk_css_number_get (&top_left_radius->vertical, height))
junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- if (xy1_gap > height - bottom_left_radius->vertical)
+ if (xy1_gap > height - _gtk_css_number_get (&bottom_left_radius->vertical, height))
junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
break;
@@ -2261,10 +2261,10 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
wc = border_width;
hc = MAX (xy1_gap - xy0_gap - 2 * border_width, 0);
- if (xy0_gap < top_right_radius->vertical)
+ if (xy0_gap < _gtk_css_number_get (&top_right_radius->vertical, height))
junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
- if (xy1_gap > height - bottom_right_radius->vertical)
+ if (xy1_gap > height - _gtk_css_number_get (&bottom_right_radius->vertical, height))
junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
break;