[gtk+/wip/multiple-backgrounds: 5/8] styleproperty: make background-image an array value



commit eeef2c30e874f63ab4c6e7f6e999080149138abc
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu May 10 11:18:29 2012 -0400

    styleproperty: make background-image an array value
    
    This also requires having the GtkCssArrayValue parse func forward the
    base GFile from the style property parse implementation.

 gtk/gtkcssarrayvalue.c        |    7 ++-
 gtk/gtkcssarrayvalueprivate.h |   10 +++-
 gtk/gtkcssstylepropertyimpl.c |  103 ++++++++++++++++++++++++++++++----------
 gtk/gtkthemingbackground.c    |    2 +-
 4 files changed, 90 insertions(+), 32 deletions(-)
---
diff --git a/gtk/gtkcssarrayvalue.c b/gtk/gtkcssarrayvalue.c
index 4a52ef8..329301b 100644
--- a/gtk/gtkcssarrayvalue.c
+++ b/gtk/gtkcssarrayvalue.c
@@ -123,7 +123,8 @@ _gtk_css_array_value_new_from_array (GtkCssValue **values,
 
 GtkCssValue *
 _gtk_css_array_value_parse (GtkCssParser *parser,
-                            GtkCssValue  *(* parse_func) (GtkCssParser *parser),
+                            GtkCssArrayValueParseFunc parse_func,
+                            GFile        *base,
                             gboolean      allow_none)
 {
   GtkCssValue *value, *result;
@@ -136,7 +137,7 @@ _gtk_css_array_value_parse (GtkCssParser *parser,
   values = g_ptr_array_new ();
 
   do {
-    value = parse_func (parser);
+    value = parse_func (parser, base);
 
     if (value == NULL)
       {
@@ -155,7 +156,7 @@ _gtk_css_array_value_parse (GtkCssParser *parser,
 
 GtkCssValue *
 _gtk_css_array_value_compute (GtkCssValue     *value,
-                              GtkCssValue *    (* compute_func) (GtkCssValue *, GtkStyleContext *),
+                              GtkCssArrayValueComputeFunc compute_func,
                               GtkStyleContext *context)
 {
   GtkCssValue *result;
diff --git a/gtk/gtkcssarrayvalueprivate.h b/gtk/gtkcssarrayvalueprivate.h
index ad3ae3c..1bc01a4 100644
--- a/gtk/gtkcssarrayvalueprivate.h
+++ b/gtk/gtkcssarrayvalueprivate.h
@@ -26,15 +26,21 @@
 
 G_BEGIN_DECLS
 
+typedef GtkCssValue * (* GtkCssArrayValueParseFunc) (GtkCssParser *,
+                                                     GFile        *);
+typedef GtkCssValue * (* GtkCssArrayValueComputeFunc) (GtkCssValue *,
+                                                       GtkStyleContext *);
+
 GtkCssValue *       _gtk_css_array_value_new            (GtkCssValue           *content);
 GtkCssValue *       _gtk_css_array_value_new_from_array (GtkCssValue          **values,
                                                          guint                  n_values);
 GtkCssValue *       _gtk_css_array_value_parse          (GtkCssParser          *parser,
-                                                         GtkCssValue *          (* parse_func) (GtkCssParser *),
+                                                         GtkCssArrayValueParseFunc parse_func,
+                                                         GFile                 *base,
                                                          gboolean               allow_none);
 
 GtkCssValue *       _gtk_css_array_value_compute        (GtkCssValue           *value,
-                                                         GtkCssValue *          (* compute_func) (GtkCssValue *, GtkStyleContext *),
+                                                         GtkCssArrayValueComputeFunc compute_func,
                                                          GtkStyleContext       *context);
 GtkCssValue *       _gtk_css_array_value_get_nth        (const GtkCssValue     *value,
                                                          guint                  i);
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 963f793..bfa0a12 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -224,7 +224,8 @@ color_assign (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
-font_family_parse_one (GtkCssParser *parser)
+font_family_parse_one (GtkCssParser *parser,
+                       GFile        *base)
 {
   char *name;
 
@@ -256,7 +257,7 @@ font_family_parse (GtkCssStyleProperty *property,
                    GtkCssParser        *parser,
                    GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, font_family_parse_one, FALSE);
+  return _gtk_css_array_value_parse (parser, font_family_parse_one, base, FALSE);
 }
 
 static void
@@ -418,7 +419,8 @@ assign_border_style (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
-parse_css_area_one (GtkCssParser *parser)
+parse_css_area_one (GtkCssParser *parser,
+                    GFile        *base)
 {
   GtkCssValue *value = _gtk_css_area_value_try_parse (parser);
   
@@ -433,11 +435,12 @@ parse_css_area (GtkCssStyleProperty *property,
                 GtkCssParser        *parser,
                 GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, parse_css_area_one, FALSE);
+  return _gtk_css_array_value_parse (parser, parse_css_area_one, base, FALSE);
 }
 
 static GtkCssValue *
-bindings_value_parse_one (GtkCssParser *parser)
+bindings_value_parse_one (GtkCssParser *parser,
+                          GFile        *base)
 {
   char *name;
 
@@ -464,7 +467,7 @@ bindings_value_parse (GtkCssStyleProperty *property,
                       GtkCssParser        *parser,
                       GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, bindings_value_parse_one, TRUE);
+  return _gtk_css_array_value_parse (parser, bindings_value_parse_one, base, TRUE);
 }
 
 static void
@@ -552,7 +555,7 @@ static GtkCssValue *
 css_image_value_parse (GtkCssStyleProperty *property,
                        GtkCssParser        *parser,
                        GFile               *base)
-{
+{ 
   GtkCssImage *image;
 
   if (_gtk_css_parser_try (parser, "none", TRUE))
@@ -564,16 +567,16 @@ css_image_value_parse (GtkCssStyleProperty *property,
         return FALSE;
     }
 
-  return _gtk_css_image_value_new (image);
+  return _gtk_css_image_value_new (image); 
 }
 
 static GtkCssValue *
-css_image_value_compute (GtkCssStyleProperty    *property,
-                         GtkStyleContext        *context,
-                         GtkCssValue            *specified)
+css_image_value_compute (GtkCssStyleProperty *property,
+                         GtkStyleContext     *context,
+                         GtkCssValue         *specified)
 {
   GtkCssImage *image, *computed;
-  
+
   image = _gtk_css_image_value_get_image (specified);
 
   if (image == NULL)
@@ -628,6 +631,51 @@ css_image_value_assign (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
+background_image_value_parse_one (GtkCssParser *parser,
+                                  GFile        *base)
+{
+  return css_image_value_parse (NULL, parser, base);
+}
+
+static GtkCssValue *
+background_image_value_parse (GtkCssStyleProperty *property,
+                              GtkCssParser        *parser,
+                              GFile               *base)
+{
+  return _gtk_css_array_value_parse (parser, background_image_value_parse_one, base, FALSE);
+}
+
+static GtkCssValue *
+background_image_value_compute_one (GtkCssValue     *value,
+                                    GtkStyleContext *context)
+{
+  return css_image_value_compute (NULL, context, value);
+}
+
+static GtkCssValue *
+background_image_value_compute (GtkCssStyleProperty    *property,
+                                GtkStyleContext        *context,
+                                GtkCssValue            *specified)
+{
+  return _gtk_css_array_value_compute (specified, background_image_value_compute_one, context);
+}
+
+static void
+background_image_value_query (GtkCssStyleProperty *property,
+                              const GtkCssValue   *css_value,
+                              GValue              *value)
+{
+  css_image_value_query (property, _gtk_css_array_value_get_nth (css_value, 0), value);
+}
+
+static GtkCssValue *
+background_image_value_assign (GtkCssStyleProperty *property,
+                               const GValue        *value)
+{
+  return _gtk_css_array_value_new (css_image_value_assign (property, value));
+}
+
+static GtkCssValue *
 font_size_parse (GtkCssStyleProperty *property,
                  GtkCssParser        *parser,
                  GFile               *base)
@@ -721,7 +769,8 @@ compute_border (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
-transition_property_parse_one (GtkCssParser *parser)
+transition_property_parse_one (GtkCssParser *parser,
+                               GFile        *base)
 {
   GtkCssValue *value;
 
@@ -741,11 +790,12 @@ transition_property_parse (GtkCssStyleProperty *property,
                            GtkCssParser        *parser,
                            GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, transition_property_parse_one, FALSE);
+  return _gtk_css_array_value_parse (parser, transition_property_parse_one, base, FALSE);
 }
 
 static GtkCssValue *
-transition_time_parse_one (GtkCssParser *parser)
+transition_time_parse_one (GtkCssParser *parser,
+                           GFile        *base)
 {
   return _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_TIME);
 }
@@ -755,7 +805,7 @@ transition_time_parse (GtkCssStyleProperty *property,
                        GtkCssParser        *parser,
                        GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, transition_time_parse_one, FALSE);
+  return _gtk_css_array_value_parse (parser, transition_time_parse_one, base, FALSE);
 }
 
 static GtkCssValue *
@@ -763,7 +813,7 @@ transition_timing_function_parse (GtkCssStyleProperty *property,
                                   GtkCssParser        *parser,
                                   GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, _gtk_css_ease_value_parse, FALSE);
+  return _gtk_css_array_value_parse (parser, (GtkCssArrayValueParseFunc) _gtk_css_ease_value_parse, base, FALSE);
 }
 
 static GtkCssValue *
@@ -858,7 +908,8 @@ compute_border_width (GtkCssStyleProperty    *property,
 }
 
 static GtkCssValue *
-background_repeat_value_parse_one (GtkCssParser *parser)
+background_repeat_value_parse_one (GtkCssParser *parser,
+                                   GFile        *base)
 {
   GtkCssValue *value = _gtk_css_background_repeat_value_try_parse (parser);
 
@@ -876,7 +927,7 @@ background_repeat_value_parse (GtkCssStyleProperty *property,
                                GtkCssParser        *parser,
                                GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, background_repeat_value_parse_one, FALSE);
+  return _gtk_css_array_value_parse (parser, background_repeat_value_parse_one, base, FALSE);
 }
 
 static GtkCssValue *
@@ -884,7 +935,7 @@ background_size_parse (GtkCssStyleProperty *property,
                        GtkCssParser        *parser,
                        GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, _gtk_css_bg_size_value_parse, FALSE);
+  return _gtk_css_array_value_parse (parser, (GtkCssArrayValueParseFunc) _gtk_css_bg_size_value_parse, base, FALSE);
 }
 
 static GtkCssValue *
@@ -900,7 +951,7 @@ background_position_parse (GtkCssStyleProperty *property,
 			   GtkCssParser        *parser,
 			   GFile               *base)
 {
-  return _gtk_css_array_value_parse (parser, _gtk_css_position_value_parse, FALSE);
+  return _gtk_css_array_value_parse (parser, (GtkCssArrayValueParseFunc) _gtk_css_position_value_parse, base, FALSE);
 }
 
 static GtkCssValue *
@@ -1400,12 +1451,12 @@ _gtk_css_style_property_init_properties (void)
                                           GTK_CSS_PROPERTY_BACKGROUND_IMAGE,
                                           CAIRO_GOBJECT_TYPE_PATTERN,
                                           GTK_STYLE_PROPERTY_ANIMATED,
-                                          css_image_value_parse,
+                                          background_image_value_parse,
                                           NULL,
-                                          css_image_value_compute,
-                                          css_image_value_query,
-                                          css_image_value_assign,
-                                          _gtk_css_image_value_new (NULL));
+                                          background_image_value_compute,
+                                          background_image_value_query,
+                                          background_image_value_assign,
+                                          _gtk_css_array_value_new (_gtk_css_image_value_new (NULL)));
 
   gtk_css_style_property_register        ("border-image-source",
                                           GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE,
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index 4bc5d5e..ead7518 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -292,7 +292,7 @@ _gtk_theming_background_init_context (GtkThemingBackground *bg)
   _gtk_theming_background_apply_clip (bg);
   _gtk_theming_background_apply_origin (bg);
 
-  bg->image = _gtk_css_image_value_get_image (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE));
+  bg->image = _gtk_css_image_value_get_image (_gtk_css_array_value_get_nth (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE), 0));
 }
 
 void



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