[gtk+/wip/cssvalue: 67/137] shadow: Make this a GtkCssValue



commit d121b07014c12bf0cb9c403759b7dc8b8f3c4a6c
Author: Benjamin Otte <otte redhat com>
Date:   Wed Mar 28 01:56:57 2012 +0200

    shadow: Make this a GtkCssValue

 gtk/gtkcssstylepropertyimpl.c |   45 +++++-------------
 gtk/gtkcssvalue.c             |   17 -------
 gtk/gtkcssvalueprivate.h      |    4 +-
 gtk/gtkshadow.c               |  107 +++++++++++++++++++++--------------------
 gtk/gtkshadowprivate.h        |   13 +----
 gtk/gtkthemingbackground.c    |   11 +---
 gtk/gtkthemingengine.c        |   27 +++--------
 7 files changed, 81 insertions(+), 143 deletions(-)
---
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index a0e9538..d49f395 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -428,7 +428,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
   guint i;
 
   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 ();
 
@@ -453,7 +453,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
               if (!_gtk_css_parser_try_double (parser, &voffset))
                 {
                   _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
-                  _gtk_shadow_unref (shadow);
+                  _gtk_css_value_unref (shadow);
                   return NULL;
                 }
 
@@ -477,7 +477,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
 
               if (color == NULL)
                 {
-                  _gtk_shadow_unref (shadow);
+                  _gtk_css_value_unref (shadow);
                   return NULL;
                 }
             }
@@ -486,7 +486,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
       if (!have_color || !have_lengths)
         {
           _gtk_css_parser_error (parser, "Must specify at least color and offsets");
-          _gtk_shadow_unref (shadow);
+          _gtk_css_value_unref (shadow);
           return NULL;
         }
 
@@ -500,22 +500,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
     }
   while (_gtk_css_parser_try (parser, ",", TRUE));
 
-  return _gtk_css_value_new_take_shadow (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);
+  return shadow;
 }
 
 static GtkCssValue *
@@ -523,13 +508,7 @@ shadow_value_compute (GtkCssStyleProperty *property,
                       GtkStyleContext     *context,
                       GtkCssValue         *specified)
 {
-  GtkShadow *shadow;
-  
-  shadow = _gtk_css_value_get_shadow (specified);
-  if (shadow)
-    shadow = _gtk_shadow_resolve (shadow, context);
-
-  return _gtk_css_value_new_take_shadow (shadow);
+  return _gtk_shadow_resolve (specified, context);
 }
 
 static GtkCssValue *
@@ -1300,31 +1279,31 @@ _gtk_css_style_property_init_properties (void)
                                           G_TYPE_NONE,
                                           GTK_STYLE_PROPERTY_INHERIT,
                                           shadow_value_parse,
-                                          shadow_value_print,
+                                          NULL,
                                           shadow_value_compute,
                                           NULL,
                                           NULL,
-                                          _gtk_css_value_new_take_shadow (NULL));
+                                          _gtk_shadow_new_none ());
 
   gtk_css_style_property_register        ("icon-shadow",
                                           G_TYPE_NONE,
                                           GTK_STYLE_PROPERTY_INHERIT,
                                           shadow_value_parse,
-                                          shadow_value_print,
+                                          NULL,
                                           shadow_value_compute,
                                           NULL,
                                           NULL,
-                                          _gtk_css_value_new_take_shadow (NULL));
+                                          _gtk_shadow_new_none ());
 
   gtk_css_style_property_register        ("box-shadow",
                                           G_TYPE_NONE,
                                           0,
                                           shadow_value_parse,
-                                          shadow_value_print,
+                                          NULL,
                                           shadow_value_compute,
                                           NULL,
                                           NULL,
-                                          _gtk_css_value_new_take_shadow (NULL));
+                                          _gtk_shadow_new_none ());
 
   gtk_css_style_property_register        ("margin-top",
                                           G_TYPE_INT,
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index 4302820..ad4c767 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -241,17 +241,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
 }
 
 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 *
 _gtk_css_value_new_take_image (GtkCssImage *v)
 {
   GtkCssValue *value;
@@ -635,9 +624,3 @@ _gtk_css_value_get_gradient (const GtkCssValue *value)
   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;
-}
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index e962326..a9dc842 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -24,7 +24,7 @@
 #include "gtkcsstypesprivate.h"
 #include "gtksymboliccolor.h"
 #include "gtkcssimageprivate.h"
