[gtk+/wip/cssnode3: 92/102] cssnode: Make classes APIs string-based
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssnode3: 92/102] cssnode: Make classes APIs string-based
- Date: Wed, 11 Mar 2015 00:24:08 +0000 (UTC)
commit 24fb45317ca6e07e43a75f46ab14926a7a31746c
Author: Benjamin Otte <otte redhat com>
Date: Tue Mar 10 02:37:57 2015 +0100
cssnode: Make classes APIs string-based
Using quarks is a bad idea now that we are calling the CssNode API
directly.
gtk/gtkcssmatcher.c | 2 +-
gtk/gtkcssnode.c | 54 ++++++++++++++++++++++++++++++++++++++++-------
gtk/gtkcssnodeprivate.h | 6 +++-
gtk/gtkstylecontext.c | 26 +++-------------------
gtk/gtkswitch.c | 2 +-
gtk/gtkwidget.c | 2 +-
6 files changed, 57 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index b2b5c75..19d5b68 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -306,7 +306,7 @@ static gboolean
gtk_css_matcher_node_has_class (const GtkCssMatcher *matcher,
GQuark class_name)
{
- return gtk_css_node_has_class (matcher->node.node, class_name);
+ return gtk_css_node_has_qclass (matcher->node.node, class_name);
}
static gboolean
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index aaace41..39b481a 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -972,7 +972,7 @@ gtk_css_node_clear_classes (GtkCssNode *cssnode)
for (l = list; l; l = l->next)
{
- gtk_css_node_remove_class (cssnode, GPOINTER_TO_UINT (l->data));
+ gtk_css_node_remove_class (cssnode, l->data);
}
g_list_free (list);
@@ -992,7 +992,7 @@ gtk_css_node_set_classes (GtkCssNode *cssnode,
{
for (i = 0; classes[i] != NULL; i++)
{
- gtk_css_node_add_class (cssnode, g_quark_from_string (classes[i]));
+ gtk_css_node_add_class (cssnode, classes[i]);
}
}
@@ -1022,9 +1022,13 @@ gtk_css_node_get_classes (GtkCssNode *cssnode)
void
gtk_css_node_add_class (GtkCssNode *cssnode,
- GQuark style_class)
+ const char *style_class)
{
- if (gtk_css_node_declaration_add_class (&cssnode->decl, style_class))
+ GQuark class_quark;
+
+ class_quark = g_quark_from_string (style_class);
+
+ if (gtk_css_node_declaration_add_class (&cssnode->decl, class_quark))
{
gtk_css_node_invalidate (cssnode, GTK_CSS_CHANGE_CLASS);
g_object_notify_by_pspec (G_OBJECT (cssnode), cssnode_properties[PROP_CLASSES]);
@@ -1033,9 +1037,15 @@ gtk_css_node_add_class (GtkCssNode *cssnode,
void
gtk_css_node_remove_class (GtkCssNode *cssnode,
- GQuark style_class)
+ const char *style_class)
{
- if (gtk_css_node_declaration_remove_class (&cssnode->decl, style_class))
+ GQuark class_quark;
+
+ class_quark = g_quark_try_string (style_class);
+ if (class_quark == 0)
+ return;
+
+ if (gtk_css_node_declaration_remove_class (&cssnode->decl, class_quark))
{
gtk_css_node_invalidate (cssnode, GTK_CSS_CHANGE_CLASS);
g_object_notify_by_pspec (G_OBJECT (cssnode), cssnode_properties[PROP_CLASSES]);
@@ -1044,15 +1054,43 @@ gtk_css_node_remove_class (GtkCssNode *cssnode,
gboolean
gtk_css_node_has_class (GtkCssNode *cssnode,
- GQuark style_class)
+ const char *style_class)
+{
+ GQuark class_quark;
+
+ class_quark = g_quark_try_string (style_class);
+ if (class_quark == 0)
+ return FALSE;
+
+ return gtk_css_node_has_qclass (cssnode, class_quark);
+}
+
+gboolean
+gtk_css_node_has_qclass (GtkCssNode *cssnode,
+ GQuark style_class)
{
return gtk_css_node_declaration_has_class (cssnode->decl, style_class);
}
+static void
+quarks_to_strings (GList *list)
+{
+ GList *l;
+
+ for (l = list; l; l = l->next)
+ {
+ l->data = (char *) g_quark_to_string (GPOINTER_TO_UINT (l->data));
+ }
+}
+
GList *
gtk_css_node_list_classes (GtkCssNode *cssnode)
{
- return gtk_css_node_declaration_list_classes (cssnode->decl);
+ GList *list = gtk_css_node_declaration_list_classes (cssnode->decl);
+
+ quarks_to_strings (list);
+
+ return list;
}
void
diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h
index afee550..8a155a7 100644
--- a/gtk/gtkcssnodeprivate.h
+++ b/gtk/gtkcssnodeprivate.h
@@ -129,10 +129,12 @@ void gtk_css_node_set_classes (GtkCssNode *
const char **classes);
char ** gtk_css_node_get_classes (GtkCssNode *cssnode);
void gtk_css_node_add_class (GtkCssNode *cssnode,
- GQuark style_class);
+ const char *style_class);
void gtk_css_node_remove_class (GtkCssNode *cssnode,
- GQuark style_class);
+ const char *style_class);
gboolean gtk_css_node_has_class (GtkCssNode *cssnode,
+ const char *style_class);
+gboolean gtk_css_node_has_qclass (GtkCssNode *cssnode,
GQuark style_class);
GList * gtk_css_node_list_classes (GtkCssNode *cssnode);
void gtk_css_node_add_region (GtkCssNode *cssnode,
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 9fb4cee..6541b13 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -1312,15 +1312,13 @@ gtk_style_context_add_class (GtkStyleContext *context,
const gchar *class_name)
{
GtkStyleContextPrivate *priv;
- GQuark class_quark;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (class_name != NULL);
priv = context->priv;
- class_quark = g_quark_from_string (class_name);
- gtk_css_node_add_class (priv->cssnode, class_quark);
+ gtk_css_node_add_class (priv->cssnode, class_name);
}
/**
@@ -1337,19 +1335,13 @@ gtk_style_context_remove_class (GtkStyleContext *context,
const gchar *class_name)
{
GtkStyleContextPrivate *priv;
- GQuark class_quark;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (class_name != NULL);
- class_quark = g_quark_try_string (class_name);
-
- if (!class_quark)
- return;
-
priv = context->priv;
- gtk_css_node_remove_class (priv->cssnode, class_quark);
+ gtk_css_node_remove_class (priv->cssnode, class_name);
}
/**
@@ -1369,19 +1361,13 @@ gtk_style_context_has_class (GtkStyleContext *context,
const gchar *class_name)
{
GtkStyleContextPrivate *priv;
- GQuark class_quark;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
g_return_val_if_fail (class_name != NULL, FALSE);
- class_quark = g_quark_try_string (class_name);
-
- if (!class_quark)
- return FALSE;
-
priv = context->priv;
- return gtk_css_node_has_class (priv->cssnode, class_quark);
+ return gtk_css_node_has_class (priv->cssnode, class_name);
}
static void
@@ -1412,16 +1398,12 @@ GList *
gtk_style_context_list_classes (GtkStyleContext *context)
{
GtkStyleContextPrivate *priv;
- GList *classes;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
priv = context->priv;
- classes = gtk_css_node_list_classes (priv->cssnode);
- quarks_to_strings (classes);
-
- return classes;
+ return gtk_css_node_list_classes (priv->cssnode);
}
/**
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index e9b9ab6..7dcf8ea 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -1042,7 +1042,7 @@ gtk_switch_init (GtkSwitch *self)
widget_node = gtk_widget_get_css_node (GTK_WIDGET (self));
priv->slider_node = gtk_css_node_new ();
gtk_css_node_set_widget_type (priv->slider_node, GTK_TYPE_SWITCH);
- gtk_css_node_add_class (priv->slider_node, g_quark_from_string (GTK_STYLE_CLASS_SLIDER));
+ gtk_css_node_add_class (priv->slider_node, GTK_STYLE_CLASS_SLIDER);
gtk_css_node_set_parent (priv->slider_node, widget_node);
gtk_css_node_set_state (priv->slider_node, gtk_css_node_get_state (widget_node));
g_signal_connect_object (priv->slider_node, "style-changed", G_CALLBACK
(gtk_css_node_style_changed_for_widget), self, 0);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 62c5805..dc88719 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -16339,7 +16339,7 @@ gtk_widget_path_append_for_widget (GtkWidgetPath *path,
classes = gtk_css_node_list_classes (widget->priv->cssnode);
for (l = classes; l; l = l->next)
- gtk_widget_path_iter_add_class (path, pos, g_quark_to_string (GPOINTER_TO_UINT (l->data)));
+ gtk_widget_path_iter_add_class (path, pos, l->data);
g_list_free (classes);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]