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>
This commit is contained in:
Simon McVittie 2012-11-07 18:44:33 +00:00
parent 65edbc1424
commit c4f6619fbd
3 changed files with 61 additions and 0 deletions

View File

@ -78,7 +78,9 @@ struct _StThemeNode {
GType element_type; GType element_type;
char *element_id; char *element_id;
char *element_class; char *element_class;
GStrv element_classes;
char *pseudo_class; char *pseudo_class;
GStrv pseudo_classes;
char *inline_style; char *inline_style;
CRDeclaration **properties; CRDeclaration **properties;

View File

@ -97,7 +97,9 @@ st_theme_node_finalize (GObject *object)
g_free (node->element_id); g_free (node->element_id);
g_free (node->element_class); g_free (node->element_class);
g_strfreev (node->element_classes);
g_free (node->pseudo_class); g_free (node->pseudo_class);
g_strfreev (node->pseudo_classes);
g_free (node->inline_style); g_free (node->inline_style);
if (node->properties) if (node->properties)
@ -145,6 +147,33 @@ st_theme_node_finalize (GObject *object)
G_OBJECT_CLASS (st_theme_node_parent_class)->finalize (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: * st_theme_node_new:
* @context: the context representing global state for this themed tree * @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_type = element_type;
node->element_id = g_strdup (element_id); node->element_id = g_strdup (element_id);
node->element_class = g_strdup (element_class); node->element_class = g_strdup (element_class);
node->element_classes = split_on_whitespace (element_class);
node->pseudo_class = g_strdup (pseudo_class); node->pseudo_class = g_strdup (pseudo_class);
node->pseudo_classes = split_on_whitespace (pseudo_class);
node->inline_style = g_strdup (inline_style); node->inline_style = g_strdup (inline_style);
return node; return node;
@ -265,6 +296,19 @@ st_theme_node_get_element_class (StThemeNode *node)
return node->element_class; 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 * const char *
st_theme_node_get_pseudo_class (StThemeNode *node) st_theme_node_get_pseudo_class (StThemeNode *node)
{ {
@ -273,6 +317,19 @@ st_theme_node_get_pseudo_class (StThemeNode *node)
return node->pseudo_class; return node->pseudo_class;
} }
/**
* 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: * st_theme_node_equal:
* @node_a: first #StThemeNode * @node_a: first #StThemeNode

View File

@ -114,7 +114,9 @@ gboolean st_theme_node_equal (StThemeNode *node_a, StThemeNode *node_b);
GType st_theme_node_get_element_type (StThemeNode *node); 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_id (StThemeNode *node);
const char *st_theme_node_get_element_class (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); 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 /* 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 * reason for adding the more specific version is that we can handle the