1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2014 Red Hat, Inc.
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18 #include "config.h"
19
20 #include "gtkcssunsetvalueprivate.h"
21
22 #include "gtkcssinheritvalueprivate.h"
23 #include "gtkcssinitialvalueprivate.h"
24 #include "gtkcssstylepropertyprivate.h"
25
26 struct _GtkCssValue {
27 GTK_CSS_VALUE_BASE
28 };
29
30 static void
gtk_css_value_unset_free(GtkCssValue * value)31 gtk_css_value_unset_free (GtkCssValue *value)
32 {
33 /* Can only happen if the unique value gets unreffed too often */
34 g_assert_not_reached ();
35 }
36
37 static GtkCssValue *
gtk_css_value_unset_compute(GtkCssValue * value,guint property_id,GtkStyleProviderPrivate * provider,GtkCssStyle * style,GtkCssStyle * parent_style)38 gtk_css_value_unset_compute (GtkCssValue *value,
39 guint property_id,
40 GtkStyleProviderPrivate *provider,
41 GtkCssStyle *style,
42 GtkCssStyle *parent_style)
43 {
44 GtkCssStyleProperty *property;
45 GtkCssValue *unset_value;
46
47 property = _gtk_css_style_property_lookup_by_id (property_id);
48
49 if (_gtk_css_style_property_is_inherit (property))
50 unset_value = _gtk_css_inherit_value_get ();
51 else
52 unset_value = _gtk_css_initial_value_get ();
53
54 return _gtk_css_value_compute (unset_value,
55 property_id,
56 provider,
57 style,
58 parent_style);
59 }
60
61 static gboolean
gtk_css_value_unset_equal(const GtkCssValue * value1,const GtkCssValue * value2)62 gtk_css_value_unset_equal (const GtkCssValue *value1,
63 const GtkCssValue *value2)
64 {
65 return TRUE;
66 }
67
68 static GtkCssValue *
gtk_css_value_unset_transition(GtkCssValue * start,GtkCssValue * end,guint property_id,double progress)69 gtk_css_value_unset_transition (GtkCssValue *start,
70 GtkCssValue *end,
71 guint property_id,
72 double progress)
73 {
74 return NULL;
75 }
76
77 static void
gtk_css_value_unset_print(const GtkCssValue * value,GString * string)78 gtk_css_value_unset_print (const GtkCssValue *value,
79 GString *string)
80 {
81 g_string_append (string, "unset");
82 }
83
84 static const GtkCssValueClass GTK_CSS_VALUE_UNSET = {
85 gtk_css_value_unset_free,
86 gtk_css_value_unset_compute,
87 gtk_css_value_unset_equal,
88 gtk_css_value_unset_transition,
89 gtk_css_value_unset_print
90 };
91
92 static GtkCssValue unset = { >K_CSS_VALUE_UNSET, 1 };
93
94 GtkCssValue *
_gtk_css_unset_value_new(void)95 _gtk_css_unset_value_new (void)
96 {
97 return _gtk_css_value_ref (&unset);
98 }
99