]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssstylefuncs.c
filechooser: Rename _gtk_file_is_path_not_local() to _gtk_file_has_native_path()
[~andy/gtk] / gtk / gtkcssstylefuncs.c
index 538079dd27410b92676f182639081fd35f9d1390..af1c1b1b6f41262fdd95bc713c15bdbcf595ebde 100644 (file)
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <cairo-gobject.h>
 
+#include "gtkcsscolorvalueprivate.h"
 #include "gtkcssimagegradientprivate.h"
 #include "gtkcssprovider.h"
+#include "gtkcssrgbavalueprivate.h"
 #include "gtkcsstypedvalueprivate.h"
 #include "gtkcsstypesprivate.h"
-#include "gtkgradient.h"
 #include "gtkprivatetypebuiltins.h"
 #include "gtkstylecontextprivate.h"
-#include "gtksymboliccolorprivate.h"
 #include "gtkthemingengine.h"
 #include "gtktypebuiltins.h"
 #include "gtkwin32themeprivate.h"
 
+#include "deprecated/gtkgradientprivate.h"
+#include "deprecated/gtksymboliccolorprivate.h"
+
 /* this is in case round() is not provided by the compiler, 
  * such as in the case of C89 compilers, like MSVC
  */
@@ -48,13 +51,15 @@ static GHashTable *parse_funcs = NULL;
 static GHashTable *print_funcs = NULL;
 static GHashTable *compute_funcs = NULL;
 
