1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Benjamin Otte <otte@gnome.org>
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 "gtkcsslookupprivate.h"
22 #include "gtkcsstypesprivate.h"
23 #include "gtkprivatetypebuiltins.h"
24 #include "gtkcssstylepropertyprivate.h"
25 #include "gtkstylepropertiesprivate.h"
28 _gtk_css_lookup_new (const GtkBitmask *relevant)
31 guint n = _gtk_css_style_property_get_n_properties ();
33 lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n);
37 lookup->missing = _gtk_bitmask_copy (relevant);
41 lookup->missing = _gtk_bitmask_new ();
42 lookup->missing = _gtk_bitmask_invert_range (lookup->missing, 0, n);
49 _gtk_css_lookup_free (GtkCssLookup *lookup)
51 g_return_if_fail (lookup != NULL);
53 _gtk_bitmask_free (lookup->missing);
58 _gtk_css_lookup_is_missing (const GtkCssLookup *lookup,
61 g_return_val_if_fail (lookup != NULL, FALSE);
63 return _gtk_bitmask_get (lookup->missing, id);
67 * _gtk_css_lookup_set:
69 * @id: id of the property to set, see _gtk_style_property_get_id()
70 * @section: (allow-none): The @section the value was defined in or %NULL
71 * @value: the "cascading value" to use
73 * Sets the @value for a given @id. No value may have been set for @id
74 * before. See _gtk_css_lookup_is_missing(). This function is used to
75 * set the "winning declaration" of a lookup. Note that for performance
76 * reasons @value and @section are not copied. It is your responsibility
77 * to ensure they are kept alive until _gtk_css_lookup_free() is called.
80 _gtk_css_lookup_set (GtkCssLookup *lookup,
82 GtkCssSection *section,
85 g_return_if_fail (lookup != NULL);
86 g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
87 g_return_if_fail (value != NULL);
89 lookup->missing = _gtk_bitmask_set (lookup->missing, id, FALSE);
90 lookup->values[id].value = value;
91 lookup->values[id].section = section;
95 * _gtk_css_lookup_set_computed:
97 * @id: id of the property to set, see _gtk_style_property_get_id()
98 * @section: (allow-none): The @section the value was defined in or %NULL
99 * @value: the "computed value" to use
101 * Sets the @value for a given @id. No value may have been set for @id
102 * before. See _gtk_css_lookup_is_missing(). This function is used to
103 * set the "winning declaration" of a lookup. Note that for performance
104 * reasons @value and @section are not copied. It is your responsibility
105 * to ensure they are kept alive until _gtk_css_lookup_free() is called.
107 * As opposed to _gtk_css_lookup_set(), this function forces a computed
108 * value and will not cause computation to happen. In particular, with this
109 * method relative lengths or symbolic colors can not be used. This is
110 * usually only useful for doing overrides. It should not be used for proper
114 _gtk_css_lookup_set_computed (GtkCssLookup *lookup,
116 GtkCssSection *section,
119 g_return_if_fail (lookup != NULL);
120 g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
121 g_return_if_fail (value != NULL);
123 lookup->missing = _gtk_bitmask_set (lookup->missing, id, FALSE);
124 lookup->values[id].computed = value;
125 lookup->values[id].section = section;
129 * _gtk_css_lookup_resolve:
130 * @lookup: the lookup
131 * @context: the context the values are resolved for
132 * @values: a new #GtkCssComputedValues to be filled with the new properties
134 * Resolves the current lookup into a styleproperties object. This is done
135 * by converting from the "winning declaration" to the "computed value".
137 * XXX: This bypasses the notion of "specified value". If this ever becomes
138 * an issue, go fix it.
141 _gtk_css_lookup_resolve (GtkCssLookup *lookup,
142 GtkStyleProviderPrivate *provider,
143 GtkCssComputedValues *values,
144 GtkCssComputedValues *parent_values)
148 g_return_if_fail (lookup != NULL);
149 g_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
150 g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
151 g_return_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values));
153 n = _gtk_css_style_property_get_n_properties ();
155 for (i = 0; i < n; i++)
157 if (lookup->values[i].computed)
158 _gtk_css_computed_values_set_value (values,
160 lookup->values[i].computed,
162 lookup->values[i].section);
163 else if (lookup->values[i].value ||
164 _gtk_bitmask_get (lookup->missing, i))
165 _gtk_css_computed_values_compute_value (values,
169 lookup->values[i].value,
170 lookup->values[i].section);
171 /* else not a relevant property */