[gtk+/wip/cssvalue: 117/137] cssvalue: Add a cssvalue for background-size



commit 83ff941257be826f277392d39abc083c671de866
Author: Benjamin Otte <otte redhat com>
Date:   Wed Apr 4 12:39:55 2012 +0200

    cssvalue: Add a cssvalue for background-size

 gtk/Makefile.am                |    2 +
 gtk/gtkcssbgsizevalue.c        |  258 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssbgsizevalueprivate.h |   45 +++++++
 gtk/gtkcssstylepropertyimpl.c  |   82 +------------
 gtk/gtkcsstypes.c              |   12 --
 gtk/gtkcsstypesprivate.h       |   12 --
 gtk/gtkcssvalue.c              |   18 ---
 gtk/gtkcssvalueprivate.h       |    2 -
 gtk/gtkthemingbackground.c     |   56 +--------
 9 files changed, 317 insertions(+), 170 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index a1c1147..01ea4ca 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -424,6 +424,7 @@ gtk_private_h_sources =		\
 	gtkcolorchooserprivate.h	\
 	gtkcontainerprivate.h   \
 	gtkcssarrayvalueprivate.h	\
+	gtkcssbgsizevalueprivate.h	\
 	gtkcsscomputedvaluesprivate.h \
 	gtkcsscornervalueprivate.h	\
 	gtkcsscustompropertyprivate.h \
@@ -636,6 +637,7 @@ gtk_base_c_sources = 		\
 	gtkcomboboxtext.c	\
 	gtkcontainer.c		\
 	gtkcssarrayvalue.c	\
+	gtkcssbgsizevalue.c	\
 	gtkcsscomputedvalues.c	\
 	gtkcsscornervalue.c	\
 	gtkcsscustomproperty.c	\