-#include "gtkshadowprivate.h"
+#include "gtkthemingengine.h"
 
 G_BEGIN_DECLS
 
@@ -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_take_symbolic_color   (GtkSymbolicColor           *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_from_theming_engine   (GtkThemingEngine           *v);
 GtkCssValue *_gtk_css_value_new_take_binding_sets     (GPtrArray                  *array);
@@ -118,7 +117,6 @@ PangoWeight                     _gtk_css_value_get_pango_weight           (const
 const GdkRGBA                  *_gtk_css_value_get_rgba                   (const GtkCssValue *value);
 cairo_pattern_t                *_gtk_css_value_get_pattern                (const GtkCssValue *value);
 GtkGradient                    *_gtk_css_value_get_gradient               (const GtkCssValue *value);
-GtkShadow                      *_gtk_css_value_get_shadow                 (const GtkCssValue *value);
 
 G_END_DECLS
 
diff --git a/gtk/gtkshadow.c b/gtk/gtkshadow.c
index c3b1f09..f274c9f 100644
--- a/gtk/gtkshadow.c
+++ b/gtk/gtkshadow.c
@@ -108,51 +108,76 @@ shadow_element_new (gdouble hoffset,
  * GtkShadow *
  ****************/
 
-G_DEFINE_BOXED_TYPE (GtkShadow, _gtk_shadow,
-                     _gtk_shadow_ref, _gtk_shadow_unref)
-
-struct _GtkShadow {
+struct _GtkCssValue {
+  GTK_CSS_VALUE_BASE
   GList *elements;
 
-  guint ref_count;
+  gboolean resolved;
 };
 
-GtkShadow *
-_gtk_shadow_new (void)
+static void
+gtk_css_value_shadow_free (GtkCssValue *shadow)
 {
-  GtkShadow *retval;
-
-  retval = g_slice_new0 (GtkShadow);
-  retval->ref_count = 1;
+  g_list_free_full (shadow->elements,
+                    (GDestroyNotify) shadow_element_free);
+  g_slice_free (GtkShadow, shadow);
+}
 
-  return retval;
+static gboolean
+gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
+                            const GtkCssValue *shadow2)
+{
+  /* FIXME */
+  return shadow1 == shadow2;
 }
 
-GtkShadow *
-_gtk_shadow_ref (GtkShadow *shadow)
+static void
+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
-_gtk_shadow_unref (GtkShadow *shadow)
-{
-  g_return_if_fail (shadow != NULL);
+  shadow_element_print (shadow->elements->data, string);
 
-  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,
-                        (GDestroyNotify) shadow_element_free);
-      g_slice_free (GtkShadow, shadow);
+      g_string_append (string, ", ");
+      shadow_element_print (l->data, string);
     }
 }
 
+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
 _gtk_shadow_append (GtkShadow        *shadow,
                     gdouble           hoffset,
@@ -193,7 +218,7 @@ _gtk_shadow_resolve (GtkShadow       *shadow,
                                              element->symbolic_color,
                                              &color))
         {
-          _gtk_shadow_unref (resolved_shadow);
+          _gtk_css_value_unref (resolved_shadow);
           return NULL;
         }
 
@@ -206,31 +231,9 @@ _gtk_shadow_resolve (GtkShadow       *shadow,
         g_list_append (resolved_shadow->elements, resolved_element);
     }
 
-  return resolved_shadow;
-}
-
-void
-_gtk_shadow_print (GtkShadow *shadow,
-                   GString   *str)
-{
-  gint length;
-  GList *l;
+  resolved_shadow->resolved = TRUE;
 
-  length = g_list_length (shadow->elements);
-
-  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);
-    }
+  return resolved_shadow;
 }
 
 void
diff --git a/gtk/gtkshadowprivate.h b/gtk/gtkshadowprivate.h
index c4fc035..b279bc9 100644
--- a/gtk/gtkshadowprivate.h
+++ b/gtk/gtkshadowprivate.h
@@ -26,19 +26,15 @@
 #include "gtksymboliccolor.h"
 #include "gtkicontheme.h"
 #include "gtkcsstypesprivate.h"
+#include "gtkcssvalueprivate.h"
 #include "gtkroundedboxprivate.h"
 
 G_BEGIN_DECLS
 
-typedef struct _GtkShadow GtkShadow;
-
-#define GTK_TYPE_SHADOW (_gtk_shadow_get_type ())
-
-GType      _gtk_shadow_get_type       (void) G_GNUC_CONST;
+typedef GtkCssValue GtkShadow;
 
 GtkShadow *_gtk_shadow_new            (void);
-GtkShadow *_gtk_shadow_ref            (GtkShadow          *shadow);
-void       _gtk_shadow_unref          (GtkShadow          *shadow);
+GtkShadow *_gtk_shadow_new_none       (void);
 
 void       _gtk_shadow_append         (GtkShadow          *shadow,
                                        gdouble             hoffset,
@@ -48,9 +44,6 @@ void       _gtk_shadow_append         (GtkShadow          *shadow,
                                        gboolean            inset,
                                        GtkSymbolicColor   *color);
 
-void       _gtk_shadow_print          (GtkShadow          *shadow,
-                                       GString            *string);
-
 GtkShadow *_gtk_shadow_resolve        (GtkShadow          *shadow,
                                        GtkStyleContext    *context);
 
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index 1515429..c23569d 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -301,14 +301,9 @@ static void
 _gtk_theming_background_apply_shadow (GtkThemingBackground *bg,
                                       cairo_t              *cr)
 {
-  GtkShadow *box_shadow;
-
-  box_shadow = _gtk_css_value_get_shadow (_gtk_style_context_peek_property (bg->context, "box-shadow"));
-
-  if (box_shadow != NULL)
-    {
-      _gtk_box_shadow_render (box_shadow, cr, &bg->padding_box);
-    }
+  _gtk_box_shadow_render (_gtk_style_context_peek_property (bg->context, "box-shadow"),
+                          cr,
+                          &bg->padding_box);
 }
 
 static void
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index e951105..9540dfd 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -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);
     }
 
-  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);
 
-  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);
   pango_cairo_show_layout (cr, layout);
@@ -2766,17 +2763,14 @@ render_spinner (GtkThemingEngine *engine,
   radius = MIN (width / 2, height / 2);
 
   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_translate (cr, x + width / 2, y + height / 2);
 
-  if (shadow != NULL)
-    {
-      _gtk_icon_shadow_paint_spinner (shadow, cr,
-                                      radius,
-                                      progress);
-    }
+  _gtk_icon_shadow_paint_spinner (shadow, cr,
+                                  radius,
+                                  progress);
 
   _gtk_theming_engine_paint_spinner (cr,
                                      radius,
@@ -2943,18 +2937,11 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine,
                                 gdouble x,
                                 gdouble y)
 {
-  GtkShadow *icon_shadow;
-
   cairo_save (cr);
 
   gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
 
-  icon_shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "icon-shadow"));
-
-  if (icon_shadow != NULL)
-    {
-      _gtk_icon_shadow_paint (icon_shadow, cr);
-    }
+  _gtk_icon_shadow_paint (_gtk_theming_engine_peek_property (engine, "icon-shadow"), cr);
 
   cairo_paint (cr);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]