cssnode: Add gtk_style_context_get_style_provider()

... and use it when looking up properties.
This commit is contained in:
Benjamin Otte 2015-01-31 16:30:05 +01:00
parent 6dc6af674c
commit 03ac5f310b
6 changed files with 54 additions and 8 deletions

View File

@ -21,6 +21,7 @@
#include "gtkcsstransientnodeprivate.h"
#include "gtkdebug.h"
#include "gtksettingsprivate.h"
G_DEFINE_TYPE (GtkCssNode, gtk_css_node, G_TYPE_OBJECT)
@ -96,6 +97,15 @@ gtk_css_node_real_get_widget_path (GtkCssNode *cssnode)
return NULL;
}
static GtkStyleProviderPrivate *
gtk_css_node_real_get_style_provider (GtkCssNode *cssnode)
{
if (cssnode->parent)
return gtk_css_node_get_style_provider (cssnode->parent);
return GTK_STYLE_PROVIDER_PRIVATE (_gtk_settings_get_style_cascade (gtk_settings_get_default (), 1));
}
static void
gtk_css_node_class_init (GtkCssNodeClass *klass)
{
@ -109,6 +119,7 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
klass->set_invalid = gtk_css_node_real_set_invalid;
klass->create_widget_path = gtk_css_node_real_create_widget_path;
klass->get_widget_path = gtk_css_node_real_get_widget_path;
klass->get_style_provider = gtk_css_node_real_get_style_provider;
}
static void
@ -424,3 +435,8 @@ gtk_css_node_get_widget_path (GtkCssNode *cssnode)
return GTK_CSS_NODE_GET_CLASS (cssnode)->get_widget_path (cssnode);
}
GtkStyleProviderPrivate *
gtk_css_node_get_style_provider (GtkCssNode *cssnode)
{
return GTK_CSS_NODE_GET_CLASS (cssnode)->get_style_provider (cssnode);
}

View File

@ -56,6 +56,7 @@ struct _GtkCssNodeClass
GtkWidgetPath * (* create_widget_path) (GtkCssNode *cssnode);
const GtkWidgetPath * (* get_widget_path) (GtkCssNode *cssnode);
GtkStyleProviderPrivate *(* get_style_provider) (GtkCssNode *cssnode);
void (* invalidate) (GtkCssNode *cssnode,
GtkCssChange change);
void (* set_invalid) (GtkCssNode *node,
@ -124,6 +125,7 @@ void gtk_css_node_set_invalid (GtkCssNode *
gboolean invalid);
GtkWidgetPath * gtk_css_node_create_widget_path (GtkCssNode *cssnode);
const GtkWidgetPath * gtk_css_node_get_widget_path (GtkCssNode *cssnode);
GtkStyleProviderPrivate *gtk_css_node_get_style_provider(GtkCssNode *cssnode);
G_END_DECLS

View File

@ -77,6 +77,17 @@ gtk_css_path_node_real_get_widget_path (GtkCssNode *node)
return path_node->path;
}
static GtkStyleProviderPrivate *
gtk_css_path_node_get_style_provider (GtkCssNode *node)
{
GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
if (path_node->context == NULL)
return GTK_CSS_NODE_CLASS (gtk_css_path_node_parent_class)->get_style_provider (node);
return gtk_style_context_get_style_provider (path_node->context);
}
static void
gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
{
@ -86,6 +97,7 @@ gtk_css_path_node_class_init (GtkCssPathNodeClass *klass)
node_class->set_invalid = gtk_css_path_node_set_invalid;
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

View File

@ -108,6 +108,17 @@ gtk_css_widget_node_get_widget_path (GtkCssNode *node)
return gtk_widget_get_path (widget_node->widget);
}
static GtkStyleProviderPrivate *
gtk_css_widget_node_get_style_provider (GtkCssNode *node)
{
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
if (widget_node->widget == NULL)
return GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->get_style_provider (node);
return gtk_style_context_get_style_provider (gtk_widget_get_style_context (widget_node->widget));
}
static void
gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
{
@ -118,6 +129,7 @@ gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
node_class->set_invalid = gtk_css_widget_node_set_invalid;
node_class->create_widget_path = gtk_css_widget_node_create_widget_path;
node_class->get_widget_path = gtk_css_widget_node_get_widget_path;
node_class->get_style_provider = gtk_css_widget_node_get_style_provider;
}
static void

View File

@ -611,6 +611,12 @@ gtk_style_context_get_root (GtkStyleContext *context)
return priv->cssnode;
}
GtkStyleProviderPrivate *
gtk_style_context_get_style_provider (GtkStyleContext *context)
{
return GTK_STYLE_PROVIDER_PRIVATE (context->priv->cascade);
}
static gboolean
gtk_style_context_has_custom_cascade (GtkStyleContext *context)
{
@ -710,14 +716,12 @@ update_properties (GtkStyleContext *context,
GtkCssStyle *style,
const GtkBitmask *parent_changes)
{
GtkStyleContextPrivate *priv;
const GtkCssNodeDeclaration *decl;
GtkCssMatcher matcher;
GtkWidgetPath *path;
GtkCssStyle *parent;
GtkCssStyle *result;
priv = context->priv;
parent = gtk_css_node_get_parent_style (context, cssnode);
decl = gtk_css_node_get_declaration (cssnode);
@ -734,7 +738,7 @@ update_properties (GtkStyleContext *context,
result = gtk_css_static_style_new_update (GTK_CSS_STATIC_STYLE (style),
parent_changes,
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
gtk_css_node_get_style_provider (cssnode),
&matcher,
parent);
@ -751,14 +755,12 @@ build_properties (GtkStyleContext *context,
gboolean override_state,
GtkStateFlags state)
{
GtkStyleContextPrivate *priv;
const GtkCssNodeDeclaration *decl;
GtkCssMatcher matcher;
GtkWidgetPath *path;
GtkCssStyle *parent;
GtkCssStyle *style;
priv = context->priv;
decl = gtk_css_node_get_declaration (cssnode);
parent = gtk_css_node_get_parent_style (context, cssnode);
@ -771,11 +773,11 @@ build_properties (GtkStyleContext *context,
gtk_widget_path_iter_set_state (path, -1, state);
if (_gtk_css_matcher_init (&matcher, path))
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
&matcher,
parent);
else
style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
NULL,
parent);
@ -2823,7 +2825,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
style = gtk_css_animated_style_new (static_style,
priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL,
timestamp,
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
gtk_css_node_get_style_provider (cssnode),
gtk_style_context_should_create_transitions (context, current) ? current : NULL);
gtk_style_context_clear_cache (context);

View File

@ -34,6 +34,8 @@ GtkCssNode * gtk_style_context_get_root (GtkStyleContext *c
void gtk_style_context_set_id (GtkStyleContext *context,
const char *id);
const char * gtk_style_context_get_id (GtkStyleContext *context);
GtkStyleProviderPrivate *
gtk_style_context_get_style_provider (GtkStyleContext *context);
const GtkBitmask *
_gtk_style_context_get_changes (GtkStyleContext *context);