-typedef gboolean         (* GtkStyleParseFunc)             (GtkCssParser           *parser,
-                                                            GFile                  *base,
-                                                            GValue                 *value);
-typedef void             (* GtkStylePrintFunc)             (const GValue           *value,
-                                                            GString                *string);
-typedef GtkCssValue *    (* GtkStyleComputeFunc)           (GtkStyleContext        *context,
-                                                            GtkCssValue            *specified);
+typedef gboolean         (* GtkStyleParseFunc)             (GtkCssParser            *parser,
+                                                            GValue                  *value);
+typedef void             (* GtkStylePrintFunc)             (const GValue            *value,
+                                                            GString                 *string);
+typedef GtkCssValue *    (* GtkStyleComputeFunc)           (GtkStyleProviderPrivate *provider,
+                                                            GtkCssComputedValues    *values,
+                                                            GtkCssComputedValues    *parent_values,
+                                                            GtkCssValue             *specified,
+                                                            GtkCssDependencies      *dependencies);
 
 static void
 register_conversion_function (GType               type,
@@ -162,13 +167,14 @@ enum_print (int         value,
 
 static gboolean
 rgba_value_parse (GtkCssParser *parser,
-                  GFile        *base,
                   GValue       *value)
 {
   GtkSymbolicColor *symbolic;
   GdkRGBA rgba;
 
-  symbolic = _gtk_symbolic_color_new_take_value (_gtk_css_symbolic_value_new (parser));
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+
+  symbolic = _gtk_css_symbolic_value_new (parser);
   if (symbolic == NULL)
     return FALSE;
 
@@ -184,6 +190,8 @@ rgba_value_parse (GtkCssParser *parser,
       g_value_take_boxed (value, symbolic);
     }
 
+  G_GNUC_END_IGNORE_DEPRECATIONS;
+
   return TRUE;
 }
 
@@ -204,8 +212,11 @@ rgba_value_print (const GValue *value,
 }
 
 static GtkCssValue *
-rgba_value_compute (GtkStyleContext *context,
-                    GtkCssValue     *specified)
+rgba_value_compute (GtkStyleProviderPrivate *provider,
+                    GtkCssComputedValues    *values,
+                    GtkCssComputedValues    *parent_values,
+                    GtkCssValue             *specified,
+                    GtkCssDependencies      *dependencies)
 {
   GdkRGBA white = { 1, 1, 1, 1 };
   const GValue *value;
@@ -215,10 +226,21 @@ rgba_value_compute (GtkStyleContext *context,
   if (G_VALUE_HOLDS (value, GTK_TYPE_SYMBOLIC_COLOR))
     {
       GtkSymbolicColor *symbolic = g_value_get_boxed (value);
+      GtkCssValue *val;
       GValue new_value = G_VALUE_INIT;
       GdkRGBA rgba;
 
-      if (!_gtk_style_context_resolve_color (context, symbolic, &rgba))
+      val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (symbolic),
+                                          provider,
+                                          _gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_COLOR),
+                                          GTK_CSS_DEPENDS_ON_COLOR,
+                                          dependencies);
+      if (val != NULL)
+        {
+          rgba = *_gtk_css_rgba_value_get_rgba (val);
+          _gtk_css_value_unref (val);
+        }
+      else
         rgba = white;
 
       g_value_init (&new_value, GDK_TYPE_RGBA);
@@ -231,13 +253,14 @@ rgba_value_compute (GtkStyleContext *context,
 
 static gboolean 
 color_value_parse (GtkCssParser *parser,
-                   GFile        *base,
                    GValue       *value)
 {
   GtkSymbolicColor *symbolic;
   GdkRGBA rgba;
 
-  symbolic = _gtk_symbolic_color_new_take_value (_gtk_css_symbolic_value_new (parser));
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+
+  symbolic = _gtk_css_symbolic_value_new (parser);
   if (symbolic == NULL)
     return FALSE;
 
@@ -258,6 +281,8 @@ color_value_parse (GtkCssParser *parser,
       g_value_take_boxed (value, symbolic);
     }
 
+  G_GNUC_END_IGNORE_DEPRECATIONS;
+
   return TRUE;
 }
 
@@ -278,10 +303,12 @@ color_value_print (const GValue *value,
 }
 
 static GtkCssValue *
-color_value_compute (GtkStyleContext *context,
-                     GtkCssValue    *specified)
+color_value_compute (GtkStyleProviderPrivate *provider,
+                     GtkCssComputedValues    *values,
+                     GtkCssComputedValues    *parent_values,
+                     GtkCssValue             *specified,
+                     GtkCssDependencies      *dependencies)
 {
-  GdkRGBA rgba;
   GdkColor color = { 0, 65535, 65535, 65535 };
   const GValue *value;
 
@@ -290,14 +317,20 @@ color_value_compute (GtkStyleContext *context,
   if (G_VALUE_HOLDS (value, GTK_TYPE_SYMBOLIC_COLOR))
     {
       GValue new_value = G_VALUE_INIT;
-
-      if (_gtk_style_context_resolve_color (context,
-                                            g_value_get_boxed (value),
-                                            &rgba))
+      GtkCssValue *val;
+
+      val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (g_value_get_boxed (value)),
+                                          provider,
+                                          _gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_COLOR),
+                                          GTK_CSS_DEPENDS_ON_COLOR,
+                                          dependencies);
+      if (val != NULL)
         {
-          color.red = rgba.red * 65535. + 0.5;
-          color.green = rgba.green * 65535. + 0.5;
-          color.blue = rgba.blue * 65535. + 0.5;
+          const GdkRGBA *rgba = _gtk_css_rgba_value_get_rgba (val);
+          color.red = rgba->red * 65535. + 0.5;
+          color.green = rgba->green * 65535. + 0.5;
+          color.blue = rgba->blue * 65535. + 0.5;
+          _gtk_css_value_unref (val);
         }
       
       g_value_init (&new_value, GDK_TYPE_COLOR);
@@ -310,12 +343,11 @@ color_value_compute (GtkStyleContext *context,
 
 static gboolean
 symbolic_color_value_parse (GtkCssParser *parser,
-                            GFile        *base,
                             GValue       *value)
 {
   GtkSymbolicColor *symbolic;
 
-  symbolic = _gtk_symbolic_color_new_take_value (_gtk_css_symbolic_value_new (parser));
+  symbolic = _gtk_css_symbolic_value_new (parser);
   if (symbolic == NULL)
     return FALSE;
 
@@ -329,6 +361,8 @@ symbolic_color_value_print (const GValue *value,
 {
   GtkSymbolicColor *symbolic = g_value_get_boxed (value);
 
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+
   if (symbolic == NULL)
     g_string_append (string, "none");
   else
@@ -337,11 +371,12 @@ symbolic_color_value_print (const GValue *value,
       g_string_append (string, s);
       g_free (s);
     }
+
+  G_GNUC_END_IGNORE_DEPRECATIONS;
 }
 
 static gboolean 
 font_description_value_parse (GtkCssParser *parser,
-                              GFile        *base,
                               GValue       *value)
 {
   PangoFontDescription *font_desc;
@@ -383,7 +418,6 @@ font_description_value_print (const GValue *value,
 
 static gboolean 
 boolean_value_parse (GtkCssParser *parser,
-                     GFile        *base,
                      GValue       *value)
 {
   if (_gtk_css_parser_try (parser, "true", TRUE) ||
@@ -417,14 +451,13 @@ boolean_value_print (const GValue *value,
 
 static gboolean 
 int_value_parse (GtkCssParser *parser,
-                 GFile        *base,
                  GValue       *value)
 {
   gint i;
 
   if (_gtk_css_parser_begins_with (parser, '-'))
     {
-      int res = _gtk_win32_theme_int_parse (parser, base, &i);
+      int res = _gtk_win32_theme_int_parse (parser, &i);
       if (res >= 0)
        {
          g_value_set_int (value, i);
@@ -452,7 +485,6 @@ int_value_print (const GValue *value,
 
 static gboolean 
 uint_value_parse (GtkCssParser *parser,
-                  GFile        *base,
                   GValue       *value)
 {
   guint u;
@@ -476,7 +508,6 @@ uint_value_print (const GValue *value,
 
 static gboolean 
 double_value_parse (GtkCssParser *parser,
-                    GFile        *base,
                     GValue       *value)
 {
   gdouble d;
@@ -500,7 +531,6 @@ double_value_print (const GValue *value,
 
 static gboolean 
 float_value_parse (GtkCssParser *parser,
-                   GFile        *base,
                    GValue       *value)
 {
   gdouble d;
@@ -524,7 +554,6 @@ float_value_print (const GValue *value,
 
 static gboolean 
 string_value_parse (GtkCssParser *parser,
-                    GFile        *base,
                     GValue       *value)
 {
   char *str = _gtk_css_parser_read_string (parser);
@@ -545,7 +574,6 @@ string_value_print (const GValue *value,
 
 static gboolean 
 theming_engine_value_parse (GtkCssParser *parser,
-                            GFile        *base,
                             GValue       *value)
 {
   GtkThemingEngine *engine;
@@ -599,7 +627,6 @@ theming_engine_value_print (const GValue *value,
 
 static gboolean 
 border_value_parse (GtkCssParser *parser,
-                    GFile        *base,
                     GValue       *value)
 {
   GtkBorder border = { 0, };
@@ -612,7 +639,7 @@ border_value_parse (GtkCssParser *parser,
        {
          /* These are strictly speaking signed, but we want to be able to use them
             for unsigned types too, as the actual ranges of values make this safe */
-         int res = _gtk_win32_theme_int_parse (parser, base, &numbers[i]);
+         int res = _gtk_win32_theme_int_parse (parser, &numbers[i]);
 
          if (res == 0) /* Parse error, report */
            return FALSE;
@@ -670,7 +697,6 @@ border_value_print (const GValue *value, GString *string)
 
 static gboolean 
 gradient_value_parse (GtkCssParser *parser,
-                      GFile        *base,
                       GValue       *value)
 {
   GtkGradient *gradient;
@@ -689,6 +715,8 @@ gradient_value_print (const GValue *value,
 {
   GtkGradient *gradient = g_value_get_boxed (value);
 
+  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+
   if (gradient == NULL)
     g_string_append (string, "none");
   else
@@ -697,11 +725,12 @@ gradient_value_print (const GValue *value,
       g_string_append (string, s);
       g_free (s);
     }
+
+  G_GNUC_END_IGNORE_DEPRECATIONS;
 }
 
 static gboolean 
 pattern_value_parse (GtkCssParser *parser,
-                     GFile        *base,
                      GValue       *value)
 {
   if (_gtk_css_parser_try (parser, "none", TRUE))
@@ -712,7 +741,7 @@ pattern_value_parse (GtkCssParser *parser,
     {
       g_value_unset (value);
       g_value_init (value, GTK_TYPE_GRADIENT);
-      return gradient_value_parse (parser, base, value);
+      return gradient_value_parse (parser, value);
     }
   else
     {
@@ -820,9 +849,11 @@ pattern_value_print (const GValue *value,
         }
       surface_print (surface, string);
       break;
-    case CAIRO_PATTERN_TYPE_SOLID:
     case CAIRO_PATTERN_TYPE_LINEAR:
     case CAIRO_PATTERN_TYPE_RADIAL:
+      g_string_append (string, "none /* FIXME: add support for printing gradients */");
+      break;
+    case CAIRO_PATTERN_TYPE_SOLID:
     default:
       g_assert_not_reached ();
       break;
@@ -830,8 +861,11 @@ pattern_value_print (const GValue *value,
 }
 
 static GtkCssValue *
-pattern_value_compute (GtkStyleContext *context,
-                       GtkCssValue     *specified)
+pattern_value_compute (GtkStyleProviderPrivate *provider,
+                       GtkCssComputedValues    *values,
+                       GtkCssComputedValues    *parent_values,
+                       GtkCssValue             *specified,
+                       GtkCssDependencies      *dependencies)
 {
   const GValue *value = _gtk_css_typed_value_get (specified);
 
@@ -840,7 +874,7 @@ pattern_value_compute (GtkStyleContext *context,
       GValue new_value = G_VALUE_INIT;
       cairo_pattern_t *gradient;
       
-      gradient = gtk_gradient_resolve_for_context (g_value_get_boxed (value), context);
+      gradient = _gtk_gradient_resolve_full (g_value_get_boxed (value), provider, values, parent_values, dependencies);
 
       g_value_init (&new_value, CAIRO_GOBJECT_TYPE_PATTERN);
       g_value_take_boxed (&new_value, gradient);
@@ -852,7 +886,6 @@ pattern_value_compute (GtkStyleContext *context,
 
 static gboolean 
 enum_value_parse (GtkCssParser *parser,
-                  GFile        *base,
                   GValue       *value)
 {
   int v;
@@ -875,7 +908,6 @@ enum_value_print (const GValue *value,
 
 static gboolean 
 flags_value_parse (GtkCssParser *parser,
-                   GFile        *base,
                    GValue       *value)
 {
   GFlagsClass *flags_class;
@@ -1027,7 +1059,6 @@ gtk_css_style_funcs_init (void)
  * _gtk_css_style_parse_value:
  * @value: the value to parse into. Must be a valid initialized #GValue
  * @parser: the parser to parse from
- * @base: the base URL for @parser
  *
  * This is the generic parsing function used for CSS values. If the
  * function fails to parse a value, it will emit an error on @parser,
@@ -1037,8 +1068,7 @@ gtk_css_style_funcs_init (void)
  **/
 gboolean
 _gtk_css_style_parse_value (GValue       *value,
-                            GtkCssParser *parser,
-                            GFile        *base)
+                            GtkCssParser *parser)
 {
   GtkStyleParseFunc func;
 
@@ -1061,7 +1091,7 @@ _gtk_css_style_parse_value (GValue       *value,
       return FALSE;
     }
 
-  return (*func) (parser, base, value);
+  return (*func) (parser, value);
 }
 
 /**
@@ -1099,23 +1129,35 @@ _gtk_css_style_print_value (const GValue *value,
 
 /**
  * _gtk_css_style_compute_value:
- * @computed: (out): a value to be filled with the result
- * @context: the context to use for computing the value
+ * @provider: Style provider to look up information from
+ * @values: The values to compute for
+ * @parent_values: Values to look up inherited values from
+ * @target_type: Type the resulting value should have
  * @specified: the value to use for the computation
+ * @dependencies: (out): Value initialized with 0 to take the dependencies
+ *     of the returned value
  *
  * Converts the @specified value into the @computed value using the
  * information in @context. The values must have matching types, ie
  * @specified must be a result of a call to
  * _gtk_css_style_parse_value() with the same type as @computed.
+ *
+ * Returns: the resulting value
  **/
 GtkCssValue *
-_gtk_css_style_compute_value (GtkStyleContext *context,
-                             GType           target_type,
-                              GtkCssValue    *specified)
+_gtk_css_style_compute_value (GtkStyleProviderPrivate *provider,
+                              GtkCssComputedValues    *values,
+                              GtkCssComputedValues    *parent_values,
+                             GType                    target_type,
+                              GtkCssValue             *specified,
+                              GtkCssDependencies      *dependencies)
 {
   GtkStyleComputeFunc func;
 
-  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
+  g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
+  g_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);
+  g_return_val_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values), NULL);
+  g_return_val_if_fail (*dependencies == 0, NULL);
 
   gtk_css_style_funcs_init ();
 
@@ -1126,7 +1168,7 @@ _gtk_css_style_compute_value (GtkStyleContext *context,
                                 GSIZE_TO_POINTER (g_type_fundamental (target_type)));
 
   if (func)
-    return func (context, specified);
+    return func (provider, values, parent_values, specified, dependencies);
   else
     return _gtk_css_value_ref (specified);
 }