diff --git a/gtk/gtkcssbgsizevalue.c b/gtk/gtkcssbgsizevalue.c
new file mode 100644
index 0000000..24e0fae
--- /dev/null
+++ b/gtk/gtkcssbgsizevalue.c
@@ -0,0 +1,258 @@
+/* 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 "gtkcssbgsizevalueprivate.h"
+
+#include "gtkcssnumbervalueprivate.h"
+
+struct _GtkCssValue {
+  GTK_CSS_VALUE_BASE
+  guint cover :1;
+  guint contain :1;
+  GtkCssValue *x;
+  GtkCssValue *y;
+};
+
+static void
+gtk_css_value_bg_size_free (GtkCssValue *value)
+{
+  if (value->x)
+    _gtk_css_value_unref (value->x);
+  if (value->y)
+    _gtk_css_value_unref (value->y);
+
+  g_slice_free (GtkCssValue, value);
+}
+
+static gboolean
+gtk_css_value_bg_size_equal (const GtkCssValue *value1,
+                             const GtkCssValue *value2)
+{
+  return value1->cover == value2->cover &&
+         value2->contain == value2->contain &&
+         (value1->x == value2->x ||
+          (value1->x != NULL && value2->x != NULL &&
+           _gtk_css_value_equal (value1->x, value2->x))) &&
+         (value1->y == value2->y ||
+          (value1->y != NULL && value2->y != NULL &&
+           _gtk_css_value_equal (value1->y, value2->y)));
+}
+
+static GtkCssValue *
+gtk_css_value_bg_size_transition (GtkCssValue *start,
+                                  GtkCssValue *end,
+                                  double       progress)
+{
+  GtkCssValue *x, *y;
+
+  if (start->cover)
+    return end->cover ? _gtk_css_value_ref (end) : NULL;
+  if (start->contain)
+    return end->contain ? _gtk_css_value_ref (end) : NULL;
+
+  if ((start->x != NULL) ^ (end->x != NULL) ||
+      (start->y != NULL) ^ (end->y != NULL))
+    return NULL;
+
+  if (start->x)
+    {
+      x = _gtk_css_value_transition (start->x, end->x, progress);
+      if (x == NULL)
+        return NULL;
+    }
+  else
+    x = NULL;
+
+  if (start->y)
+    {
+      y = _gtk_css_value_transition (start->y, end->y, progress);
+      if (y == NULL)
+        {
+          _gtk_css_value_unref (x);
+          return NULL;
+        }
+    }
+  else
+    y = NULL;
+
+  return _gtk_css_bg_size_value_new (x, y);
+}
+
+static void
+gtk_css_value_bg_size_print (const GtkCssValue *value,
+                             GString           *string)
+{
+  if (value->cover)
+    g_string_append (string, "cover");
+  else if (value->contain)
+    g_string_append (string, "contain");
+  else
+    {
+      if (value->x == NULL)
+        g_string_append (string, "auto");
+      else
+        _gtk_css_value_print (value->x, string);
+
+      if (value->y)
+        {
+          g_string_append_c (string, ' ');
+          _gtk_css_value_print (value->y, string);
+        }
+    }
+}
+
+static const GtkCssValueClass GTK_CSS_VALUE_BG_SIZE = {
+  gtk_css_value_bg_size_free,
+  gtk_css_value_bg_size_equal,
+  gtk_css_value_bg_size_transition,
+  gtk_css_value_bg_size_print
+};
+
+static GtkCssValue auto_singleton = { &GTK_CSS_VALUE_BG_SIZE, 1, FALSE, FALSE, NULL, NULL };
+static GtkCssValue cover_singleton = { &GTK_CSS_VALUE_BG_SIZE, 1, TRUE, FALSE, NULL, NULL };
+static GtkCssValue contain_singleton = { &GTK_CSS_VALUE_BG_SIZE, 1, FALSE, TRUE, NULL, NULL };
+
+GtkCssValue *
+_gtk_css_bg_size_value_new (GtkCssValue *x,
+                            GtkCssValue *y)
+{
+  GtkCssValue *result;
+
+  if (x == NULL && y == NULL)
+    return _gtk_css_value_ref (&auto_singleton);
+
+  result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_BG_SIZE);
+  result->x = x;
+  result->y = y;
+
+  return result;
+}
+
+GtkCssValue *
+_gtk_css_bg_size_value_parse (GtkCssParser *parser)
+{
+  GtkCssValue *x, *y;
+
+  if (_gtk_css_parser_try (parser, "cover", TRUE))
+    return _gtk_css_value_ref (&cover_singleton);
+  else if (_gtk_css_parser_try (parser, "contain", TRUE))
+    return _gtk_css_value_ref (&contain_singleton);
+
+  if (_gtk_css_parser_try (parser, "auto", TRUE))
+    x = NULL;
+  else
+    {
+      x = _gtk_css_number_value_parse (parser,
+                                       GTK_CSS_POSITIVE_ONLY
+                                       | GTK_CSS_PARSE_PERCENT
+                                       | GTK_CSS_PARSE_LENGTH);
+      if (x == NULL)
+        return NULL;
+    }
+
+  if (_gtk_css_parser_try (parser, "auto", TRUE))
+    y = NULL;
+  else if (!_gtk_css_parser_has_number (parser))
+    y = NULL;
+  else
+    {
+      y = _gtk_css_number_value_parse (parser,
+                                       GTK_CSS_POSITIVE_ONLY
+                                       | GTK_CSS_PARSE_PERCENT
+                                       | GTK_CSS_PARSE_LENGTH);
+      if (y == NULL)
+        {
+          _gtk_css_value_unref (x);
+          return NULL;
+        }
+    }
+
+  return _gtk_css_bg_size_value_new (x, y);
+}
+
+static void
+gtk_css_bg_size_compute_size_for_cover_contain (gboolean     cover,
+                                                GtkCssImage *image,
+                                                double       width,
+                                                double       height,
+                                                double      *concrete_width,
+                                                double      *concrete_height)
+{
+  double aspect, image_aspect;
+  
+  image_aspect = _gtk_css_image_get_aspect_ratio (image);
+  if (image_aspect == 0.0)
+    {
+      *concrete_width = width;
+      *concrete_height = height;
+      return;
+    }
+
+  aspect = width / height;
+
+  if ((aspect >= image_aspect && cover) ||
+      (aspect < image_aspect && !cover))
+    {
+      *concrete_width = width;
+      *concrete_height = width / image_aspect;
+    }
+  else
+    {
+      *concrete_height = height;
+      *concrete_width = height * image_aspect;
+    }
+}
+
+void
+_gtk_css_bg_size_value_compute_size (const GtkCssValue *value,
+                                     GtkCssImage       *image,
+                                     double             area_width,
+                                     double             area_height,
+                                     double            *out_width,
+                                     double            *out_height)
+{
+  g_return_if_fail (value->class == &GTK_CSS_VALUE_BG_SIZE);
+
+  if (value->contain || value->cover)
+    gtk_css_bg_size_compute_size_for_cover_contain (value->cover,
+                                                    image,
+                                                    area_width, area_height,
+                                                    out_width, out_height);
+  else
+    _gtk_css_image_get_concrete_size (image,
+                                      /* note: 0 does the right thing here for 'auto' */
+                                      value->x ? _gtk_css_number_value_get (value->x, area_width) : 0,
+                                      value->y ? _gtk_css_number_value_get (value->y, area_height) : 0,
+                                      area_width, area_height,
+                                      out_width, out_height);
+}
+
+GtkCssValue *
+_gtk_css_bg_size_value_compute (GtkCssValue     *value,
+                                GtkStyleContext *context)
+{
+  g_return_val_if_fail (value->class == &GTK_CSS_VALUE_BG_SIZE, NULL);
+
+  if (value->x == NULL && value->y == NULL)
+    return _gtk_css_value_ref (value);
+
+  return _gtk_css_bg_size_value_new (value->x ? _gtk_css_number_value_compute (value->x, context) : NULL,
+                                     value->y ? _gtk_css_number_value_compute (value->y, context) : NULL);
+}
+
diff --git a/gtk/gtkcssbgsizevalueprivate.h b/gtk/gtkcssbgsizevalueprivate.h
new file mode 100644
index 0000000..cae8d13
--- /dev/null
+++ b/gtk/gtkcssbgsizevalueprivate.h
@@ -0,0 +1,45 @@
+/*
+ * 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_BG_SIZE_VALUE_PRIVATE_H__
+#define __GTK_CSS_BG_SIZE_VALUE_PRIVATE_H__
+
+#include "gtkcssparserprivate.h"
+#include "gtkcssimageprivate.h"
+#include "gtkcssvalueprivate.h"
+
+G_BEGIN_DECLS
+
+GtkCssValue *   _gtk_css_bg_size_value_new          (GtkCssValue            *x,
+                                                     GtkCssValue            *y);
+GtkCssValue *   _gtk_css_bg_size_value_parse        (GtkCssParser           *parser);
+
+void            _gtk_css_bg_size_value_compute_size (const GtkCssValue      *bg_size,
+                                                     GtkCssImage            *image,
+                                                     double                  area_width,
+                                                     double                  area_height,
+                                                     double                 *out_width,
+                                                     double                 *out_height);
+GtkCssValue *   _gtk_css_bg_size_value_compute      (GtkCssValue            *bg_size,
+                                                     GtkStyleContext        *context);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_BG_SIZE_VALUE_PRIVATE_H__ */
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 4100125..b8f671e 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -41,6 +41,7 @@
 #include "gtkanimationdescription.h"
 #include "gtkbindings.h"
 #include "gtkcssarrayvalueprivate.h"
