]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssinheritvalue.c
css: Introduce dependencies for value computations
[~andy/gtk] / gtk / gtkcssinheritvalue.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2011 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 "gtkcssinheritvalueprivate.h"
21
22 #include "gtkcssstylepropertyprivate.h"
23 #include "gtkstylecontextprivate.h"
24
25 struct _GtkCssValue {
26   GTK_CSS_VALUE_BASE
27 };
28
29 static void
30 gtk_css_value_inherit_free (GtkCssValue *value)
31 {
32   /* Can only happen if the unique value gets unreffed too often */
33   g_assert_not_reached ();
34 }
35
36 static GtkCssValue *
37 gtk_css_value_inherit_compute (GtkCssValue        *value,
38                                guint               property_id,
39                                GtkStyleContext    *context,
40                                GtkCssDependencies *dependencies)
41 {
42   GtkStyleContext *parent = gtk_style_context_get_parent (context);
43
44   *dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
45
46   if (parent)
47     return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, property_id));
48   else
49     return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
50                                    property_id,
51                                    context,
52                                    NULL);
53 }
54
55 static gboolean
56 gtk_css_value_inherit_equal (const GtkCssValue *value1,
57                              const GtkCssValue *value2)
58 {
59   return TRUE;
60 }
61
62 static GtkCssValue *
63 gtk_css_value_inherit_transition (GtkCssValue *start,
64                                   GtkCssValue *end,
65                                   double       progress)
66 {
67   return NULL;
68 }
69
70 static void
71 gtk_css_value_inherit_print (const GtkCssValue *value,
72                              GString           *string)
73 {
74   g_string_append (string, "inherit");
75 }
76
77 static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
78   gtk_css_value_inherit_free,
79   gtk_css_value_inherit_compute,
80   gtk_css_value_inherit_equal,
81   gtk_css_value_inherit_transition,
82   gtk_css_value_inherit_print
83 };
84
85 static GtkCssValue inherit = { &GTK_CSS_VALUE_INHERIT, 1 };
86
87 GtkCssValue *
88 _gtk_css_inherit_value_new (void)
89 {
90   return _gtk_css_value_ref (&inherit);
91 }