1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gtkcssrgbavalueprivate.h"
22 #include "gtkstylecontextprivate.h"
23 #include "gtksymboliccolorprivate.h"
31 gtk_css_value_rgba_free (GtkCssValue *value)
33 g_slice_free (GtkCssValue, value);
37 gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
38 const GtkCssValue *rgba2)
40 return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
44 gtk_css_value_rgba_print (const GtkCssValue *rgba,
47 char *s = gdk_rgba_to_string (&rgba->rgba);
48 g_string_append (string, s);
52 static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
53 gtk_css_value_rgba_free,
54 gtk_css_value_rgba_equal,
55 gtk_css_value_rgba_print
59 _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
63 g_return_val_if_fail (rgba != NULL, NULL);
65 value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_RGBA);
72 _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
74 g_return_val_if_fail (rgba->class == >K_CSS_VALUE_RGBA, NULL);
80 _gtk_css_rgba_value_compute_from_symbolic (GtkCssValue *rgba,
81 GtkCssValue *fallback,
82 GtkStyleContext *context,
83 gboolean for_color_property)
85 GtkSymbolicColor *symbolic;
86 GtkCssValue *resolved;
88 g_return_val_if_fail (rgba != NULL, NULL);
90 symbolic = _gtk_css_value_get_symbolic_color (rgba);
92 if (symbolic == _gtk_symbolic_color_get_current_color ())
94 /* The computed value of the ‘currentColor’ keyword is the computed
95 * value of the ‘color’ property. If the ‘currentColor’ keyword is
96 * set on the ‘color’ property itself, it is treated as ‘color: inherit’.
98 if (for_color_property)
100 GtkStyleContext *parent = gtk_style_context_get_parent (context);
103 return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, "color"));
105 return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, TRUE);
109 return _gtk_css_value_ref (_gtk_style_context_peek_property (context, "color"));
113 resolved = _gtk_style_context_resolve_color_value (context, symbolic);
115 if (resolved == NULL)
116 return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, for_color_property);
118 g_assert (resolved->class == >K_CSS_VALUE_RGBA);