summaryrefslogtreecommitdiff
path: root/gtk/gtkcsspathnode.c
blob: 64cd49260bdf76cf163e5bd3cdf00c402dff54db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* GTK - The GIMP Toolkit
 * Copyright (C) 2014 Benjamin Otte <otte@gnome.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "gtkcsspathnodeprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtkprivate.h"
#include "gtkstylecontextprivate.h"

G_DEFINE_TYPE (GtkCssPathNode, gtk_css_path_node, GTK_TYPE_CSS_NODE)

static void
gtk_css_path_node_finalize (GObject *object)
{
  GtkCssPathNode *node = GTK_CSS_PATH_NODE (object);

  if (node->path)
    gtk_widget_path_unref (node->path);

  G_OBJECT_CLASS (gtk_css_path_node_parent_class)->finalize (object);
}

static void
gtk_css_path_node_invalidate (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->context)
    gtk_style_context_validate (path_node->context, NULL);
}

static gboolean
gtk_css_path_node_real_init_matcher (GtkCssNode     *node,
                                     GtkCssMatcher  *matcher)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->path == NULL ||
      gtk_widget_path_length (path_node->path) == 0)
    return FALSE;

  return _gtk_css_matcher_init (matcher,
                                path_node->path,
                                gtk_css_node_get_declaration (node));
}

static GtkWidgetPath *
gtk_css_path_node_real_create_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
  GtkWidgetPath *path;
  guint length;

  if (path_node->path == NULL)
    path = gtk_widget_path_new ();
  else
    path = gtk_widget_path_copy (path_node->path);

  length = gtk_widget_path_length (path);
  if (length > 0)
    {
      gtk_css_node_declaration_add_to_widget_path (gtk_css_node_get_declaration (node),
                                                   path,
                                                   length - 1);
    }

  return path;
}

static const GtkWidgetPath *
gtk_css_path_node_real_get_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  return path_node->path;
}

static GtkCssStyle *
gtk_css_path_node_update_style (GtkCssNode   *cssnode,
                                GtkCssChange  change,
                                gint64        timestamp,
                                GtkCssStyle  *style)
{
  /* This should get rid of animations */
  return GTK_CSS_NODE_CLASS (gtk_css_path_node_parent_class)->update_style (cssnode, change, 0, style);
}

static GtkStyleProvider *
gtk_css_path_node_get_style_provider (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->context == NULL)
    return NULL;

  return gtk_style_context_get_style_provider (path_node->context);
}

static void
gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
{
  GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = gtk_css_path_node_finalize;

  node_class->invalidate = gtk_css_path_node_invalidate;
  node_class->update_style = gtk_css_path_node_update_style;
  node_class->init_matcher = gtk_css_path_node_real_init_matcher;
  node_class->create_widget_path = gtk_css_path_node_real_create_widget_path;
  node_class->get_widget_path = gtk_css_path_node_real_get_widget_path;
  node_class->get_style_provider = gtk_css_path_node_get_style_provider;
}

static void
gtk_css_path_node_init (GtkCssPathNode *cssnode)
{
}

GtkCssNode *
gtk_css_path_node_new (GtkStyleContext *context)
{
  GtkCssPathNode *node;
  
  g_return_val_if_fail (context == NULL || GTK_IS_STYLE_CONTEXT (context), NULL);

  node = g_object_new (GTK_TYPE_CSS_PATH_NODE, NULL);
  node->context = context;

  return GTK_CSS_NODE (node);
}

void
gtk_css_path_node_unset_context (GtkCssPathNode *node)
{
  gtk_internal_return_if_fail (GTK_IS_CSS_PATH_NODE (node));
  gtk_internal_return_if_fail (node->context != NULL);

  node->context = NULL;

  gtk_css_node_invalidate_style_provider (GTK_CSS_NODE (node));
}

void
gtk_css_path_node_set_widget_path (GtkCssPathNode *node,
                                   GtkWidgetPath  *path)
{
  gtk_internal_return_if_fail (GTK_IS_CSS_PATH_NODE (node));

  if (node->path == path)
    return;

  if (node->path)
    gtk_widget_path_unref (node->path);

  if (path)
    gtk_widget_path_ref (path);

  node->path = path;

  gtk_css_node_invalidate (GTK_CSS_NODE (node), GTK_CSS_CHANGE_ANY);
}

GtkWidgetPath *
gtk_css_path_node_get_widget_path (GtkCssPathNode *node)
{
  gtk_internal_return_val_if_fail (GTK_IS_CSS_PATH_NODE (node), NULL);

  return node->path;
}