]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssbgsizevalue.c
separator: Don't use padding and borders wrongly
[~andy/gtk] / gtk / gtkcssbgsizevalue.c
index 2bff385b9f3ade956633afe7f8aa58d080bc3130..662ceb7d1ed5592f17369c00aadd8b7f2f03a8e0 100644 (file)
@@ -40,19 +40,33 @@ gtk_css_value_bg_size_free (GtkCssValue *value)
   g_slice_free (GtkCssValue, value);
 }
 
-GtkCssValue *
-gtk_css_value_bg_size_compute (GtkCssValue        *value,
-                               guint               property_id,
-                               GtkStyleContext    *context,
-                               GtkCssDependencies *dependencies)
+static GtkCssValue *
+gtk_css_value_bg_size_compute (GtkCssValue             *value,
+                               guint                    property_id,
+                               GtkStyleProviderPrivate *provider,
+                               GtkCssComputedValues    *values,
+                               GtkCssComputedValues    *parent_values,
+                               GtkCssDependencies      *dependencies)
 {
+  GtkCssValue *x, *y;
+  GtkCssDependencies x_deps, y_deps;
+
   if (value->x == NULL && value->y == NULL)
     return _gtk_css_value_ref (value);
 
-  *dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
+  x_deps = y_deps = 0;
+  x = y = NULL;
+
+  if (value->x)
+    x = _gtk_css_value_compute (value->x, property_id, provider, values, parent_values, &x_deps);
+
+  if (value->y)
+    y = _gtk_css_value_compute (value->y, property_id, provider, values, parent_values, &y_deps);
 
-  return _gtk_css_bg_size_value_new (value->x ? _gtk_css_value_compute (value->x, property_id, context, NULL) : NULL,
-                                     value->y ? _gtk_css_value_compute (value->y, property_id, context, NULL) : NULL);
+  *dependencies = _gtk_css_dependencies_union (x_deps, y_deps);
+
+  return _gtk_css_bg_size_value_new (value->x ? x : NULL,
+                                     value->y ? y : NULL);
 }
 
 static gboolean
@@ -60,7 +74,7 @@ gtk_css_value_bg_size_equal (const GtkCssValue *value1,
                              const GtkCssValue *value2)
 {
   return value1->cover == value2->cover &&
-         value2->contain == value2->contain &&
+         value1->contain == value2->contain &&
          (value1->x == value2->x ||
           (value1->x != NULL && value2->x != NULL &&
            _gtk_css_value_equal (value1->x, value2->x))) &&
@@ -72,6 +86,7 @@ gtk_css_value_bg_size_equal (const GtkCssValue *value1,
 static GtkCssValue *
 gtk_css_value_bg_size_transition (GtkCssValue *start,
                                   GtkCssValue *end,
+                                  guint        property_id,
                                   double       progress)
 {
   GtkCssValue *x, *y;
@@ -87,7 +102,7 @@ gtk_css_value_bg_size_transition (GtkCssValue *start,
 
   if (start->x)
     {
-      x = _gtk_css_value_transition (start->x, end->x, progress);
+      x = _gtk_css_value_transition (start->x, end->x, property_id, progress);
       if (x == NULL)
         return NULL;
     }
@@ -96,7 +111,7 @@ gtk_css_value_bg_size_transition (GtkCssValue *start,
 
   if (start->y)
     {
-      y = _gtk_css_value_transition (start->y, end->y, progress);
+      y = _gtk_css_value_transition (start->y, end->y, property_id, progress);
       if (y == NULL)
         {
           _gtk_css_value_unref (x);
@@ -246,16 +261,33 @@ _gtk_css_bg_size_value_compute_size (const GtkCssValue *value,
   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);
+    {
+      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);
+    {
+      double x, y;
+
+      /* note: 0 does the right thing later for 'auto' */
+      x = value->x ? _gtk_css_number_value_get (value->x, area_width) : 0;
+      y = value->y ? _gtk_css_number_value_get (value->y, area_height) : 0;
+
+      if ((x <= 0 && value->x) ||
+          (y <= 0 && value->y))
+        {
+          *out_width = 0;
+          *out_height = 0;
+        }
+      else
+        {
+          _gtk_css_image_get_concrete_size (image,
+                                            x, y,
+                                            area_width, area_height,
+                                            out_width, out_height);
+        }
+    }
 }