[gnome-shell] Store CSS classes and pseudo-classes pre-split in the StThemeNode
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] Store CSS classes and pseudo-classes pre-split in the StThemeNode
- Date: Wed, 14 Nov 2012 19:25:05 +0000 (UTC)
commit c4f6619fbdd79f4494a5b43f2d27d449e2b4b75e
Author: Simon McVittie <simon mcvittie collabora co uk>
Date: Wed Nov 7 18:44:33 2012 +0000
Store CSS classes and pseudo-classes pre-split in the StThemeNode
Tokenizing every time we want to evaluate CSS seems a poor plan.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=687465
Reviewed-by: Jasper St. Pierre <jstpierre mecheye net>
src/st/st-theme-node-private.h | 2 +
src/st/st-theme-node.c | 57 ++++++++++++++++++++++++++++++++++++++++
src/st/st-theme-node.h | 2 +
3 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/src/st/st-theme-node-private.h b/src/st/st-theme-node-private.h
index 9ceee1c..5958441 100644
--- a/src/st/st-theme-node-private.h
+++ b/src/st/st-theme-node-private.h
@@ -78,7 +78,9 @@ struct _StThemeNode {
GType element_type;
char *element_id;
char *element_class;
+ GStrv element_classes;
char *pseudo_class;
+ GStrv pseudo_classes;
char *inline_style;
CRDeclaration **properties;
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index 7e966e8..31bcf8a 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -97,7 +97,9 @@ st_theme_node_finalize (GObject *object)
g_free (node->element_id);
g_free (node->element_class);
+ g_strfreev (node->element_classes);
g_free (node->pseudo_class);
+ g_strfreev (node->pseudo_classes);
g_free (node->inline_style);
if (node->properties)
@@ -145,6 +147,33 @@ st_theme_node_finalize (GObject *object)
G_OBJECT_CLASS (st_theme_node_parent_class)->finalize (object);
}
+static GStrv
+split_on_whitespace (const gchar *s)
+{
+ gchar *cur;
+ gchar *l;
+ gchar *temp;
+ GPtrArray *arr;
+
+ if (s == NULL)
+ return NULL;
+
+ arr = g_ptr_array_new ();
+ l = g_strdup (s);
+
+ cur = strtok_r (l, " \t\f\r\n", &temp);
+
+ while (cur != NULL)
+ {
+ g_ptr_array_add (arr, g_strdup (cur));
+ cur = strtok_r (NULL, " \t\f\r\n", &temp);
+ }
+
+ g_free (l);
+ g_ptr_array_add (arr, NULL);
+ return (GStrv) g_ptr_array_free (arr, FALSE);
+}
+
/**
* st_theme_node_new:
* @context: the context representing global state for this themed tree
@@ -202,7 +231,9 @@ st_theme_node_new (StThemeContext *context,
node->element_type = element_type;
node->element_id = g_strdup (element_id);
node->element_class = g_strdup (element_class);
+ node->element_classes = split_on_whitespace (element_class);
node->pseudo_class = g_strdup (pseudo_class);
+ node->pseudo_classes = split_on_whitespace (pseudo_class);
node->inline_style = g_strdup (inline_style);
return node;
@@ -265,6 +296,19 @@ st_theme_node_get_element_class (StThemeNode *node)
return node->element_class;
}
+/**
+ * st_theme_node_get_element_classes:
+ *
+ * Returns: (transfer none): the element's classes
+ */
+GStrv
+st_theme_node_get_element_classes (StThemeNode *node)
+{
+ g_return_val_if_fail (ST_IS_THEME_NODE (node), NULL);
+
+ return node->element_classes;
+}
+
const char *
st_theme_node_get_pseudo_class (StThemeNode *node)
{
@@ -274,6 +318,19 @@ st_theme_node_get_pseudo_class (StThemeNode *node)
}
/**
+ * st_theme_node_get_pseudo_classes:
+ *
+ * Returns: (transfer none): the element's pseudo-classes
+ */
+GStrv
+st_theme_node_get_pseudo_classes (StThemeNode *node)
+{
+ g_return_val_if_fail (ST_IS_THEME_NODE (node), NULL);
+
+ return node->pseudo_classes;
+}
+
+/**
* st_theme_node_equal:
* @node_a: first #StThemeNode
* @node_b: second #StThemeNode
diff --git a/src/st/st-theme-node.h b/src/st/st-theme-node.h
index 2c672eb..31b200d 100644
--- a/src/st/st-theme-node.h
+++ b/src/st/st-theme-node.h
@@ -114,7 +114,9 @@ gboolean st_theme_node_equal (StThemeNode *node_a, StThemeNode *node_b);
GType st_theme_node_get_element_type (StThemeNode *node);
const char *st_theme_node_get_element_id (StThemeNode *node);
const char *st_theme_node_get_element_class (StThemeNode *node);
+GStrv st_theme_node_get_element_classes (StThemeNode *node);
const char *st_theme_node_get_pseudo_class (StThemeNode *node);
+GStrv st_theme_node_get_pseudo_classes (StThemeNode *node);
/* Generic getters ... these are not cached so are less efficient. The other
* reason for adding the more specific version is that we can handle the
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]