[gtk+/wip/cssvalue: 68/141] shadow: Move parse function into GtkShadow
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 68/141] shadow: Move parse function into GtkShadow
- Date: Sat, 7 Apr 2012 17:51:51 +0000 (UTC)
commit 11b1af620cd9db655da0b925bd9f02b14f961e8c
Author: Benjamin Otte <otte redhat com>
Date: Wed Mar 28 02:25:22 2012 +0200
shadow: Move parse function into GtkShadow
This way, we have less public API.
And gtkcssstylepropertyimpl.c looks less scary (only 1624 lines now).
gtk/gtkcssstylepropertyimpl.c | 81 +------------------------------
gtk/gtkshadow.c | 108 +++++++++++++++++++++++++++++++----------
gtk/gtkshadowprivate.h | 11 +---
3 files changed, 85 insertions(+), 115 deletions(-)
---
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index d49f395..17a638f 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -421,86 +421,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
- gboolean have_inset, have_color, have_lengths;
- gdouble hoffset, voffset, blur, spread;
- GtkSymbolicColor *color;
- GtkShadow *shadow;
- guint i;
-
- if (_gtk_css_parser_try (parser, "none", TRUE))
- return _gtk_shadow_new_none ();
-
- shadow = _gtk_shadow_new ();
-
- do
- {
- have_inset = have_lengths = have_color = FALSE;
-
- for (i = 0; i < 3; i++)
- {
- if (!have_inset &&
- _gtk_css_parser_try (parser, "inset", TRUE))
- {
- have_inset = TRUE;
- continue;
- }
-
- if (!have_lengths &&
- _gtk_css_parser_try_double (parser, &hoffset))
- {
- have_lengths = TRUE;
-
- if (!_gtk_css_parser_try_double (parser, &voffset))
- {
- _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
- _gtk_css_value_unref (shadow);
- return NULL;
- }
-
- if (!_gtk_css_parser_try_double (parser, &blur))
- blur = 0;
-
- if (!_gtk_css_parser_try_double (parser, &spread))
- spread = 0;
-
- continue;
- }
-
- if (!have_color)
- {
- have_color = TRUE;
-
- /* XXX: the color is optional and UA-defined if it's missing,
- * but it doesn't really make sense for us...
- */
- color = _gtk_css_parser_read_symbolic_color (parser);
-
- if (color == NULL)
- {
- _gtk_css_value_unref (shadow);
- return NULL;
- }
- }
- }
-
- if (!have_color || !have_lengths)
- {
- _gtk_css_parser_error (parser, "Must specify at least color and offsets");
- _gtk_css_value_unref (shadow);
- return NULL;
- }
-
- _gtk_shadow_append (shadow,
- hoffset, voffset,
- blur, spread,
- have_inset, color);
-
- gtk_symbolic_color_unref (color);
-
- }
- while (_gtk_css_parser_try (parser, ",", TRUE));
-
- return shadow;
+ return _gtk_shadow_parse (parser);
}
static GtkCssValue *
diff --git a/gtk/gtkshadow.c b/gtk/gtkshadow.c
index f274c9f..b1bf70d 100644
--- a/gtk/gtkshadow.c
+++ b/gtk/gtkshadow.c
@@ -111,8 +111,6 @@ shadow_element_new (gdouble hoffset,
struct _GtkCssValue {
GTK_CSS_VALUE_BASE
GList *elements;
-
- gboolean resolved;
};
static void
@@ -164,13 +162,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
gtk_css_value_shadow_print
};
-static GtkCssValue none_singleton = { >K_CSS_VALUE_SHADOW, 1, NULL, FALSE };
-
-GtkShadow *
-_gtk_shadow_new (void)
-{
- return _gtk_css_value_new (GtkShadow, >K_CSS_VALUE_SHADOW);
-}
+static GtkCssValue none_singleton = { >K_CSS_VALUE_SHADOW, 1, NULL };
GtkShadow *
_gtk_shadow_new_none (void)
@@ -178,25 +170,91 @@ _gtk_shadow_new_none (void)
return _gtk_css_value_ref (&none_singleton);
}
-void
-_gtk_shadow_append (GtkShadow *shadow,
- gdouble hoffset,
- gdouble voffset,
- gdouble radius,
- gdouble spread,
- gboolean inset,
- GtkSymbolicColor *color)
+GtkShadow *
+_gtk_shadow_parse (GtkCssParser *parser)
{
+ gboolean have_inset, have_color, have_lengths;
+ gdouble hoffset, voffset, blur, spread;
+ GtkSymbolicColor *color;
GtkShadowElement *element;
+ GtkShadow *shadow;
+ guint i;
+
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ return _gtk_shadow_new_none ();
+
+ shadow = _gtk_css_value_new (GtkShadow, >K_CSS_VALUE_SHADOW);
+
+ do
+ {
+ have_inset = have_lengths = have_color = FALSE;
- g_return_if_fail (shadow != NULL);
- g_return_if_fail (color != NULL);
+ for (i = 0; i < 3; i++)
+ {
+ if (!have_inset &&
+ _gtk_css_parser_try (parser, "inset", TRUE))
+ {
+ have_inset = TRUE;
+ continue;
+ }
+
+ if (!have_lengths &&
+ _gtk_css_parser_try_double (parser, &hoffset))
+ {
+ have_lengths = TRUE;
+
+ if (!_gtk_css_parser_try_double (parser, &voffset))
+ {
+ _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
+ _gtk_css_value_unref (shadow);
+ return NULL;
+ }
+
+ if (!_gtk_css_parser_try_double (parser, &blur))
+ blur = 0;
+
+ if (!_gtk_css_parser_try_double (parser, &spread))
+ spread = 0;
+
+ continue;
+ }
+
+ if (!have_color)
+ {
+ have_color = TRUE;
+
+ /* XXX: the color is optional and UA-defined if it's missing,
+ * but it doesn't really make sense for us...
+ */
+ color = _gtk_css_parser_read_symbolic_color (parser);
+
+ if (color == NULL)
+ {
+ _gtk_css_value_unref (shadow);
+ return NULL;
+ }
+ }
+ }
+
+ if (!have_color || !have_lengths)
+ {
+ _gtk_css_parser_error (parser, "Must specify at least color and offsets");
+ _gtk_css_value_unref (shadow);
+ return NULL;
+ }
- element = shadow_element_new (hoffset, voffset,
- radius, spread, inset,
- NULL, color);
+ element = shadow_element_new (hoffset, voffset,
+ blur, spread, have_inset,
+ NULL, color);
- shadow->elements = g_list_append (shadow->elements, element);
+ shadow->elements = g_list_append (shadow->elements, element);
+
+ gtk_symbolic_color_unref (color);
+
+ }
+ while (_gtk_css_parser_try (parser, ",", TRUE));
+
+ return shadow;
}
GtkShadow *
@@ -208,7 +266,7 @@ _gtk_shadow_resolve (GtkShadow *shadow,
GdkRGBA color;
GList *l;
- resolved_shadow = _gtk_shadow_new ();
+ resolved_shadow = _gtk_css_value_new (GtkShadow, >K_CSS_VALUE_SHADOW);
for (l = shadow->elements; l != NULL; l = l->next)
{
@@ -231,8 +289,6 @@ _gtk_shadow_resolve (GtkShadow *shadow,
g_list_append (resolved_shadow->elements, resolved_element);
}
- resolved_shadow->resolved = TRUE;
-
return resolved_shadow;
}
diff --git a/gtk/gtkshadowprivate.h b/gtk/gtkshadowprivate.h
index b279bc9..b556675 100644
--- a/gtk/gtkshadowprivate.h
+++ b/gtk/gtkshadowprivate.h
@@ -25,6 +25,7 @@
#include "gtkstylecontext.h"
#include "gtksymboliccolor.h"
#include "gtkicontheme.h"
+#include "gtkcssparserprivate.h"
#include "gtkcsstypesprivate.h"
#include "gtkcssvalueprivate.h"
#include "gtkroundedboxprivate.h"
@@ -33,16 +34,8 @@ G_BEGIN_DECLS
typedef GtkCssValue GtkShadow;
-GtkShadow *_gtk_shadow_new (void);
GtkShadow *_gtk_shadow_new_none (void);
-
-void _gtk_shadow_append (GtkShadow *shadow,
- gdouble hoffset,
- gdouble voffset,
- gdouble radius,
- gdouble spread,
- gboolean inset,
- GtkSymbolicColor *color);
+GtkShadow *_gtk_shadow_parse (GtkCssParser *parser);
GtkShadow *_gtk_shadow_resolve (GtkShadow *shadow,
GtkStyleContext *context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]