]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcsspositionvalue.c
GtkBubbleWindow: rework how drawing is done
[~andy/gtk] / gtk / gtkcsspositionvalue.c
index d37d94c4c43de53930159f076e8f7f2b317aa75d..8f09db72f2517cb11675c62614b45e2443330bcb 100644 (file)
@@ -36,6 +36,30 @@ gtk_css_value_position_free (GtkCssValue *value)
   g_slice_free (GtkCssValue, value);
 }
 
+static GtkCssValue *
+gtk_css_value_position_compute (GtkCssValue             *position,
+                                guint                    property_id,
+                                GtkStyleProviderPrivate *provider,
+                                GtkCssComputedValues    *values,
+                                GtkCssComputedValues    *parent_values,
+                                GtkCssDependencies      *dependencies)
+{
+  GtkCssValue *x, *y;
+  GtkCssDependencies x_deps, y_deps;
+
+  x = _gtk_css_value_compute (position->x, property_id, provider, values, parent_values, &x_deps);
+  y = _gtk_css_value_compute (position->y, property_id, provider, values, parent_values, &y_deps);
+  *dependencies = _gtk_css_dependencies_union (x_deps, y_deps);
+  if (x == position->x && y == position->y)
+    {
+      _gtk_css_value_unref (x);
+      _gtk_css_value_unref (y);
+      return _gtk_css_value_ref (position);
+    }
+
+  return _gtk_css_position_value_new (x, y);
+}
+
 static gboolean
 gtk_css_value_position_equal (const GtkCssValue *position1,
                               const GtkCssValue *position2)
@@ -47,14 +71,15 @@ gtk_css_value_position_equal (const GtkCssValue *position1,
 static GtkCssValue *
 gtk_css_value_position_transition (GtkCssValue *start,
                                    GtkCssValue *end,
+                                   guint        property_id,
                                    double       progress)
 {
   GtkCssValue *x, *y;
 
-  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;
-  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);
@@ -120,12 +145,6 @@ gtk_css_value_position_print (const GtkCssValue *position,
         g_string_append (string, "center ");
       _gtk_css_value_print (position->y, string);
     }
-  _gtk_css_value_print (position->x, string);
-  if (!_gtk_css_value_equal (position->x, position->y))
-    {
-      g_string_append_c (string, ' ');
-      _gtk_css_value_print (position->y, string);
-    }
 
 done:
   for (i = 0; i < G_N_ELEMENTS (values); i++)
@@ -135,6 +154,7 @@ done:
 
 static const GtkCssValueClass GTK_CSS_VALUE_POSITION = {
   gtk_css_value_position_free,
+  gtk_css_value_position_compute,
   gtk_css_value_position_equal,
   gtk_css_value_position_transition,
   gtk_css_value_position_print
@@ -153,8 +173,8 @@ _gtk_css_position_value_new (GtkCssValue *x,
   return result;
 }
 
-GtkCssValue *
-_gtk_css_position_value_parse (GtkCssParser *parser)
+static GtkCssValue *
+position_value_parse (GtkCssParser *parser, gboolean try)
 {
   static const struct {
     const char *name;
@@ -193,12 +213,22 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
     }
   if (names[first].name == NULL)
     {
-      missing = &y;
-      x = _gtk_css_number_value_parse (parser,
-                                       GTK_CSS_PARSE_PERCENT
-                                       | GTK_CSS_PARSE_LENGTH);
-      if (x == NULL)
-       return NULL;
+      if (_gtk_css_parser_has_number (parser))
+        {
+          missing = &y;
+          x = _gtk_css_number_value_parse (parser,
+                                           GTK_CSS_PARSE_PERCENT
+                                           | GTK_CSS_PARSE_LENGTH);
+
+          if (x == NULL)
+            return NULL;
+        }
+      else
+        {
+          if (!try)
+            _gtk_css_parser_error (parser, "Unrecognized position value");
+          return NULL;
+        }
     }
 
   for (second = 0; names[second].name != NULL; second++)
@@ -216,7 +246,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
         {
           if (missing != &y)
             {
-              _gtk_css_parser_error (parser, "Invalid combination of values");
+              if (!try)
+                _gtk_css_parser_error (parser, "Invalid combination of values");
               _gtk_css_value_unref (y);
               return NULL;
             }
@@ -240,7 +271,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
       if ((names[first].horizontal && !names[second].vertical) ||
           (!names[first].horizontal && !names[second].horizontal))
         {
-          _gtk_css_parser_error (parser, "Invalid combination of values");
+          if (!try)
+            _gtk_css_parser_error (parser, "Invalid combination of values");
           _gtk_css_value_unref (x);
           _gtk_css_value_unref (y);
           return NULL;
@@ -250,6 +282,18 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
   return _gtk_css_position_value_new (x, y);
 }
 
+GtkCssValue *
+_gtk_css_position_value_parse (GtkCssParser *parser)
+{
+  return position_value_parse (parser, FALSE);
+}
+
+GtkCssValue *
+_gtk_css_position_value_try_parse (GtkCssParser *parser)
+{
+  return position_value_parse (parser, TRUE);
+}
+
 double
 _gtk_css_position_value_get_x (const GtkCssValue *position,
                                double             one_hundred_percent)
@@ -270,23 +314,3 @@ _gtk_css_position_value_get_y (const GtkCssValue *position,
   return _gtk_css_number_value_get (position->y, one_hundred_percent);
 }
 
-GtkCssValue *
-_gtk_css_position_value_compute (GtkCssValue     *position,
-                                 GtkStyleContext *context)
-{
-  GtkCssValue *x, *y;
-
-  g_return_val_if_fail (position->class == &GTK_CSS_VALUE_POSITION, NULL);
-
-  x = _gtk_css_number_value_compute (position->x, context);
-  y = _gtk_css_number_value_compute (position->y, context);
-  if (x == position->x && y == position->y)
-    {
-      _gtk_css_value_unref (x);
-      _gtk_css_value_unref (y);
-      return _gtk_css_value_ref (position);
-    }
-
-  return _gtk_css_position_value_new (x, y);
-}
-