Commit ccd44379 authored by Benjamin Otte's avatar Benjamin Otte

shadow: Make this a GtkCssValue

parent 38ac6879
...@@ -428,7 +428,7 @@ shadow_value_parse (GtkCssStyleProperty *property, ...@@ -428,7 +428,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
guint i; guint i;
if (_gtk_css_parser_try (parser, "none", TRUE)) if (_gtk_css_parser_try (parser, "none", TRUE))
return _gtk_css_value_new_take_shadow (NULL); return _gtk_shadow_new_none ();
shadow = _gtk_shadow_new (); shadow = _gtk_shadow_new ();
...@@ -453,7 +453,7 @@ shadow_value_parse (GtkCssStyleProperty *property, ...@@ -453,7 +453,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
if (!_gtk_css_parser_try_double (parser, &voffset)) if (!_gtk_css_parser_try_double (parser, &voffset))
{ {
_gtk_css_parser_error (parser, "Horizontal and vertical offsets are required"); _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
_gtk_shadow_unref (shadow); _gtk_css_value_unref (shadow);
return NULL; return NULL;
} }
...@@ -477,7 +477,7 @@ shadow_value_parse (GtkCssStyleProperty *property, ...@@ -477,7 +477,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
if (color == NULL) if (color == NULL)
{ {
_gtk_shadow_unref (shadow); _gtk_css_value_unref (shadow);
return NULL; return NULL;
} }
} }
...@@ -486,7 +486,7 @@ shadow_value_parse (GtkCssStyleProperty *property, ...@@ -486,7 +486,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
if (!have_color || !have_lengths) if (!have_color || !have_lengths)
{ {
_gtk_css_parser_error (parser, "Must specify at least color and offsets"); _gtk_css_parser_error (parser, "Must specify at least color and offsets");
_gtk_shadow_unref (shadow); _gtk_css_value_unref (shadow);
return NULL; return NULL;
} }
...@@ -500,22 +500,7 @@ shadow_value_parse (GtkCssStyleProperty *property, ...@@ -500,22 +500,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
} }
while (_gtk_css_parser_try (parser, ",", TRUE)); while (_gtk_css_parser_try (parser, ",", TRUE));
return _gtk_css_value_new_take_shadow (shadow); return shadow;
}
static void
shadow_value_print (GtkCssStyleProperty *property,
const GtkCssValue *value,
GString *string)
{
GtkShadow *shadow;
shadow = _gtk_css_value_get_shadow (value);
if (shadow == NULL)
g_string_append (string, "none");
else
_gtk_shadow_print (shadow, string);
} }
static GtkCssValue * static GtkCssValue *
...@@ -523,13 +508,7 @@ shadow_value_compute (GtkCssStyleProperty *property, ...@@ -523,13 +508,7 @@ shadow_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context, GtkStyleContext *context,
GtkCssValue *specified) GtkCssValue *specified)
{ {
GtkShadow *shadow; return _gtk_shadow_resolve (specified, context);
shadow = _gtk_css_value_get_shadow (specified);
if (shadow)
shadow = _gtk_shadow_resolve (shadow, context);
return _gtk_css_value_new_take_shadow (shadow);
} }
static GtkCssValue * static GtkCssValue *
...@@ -1310,31 +1289,31 @@ _gtk_css_style_property_init_properties (void) ...@@ -1310,31 +1289,31 @@ _gtk_css_style_property_init_properties (void)
G_TYPE_NONE, G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT,
shadow_value_parse, shadow_value_parse,
shadow_value_print, NULL,
shadow_value_compute, shadow_value_compute,
NULL, NULL,
NULL, NULL,
_gtk_css_value_new_take_shadow (NULL)); _gtk_shadow_new_none ());
gtk_css_style_property_register ("icon-shadow", gtk_css_style_property_register ("icon-shadow",
G_TYPE_NONE, G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT, GTK_STYLE_PROPERTY_INHERIT,
shadow_value_parse, shadow_value_parse,
shadow_value_print, NULL,
shadow_value_compute, shadow_value_compute,
NULL, NULL,
NULL, NULL,
_gtk_css_value_new_take_shadow (NULL)); _gtk_shadow_new_none ());
gtk_css_style_property_register ("box-shadow", gtk_css_style_property_register ("box-shadow",
G_TYPE_NONE, G_TYPE_NONE,
0, 0,
shadow_value_parse, shadow_value_parse,
shadow_value_print, NULL,
shadow_value_compute, shadow_value_compute,
NULL, NULL,
NULL, NULL,
_gtk_css_value_new_take_shadow (NULL)); _gtk_shadow_new_none ());
gtk_css_style_property_register ("margin-top", gtk_css_style_property_register ("margin-top",
G_TYPE_INT, G_TYPE_INT,
......
...@@ -269,17 +269,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v) ...@@ -269,17 +269,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
return value; return value;
} }
GtkCssValue *
_gtk_css_value_new_take_shadow (GtkShadow *v)
{
GtkCssValue *value;
value = gtk_css_value_new (GTK_TYPE_SHADOW);
value->u.ptr = v;
return value;
}
GtkCssValue * GtkCssValue *
_gtk_css_value_new_take_image (GtkCssImage *v) _gtk_css_value_new_take_image (GtkCssImage *v)
{ {
...@@ -664,9 +653,3 @@ _gtk_css_value_get_gradient (const GtkCssValue *value) ...@@ -664,9 +653,3 @@ _gtk_css_value_get_gradient (const GtkCssValue *value)
return value->u.ptr; return value->u.ptr;
} }
GtkShadow *
_gtk_css_value_get_shadow (const GtkCssValue *value)
{
g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_SHADOW), NULL);
return value->u.ptr;
}
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "gtkcsstypesprivate.h" #include "gtkcsstypesprivate.h"
#include "gtksymboliccolor.h" #include "gtksymboliccolor.h"
#include "gtkcssimageprivate.h" #include "gtkcssimageprivate.h"
#include "gtkshadowprivate.h" #include "gtkthemingengine.h"
G_BEGIN_DECLS G_BEGIN_DECLS
...@@ -85,7 +85,6 @@ GtkCssValue *_gtk_css_value_new_from_rgba (const GdkRGBA ...@@ -85,7 +85,6 @@ GtkCssValue *_gtk_css_value_new_from_rgba (const GdkRGBA
GtkCssValue *_gtk_css_value_new_from_color (const GdkColor *v); GtkCssValue *_gtk_css_value_new_from_color (const GdkColor *v);
GtkCssValue *_gtk_css_value_new_take_symbolic_color (GtkSymbolicColor *v); GtkCssValue *_gtk_css_value_new_take_symbolic_color (GtkSymbolicColor *v);
GtkCssValue *_gtk_css_value_new_take_pattern (cairo_pattern_t *v); GtkCssValue *_gtk_css_value_new_take_pattern (cairo_pattern_t *v);
GtkCssValue *_gtk_css_value_new_take_shadow (GtkShadow *v);
GtkCssValue *_gtk_css_value_new_take_image (GtkCssImage *v); GtkCssValue *_gtk_css_value_new_take_image (GtkCssImage *v);
GtkCssValue *_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v); GtkCssValue *_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v);
GtkCssValue *_gtk_css_value_new_take_binding_sets (GPtrArray *array); GtkCssValue *_gtk_css_value_new_take_binding_sets (GPtrArray *array);
...@@ -118,7 +117,6 @@ PangoWeight _gtk_css_value_get_pango_weight (const ...@@ -118,7 +117,6 @@ PangoWeight _gtk_css_value_get_pango_weight (const
const GdkRGBA *_gtk_css_value_get_rgba (const GtkCssValue *value); const GdkRGBA *_gtk_css_value_get_rgba (const GtkCssValue *value);
cairo_pattern_t *_gtk_css_value_get_pattern (const GtkCssValue *value); cairo_pattern_t *_gtk_css_value_get_pattern (const GtkCssValue *value);
GtkGradient *_gtk_css_value_get_gradient (const GtkCssValue *value); GtkGradient *_gtk_css_value_get_gradient (const GtkCssValue *value);
GtkShadow *_gtk_css_value_get_shadow (const GtkCssValue *value);
G_END_DECLS G_END_DECLS
......
...@@ -108,51 +108,76 @@ shadow_element_new (gdouble hoffset, ...@@ -108,51 +108,76 @@ shadow_element_new (gdouble hoffset,
* GtkShadow * * GtkShadow *
****************/ ****************/
G_DEFINE_BOXED_TYPE (GtkShadow, _gtk_shadow, struct _GtkCssValue {
_gtk_shadow_ref, _gtk_shadow_unref) GTK_CSS_VALUE_BASE
struct _GtkShadow {
GList *elements; GList *elements;
guint ref_count; gboolean resolved;
}; };
GtkShadow * static void
_gtk_shadow_new (void) gtk_css_value_shadow_free (GtkCssValue *shadow)
{ {
GtkShadow *retval; g_list_free_full (shadow->elements,
(GDestroyNotify) shadow_element_free);
retval = g_slice_new0 (GtkShadow); g_slice_free (GtkShadow, shadow);
retval->ref_count = 1; }
return retval; static gboolean
gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
const GtkCssValue *shadow2)
{
/* FIXME */
return shadow1 == shadow2;
} }
GtkShadow * static void
_gtk_shadow_ref (GtkShadow *shadow) gtk_css_value_shadow_print (const GtkCssValue *shadow,
GString *string)
{ {
g_return_val_if_fail (shadow != NULL, NULL); gint length;
GList *l;
shadow->ref_count++; length = g_list_length (shadow->elements);
return shadow; if (length == 0)
} {
g_string_append (string, "none");
return;
}
void shadow_element_print (shadow->elements->data, string);
_gtk_shadow_unref (GtkShadow *shadow)
{
g_return_if_fail (shadow != NULL);
shadow->ref_count--; if (length == 1)
return;
if (shadow->ref_count == 0) for (l = g_list_next (shadow->elements); l != NULL; l = l->next)
{ {
g_list_free_full (shadow->elements, g_string_append (string, ", ");
(GDestroyNotify) shadow_element_free); shadow_element_print (l->data, string);
g_slice_free (GtkShadow, shadow);
} }
} }
static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
gtk_css_value_shadow_free,
gtk_css_value_shadow_equal,
gtk_css_value_shadow_print
};
static GtkCssValue none_singleton = { &GTK_CSS_VALUE_SHADOW, 1, NULL, FALSE };
GtkShadow *
_gtk_shadow_new (void)
{
return _gtk_css_value_new (GtkShadow, &GTK_CSS_VALUE_SHADOW);
}
GtkShadow *
_gtk_shadow_new_none (void)
{
return _gtk_css_value_ref (&none_singleton);
}
void void
_gtk_shadow_append (GtkShadow *shadow, _gtk_shadow_append (GtkShadow *shadow,
gdouble hoffset, gdouble hoffset,
...@@ -193,7 +218,7 @@ _gtk_shadow_resolve (GtkShadow *shadow, ...@@ -193,7 +218,7 @@ _gtk_shadow_resolve (GtkShadow *shadow,
element->symbolic_color, element->symbolic_color,
&color)) &color))
{ {
_gtk_shadow_unref (resolved_shadow); _gtk_css_value_unref (resolved_shadow);
return NULL; return NULL;
} }
...@@ -206,31 +231,9 @@ _gtk_shadow_resolve (GtkShadow *shadow, ...@@ -206,31 +231,9 @@ _gtk_shadow_resolve (GtkShadow *shadow,
g_list_append (resolved_shadow->elements, resolved_element); g_list_append (resolved_shadow->elements, resolved_element);
} }
return resolved_shadow; resolved_shadow->resolved = TRUE;
}
void
_gtk_shadow_print (GtkShadow *shadow,
GString *str)
{
gint length;
GList *l;
length = g_list_length (shadow->elements); return resolved_shadow;
if (length == 0)
return;
shadow_element_print (shadow->elements->data, str);
if (length == 1)
return;
for (l = g_list_next (shadow->elements); l != NULL; l = l->next)
{
g_string_append (str, ", ");
shadow_element_print (l->data, str);
}
} }
void void
......
...@@ -26,19 +26,15 @@ ...@@ -26,19 +26,15 @@
#include "gtksymboliccolor.h" #include "gtksymboliccolor.h"
#include "gtkicontheme.h" #include "gtkicontheme.h"
#include "gtkcsstypesprivate.h" #include "gtkcsstypesprivate.h"
#include "gtkcssvalueprivate.h"
#include "gtkroundedboxprivate.h" #include "gtkroundedboxprivate.h"
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _GtkShadow GtkShadow; typedef GtkCssValue GtkShadow;
#define GTK_TYPE_SHADOW (_gtk_shadow_get_type ())
GType _gtk_shadow_get_type (void) G_GNUC_CONST;
GtkShadow *_gtk_shadow_new (void); GtkShadow *_gtk_shadow_new (void);
GtkShadow *_gtk_shadow_ref (GtkShadow *shadow); GtkShadow *_gtk_shadow_new_none (void);
void _gtk_shadow_unref (GtkShadow *shadow);
void _gtk_shadow_append (GtkShadow *shadow, void _gtk_shadow_append (GtkShadow *shadow,
gdouble hoffset, gdouble hoffset,
...@@ -48,9 +44,6 @@ void _gtk_shadow_append (GtkShadow *shadow, ...@@ -48,9 +44,6 @@ void _gtk_shadow_append (GtkShadow *shadow,
gboolean inset, gboolean inset,
GtkSymbolicColor *color); GtkSymbolicColor *color);
void _gtk_shadow_print (GtkShadow *shadow,
GString *string);
GtkShadow *_gtk_shadow_resolve (GtkShadow *shadow, GtkShadow *_gtk_shadow_resolve (GtkShadow *shadow,
GtkStyleContext *context); GtkStyleContext *context);
......
...@@ -301,14 +301,9 @@ static void ...@@ -301,14 +301,9 @@ static void
_gtk_theming_background_apply_shadow (GtkThemingBackground *bg, _gtk_theming_background_apply_shadow (GtkThemingBackground *bg,
cairo_t *cr) cairo_t *cr)
{ {
GtkShadow *box_shadow; _gtk_box_shadow_render (_gtk_style_context_peek_property (bg->context, "box-shadow"),
cr,
box_shadow = _gtk_css_value_get_shadow (_gtk_style_context_peek_property (bg->context, "box-shadow")); &bg->padding_box);
if (box_shadow != NULL)
{
_gtk_box_shadow_render (box_shadow, cr, &bg->padding_box);
}
} }
static void static void
......
...@@ -2132,14 +2132,11 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine, ...@@ -2132,14 +2132,11 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1); fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
} }
text_shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "text-shadow")); text_shadow = _gtk_theming_engine_peek_property (engine, "text-shadow");
prepare_context_for_layout (cr, x, y, layout); prepare_context_for_layout (cr, x, y, layout);
if (text_shadow != NULL) _gtk_text_shadow_paint_layout (text_shadow, cr, layout);
{
_gtk_text_shadow_paint_layout (text_shadow, cr, layout);
}
gdk_cairo_set_source_rgba (cr, &fg_color); gdk_cairo_set_source_rgba (cr, &fg_color);
pango_cairo_show_layout (cr, layout); pango_cairo_show_layout (cr, layout);
...@@ -2766,17 +2763,14 @@ render_spinner (GtkThemingEngine *engine, ...@@ -2766,17 +2763,14 @@ render_spinner (GtkThemingEngine *engine,
radius = MIN (width / 2, height / 2); radius = MIN (width / 2, height / 2);
gtk_theming_engine_get_color (engine, state, &color); gtk_theming_engine_get_color (engine, state, &color);
shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "icon-shadow")); shadow = _gtk_theming_engine_peek_property (engine, "icon-shadow");
cairo_save (cr); cairo_save (cr);
cairo_translate (cr, x + width / 2, y + height / 2); cairo_translate (cr, x + width / 2, y + height / 2);
if (shadow != NULL) _gtk_icon_shadow_paint_spinner (shadow, cr,
{ radius,
_gtk_icon_shadow_paint_spinner (shadow, cr, progress);
radius,
progress);
}
_gtk_theming_engine_paint_spinner (cr, _gtk_theming_engine_paint_spinner (cr,
radius, radius,
...@@ -2943,18 +2937,11 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine, ...@@ -2943,18 +2937,11 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
GtkShadow *icon_shadow;
cairo_save (cr); cairo_save (cr);
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y); gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
icon_shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "icon-shadow")); _gtk_icon_shadow_paint (_gtk_theming_engine_peek_property (engine, "icon-shadow"), cr);
if (icon_shadow != NULL)
{
_gtk_icon_shadow_paint (icon_shadow, cr);
}
cairo_paint (cr); cairo_paint (cr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment