[gtk+/wip/cssvalue: 76/165] cssvalue: Add a cssvalue for images



commit c21da18bc3d6f11bfe1ee6631f647c372b21b141
Author: Benjamin Otte <otte redhat com>
Date:   Thu Mar 29 02:58:32 2012 +0200

    cssvalue: Add a cssvalue for images

 gtk/Makefile.am                   |    2 +
 gtk/gtkborderimage.c              |    3 +-
 gtk/gtkcssimagevalue.c            |   81 +++++++++++++++++++++++++++++++++++++
 gtk/gtkcssimagevalueprivate.h     |   35 ++++++++++++++++
 gtk/gtkcssshorthandpropertyimpl.c |    5 +-
 gtk/gtkcssstylepropertyimpl.c     |   33 +++++----------
 gtk/gtkcssvalue.c                 |   18 --------
 gtk/gtkcssvalueprivate.h          |    3 -
 gtk/gtkthemingbackground.c        |    6 ++-
 9 files changed, 137 insertions(+), 49 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 1532f00..f359fe4 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -431,6 +431,7 @@ gtk_private_h_sources =		\
 	gtkcssimagelinearprivate.h	\
 	gtkcssimageprivate.h	\
 	gtkcssimageurlprivate.h	\
+	gtkcssimagevalueprivate.h	\
 	gtkcssimagewin32private.h	\
 	gtkcssinheritvalueprivate.h	\
 	gtkcssinitialvalueprivate.h	\
@@ -634,6 +635,7 @@ gtk_base_c_sources = 		\
 	gtkcssimagegradient.c	\
 	gtkcssimagelinear.c	\
 	gtkcssimageurl.c	\
+	gtkcssimagevalue.c	\
 	gtkcssimagewin32.c	\
 	gtkcssinheritvalue.c	\
 	gtkcssinitialvalue.c	\
diff --git a/gtk/gtkborderimage.c b/gtk/gtkborderimage.c
index a05c9d5..399e869 100644
--- a/gtk/gtkborderimage.c
+++ b/gtk/gtkborderimage.c
@@ -25,6 +25,7 @@
 #include <math.h>
 
 #include "gtkborderimageprivate.h"
+#include "gtkcssimagevalueprivate.h"
 #include "gtkstylepropertiesprivate.h"
 #include "gtkthemingengineprivate.h"
 
@@ -39,7 +40,7 @@ _gtk_border_image_init (GtkBorderImage   *image,
 {
   GtkBorder *width;
 
-  image->source = _gtk_css_value_get_object (_gtk_theming_engine_peek_property (engine, "border-image-source"));
+  image->source = _gtk_css_image_value_get_image (_gtk_theming_engine_peek_property (engine, "border-image-source"));
   if (image->source == NULL)
     return FALSE;
 
diff --git a/gtk/gtkcssimagevalue.c b/gtk/gtkcssimagevalue.c
new file mode 100644
index 0000000..f9028ae
--- /dev/null
+++ b/gtk/gtkcssimagevalue.c
@@ -0,0 +1,81 @@
+/* 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 "gtkcssimagevalueprivate.h"
+
+#include "gtkstylepropertyprivate.h"
+
+struct _GtkCssValue {
+  GTK_CSS_VALUE_BASE
+  GtkCssImage *image;
+};
+
+static void
+gtk_css_value_image_free (GtkCssValue *value)
+{
+  g_object_unref (value->image);
+  g_slice_free (GtkCssValue, value);
+}
+
+static gboolean
+gtk_css_value_image_equal (const GtkCssValue *value1,
+                           const GtkCssValue *value2)
+{
+  return value1->image == value2->image;
+}
+
+static void
+gtk_css_value_image_print (const GtkCssValue *value,
+                           GString           *string)
+{
+  if (value->image)
+    _gtk_css_image_print (value->image, string);
+  else
+    g_string_append (string, "none");
+}
+
+static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
+  gtk_css_value_image_free,
+  gtk_css_value_image_equal,
+  gtk_css_value_image_print
+};
+
+GtkCssValue *
+_gtk_css_image_value_new (GtkCssImage *image)
+{
+  static GtkCssValue none_singleton = { &GTK_CSS_VALUE_IMAGE, 1, NULL };
+  GtkCssValue *value;
+
+  if (image == NULL)
+    return _gtk_css_value_ref (&none_singleton);
+
+  value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IMAGE);
+  value->image = image;
+
+  return value;
+}
+
+GtkCssImage *
+_gtk_css_image_value_get_image (const GtkCssValue *value)
+{
+  g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IMAGE, NULL);
+
+  return value->image;
+}
+
diff --git a/gtk/gtkcssimagevalueprivate.h b/gtk/gtkcssimagevalueprivate.h
new file mode 100644
index 0000000..2e34850
--- /dev/null
+++ b/gtk/gtkcssimagevalueprivate.h
@@ -0,0 +1,35 @@
+/*
+ * 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_IMAGE_VALUE_PRIVATE_H__
+#define __GTK_CSS_IMAGE_VALUE_PRIVATE_H__
+
+#include "gtkcssimageprivate.h"
+#include "gtkcssvalueprivate.h"
+
+G_BEGIN_DECLS
+
+GtkCssValue *   _gtk_css_image_value_new           (GtkCssImage         *image);
+
+GtkCssImage *   _gtk_css_image_value_get_image     (const GtkCssValue   *image);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_IMAGE_VALUE_PRIVATE_H__ */
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index e4d98a0..fe67070 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -26,6 +26,7 @@
 
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssimageprivate.h"
+#include "gtkcssimagevalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssstylefuncsprivate.h"
 #include "gtkcsstypesprivate.h"
@@ -275,7 +276,7 @@ parse_border_image (GtkCssShorthandProperty  *shorthand,
       if (!image)
         return FALSE;
     }
-  values[0] = _gtk_css_value_new_take_image (image);
+  values[0] = _gtk_css_image_value_new (image);
 
   if (value_is_done_parsing (parser))
     return TRUE;
@@ -484,7 +485,7 @@ parse_background (GtkCssShorthandProperty  *shorthand,
                 return FALSE;
             }
 
-          values[0] = _gtk_css_value_new_take_image (image);
+          values[0] = _gtk_css_image_value_new (image);
         }
       else if (values[1] == NULL &&
                _gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &enum_value))
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index b055ed1..a2e35b1 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -42,7 +42,7 @@
 #include "gtkbindings.h"
 #include "gtkcssimagegradientprivate.h"
 #include "gtkcssimageprivate.h"
-#include "gtkcssimageprivate.h"
+#include "gtkcssimagevalueprivate.h"
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
@@ -563,20 +563,7 @@ css_image_value_parse (GtkCssStyleProperty *property,
         return FALSE;
     }
 
-  return _gtk_css_value_new_take_image (image);
-}
-
-static void
-css_image_value_print (GtkCssStyleProperty *property,
-                       const GtkCssValue   *value,
-                       GString             *string)
-{
-  GtkCssImage *image = _gtk_css_value_get_image (value);
-
-  if (image)
-    _gtk_css_image_print (image, string);
-  else
-    g_string_append (string, "none");
+  return _gtk_css_image_value_new (image);
 }
 
 static GtkCssValue *
