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 "gtkcssbordervalueprivate.h"
22 #include "gtkcssnumbervalueprivate.h"
27 GtkCssValue *values[4];
31 gtk_css_value_border_free (GtkCssValue *value)
35 for (i = 0; i < 4; i++)
38 _gtk_css_value_unref (value->values[i]);
41 g_slice_free (GtkCssValue, value);
45 gtk_css_value_border_compute (GtkCssValue *value,
47 GtkStyleProviderPrivate *provider,
48 GtkCssComputedValues *values,
49 GtkCssComputedValues *parent_values,
50 GtkCssDependencies *dependencies)
52 GtkCssValue *computed;
53 GtkCssDependencies child_deps;
54 gboolean changed = FALSE;
57 computed = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
58 computed->fill = value->fill;
60 for (i = 0; i < 4; i++)
64 computed->values[i] = _gtk_css_value_compute (value->values[i], property_id, provider, values, parent_values, &child_deps);
65 *dependencies = _gtk_css_dependencies_union (*dependencies, child_deps);
66 changed |= (computed->values[i] != value->values[i]);
72 _gtk_css_value_unref (computed);
73 return _gtk_css_value_ref (value);
80 gtk_css_value_border_equal (const GtkCssValue *value1,
81 const GtkCssValue *value2)
85 if (value1->fill != value2->fill)
88 for (i = 0; i < 4; i++)
90 if (!_gtk_css_value_equal0 (value1->values[i], value2->values[i]))
98 gtk_css_value_border_transition (GtkCssValue *start,
107 gtk_css_value_border_print (const GtkCssValue *value,
112 if (!_gtk_css_value_equal0 (value->values[GTK_CSS_RIGHT], value->values[GTK_CSS_LEFT]))
114 else if (!_gtk_css_value_equal0 (value->values[GTK_CSS_TOP], value->values[GTK_CSS_BOTTOM]))
116 else if (!_gtk_css_value_equal0 (value->values[GTK_CSS_TOP], value->values[GTK_CSS_RIGHT]))
121 for (i = 0; i < n; i++)
124 g_string_append_c (string, ' ');
126 if (value->values[i] == NULL)
127 g_string_append (string, "auto");
129 _gtk_css_value_print (value->values[i], string);
133 g_string_append (string, " fill");
136 static const GtkCssValueClass GTK_CSS_VALUE_BORDER = {
137 gtk_css_value_border_free,
138 gtk_css_value_border_compute,
139 gtk_css_value_border_equal,
140 gtk_css_value_border_transition,
141 gtk_css_value_border_print
145 _gtk_css_border_value_new (GtkCssValue *top,
152 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_BORDER);
153 result->values[GTK_CSS_TOP] = top;
154 result->values[GTK_CSS_RIGHT] = right;
155 result->values[GTK_CSS_BOTTOM] = bottom;
156 result->values[GTK_CSS_LEFT] = left;
162 _gtk_css_border_value_parse (GtkCssParser *parser,
163 GtkCssNumberParseFlags flags,
170 result = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
173 result->fill = _gtk_css_parser_try (parser, "fill", TRUE);
175 for (i = 0; i < 4; i++)
177 if (allow_auto && _gtk_css_parser_try (parser, "auto", TRUE))
180 if (!_gtk_css_parser_has_number (parser))
183 result->values[i] = _gtk_css_number_value_parse (parser, flags);
184 if (result->values[i] == NULL)
186 _gtk_css_value_unref (result);
193 _gtk_css_parser_error (parser, "Expected a number");
194 _gtk_css_value_unref (result);
198 if (allow_fill && !result->fill)
199 result->fill = _gtk_css_parser_try (parser, "fill", TRUE);
203 if (result->values[(i - 1) >> 1])
204 result->values[i] = _gtk_css_value_ref (result->values[(i - 1) >> 1]);
211 _gtk_css_border_value_get_top (const GtkCssValue *value)
213 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
215 return value->values[GTK_CSS_TOP];
219 _gtk_css_border_value_get_right (const GtkCssValue *value)
221 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
223 return value->values[GTK_CSS_RIGHT];
227 _gtk_css_border_value_get_bottom (const GtkCssValue *value)
229 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
231 return value->values[GTK_CSS_BOTTOM];
235 _gtk_css_border_value_get_left (const GtkCssValue *value)
237 g_return_val_if_fail (value->class == >K_CSS_VALUE_BORDER, NULL);
239 return value->values[GTK_CSS_LEFT];