[gtk/wip/baedert/css-values: 1/7] css: Move border-width special cases out of GtkCssDimensionValue



commit c687f485fdd0a94c17b1efb09d415149b2a5603b
Author: Timm Bäder <mail baedert org>
Date:   Sat Jan 11 12:22:19 2020 +0100

    css: Move border-width special cases out of GtkCssDimensionValue
    
    Move them to style computation instead, so we don't have them in such a
    generic place.

 gtk/gtkcssdimensionvalue.c | 34 --------------------------------
 gtk/gtkcssstaticstyle.c    | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtkcssdimensionvalue.c b/gtk/gtkcssdimensionvalue.c
index a45d2a50d5..90078dfb09 100644
--- a/gtk/gtkcssdimensionvalue.c
+++ b/gtk/gtkcssdimensionvalue.c
@@ -66,40 +66,6 @@ gtk_css_value_dimension_compute (GtkCssValue      *number,
                                  GtkCssStyle      *style,
                                  GtkCssStyle      *parent_style)
 {
-  GtkBorderStyle border_style;
-
-  /* special case according to http://dev.w3.org/csswg/css-backgrounds/#the-border-width */
-  switch (property_id)
-    {
-      case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
-        border_style = _gtk_css_border_style_value_get(gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return gtk_css_dimension_value_new (0, GTK_CSS_NUMBER);
-        break;
-      case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
-        border_style = _gtk_css_border_style_value_get(gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return gtk_css_dimension_value_new (0, GTK_CSS_NUMBER);
-        break;
-      case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
-        border_style = _gtk_css_border_style_value_get(gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return gtk_css_dimension_value_new (0, GTK_CSS_NUMBER);
-        break;
-      case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
-        border_style = _gtk_css_border_style_value_get(gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return gtk_css_dimension_value_new (0, GTK_CSS_NUMBER);
-        break;
-      case GTK_CSS_PROPERTY_OUTLINE_WIDTH:
-        border_style = _gtk_css_border_style_value_get(gtk_css_style_get_value (style, 
GTK_CSS_PROPERTY_OUTLINE_STYLE));
-        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
-          return gtk_css_dimension_value_new (0, GTK_CSS_NUMBER);
-        break;
-      default:
-        break;
-    }
-
   switch (number->unit)
     {
     default:
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index 6cb835d6e2..e4439dcce1 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -37,6 +37,7 @@
 #include "gtkstyleanimationprivate.h"
 #include "gtkstylepropertyprivate.h"
 #include "gtkstyleproviderprivate.h"
+#include "gtkcssdimensionvalueprivate.h"
 
 G_DEFINE_TYPE (GtkCssStaticStyle, gtk_css_static_style, GTK_TYPE_CSS_STYLE)
 
@@ -206,9 +207,57 @@ gtk_css_static_style_compute_value (GtkCssStaticStyle *style,
                                     GtkCssSection     *section)
 {
   GtkCssValue *value;
+  GtkBorderStyle border_style;
 
   gtk_internal_return_if_fail (id < GTK_CSS_PROPERTY_N_PROPERTIES);
 
+  /* special case according to http://dev.w3.org/csswg/css-backgrounds/#the-border-width */
+  switch (id)
+    {
+      /* We have them ordered in gtkcssstylepropertyimpl.c accordingly, so the
+       * border styles are already computed when we compute the border widths */
+      case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
+        border_style = _gtk_css_border_style_value_get (gtk_css_style_get_value ((GtkCssStyle *)style,
+                                                                                 
GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            gtk_css_static_style_set_value (style, id, gtk_css_dimension_value_new (0, GTK_CSS_NUMBER), 
section);
+            return;
+          }
+        break;
+      case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
+        border_style = _gtk_css_border_style_value_get (gtk_css_style_get_value ((GtkCssStyle *)style,
+                                                                                 
GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            gtk_css_static_style_set_value (style, id, gtk_css_dimension_value_new (0, GTK_CSS_NUMBER), 
section);
+            return;
+          }
+        break;
+      case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
+        border_style = _gtk_css_border_style_value_get (gtk_css_style_get_value ((GtkCssStyle *)style,
+                                                                                 
GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            gtk_css_static_style_set_value (style, id, gtk_css_dimension_value_new (0, GTK_CSS_NUMBER), 
section);
+            return;
+          }
+        break;
+      case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
+        border_style = _gtk_css_border_style_value_get (gtk_css_style_get_value ((GtkCssStyle *)style,
+                                                                                 
GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          {
+            gtk_css_static_style_set_value (style, id, gtk_css_dimension_value_new (0, GTK_CSS_NUMBER), 
section);
+            return;
+          }
+        break;
+      default:
+        /* Go ahead */
+        break;
+    }
+
+
   /* http://www.w3.org/TR/css3-cascade/#cascade
    * Then, for every element, the value for each property can be found
    * by following this pseudo-algorithm:


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