[gtk+/wip/cssvalue: 127/141] symboliccolor: Pass the current color to the resolve function



commit b41d09a0e15fdf7eeb0510efbd8c4917bfd73d52
Author: Benjamin Otte <otte redhat com>
Date:   Thu Apr 5 22:12:37 2012 +0200

    symboliccolor: Pass the current color to the resolve function
    
    This way, we can resolve things like
      mix (currentColor, &otherColor);
    and therefore parse currentColor as a regular color.

 gtk/gtkcssrgbavalue.c         |   38 +++++++++++++++++---------------------
 gtk/gtkstylecontext.c         |    4 ++++
 gtk/gtkstylecontextprivate.h  |    1 +
 gtk/gtksymboliccolor.c        |   23 ++++++++++++++++-------
 gtk/gtksymboliccolorprivate.h |    1 +
 5 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkcssrgbavalue.c b/gtk/gtkcssrgbavalue.c
index 490ca35..7ae1f18 100644
--- a/gtk/gtkcssrgbavalue.c
+++ b/gtk/gtkcssrgbavalue.c
@@ -19,6 +19,7 @@
 
 #include "gtkcssrgbavalueprivate.h"
 
+#include "gtkcssstylepropertyprivate.h"
 #include "gtkstylecontextprivate.h"
 #include "gtksymboliccolorprivate.h"
 
@@ -100,34 +101,29 @@ _gtk_css_rgba_value_compute_from_symbolic (GtkCssValue     *rgba,
                                            gboolean         for_color_property)
 {
   GtkSymbolicColor *symbolic;
-  GtkCssValue *resolved;
+  GtkCssValue *resolved, *current;
 
   g_return_val_if_fail (rgba != NULL, NULL);
 
-  symbolic = _gtk_css_value_get_symbolic_color (rgba);
-
-  if (symbolic == _gtk_symbolic_color_get_current_color ())
+  /* The computed value of the âcurrentColorâ keyword is the computed
+   * value of the âcolorâ property. If the âcurrentColorâ keyword is
+   * set on the âcolorâ property itself, it is treated as âcolor: inheritâ. 
+   */
+  if (for_color_property)
     {
-      /* The computed value of the âcurrentColorâ keyword is the computed
-       * value of the âcolorâ property. If the âcurrentColorâ keyword is
-       * set on the âcolorâ property itself, it is treated as âcolor: inheritâ. 
-       */
-      if (for_color_property)
-        {
-          GtkStyleContext *parent = gtk_style_context_get_parent (context);
-
-          if (parent)
-            return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR));
-          else
-            return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, TRUE);
-        }
+      GtkStyleContext *parent = gtk_style_context_get_parent (context);
+
+      if (parent)
+        current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
       else
-        {
-          return _gtk_css_value_ref (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
-        }
+        current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
+    }
+  else
+    {
+      current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
     }
   
