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 "gtkcssvalueprivate.h"
26 G_DEFINE_BOXED_TYPE (GtkCssValue, _gtk_css_value, _gtk_css_value_ref, _gtk_css_value_unref)
29 _gtk_css_value_alloc (const GtkCssValueClass *klass,
34 value = g_slice_alloc0 (size);
43 _gtk_css_value_ref (GtkCssValue *value)
45 g_return_val_if_fail (value != NULL, NULL);
47 g_atomic_int_add (&value->ref_count, 1);
53 _gtk_css_value_unref (GtkCssValue *value)
58 if (!g_atomic_int_dec_and_test (&value->ref_count))
61 value->class->free (value);
65 * _gtk_css_value_compute:
66 * @value: the value to compute from
67 * @property_id: the ID of the property to compute
68 * @context: the context to use for resolving
70 * Converts the specified @value into the computed value for the CSS
71 * property given by @property_id using the information in @context.
72 * This step is explained in detail in
73 * <ulink url="http://www.w3.org/TR/css3-cascade/#computed>
74 * the CSS documentation</ulink>.
76 * Returns: the comptued value
79 _gtk_css_value_compute (GtkCssValue *value,
81 GtkStyleContext *context)
83 g_return_val_if_fail (value != NULL, NULL);
84 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
86 return value->class->compute (value, property_id, context);
90 _gtk_css_value_equal (const GtkCssValue *value1,
91 const GtkCssValue *value2)
93 g_return_val_if_fail (value1 != NULL, FALSE);
94 g_return_val_if_fail (value2 != NULL, FALSE);
96 if (value1->class != value2->class)
99 return value1->class->equal (value1, value2);
103 _gtk_css_value_equal0 (const GtkCssValue *value1,
104 const GtkCssValue *value2)
106 if (value1 == NULL && value2 == NULL)
109 if (value1 == NULL || value2 == NULL)
112 return _gtk_css_value_equal (value1, value2);
116 _gtk_css_value_transition (GtkCssValue *start,
120 g_return_val_if_fail (start != NULL, FALSE);
121 g_return_val_if_fail (end != NULL, FALSE);
123 if (start->class != end->class)
126 return start->class->transition (start, end, progress);
130 _gtk_css_value_to_string (const GtkCssValue *value)
134 g_return_val_if_fail (value != NULL, NULL);
136 string = g_string_new (NULL);
137 _gtk_css_value_print (value, string);
138 return g_string_free (string, FALSE);
142 * _gtk_css_value_print:
143 * @value: the value to print
144 * @string: the string to print to
146 * Prints @value to the given @string in CSS format. The @value must be a
147 * valid specified value as parsed using the parse functions or as assigned
148 * via _gtk_style_property_assign().
151 _gtk_css_value_print (const GtkCssValue *value,
154 g_return_if_fail (value != NULL);
155 g_return_if_fail (string != NULL);
157 value->class->print (value, string);