@@ -586,7 +573,7 @@ css_image_value_compute (GtkCssStyleProperty    *property,
 {
   GtkCssImage *image, *computed;
   
-  image = _gtk_css_value_get_image (specified);
+  image = _gtk_css_image_value_get_image (specified);
 
   if (image == NULL)
     return _gtk_css_value_ref (specified);
@@ -599,7 +586,7 @@ css_image_value_compute (GtkCssStyleProperty    *property,
       return _gtk_css_value_ref (specified);
     }
 
-  return _gtk_css_value_new_take_image (computed);
+  return _gtk_css_image_value_new (computed);
 }
 
 static void
@@ -607,7 +594,7 @@ css_image_value_query (GtkCssStyleProperty *property,
                        const GtkCssValue   *css_value,
                        GValue              *value)
 {
-  GtkCssImage *image = _gtk_css_value_get_image (css_value);
+  GtkCssImage *image = _gtk_css_image_value_get_image (css_value);
   cairo_pattern_t *pattern;
   cairo_surface_t *surface;
   cairo_matrix_t matrix;
@@ -636,7 +623,7 @@ css_image_value_assign (GtkCssStyleProperty *property,
                         const GValue        *value)
 {
   g_warning ("FIXME: assigning images is not implemented");
-  return _gtk_css_value_new_take_image (NULL);
+  return _gtk_css_image_value_new (NULL);
 }
 
 static GtkCssValue *
@@ -1673,23 +1660,23 @@ _gtk_css_style_property_init_properties (void)
                                           CAIRO_GOBJECT_TYPE_PATTERN,
                                           0,
                                           css_image_value_parse,
-                                          css_image_value_print,
+                                          NULL,
                                           css_image_value_compute,
                                           css_image_value_query,
                                           css_image_value_assign,
                                           NULL,
-                                          _gtk_css_value_new_take_image (NULL));
+                                          _gtk_css_image_value_new (NULL));
 
   gtk_css_style_property_register        ("border-image-source",
                                           CAIRO_GOBJECT_TYPE_PATTERN,
                                           0,
                                           css_image_value_parse,
-                                          css_image_value_print,
+                                          NULL,
                                           css_image_value_compute,
                                           css_image_value_query,
                                           css_image_value_assign,
                                           NULL,
-                                          _gtk_css_value_new_take_image (NULL));
+                                          _gtk_css_image_value_new (NULL));
   gtk_css_style_property_register        ("border-image-repeat",
                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
                                           0,
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index 069a8a2..0ab7f56 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -270,17 +270,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
 }
 
 GtkCssValue *
-_gtk_css_value_new_take_image (GtkCssImage *v)
-{
-  GtkCssValue *value;
-
-  value = gtk_css_value_new (GTK_TYPE_CSS_IMAGE);
-  value->u.ptr = v;
-
-  return value;
-}
-
-GtkCssValue *
 _gtk_css_value_new_from_theming_engine (GtkThemingEngine *v)
 {
   GtkCssValue *value;
@@ -563,13 +552,6 @@ _gtk_css_value_get_strv (const GtkCssValue *value)
   return value->u.ptr;
 }
 
-GtkCssImage *
-_gtk_css_value_get_image (const GtkCssValue *value)
-{
-  g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_IMAGE), NULL);
-  return value->u.ptr;
-}
-
 GtkBorderStyle
 _gtk_css_value_get_border_style (const GtkCssValue *value)
 {
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index 22e885a..4fa5589 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -23,7 +23,6 @@
 #include <glib-object.h>
 #include "gtkcsstypesprivate.h"
 #include "gtksymboliccolor.h"
-#include "gtkcssimageprivate.h"
 #include "gtkthemingengine.h"
 
 G_BEGIN_DECLS
@@ -84,7 +83,6 @@ GtkCssValue *_gtk_css_value_new_from_boxed            (GType
 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_image            (GtkCssImage                *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_from_background_size  (const GtkCssBackgroundSize *v);
@@ -103,7 +101,6 @@ gpointer                        _gtk_css_value_get_object                 (const
 gpointer                        _gtk_css_value_get_boxed                  (const GtkCssValue *value);
 const char **                   _gtk_css_value_get_strv                   (const GtkCssValue *value);
 GtkSymbolicColor               *_gtk_css_value_get_symbolic_color         (const GtkCssValue *value);
-GtkCssImage                    *_gtk_css_value_get_image                  (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);
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index 4fee2ee..63050fa 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -21,8 +21,10 @@
 
 #include "config.h"
 
-#include "gtkcsstypesprivate.h"
 #include "gtkthemingbackgroundprivate.h"
+
+#include "gtkcssimagevalueprivate.h"
+#include "gtkcsstypesprivate.h"
 #include "gtkthemingengineprivate.h"
 
 #include <math.h>
@@ -335,7 +337,7 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg)
   _gtk_theming_background_apply_clip (bg);
   _gtk_theming_background_apply_origin (bg);
 
-  bg->image = _gtk_css_value_get_image (_gtk_style_context_peek_property (bg->context, "background-image"));
+  bg->image = _gtk_css_image_value_get_image (_gtk_style_context_peek_property (bg->context, "background-image"));
 }
 
 void



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