Add support for inline styles

Add support for passing an inline-style string when creating a
StThemeNode.

Hook this up to a new 'style' property of StWidget.

Add a test case that demonstrates using this to update font sizes
on the fly.

https://bugzilla.gnome.org/show_bug.cgi?id=595991
This commit is contained in:
Owen W. Taylor
2009-09-19 22:56:09 -04:00
parent 3c646ec516
commit 6527dbc8b7
9 changed files with 190 additions and 26 deletions

View File

@ -33,10 +33,14 @@ struct _StThemeNode {
char *element_id;
char *element_class;
char *pseudo_class;
char *inline_style;
CRDeclaration **properties;
int n_properties;
/* We hold onto these separately so we can destroy them on finalize */
CRDeclaration *inline_properties;
guint properties_computed : 1;
guint borders_computed : 1;
guint background_computed : 1;
@ -76,6 +80,7 @@ st_theme_node_finalize (GObject *object)
g_free (node->element_id);
g_free (node->element_class);
g_free (node->pseudo_class);
g_free (node->inline_style);
if (node->properties)
{
@ -84,6 +89,12 @@ st_theme_node_finalize (GObject *object)
node->n_properties = 0;
}
if (node->inline_properties)
{
/* This destroys the list, not just the head of the list */
cr_declaration_destroy (node->inline_properties);
}
if (node->font_desc)
{
pango_font_description_free (node->font_desc);
@ -131,7 +142,8 @@ st_theme_node_new (StThemeContext *context,
GType element_type,
const char *element_id,
const char *element_class,
const char *pseudo_class)
const char *pseudo_class,
const char *inline_style)
{
StThemeNode *node;
@ -156,6 +168,7 @@ st_theme_node_new (StThemeContext *context,
node->element_id = g_strdup (element_id);
node->element_class = g_strdup (element_class);
node->pseudo_class = g_strdup (pseudo_class);
node->inline_style = g_strdup (inline_style);
return node;
}
@ -230,11 +243,32 @@ ensure_properties (StThemeNode *node)
{
if (!node->properties_computed)
{
GPtrArray *properties = NULL;
node->properties_computed = TRUE;
if (node->theme)
_st_theme_get_matched_properties (node->theme, node,
&node->properties, &node->n_properties);
properties = _st_theme_get_matched_properties (node->theme, node);
if (node->inline_style)
{
CRDeclaration *cur_decl;
if (!properties)
properties = g_ptr_array_new ();
node->inline_properties = cr_declaration_parse_list_from_buf ((const guchar *)node->inline_style,
CR_UTF_8);
for (cur_decl = node->inline_properties; cur_decl; cur_decl = cur_decl->next)
g_ptr_array_add (properties, cur_decl);
}
if (properties)
{
node->n_properties = properties->len;
node->properties = (CRDeclaration **)g_ptr_array_free (properties, FALSE);
}
}
}