+#include "gtkcssbgsizevalueprivate.h"
 #include "gtkcsscornervalueprivate.h"
 #include "gtkcsseasevalueprivate.h"
 #include "gtkcssenginevalueprivate.h"
@@ -888,65 +889,7 @@ background_size_parse (GtkCssStyleProperty *property,
                        GtkCssParser        *parser,
                        GFile               *base)
 {
-  GtkCssBackgroundSize size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE};
-
-  if (_gtk_css_parser_try (parser, "cover", TRUE))
-    size.cover = TRUE;
-  else if (_gtk_css_parser_try (parser, "contain", TRUE))
-    size.contain = TRUE;
-  else
-    {
-      if (_gtk_css_parser_try (parser, "auto", TRUE))
-        _gtk_css_number_init (&size.width, 0, GTK_CSS_PX);
-      else if (!_gtk_css_parser_read_number (parser,
-                                             &size.width,
-                                             GTK_CSS_POSITIVE_ONLY
-                                             | GTK_CSS_PARSE_PERCENT
-                                             | GTK_CSS_PARSE_LENGTH))
-        return NULL;
-
-      if (_gtk_css_parser_try (parser, "auto", TRUE))
-        _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
-      else if (_gtk_css_parser_has_number (parser))
-        {
-          if (!_gtk_css_parser_read_number (parser,
-                                            &size.height,
-                                            GTK_CSS_POSITIVE_ONLY
-                                            | GTK_CSS_PARSE_PERCENT
-                                            | GTK_CSS_PARSE_LENGTH))
-            return NULL;
-        }
-      else
-        _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
-    }
-
-  return _gtk_css_value_new_from_background_size (&size);
-}
-
-static void
-background_size_print (GtkCssStyleProperty *property,
-                       const GtkCssValue   *value,
-                       GString             *string)
-{
-  const GtkCssBackgroundSize *size = _gtk_css_value_get_background_size (value);
-
-  if (size->cover)
-    g_string_append (string, "cover");
-  else if (size->contain)
-    g_string_append (string, "contain");
-  else
-    {
-      if (size->width.value == 0)
-        g_string_append (string, "auto");
-      else
-        _gtk_css_number_print (&size->width, string);
-
-      if (size->height.value != 0)
-        {
-          g_string_append (string, " ");
-          _gtk_css_number_print (&size->height, string);
-        }
-    }
+  return _gtk_css_bg_size_value_parse (parser);
 }
 
 static GtkCssValue *
