Commit 83be7e5d authored by Benjamin Otte's avatar Benjamin Otte

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.
parent 1223d53a
......@@ -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);
......
......@@ -2524,12 +2524,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);
}
......@@ -2547,6 +2550,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)
......
......@@ -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,
......
......@@ -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 ();
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment