return g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
}
-void
-_gtk_style_context_set_widget (GtkStyleContext *context,
- GtkWidget *widget)
+GtkStyleContext *
+gtk_style_context_new_for_node (GtkCssNode *node)
{
GtkStyleContextPrivate *priv;
+ GtkStyleContext *context;
- g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
- g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
- g_return_if_fail (!gtk_style_context_is_saved (context));
+ g_return_val_if_fail (GTK_IS_CSS_NODE (node), NULL);
- priv = context->priv;
+ context = gtk_style_context_new ();
- if (!GTK_IS_CSS_WIDGET_NODE (priv->cssnode))
- {
- g_object_unref (priv->cssnode);
- priv->cssnode = gtk_css_widget_node_new (widget);
- gtk_css_node_set_state (priv->cssnode, GTK_STATE_FLAG_DIR_LTR);
- }
-
- if (widget)
- {
- gtk_css_node_set_widget_type (priv->cssnode, G_OBJECT_TYPE (widget));
- }
- else
- {
- gtk_css_node_set_widget_type (priv->cssnode, G_TYPE_NONE);
- gtk_css_widget_node_widget_destroyed (GTK_CSS_WIDGET_NODE (priv->cssnode));
- }
+ priv = context->priv;
+ g_object_unref (priv->cssnode);
+ priv->cssnode = g_object_ref (node);
- gtk_css_node_invalidate (gtk_style_context_get_root (context), GTK_CSS_CHANGE_ANY_SELF);
+ return context;
}
/**
if (parent)
{
+ GtkCssNode *root = gtk_style_context_get_root (context);
g_object_ref (parent);
- gtk_css_node_set_parent (gtk_style_context_get_root (context),
- gtk_style_context_get_root (parent));
+
+ if (gtk_css_node_get_parent (root) == NULL)
+ gtk_css_node_set_parent (root, gtk_style_context_get_root (parent));
}
else
{
#include "gtksizerequest.h"
#include "gtkstylecontextprivate.h"
#include "gtkcssprovider.h"
+#include "gtkcsswidgetnodeprivate.h"
#include "gtkmodifierstyle.h"
#include "gtkversion.h"
#include "gtkdebug.h"
* the font to use for text.
*/
GtkStyle *style;
+ GtkCssNode *cssnode;
GtkStyleContext *context;
/* Widget's path for styling */
static void gtk_widget_base_class_init (gpointer g_class);
static void gtk_widget_class_init (GtkWidgetClass *klass);
static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
-static void gtk_widget_init (GtkWidget *widget);
+static void gtk_widget_init (GTypeInstance *instance,
+ gpointer g_class);
static void gtk_widget_set_property (GObject *object,
guint prop_id,
const GValue *value,
NULL, /* class_init */
sizeof (GtkWidget),
0, /* n_preallocs */
- (GInstanceInitFunc) gtk_widget_init,
+ gtk_widget_init,
NULL, /* value_table */
};
}
static void
-gtk_widget_init (GtkWidget *widget)
+gtk_widget_init (GTypeInstance *instance, gpointer g_class)
{
+ GtkWidget *widget = GTK_WIDGET (instance);
GtkWidgetPrivate *priv;
widget->priv = gtk_widget_get_instance_private (widget);
_gtk_size_request_cache_init (&priv->requests);
+ priv->cssnode = gtk_css_widget_node_new (widget);
+ gtk_css_node_set_state (priv->cssnode, GTK_STATE_FLAG_DIR_LTR);
+ /* need to set correct type here, and only class has the correct type here */
+ gtk_css_node_set_widget_type (priv->cssnode, G_TYPE_FROM_CLASS (g_class));
+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
priv->style = gtk_widget_get_default_style ();
G_GNUC_END_IGNORE_DEPRECATIONS;
gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
if (priv->context)
gtk_style_context_set_parent (priv->context, NULL);
+ gtk_css_node_set_parent (widget->priv->cssnode, NULL);
_gtk_widget_update_parent_muxer (widget);
data.flags_to_unset = 0;
gtk_widget_propagate_state (widget, &data);
+ if (gtk_css_node_get_parent (widget->priv->cssnode) == NULL)
+ gtk_css_node_set_parent (widget->priv->cssnode, parent->priv->cssnode);
if (priv->context)
gtk_style_context_set_parent (priv->context,
gtk_widget_get_style_context (parent));
if (priv->path)
gtk_widget_path_free (priv->path);
+ gtk_css_widget_node_widget_destroyed (GTK_CSS_WIDGET_NODE (priv->cssnode));
+ g_object_unref (priv->cssnode);
+
if (priv->context)
- {
- _gtk_style_context_set_widget (priv->context, NULL);
- g_object_unref (priv->context);
- }
+ g_object_unref (priv->context);
_gtk_size_request_cache_free (&priv->requests);
GdkScreen *screen;
GdkFrameClock *frame_clock;
- priv->context = gtk_style_context_new ();
+ priv->context = gtk_style_context_new_for_node (priv->cssnode);
gtk_style_context_set_id (priv->context, priv->name);
gtk_style_context_set_state (priv->context, priv->state_flags);
if (frame_clock)
gtk_style_context_set_frame_clock (priv->context, frame_clock);
- _gtk_style_context_set_widget (priv->context, widget);
-
if (priv->parent)
gtk_style_context_set_parent (priv->context,
gtk_widget_get_style_context (priv->parent));