]> Pileus Git - ~andy/gtk/commitdiff
css: Move special case code for border widths
authorBenjamin Otte <otte@redhat.com>
Mon, 1 Oct 2012 16:21:30 +0000 (18:21 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 2 Oct 2012 12:16:35 +0000 (14:16 +0200)
We need to store the border widths independant of them being set to 0 by
border styles, because otherwise we'd need to track that dependency and
recompute on changes, and I don't want to add more entries to
GtkCssDependencies just for this special case.

By moving the code that does the setting to 0 from the compute stage to
the query stage, we can achieve this.

Now we need to just be aware that the actual value stored is not set to
0 when we use gtk_css_computed_values_get_value().

gtk/gtkcssnumbervalue.c
gtk/gtkcssstyleproperty.c

index 58f4652511213e1ade5224156eae9629d52bb4a7..8d7eaa96ee9055263c8e3b6c0e84950da3d81458 100644 (file)
@@ -42,40 +42,6 @@ gtk_css_value_number_compute (GtkCssValue             *number,
                               GtkCssComputedValues    *parent_values,
                               GtkCssDependencies      *dependencies)
 {
-  GtkBorderStyle border_style;
-
-  /* I don't like this special case being here in this generic code path, but no idea where else to put it. */
-  switch (property_id)
-    {
-      case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
-        border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return _gtk_css_number_value_new (0, GTK_CSS_PX);
-        break;
-      case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
-        border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return _gtk_css_number_value_new (0, GTK_CSS_PX);
-        break;
-      case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
-        border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return _gtk_css_number_value_new (0, GTK_CSS_PX);
-        break;
-      case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
-        border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return _gtk_css_number_value_new (0, GTK_CSS_PX);
-        break;
-      case GTK_CSS_PROPERTY_OUTLINE_WIDTH:
-        border_style = _gtk_css_border_style_value_get (_gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_OUTLINE_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return _gtk_css_number_value_new (0, GTK_CSS_PX);
-        break;
-      default:
-        break;
-    }
-
   switch (number->unit)
     {
     default:
index 98e137d01db92c9dd15b8824eb537eb6a21c00e9..7bb1e688e21a303e54c3b0c533a6bad71f3f8077 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "gtkcssstylepropertyprivate.h"
 
+#include "gtkcssenumvalueprivate.h"
 #include "gtkcssinheritvalueprivate.h"
 #include "gtkcssinitialvalueprivate.h"
 #include "gtkcssstylefuncsprivate.h"
@@ -129,6 +130,63 @@ _gtk_css_style_property_assign (GtkStyleProperty   *property,
   _gtk_css_value_unref (css_value);
 }
 
+static gboolean
+_gtk_css_style_property_query_special_case (GtkCssStyleProperty *property,
+                                            GValue              *value,
+                                            GtkStyleQueryFunc    query_func,
+                                            gpointer             query_data)
+{
+  GtkBorderStyle border_style;
+
+  switch (property->id)
+    {
+      case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
+        border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_TOP_STYLE, query_data));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            g_value_init (value, G_TYPE_INT);
+            return TRUE;
+          }
+        break;
+      case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
+        border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE, query_data));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            g_value_init (value, G_TYPE_INT);
+            return TRUE;
+          }
+        break;
+      case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
+        border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE, query_data));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            g_value_init (value, G_TYPE_INT);
+            return TRUE;
+          }
+        break;
+      case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
+        border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_BORDER_LEFT_STYLE, query_data));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            g_value_init (value, G_TYPE_INT);
+            return TRUE;
+          }
+        break;
+      case GTK_CSS_PROPERTY_OUTLINE_WIDTH:
+        border_style = _gtk_css_border_style_value_get (query_func (GTK_CSS_PROPERTY_OUTLINE_STYLE, query_data));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            g_value_init (value, G_TYPE_INT);
+            return TRUE;
+          }
+        break;
+      default:
+        break;
+    }
+
+  return FALSE;
+}
+
 static void
 _gtk_css_style_property_query (GtkStyleProperty   *property,
                                GValue             *value,
@@ -138,6 +196,10 @@ _gtk_css_style_property_query (GtkStyleProperty   *property,
   GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
   GtkCssValue *css_value;
   
+  /* I don't like this special case being here in this generic code path, but no idea where else to put it. */
+  if (_gtk_css_style_property_query_special_case (style_property, value, query_func, query_data))
+    return;
+
   css_value = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data);
   if (css_value == NULL)
     css_value =_gtk_css_style_property_get_initial_value (style_property);