-  resolved = _gtk_style_context_resolve_color_value (context, symbolic);
+  resolved = _gtk_style_context_resolve_color_value (context, current, symbolic);
 
   if (resolved == NULL)
     return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, for_color_property);
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 99b013f..9770504 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -2527,12 +2527,15 @@ gtk_style_context_color_lookup_func (gpointer    contextp,
 
 GtkCssValue *
 _gtk_style_context_resolve_color_value (GtkStyleContext  *context,
+                                        GtkCssValue      *current,
 					GtkSymbolicColor *color)
 {
   g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
+  g_return_val_if_fail (current != NULL, FALSE);
   g_return_val_if_fail (color != NULL, FALSE);
 
   return _gtk_symbolic_color_resolve_full (color,
+                                           current,
                                            gtk_style_context_color_lookup_func,
                                            context);
 }
@@ -2550,6 +2553,7 @@ _gtk_style_context_resolve_color (GtkStyleContext  *context,
   g_return_val_if_fail (result != NULL, FALSE);
 
   val = _gtk_symbolic_color_resolve_full (color,
+                                          _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
 					  gtk_style_context_color_lookup_func,
 					  context);
   if (val == NULL)
diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h
index 43566c9..c0a2881 100644
--- a/gtk/gtkstylecontextprivate.h
+++ b/gtk/gtkstylecontextprivate.h
@@ -45,6 +45,7 @@ gboolean       _gtk_style_context_resolve_color              (GtkStyleContext  *
                                                               GtkSymbolicColor *color,
                                                               GdkRGBA          *result);
 GtkCssValue *  _gtk_style_context_resolve_color_value        (GtkStyleContext  *context,
+                                                              GtkCssValue      *current,
                                                               GtkSymbolicColor *color);
 void           _gtk_style_context_get_cursor_color           (GtkStyleContext *context,
                                                               GdkRGBA         *primary_color,
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index fdbcce7..994b230 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -629,15 +629,19 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
 			    GtkStyleProperties *props,
 			    GdkRGBA            *resolved_color)
 {
-  GtkCssValue *v;
+  GdkRGBA pink = { 1.0, 0.5, 0.5, 1.0 };
+  GtkCssValue *v, *current;
 
   g_return_val_if_fail (color != NULL, FALSE);
   g_return_val_if_fail (resolved_color != NULL, FALSE);
   g_return_val_if_fail (props == NULL || GTK_IS_STYLE_PROPERTIES (props), FALSE);
 
+  current = _gtk_css_rgba_value_new_from_rgba (&pink);
   v =_gtk_symbolic_color_resolve_full (color,
+                                       current,
 				       resolve_lookup_color,
 				       props);
+  _gtk_css_value_unref (current);
   if (v == NULL)
     return FALSE;
 
@@ -648,12 +652,14 @@ gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
 
 GtkCssValue *
 _gtk_symbolic_color_resolve_full (GtkSymbolicColor           *color,
+                                  GtkCssValue                *current,
 				  GtkSymbolicColorLookupFunc  func,
 				  gpointer                    data)
 {
   GtkCssValue *value;
 
   g_return_val_if_fail (color != NULL, FALSE);
+  g_return_val_if_fail (current != NULL, FALSE);
   g_return_val_if_fail (func != NULL, FALSE);
 
   value = NULL;
@@ -670,7 +676,7 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor           *color,
 	if (!named_color)
 	  return NULL;
 
-	return _gtk_symbolic_color_resolve_full (named_color, func, data);
+	return _gtk_symbolic_color_resolve_full (named_color, current, func, data);
       }
 
       break;
@@ -679,7 +685,7 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor           *color,
 	GtkCssValue *val;
 	GdkRGBA shade;
 
-	val = _gtk_symbolic_color_resolve_full (color->shade.color, func, data);
+	val = _gtk_symbolic_color_resolve_full (color->shade.color, current, func, data);
 	if (val == NULL)
 	  return NULL;
 
@@ -697,7 +703,7 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor           *color,
 	GtkCssValue *val;
 	GdkRGBA alpha;
 
-	val = _gtk_symbolic_color_resolve_full (color->alpha.color, func, data);
+	val = _gtk_symbolic_color_resolve_full (color->alpha.color, current, func, data);
 	if (val == NULL)
 	  return NULL;
 
@@ -715,13 +721,13 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor           *color,
 	GtkCssValue *val;
 	GdkRGBA color1, color2, res;
 
-	val = _gtk_symbolic_color_resolve_full (color->mix.color1, func, data);
+	val = _gtk_symbolic_color_resolve_full (color->mix.color1, current, func, data);
 	if (val == NULL)
 	  return NULL;
 	color1 = *_gtk_css_rgba_value_get_rgba (val);
 	_gtk_css_value_unref (val);
 
-	val = _gtk_symbolic_color_resolve_full (color->mix.color2, func, data);
+	val = _gtk_symbolic_color_resolve_full (color->mix.color2, current, func, data);
 	if (val == NULL)
 	  return NULL;
 	color2 = *_gtk_css_rgba_value_get_rgba (val);
@@ -751,7 +757,10 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor           *color,
 
       break;
     case COLOR_TYPE_CURRENT_COLOR:
-      return NULL;
+      if (current)
+        return _gtk_css_value_ref (current);
+      else
+        return NULL;
       break;
     default:
       g_assert_not_reached ();
diff --git a/gtk/gtksymboliccolorprivate.h b/gtk/gtksymboliccolorprivate.h
index 2e9514c..a5b425c 100644
--- a/gtk/gtksymboliccolorprivate.h
+++ b/gtk/gtksymboliccolorprivate.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 typedef GtkSymbolicColor * (* GtkSymbolicColorLookupFunc) (gpointer data, const char *name);
 
 GtkCssValue *      _gtk_symbolic_color_resolve_full       (GtkSymbolicColor           *color,
+                                                           GtkCssValue                *current,
                                                            GtkSymbolicColorLookupFunc  func,
                                                            gpointer                    data);
 



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