[gtk+/wip/cssvalue] cssvalue: Add a value for border-radius corner properties
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue] cssvalue: Add a value for border-radius corner properties
- Date: Wed, 4 Apr 2012 10:44:43 +0000 (UTC)
commit 349255f388c70411a7ec4adc9e6092dcfe4c3963
Author: Benjamin Otte <otte redhat com>
Date: Tue Apr 3 18:39:01 2012 +0200
cssvalue: Add a value for border-radius corner properties
... and convert those properties to this value.
gtk/Makefile.am | 2 +
gtk/gtkcsscornervalue.c | 164 +++++++++++++++++++++++++++++++++++++
gtk/gtkcsscornervalueprivate.h | 42 ++++++++++
gtk/gtkcssshorthandpropertyimpl.c | 89 +++++++++++----------
gtk/gtkcssstylepropertyimpl.c | 88 +++++++-------------
gtk/gtkcsstypes.c | 1 -
gtk/gtkcsstypesprivate.h | 8 --
gtk/gtkcssvalue.c | 18 ----
gtk/gtkcssvalueprivate.h | 2 -
gtk/gtkroundedbox.c | 65 +++++++--------
gtk/gtkroundedboxprivate.h | 5 -
gtk/gtkthemingbackground.c | 2 +-
gtk/gtkthemingengine.c | 37 ++++-----
13 files changed, 331 insertions(+), 192 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 8c8408d..1f404b1 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -425,6 +425,7 @@ gtk_private_h_sources = \
gtkcontainerprivate.h \
gtkcssarrayvalueprivate.h \
gtkcsscomputedvaluesprivate.h \
+ gtkcsscornervalueprivate.h \
gtkcsscustompropertyprivate.h \
gtkcsseasevalueprivate.h \
gtkcssenumvalueprivate.h \
@@ -633,6 +634,7 @@ gtk_base_c_sources = \
gtkcontainer.c \
gtkcssarrayvalue.c \
gtkcsscomputedvalues.c \
+ gtkcsscornervalue.c \
gtkcsscustomproperty.c \
gtkcsseasevalue.c \
gtkcssenumvalue.c \
diff --git a/gtk/gtkcsscornervalue.c b/gtk/gtkcsscornervalue.c
new file mode 100644
index 0000000..c0db4dd
--- /dev/null
+++ b/gtk/gtkcsscornervalue.c
@@ -0,0 +1,164 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkcsscornervalueprivate.h"
+
+#include "gtkcssnumbervalueprivate.h"
+
+struct _GtkCssValue {
+ GTK_CSS_VALUE_BASE
+ GtkCssValue *x;
+ GtkCssValue *y;
+};
+
+static void
+gtk_css_value_corner_free (GtkCssValue *value)
+{
+ _gtk_css_value_unref (value->x);
+ _gtk_css_value_unref (value->y);
+
+ g_slice_free (GtkCssValue, value);
+}
+
+static gboolean
+gtk_css_value_corner_equal (const GtkCssValue *corner1,
+ const GtkCssValue *corner2)
+{
+ return _gtk_css_value_equal (corner1->x, corner2->x)
+ && _gtk_css_value_equal (corner1->y, corner2->y);
+}
+
+static GtkCssValue *
+gtk_css_value_corner_transition (GtkCssValue *start,
+ GtkCssValue *end,
+ double progress)
+{
+ GtkCssValue *x, *y;
+
+ x = _gtk_css_value_transition (start->x, end->x, progress);
+ if (x == NULL)
+ return NULL;
+ y = _gtk_css_value_transition (start->y, end->y, progress);
+ if (y == NULL)
+ {
+ _gtk_css_value_unref (x);
+ return NULL;
+ }
+
+ return _gtk_css_corner_value_new (x, y);
+}
+
+static void
+gtk_css_value_corner_print (const GtkCssValue *corner,
+ GString *string)
+{
+ _gtk_css_value_print (corner->x, string);
+ if (!_gtk_css_value_equal (corner->x, corner->y))
+ {
+ g_string_append_c (string, ' ');
+ _gtk_css_value_print (corner->y, string);
+ }
+}
+
+static const GtkCssValueClass GTK_CSS_VALUE_CORNER = {
+ gtk_css_value_corner_free,
+ gtk_css_value_corner_equal,
+ gtk_css_value_corner_transition,
+ gtk_css_value_corner_print
+};
+
+GtkCssValue *
+_gtk_css_corner_value_new (GtkCssValue *x,
+ GtkCssValue *y)
+{
+ GtkCssValue *result;
+
+ result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_CORNER);
+ result->x = x;
+ result->y = y;
+
+ return result;
+}
+
+GtkCssValue *
+_gtk_css_corner_value_parse (GtkCssParser *parser)
+{
+ GtkCssValue *x, *y;
+
+ x = _gtk_css_number_value_parse (parser,
+ GTK_CSS_POSITIVE_ONLY
+ | GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_NUMBER_AS_PIXELS
+ | GTK_CSS_PARSE_LENGTH);
+ if (x == NULL)
+ return NULL;
+
+ if (!_gtk_css_parser_has_number (parser))
+ y = _gtk_css_value_ref (x);
+ else
+ {
+ y = _gtk_css_number_value_parse (parser,
+ GTK_CSS_POSITIVE_ONLY
+ | GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_NUMBER_AS_PIXELS
+ | GTK_CSS_PARSE_LENGTH);
+ if (y == NULL)
+ {
+ _gtk_css_value_unref (x);
+ return NULL;
+ }
+ }
+
+ return _gtk_css_corner_value_new (x, y);
+}
+
+double
+_gtk_css_corner_value_get_x (const GtkCssValue *corner,
+ double one_hundred_percent)
+{
+ g_return_val_if_fail (corner != NULL, 0.0);
+ g_return_val_if_fail (corner->class == >K_CSS_VALUE_CORNER, 0.0);
+
+ return _gtk_css_number_value_get (corner->x, one_hundred_percent);
+}
+
+double
+_gtk_css_corner_value_get_y (const GtkCssValue *corner,
+ double one_hundred_percent)
+{
+ g_return_val_if_fail (corner != NULL, 0.0);
+ g_return_val_if_fail (corner->class == >K_CSS_VALUE_CORNER, 0.0);
+
+ return _gtk_css_number_value_get (corner->y, one_hundred_percent);
+}
+
+GtkCssValue *
+_gtk_css_corner_value_compute (GtkCssValue *corner,
+ GtkStyleContext *context)
+{
+ GtkCssValue *x, *y;
+
+ g_return_val_if_fail (corner->class == >K_CSS_VALUE_CORNER, NULL);
+
+ x = _gtk_css_number_value_compute (corner->x, context);
+ y = _gtk_css_number_value_compute (corner->y, context);
+
+ return _gtk_css_corner_value_new (x, y);
+}
+
diff --git a/gtk/gtkcsscornervalueprivate.h b/gtk/gtkcsscornervalueprivate.h
new file mode 100644
index 0000000..8427c00
--- /dev/null
+++ b/gtk/gtkcsscornervalueprivate.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright  2012 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Alexander Larsson <alexl gnome org>
+ */
+
+#ifndef __GTK_CSS_COORD_VALUE_PRIVATE_H__
+#define __GTK_CSS_COORD_VALUE_PRIVATE_H__
+
+#include "gtkcssparserprivate.h"
+#include "gtkcssvalueprivate.h"
+
+G_BEGIN_DECLS
+
+GtkCssValue * _gtk_css_corner_value_new (GtkCssValue *x,
+ GtkCssValue *y);
+GtkCssValue * _gtk_css_corner_value_parse (GtkCssParser *parser);
+
+double _gtk_css_corner_value_get_x (const GtkCssValue *corner,
+ double one_hundred_percent);
+double _gtk_css_corner_value_get_y (const GtkCssValue *corner,
+ double one_hundred_percent);
+GtkCssValue * _gtk_css_corner_value_compute (GtkCssValue *corner,
+ GtkStyleContext *context);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_COORD_VALUE_PRIVATE_H__ */
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 11d94b8..241aafc 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -25,6 +25,7 @@
#include <math.h>
#include "gtkcssarrayvalueprivate.h"
+#include "gtkcsscornervalueprivate.h"
#include "gtkcssenumvalueprivate.h"
#include "gtkcssimageprivate.h"
#include "gtkcssimagevalueprivate.h"
@@ -132,70 +133,79 @@ parse_border_radius (GtkCssShorthandProperty *shorthand,
GtkCssParser *parser,
GFile *base)
{
- GtkCssBorderCornerRadius borders[4];
+ GtkCssValue *x[4] = { NULL, }, *y[4] = { NULL, };
guint i;
- for (i = 0; i < G_N_ELEMENTS (borders); i++)
+ for (i = 0; i < 4; i++)
{
if (!_gtk_css_parser_has_number (parser))
break;
- 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;
+ x[i] = _gtk_css_number_value_parse (parser,
+ GTK_CSS_POSITIVE_ONLY
+ | GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_NUMBER_AS_PIXELS
+ | GTK_CSS_PARSE_LENGTH);
+ if (x[i] == NULL)
+ goto fail;
}
if (i == 0)
{
_gtk_css_parser_error (parser, "Expected a number");
- return FALSE;
+ goto fail;
}
/* The magic (i - 1) >> 1 below makes it take the correct value
* according to spec. Feel free to check the 4 cases */
- for (; i < G_N_ELEMENTS (borders); i++)
- borders[i].horizontal = borders[(i - 1) >> 1].horizontal;
+ for (; i < 4; i++)
+ x[i] = _gtk_css_value_ref (x[(i - 1) >> 1]);
if (_gtk_css_parser_try (parser, "/", TRUE))
{
- for (i = 0; i < G_N_ELEMENTS (borders); i++)
+ for (i = 0; i < 4; i++)
{
if (!_gtk_css_parser_has_number (parser))
break;
- 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;
+ y[i] = _gtk_css_number_value_parse (parser,
+ GTK_CSS_POSITIVE_ONLY
+ | GTK_CSS_PARSE_PERCENT
+ | GTK_CSS_NUMBER_AS_PIXELS
+ | GTK_CSS_PARSE_LENGTH);
+ if (y[i] == NULL)
+ goto fail;
}
if (i == 0)
{
_gtk_css_parser_error (parser, "Expected a number");
- return FALSE;
+ goto fail;
}
- for (; i < G_N_ELEMENTS (borders); i++)
- borders[i].vertical = borders[(i - 1) >> 1].vertical;
-
+ for (; i < 4; i++)
+ y[i] = _gtk_css_value_ref (y[(i - 1) >> 1]);
}
else
{
- for (i = 0; i < G_N_ELEMENTS (borders); i++)
- borders[i].vertical = borders[i].horizontal;
+ for (i = 0; i < 4; i++)
+ y[i] = _gtk_css_value_ref (x[i]);
}
- for (i = 0; i < G_N_ELEMENTS (borders); i++)
+ for (i = 0; i < 4; i++)
{
- values[i] = _gtk_css_value_new_from_border_corner_radius (&borders[i]);
+ values[i] = _gtk_css_corner_value_new (x[i], y[i]);
}
return TRUE;
+
+fail:
+ for (i = 0; i < 4; i++)
+ {
+ if (x[i])
+ _gtk_css_value_unref (x[i]);
+ if (y[i])
+ _gtk_css_value_unref (y[i]);
+ }
+ return FALSE;
}
static gboolean
@@ -606,19 +616,19 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand,
GtkStateFlags state,
const GValue *value)
{
- GtkCssBorderCornerRadius border;
- GValue v = G_VALUE_INIT;
+ GtkCssValue *css_value;
guint i;
- _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);
+ css_value = _gtk_css_corner_value_new (_gtk_css_number_value_new (g_value_get_int (value), GTK_CSS_PX),
+ _gtk_css_number_value_new (g_value_get_int (value), GTK_CSS_PX));
for (i = 0; i < 4; i++)
- _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, i)), props, state, &v);
+ _gtk_style_properties_set_property_by_property (props,
+ _gtk_css_shorthand_property_get_subproperty (shorthand, i),
+ state,
+ css_value);
- g_value_unset (&v);
+ _gtk_css_value_unref (css_value);
}
static void
@@ -627,7 +637,6 @@ pack_border_radius (GtkCssShorthandProperty *shorthand,
GtkStyleQueryFunc query_func,
gpointer query_data)
{
- const GtkCssBorderCornerRadius *top_left;
GtkCssStyleProperty *prop;
GtkCssValue *v;
int i = 0;
@@ -635,11 +644,7 @@ pack_border_radius (GtkCssShorthandProperty *shorthand,
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 = _gtk_css_value_get_border_corner_radius (v);
- if (top_left)
- i = top_left->horizontal.value;
- }
+ i = _gtk_css_corner_value_get_x (v, 100);
g_value_init (value, G_TYPE_INT);
g_value_set_int (value, i);
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index c43d851..3d36789 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -41,6 +41,7 @@
#include "gtkanimationdescription.h"
#include "gtkbindings.h"
#include "gtkcssarrayvalueprivate.h"
+#include "gtkcsscornervalueprivate.h"
#include "gtkcsseasevalueprivate.h"
#include "gtkcssimagegradientprivate.h"
#include "gtkcssimageprivate.h"
@@ -502,45 +503,15 @@ border_corner_radius_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
- GtkCssBorderCornerRadius corner;
-
- 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_has_number (parser))
- corner.vertical = corner.horizontal;
- 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;
-
- return _gtk_css_value_new_from_border_corner_radius (&corner);
+ return _gtk_css_corner_value_parse (parser);
}
-static void
-border_corner_radius_value_print (GtkCssStyleProperty *property,
- const GtkCssValue *value,
- GString *string)
+static GtkCssValue *
+border_corner_radius_value_compute (GtkCssStyleProperty *property,
+ GtkStyleContext *context,
+ GtkCssValue *specified)
{
- const GtkCssBorderCornerRadius *corner;
-
- corner = _gtk_css_value_get_border_corner_radius (value);
-
- _gtk_css_number_print (&corner->horizontal, string);
-
- if (!_gtk_css_number_equal (&corner->horizontal, &corner->vertical))
- {
- g_string_append_c (string, ' ');
- _gtk_css_number_print (&corner->vertical, string);
- }
+ return _gtk_css_corner_value_compute (specified, context);
}
static GtkCssValue *
@@ -1226,7 +1197,6 @@ _gtk_css_style_property_init_properties (void)
{
GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE };
GtkCssBackgroundPosition default_background_position = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT)};
- 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 };
@@ -1537,48 +1507,52 @@ _gtk_css_style_property_init_properties (void)
gtk_css_style_property_register ("border-top-left-radius",
GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS,
- GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
+ G_TYPE_NONE,
0,
border_corner_radius_value_parse,
- border_corner_radius_value_print,
NULL,
- query_simple,
- assign_simple,
+ border_corner_radius_value_compute,
+ NULL,
+ NULL,
NULL,
- _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
+ _gtk_css_corner_value_new (_gtk_css_number_value_new (0, GTK_CSS_PX),
+ _gtk_css_number_value_new (0, GTK_CSS_PX)));
gtk_css_style_property_register ("border-top-right-radius",
GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS,
- GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
+ G_TYPE_NONE,
0,
border_corner_radius_value_parse,
- border_corner_radius_value_print,
NULL,
- query_simple,
- assign_simple,
+ border_corner_radius_value_compute,
+ NULL,
NULL,
- _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
+ NULL,
+ _gtk_css_corner_value_new (_gtk_css_number_value_new (0, GTK_CSS_PX),
+ _gtk_css_number_value_new (0, GTK_CSS_PX)));
gtk_css_style_property_register ("border-bottom-right-radius",
GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS,
- GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
+ G_TYPE_NONE,
0,
border_corner_radius_value_parse,
- border_corner_radius_value_print,
NULL,
- query_simple,
- assign_simple,
+ border_corner_radius_value_compute,
NULL,
- _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
+ NULL,
+ NULL,
+ _gtk_css_corner_value_new (_gtk_css_number_value_new (0, GTK_CSS_PX),
+ _gtk_css_number_value_new (0, GTK_CSS_PX)));
gtk_css_style_property_register ("border-bottom-left-radius",
GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS,
- GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
+ G_TYPE_NONE,
0,
border_corner_radius_value_parse,
- border_corner_radius_value_print,
NULL,
- query_simple,
- assign_simple,
+ border_corner_radius_value_compute,
+ NULL,
+ NULL,
NULL,
- _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
+ _gtk_css_corner_value_new (_gtk_css_number_value_new (0, GTK_CSS_PX),
+ _gtk_css_number_value_new (0, GTK_CSS_PX)));
gtk_css_style_property_register ("outline-style",
GTK_CSS_PROPERTY_OUTLINE_STYLE,
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index 640ab31..f3031e1 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -34,7 +34,6 @@ G_DEFINE_BOXED_TYPE (TypeName, type_name, type_name ## _copy, g_free)
DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBackgroundSize, _gtk_css_background_size)
DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBackgroundPosition, _gtk_css_background_position)
-DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBorderCornerRadius, _gtk_css_border_corner_radius)
DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBorderImageRepeat, _gtk_css_border_image_repeat)
typedef struct _GtkCssChangeTranslation GtkCssChangeTranslation;
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 4ac71f5..05185d7 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -187,7 +187,6 @@ typedef enum /*< skip >*/ {
typedef struct _GtkCssNumber GtkCssNumber;
typedef struct _GtkCssBackgroundSize GtkCssBackgroundSize;
typedef struct _GtkCssBackgroundPosition GtkCssBackgroundPosition;
-typedef struct _GtkCssBorderCornerRadius GtkCssBorderCornerRadius;
typedef struct _GtkCssBorderImageRepeat GtkCssBorderImageRepeat;
struct _GtkCssNumber {
@@ -207,11 +206,6 @@ struct _GtkCssBackgroundPosition {
GtkCssNumber y;
};
-struct _GtkCssBorderCornerRadius {
- GtkCssNumber horizontal;
- GtkCssNumber vertical;
-};
-
struct _GtkCssBorderImageRepeat {
GtkCssBorderRepeatStyle vrepeat;
GtkCssBorderRepeatStyle hrepeat;
@@ -219,12 +213,10 @@ struct _GtkCssBorderImageRepeat {
#define GTK_TYPE_CSS_BACKGROUND_SIZE _gtk_css_background_size_get_type ()
#define GTK_TYPE_CSS_BACKGROUND_POSITION _gtk_css_background_position_get_type ()
-#define GTK_TYPE_CSS_BORDER_CORNER_RADIUS _gtk_css_border_corner_radius_get_type ()
#define GTK_TYPE_CSS_BORDER_IMAGE_REPEAT _gtk_css_border_image_repeat_get_type ()
GType _gtk_css_background_size_get_type (void);
GType _gtk_css_background_position_get_type (void);
-GType _gtk_css_border_corner_radius_get_type (void);
GType _gtk_css_border_image_repeat_get_type (void);
GtkCssChange _gtk_css_change_for_sibling (GtkCssChange match);
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index f3bca9e..86b76b0 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -283,17 +283,6 @@ _gtk_css_value_new_from_background_position (const GtkCssBackgroundPosition *v)
}
GtkCssValue *
-_gtk_css_value_new_from_border_corner_radius (const GtkCssBorderCornerRadius *v)
-{
- GtkCssValue *value;
-
- value = gtk_css_value_new (GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
- value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_BORDER_CORNER_RADIUS, v);
-
- return value;
-}
-
-GtkCssValue *
_gtk_css_value_new_from_border_image_repeat (const GtkCssBorderImageRepeat *v)
{
GtkCssValue *value;
@@ -550,13 +539,6 @@ _gtk_css_value_get_border_image_repeat (const GtkCssValue *value)
return value->u.ptr;
}
-const GtkCssBorderCornerRadius *
-_gtk_css_value_get_border_corner_radius (const GtkCssValue *value)
-{
- g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS), NULL);
- return value->u.ptr;
-}
-
GtkGradient *
_gtk_css_value_get_gradient (const GtkCssValue *value)
{
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index a3143a3..aacc230 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -92,7 +92,6 @@ GtkCssValue *_gtk_css_value_new_from_theming_engine (GtkThemingEngine
GtkCssValue *_gtk_css_value_new_take_binding_sets (GPtrArray *array);
GtkCssValue *_gtk_css_value_new_from_background_size (const GtkCssBackgroundSize *v);
GtkCssValue *_gtk_css_value_new_from_background_position (const GtkCssBackgroundPosition *v);
-GtkCssValue *_gtk_css_value_new_from_border_corner_radius (const GtkCssBorderCornerRadius *v);
GtkCssValue *_gtk_css_value_new_from_border_image_repeat (const GtkCssBorderImageRepeat *v);
void _gtk_css_value_init_gvalue (const GtkCssValue *value,
GValue *g_value);
@@ -106,7 +105,6 @@ const char ** _gtk_css_value_get_strv (const
GtkSymbolicColor *_gtk_css_value_get_symbolic_color (const GtkCssValue *value);
const GtkCssBackgroundSize *_gtk_css_value_get_background_size (const GtkCssValue *value);
const GtkCssBackgroundPosition *_gtk_css_value_get_background_position (const GtkCssValue *value);
-const GtkCssBorderCornerRadius *_gtk_css_value_get_border_corner_radius (const GtkCssValue *value);
const GtkCssBorderImageRepeat *_gtk_css_value_get_border_image_repeat (const GtkCssValue *value);
GtkGradient *_gtk_css_value_get_gradient (const GtkCssValue *value);
diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c
index e9ed1c5..2b11982 100644
--- a/gtk/gtkroundedbox.c
+++ b/gtk/gtkroundedbox.c
@@ -18,6 +18,10 @@
#include "config.h"
#include "gtkroundedboxprivate.h"
+
+#include "gtkcsscornervalueprivate.h"
+#include "gtkcsstypesprivate.h"
+#include "gtkstylecontextprivate.h"
#include "gtkthemingengineprivate.h"
#include <string.h>
@@ -74,38 +78,38 @@ gtk_rounded_box_clamp_border_radius (GtkRoundedBox *box)
box->corner[GTK_CSS_BOTTOM_LEFT].vertical *= factor;
}
-void
+static void
_gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
- GtkCssBorderCornerRadius **corner,
+ GtkCssValue **corner,
GtkJunctionSides junction)
{
if (corner[GTK_CSS_TOP_LEFT] && (junction & GTK_JUNCTION_CORNER_TOPLEFT) == 0)
{
- 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);
+ box->corner[GTK_CSS_TOP_LEFT].horizontal = _gtk_css_corner_value_get_x (corner[GTK_CSS_TOP_LEFT],
+ box->box.width);
+ box->corner[GTK_CSS_TOP_LEFT].vertical = _gtk_css_corner_value_get_y (corner[GTK_CSS_TOP_LEFT],
+ box->box.height);
}
if (corner[GTK_CSS_TOP_RIGHT] && (junction & GTK_JUNCTION_CORNER_TOPRIGHT) == 0)
{
- 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);
+ box->corner[GTK_CSS_TOP_RIGHT].horizontal = _gtk_css_corner_value_get_x (corner[GTK_CSS_TOP_RIGHT],
+ box->box.width);
+ box->corner[GTK_CSS_TOP_RIGHT].vertical = _gtk_css_corner_value_get_y (corner[GTK_CSS_TOP_RIGHT],
+ box->box.height);
}
if (corner[GTK_CSS_BOTTOM_RIGHT] && (junction & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == 0)
{
- 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);
+ box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal = _gtk_css_corner_value_get_x (corner[GTK_CSS_BOTTOM_RIGHT],
+ box->box.width);
+ box->corner[GTK_CSS_BOTTOM_RIGHT].vertical = _gtk_css_corner_value_get_y (corner[GTK_CSS_BOTTOM_RIGHT],
+ box->box.height);
}
if (corner[GTK_CSS_BOTTOM_LEFT] && (junction & GTK_JUNCTION_CORNER_BOTTOMLEFT) == 0)
{
- 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);
+ box->corner[GTK_CSS_BOTTOM_LEFT].horizontal = _gtk_css_corner_value_get_x (corner[GTK_CSS_BOTTOM_LEFT],
+ box->box.width);
+ box->corner[GTK_CSS_BOTTOM_LEFT].vertical = _gtk_css_corner_value_get_y (corner[GTK_CSS_BOTTOM_LEFT],
+ box->box.height);
}
gtk_rounded_box_clamp_border_radius (box);
@@ -114,35 +118,24 @@ _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
void
_gtk_rounded_box_apply_border_radius_for_context (GtkRoundedBox *box,
GtkStyleContext *context,
- GtkStateFlags state,
GtkJunctionSides junction)
{
- GtkCssBorderCornerRadius *corner[4];
- guint i;
-
- gtk_style_context_get (context, state,
- /* Can't use border-radius as it's an int for
- * backwards compat */
- "border-top-left-radius", &corner[GTK_CSS_TOP_LEFT],
- "border-top-right-radius", &corner[GTK_CSS_TOP_RIGHT],
- "border-bottom-right-radius", &corner[GTK_CSS_BOTTOM_RIGHT],
- "border-bottom-left-radius", &corner[GTK_CSS_BOTTOM_LEFT],
- NULL);
+ GtkCssValue *corner[4];
- _gtk_rounded_box_apply_border_radius (box, corner, junction);
+ corner[GTK_CSS_TOP_LEFT] = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS);
+ corner[GTK_CSS_TOP_RIGHT] = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS);
+ corner[GTK_CSS_BOTTOM_LEFT] = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS);
+ corner[GTK_CSS_BOTTOM_RIGHT] = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS);
- for (i = 0; i < 4; i++)
- g_free (corner[i]);
+ _gtk_rounded_box_apply_border_radius (box, corner, junction);
}
void
_gtk_rounded_box_apply_border_radius_for_engine (GtkRoundedBox *box,
GtkThemingEngine *engine,
- GtkStateFlags state,
GtkJunctionSides junction)
{
- _gtk_rounded_box_apply_border_radius_for_context (box, _gtk_theming_engine_get_context (engine),
- state, junction);
+ _gtk_rounded_box_apply_border_radius_for_context (box, _gtk_theming_engine_get_context (engine), junction);
}
static void
diff --git a/gtk/gtkroundedboxprivate.h b/gtk/gtkroundedboxprivate.h
index 3fa4c93..61b16e8 100644
--- a/gtk/gtkroundedboxprivate.h
+++ b/gtk/gtkroundedboxprivate.h
@@ -47,16 +47,11 @@ void _gtk_rounded_box_init_rect (GtkRoundedBox
double width,
double height);
-void _gtk_rounded_box_apply_border_radius (GtkRoundedBox *box,
- GtkCssBorderCornerRadius **corner,
- GtkJunctionSides junction);
void _gtk_rounded_box_apply_border_radius_for_engine (GtkRoundedBox *box,
GtkThemingEngine *engine,
- GtkStateFlags state,
GtkJunctionSides junction);
void _gtk_rounded_box_apply_border_radius_for_context (GtkRoundedBox *box,
GtkStyleContext *context,
- GtkStateFlags state,
GtkJunctionSides junction);
void _gtk_rounded_box_shrink (GtkRoundedBox *box,
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index 4da48ca..d905716 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -324,7 +324,7 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg)
*/
_gtk_rounded_box_init_rect (&bg->padding_box, 0, 0, bg->paint_area.width, bg->paint_area.height);
- _gtk_rounded_box_apply_border_radius_for_context (&bg->padding_box, bg->context, bg->flags, bg->junction);
+ _gtk_rounded_box_apply_border_radius_for_context (&bg->padding_box, bg->context, bg->junction);
bg->clip_box = bg->padding_box;
_gtk_rounded_box_shrink (&bg->padding_box,
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 11f22a9..675f8ae 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -29,6 +29,7 @@
#include "gtkborderimageprivate.h"
#include "gtkpango.h"
#include "gtkcssarrayvalueprivate.h"
+#include "gtkcsscornervalueprivate.h"
#include "gtkcssenumvalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssrgbavalueprivate.h"
@@ -1817,7 +1818,7 @@ render_frame_internal (GtkThemingEngine *engine,
}
_gtk_rounded_box_init_rect (&border_box, x, y, width, height);
- _gtk_rounded_box_apply_border_radius_for_engine (&border_box, engine, state, junction);
+ _gtk_rounded_box_apply_border_radius_for_engine (&border_box, engine, junction);
render_border (cr, &border_box, &border, hidden_side, colors, border_style);
}
@@ -2195,8 +2196,7 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
GtkJunctionSides junction;
GtkStateFlags state;
gint border_width;
- GtkCssBorderCornerRadius *top_left_radius, *top_right_radius;
- GtkCssBorderCornerRadius *bottom_left_radius, *bottom_right_radius;
+ GtkCssValue *corner[4];
gdouble x0, y0, x1, y1, xc, yc, wc, hc;
GtkBorder border;
@@ -2205,12 +2205,10 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
junction = gtk_theming_engine_get_junction_sides (engine);
gtk_theming_engine_get_border (engine, state, &border);
- gtk_theming_engine_get (engine, state,
- "border-top-left-radius", &top_left_radius,
- "border-top-right-radius", &top_right_radius,
- "border-bottom-right-radius", &bottom_right_radius,
- "border-bottom-left-radius", &bottom_left_radius,
- NULL);
+ corner[GTK_CSS_TOP_LEFT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_LEFT_RADIUS);
+ corner[GTK_CSS_TOP_RIGHT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_TOP_RIGHT_RADIUS);
+ corner[GTK_CSS_BOTTOM_LEFT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_BOTTOM_LEFT_RADIUS);
+ corner[GTK_CSS_BOTTOM_RIGHT] = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_BOTTOM_RIGHT_RADIUS);
border_width = MIN (MIN (border.top, border.bottom),
MIN (border.left, border.right));
@@ -2225,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 < _gtk_css_number_get (&top_left_radius->horizontal, width))
+ if (xy0_gap < _gtk_css_corner_value_get_x (corner[GTK_CSS_TOP_LEFT], width))
junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- if (xy1_gap > width - _gtk_css_number_get (&top_right_radius->horizontal, width))
+ if (xy1_gap > width - _gtk_css_corner_value_get_x (corner[GTK_CSS_TOP_RIGHT], width))
junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
break;
case GTK_POS_BOTTOM:
@@ -2237,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 < _gtk_css_number_get (&bottom_left_radius->horizontal, width))
+ if (xy0_gap < _gtk_css_corner_value_get_x (corner[GTK_CSS_BOTTOM_LEFT], width))
junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
- if (xy1_gap > width - _gtk_css_number_get (&bottom_right_radius->horizontal, width))
+ if (xy1_gap > width - _gtk_css_corner_value_get_x (corner[GTK_CSS_BOTTOM_RIGHT], width))
junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
break;
@@ -2250,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 < _gtk_css_number_get (&top_left_radius->vertical, height))
+ if (xy0_gap < _gtk_css_corner_value_get_y (corner[GTK_CSS_TOP_LEFT], height))
junction |= GTK_JUNCTION_CORNER_TOPLEFT;
- if (xy1_gap > height - _gtk_css_number_get (&bottom_left_radius->vertical, height))
+ if (xy1_gap > height - _gtk_css_corner_value_get_y (corner[GTK_CSS_BOTTOM_LEFT], height))
junction |= GTK_JUNCTION_CORNER_BOTTOMLEFT;
break;
@@ -2263,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 < _gtk_css_number_get (&top_right_radius->vertical, height))
+ if (xy0_gap < _gtk_css_corner_value_get_y (corner[GTK_CSS_TOP_RIGHT], height))
junction |= GTK_JUNCTION_CORNER_TOPRIGHT;
- if (xy1_gap > height - _gtk_css_number_get (&bottom_right_radius->vertical, height))
+ if (xy1_gap > height - _gtk_css_corner_value_get_y (corner[GTK_CSS_BOTTOM_RIGHT], height))
junction |= GTK_JUNCTION_CORNER_BOTTOMRIGHT;
break;
@@ -2284,11 +2282,6 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
0, junction);
cairo_restore (cr);
-
- g_free (top_left_radius);
- g_free (top_right_radius);
- g_free (bottom_right_radius);
- g_free (bottom_left_radius);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]