@@ -954,21 +897,7 @@ background_size_compute (GtkCssStyleProperty    *property,
                          GtkStyleContext        *context,
                          GtkCssValue            *specified)
 {
-  const GtkCssBackgroundSize *ssize = _gtk_css_value_get_background_size (specified);
-  GtkCssBackgroundSize csize;
-  gboolean changed;
-
-  csize.cover = ssize->cover;
-  csize.contain = ssize->contain;
-  changed = _gtk_css_number_compute (&csize.width,
-				     &ssize->width,
-				     context);
-  changed |= _gtk_css_number_compute (&csize.height,
-				      &ssize->height,
-				      context);
-  if (changed)
-    return _gtk_css_value_new_from_background_size (&csize);
-  return _gtk_css_value_ref (specified);
+  return _gtk_css_bg_size_value_compute (specified, context);
 }
 
 static GtkCssValue *
@@ -1003,7 +932,6 @@ gtk_symbolic_color_new_rgba (double red,
 void
 _gtk_css_style_property_init_properties (void)
 {
-  GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE };
   GtkBorder border_of_ones = { 1, 1, 1, 1 };
 
   /* Initialize "color" and "font-size" first,
@@ -1421,12 +1349,12 @@ _gtk_css_style_property_init_properties (void)
                                           G_TYPE_NONE,
                                           0,
                                           background_size_parse,
-                                          background_size_print,
+                                          NULL,
                                           background_size_compute,
                                           NULL,
                                           NULL,
                                           NULL,
-                                          _gtk_css_value_new_from_background_size (&default_background_size));
+                                          _gtk_css_bg_size_value_new (NULL, NULL));
   gtk_css_style_property_register        ("background-position",
                                           GTK_CSS_PROPERTY_BACKGROUND_POSITION,
                                           G_TYPE_NONE,
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index af1a699..3962e2f 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -22,18 +22,6 @@
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkstylecontextprivate.h"
 
-#define DEFINE_BOXED_TYPE_WITH_COPY_FUNC(TypeName, type_name) \
-\
-static TypeName * \
-type_name ## _copy (const TypeName *foo) \
-{ \
-  return g_memdup (foo, sizeof (TypeName)); \
-} \
-\
-G_DEFINE_BOXED_TYPE (TypeName, type_name, type_name ## _copy, g_free)
-
-DEFINE_BOXED_TYPE_WITH_COPY_FUNC (GtkCssBackgroundSize, _gtk_css_background_size)
-
 typedef struct _GtkCssChangeTranslation GtkCssChangeTranslation;
 struct _GtkCssChangeTranslation {
   GtkCssChange from;
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index cc56937..b083889 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -158,24 +158,12 @@ typedef enum /*< skip >*/ {
 } GtkCssUnit;
 
 typedef struct _GtkCssNumber GtkCssNumber;
-typedef struct _GtkCssBackgroundSize GtkCssBackgroundSize;
 
 struct _GtkCssNumber {
   gdouble        value;
   GtkCssUnit     unit;
 };
 
-struct _GtkCssBackgroundSize {
-  GtkCssNumber width;  /* 0 means auto here */
-  GtkCssNumber height; /* 0 means auto here */
-  guint cover :1;
-  guint contain :1;
-};
-
-#define GTK_TYPE_CSS_BACKGROUND_SIZE _gtk_css_background_size_get_type ()
-
-GType           _gtk_css_background_size_get_type               (void);
-
 GtkCssChange    _gtk_css_change_for_sibling                      (GtkCssChange       match);
 GtkCssChange    _gtk_css_change_for_child                        (GtkCssChange       match);
 
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index 25a0a1d..9aefcfa 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -250,17 +250,6 @@ _gtk_css_value_new_from_color (const GdkColor *v)
 }
 
 GtkCssValue *
-_gtk_css_value_new_from_background_size (const GtkCssBackgroundSize *v)
-{
-  GtkCssValue *value;
-
-  value = gtk_css_value_new (GTK_TYPE_CSS_BACKGROUND_SIZE);
-  value->u.ptr = g_boxed_copy0 (GTK_TYPE_CSS_BACKGROUND_SIZE, v);
-
-  return value;
-}
-
-GtkCssValue *
 _gtk_css_value_new_from_border_style (GtkBorderStyle style)
 {
   GtkCssValue *value;
@@ -485,13 +474,6 @@ _gtk_css_value_get_border_style (const GtkCssValue *value)
   return value->u.gint;
 }
 
-const GtkCssBackgroundSize *
-_gtk_css_value_get_background_size (const GtkCssValue *value)
-{
-  g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_CSS_BACKGROUND_SIZE), NULL);
-  return value->u.ptr;
-}
-
 GtkGradient *
 _gtk_css_value_get_gradient (const GtkCssValue *value)
 {
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index 7cd450a..0dc1f9a 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -88,7 +88,6 @@ GtkCssValue *_gtk_css_value_new_from_color            (const GdkColor
 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_binding_sets     (GPtrArray                  *array);
-GtkCssValue *_gtk_css_value_new_from_background_size  (const GtkCssBackgroundSize *v);
 void         _gtk_css_value_init_gvalue               (const GtkCssValue          *value,
 						       GValue                     *g_value);
 
@@ -99,7 +98,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);
-const GtkCssBackgroundSize     *_gtk_css_value_get_background_size        (const GtkCssValue *value);
 GtkGradient                    *_gtk_css_value_get_gradient               (const GtkCssValue *value);
 
 G_END_DECLS
diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c
index 4cb43aa..245164c 100644
--- a/gtk/gtkthemingbackground.c
+++ b/gtk/gtkthemingbackground.c
@@ -24,6 +24,7 @@
 #include "gtkthemingbackgroundprivate.h"
 
 #include "gtkcssarrayvalueprivate.h"
+#include "gtkcssbgsizevalueprivate.h"
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssimagevalueprivate.h"
 #include "gtkcssshadowsvalueprivate.h"
@@ -113,39 +114,6 @@ _gtk_theming_background_apply_clip (GtkThemingBackground *bg)
 }
 
 static void
-_gtk_theming_background_get_cover_contain (GtkCssImage *image,
-                                           gboolean     cover,
-                                           double       width,
-                                           double       height,
-                                           double      *concrete_width,
-                                           double      *concrete_height)
-{
-  double aspect, image_aspect;
-  
-  image_aspect = _gtk_css_image_get_aspect_ratio (image);
-  if (image_aspect == 0.0)
-    {
-      *concrete_width = width;
-      *concrete_height = height;
-      return;
-    }
-
-  aspect = width / height;
-
-  if ((aspect >= image_aspect && cover) ||
-      (aspect < image_aspect && !cover))
-    {
-      *concrete_width = width;
-      *concrete_height = width / image_aspect;
-    }
-  else
-    {
-      *concrete_height = height;
-      *concrete_width = height * image_aspect;
-    }
-}
-
-static void
 _gtk_theming_background_paint (GtkThemingBackground *bg,
                                cairo_t              *cr)
 {
@@ -161,13 +129,11 @@ _gtk_theming_background_paint (GtkThemingBackground *bg,
       && bg->image_rect.width > 0
       && bg->image_rect.height > 0)
     {
-      const GtkCssBackgroundSize *size;
       const GtkCssValue *pos, *repeat;
       double image_width, image_height;
       double width, height;
       GtkCssRepeatStyle hrepeat, vrepeat;
 
-      size = _gtk_css_value_get_background_size (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_SIZE));
       pos = _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_POSITION);
       repeat = _gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_REPEAT);
       hrepeat = _gtk_css_background_repeat_value_get_x (repeat);
@@ -175,20 +141,12 @@ _gtk_theming_background_paint (GtkThemingBackground *bg,
       width = bg->image_rect.width;
       height = bg->image_rect.height;
 
-      if (size->contain || size->cover)
-        _gtk_theming_background_get_cover_contain (bg->image,
-                                                   size->cover,
-                                                   width,
-                                                   height,
-                                                   &image_width,
-                                                   &image_height);
-      else
-        _gtk_css_image_get_concrete_size (bg->image,
-                                          /* note: 0 does the right thing here for 'auto' */
-                                          _gtk_css_number_get (&size->width, width),
-                                          _gtk_css_number_get (&size->height, height),
-                                          width, height,
-                                          &image_width, &image_height);
+      _gtk_css_bg_size_value_compute_size (_gtk_style_context_peek_property (bg->context, GTK_CSS_PROPERTY_BACKGROUND_SIZE),
+                                           bg->image,
+                                           width,
+                                           height,
+                                           &image_width,
+                                           &image_height);
 
       /* optimization */
       if (image_width == width)



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