forked from AuroraMiddleware/gtk
stylecontext: Move gtk_style_context_validate() to GtkCssWidgetNode
This commit is contained in:
parent
649edbe2fc
commit
c550cf122a
@ -20,10 +20,15 @@
|
||||
#include "gtkcsswidgetnodeprivate.h"
|
||||
|
||||
#include "gtkcontainerprivate.h"
|
||||
#include "gtkcssanimatedstyleprivate.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkstylecontextprivate.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
|
||||
/* When these change we do a full restyling. Otherwise we try to figure out
|
||||
* if we need to change things. */
|
||||
#define GTK_CSS_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
|
||||
|
||||
G_DEFINE_TYPE (GtkCssWidgetNode, gtk_css_widget_node, GTK_TYPE_CSS_NODE)
|
||||
|
||||
static void
|
||||
@ -53,6 +58,23 @@ gtk_css_widget_node_set_invalid (GtkCssNode *node,
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_style_needs_full_revalidate (GtkCssStyle *style,
|
||||
GtkCssChange change)
|
||||
{
|
||||
/* Try to avoid invalidating if we can */
|
||||
if (change & GTK_CSS_RADICAL_CHANGE)
|
||||
return TRUE;
|
||||
|
||||
if (GTK_IS_CSS_ANIMATED_STYLE (style))
|
||||
style = GTK_CSS_ANIMATED_STYLE (style)->style;
|
||||
|
||||
if (gtk_css_static_style_get_change (GTK_CSS_STATIC_STYLE (style)) & change)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GtkBitmask *
|
||||
gtk_css_widget_node_validate (GtkCssNode *node,
|
||||
gint64 timestamp,
|
||||
@ -60,6 +82,9 @@ gtk_css_widget_node_validate (GtkCssNode *node,
|
||||
const GtkBitmask *parent_changes)
|
||||
{
|
||||
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
||||
GtkStyleContext *context;
|
||||
GtkBitmask *changes;
|
||||
GtkCssStyle *style;
|
||||
|
||||
change |= widget_node->pending_changes;
|
||||
widget_node->pending_changes = 0;
|
||||
@ -67,11 +92,80 @@ gtk_css_widget_node_validate (GtkCssNode *node,
|
||||
if (widget_node->widget == NULL)
|
||||
return _gtk_bitmask_new ();
|
||||
|
||||
return _gtk_style_context_validate (gtk_widget_get_style_context (widget_node->widget),
|
||||
node,
|
||||
timestamp,
|
||||
change,
|
||||
parent_changes);
|
||||
context = gtk_widget_get_style_context (widget_node->widget);
|
||||
style = gtk_css_node_get_style (node);
|
||||
if (style == NULL)
|
||||
style = gtk_css_static_style_get_default ();
|
||||
g_object_ref (style);
|
||||
|
||||
/* Try to avoid invalidating if we can */
|
||||
if (gtk_css_style_needs_full_revalidate (style, change))
|
||||
{
|
||||
GtkCssStyle *new_style, *static_style;
|
||||
GtkCssNode *parent;
|
||||
|
||||
parent = gtk_css_node_get_parent (node);
|
||||
|
||||
static_style = gtk_css_node_create_style (node);
|
||||
new_style = gtk_css_animated_style_new (static_style,
|
||||
parent ? gtk_css_node_get_style (parent) : NULL,
|
||||
timestamp,
|
||||
gtk_css_node_get_style_provider (node),
|
||||
gtk_style_context_should_create_transitions (context, style) ? style : NULL);
|
||||
|
||||
gtk_css_node_set_style (node, new_style);
|
||||
|
||||
g_object_unref (static_style);
|
||||
g_object_unref (new_style);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_gtk_bitmask_is_empty (parent_changes))
|
||||
{
|
||||
GtkCssStyle *new_values;
|
||||
|
||||
if (GTK_IS_CSS_ANIMATED_STYLE (style))
|
||||
{
|
||||
GtkCssStyle *new_base;
|
||||
|
||||
new_base = gtk_css_node_update_style (node,
|
||||
GTK_CSS_ANIMATED_STYLE (style)->style,
|
||||
parent_changes);
|
||||
new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (style),
|
||||
new_base,
|
||||
timestamp);
|
||||
g_object_unref (new_base);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_values = gtk_css_node_update_style (node,
|
||||
style,
|
||||
parent_changes);
|
||||
}
|
||||
|
||||
gtk_css_node_set_style (node, new_values);
|
||||
g_object_unref (new_values);
|
||||
}
|
||||
else if ((change & GTK_CSS_CHANGE_ANIMATE) &&
|
||||
GTK_IS_CSS_ANIMATED_STYLE (style))
|
||||
{
|
||||
GtkCssStyle *new_values;
|
||||
|
||||
new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (style),
|
||||
GTK_CSS_ANIMATED_STYLE (style)->style,
|
||||
timestamp);
|
||||
gtk_css_node_set_style (node, new_values);
|
||||
g_object_unref (new_values);
|
||||
}
|
||||
}
|
||||
|
||||
changes = gtk_css_style_get_difference (gtk_css_node_get_style (node), style);
|
||||
|
||||
g_object_unref (style);
|
||||
|
||||
gtk_style_context_validate (context, changes);
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
static GtkWidgetPath *
|
||||
|
@ -130,13 +130,6 @@
|
||||
* %GTK_STYLE_PROVIDER_PRIORITY_USER priority.
|
||||
*/
|
||||
|
||||
/* When these change we do a full restyling. Otherwise we try to figure out
|
||||
* if we need to change things. */
|
||||
#define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
|
||||
/* When these change we don’t clear the cache. This takes more memory but makes
|
||||
* things go faster. */
|
||||
#define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
|
||||
|
||||
typedef struct PropertyValue PropertyValue;
|
||||
|
||||
struct PropertyValue
|
||||
@ -2589,24 +2582,7 @@ gtk_style_context_do_invalidate (GtkStyleContext *context,
|
||||
priv->invalidating_context = NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_style_context_style_needs_full_revalidate (GtkCssStyle *style,
|
||||
GtkCssChange change)
|
||||
{
|
||||
/* Try to avoid invalidating if we can */
|
||||
if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
|
||||
return TRUE;
|
||||
|
||||
if (GTK_IS_CSS_ANIMATED_STYLE (style))
|
||||
style = GTK_CSS_ANIMATED_STYLE (style)->style;
|
||||
|
||||
if (gtk_css_static_style_get_change (GTK_CSS_STATIC_STYLE (style)) & change)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gboolean
|
||||
gtk_style_context_should_create_transitions (GtkStyleContext *context,
|
||||
GtkCssStyle *previous_style)
|
||||
{
|
||||
@ -2636,95 +2612,16 @@ gtk_style_context_should_create_transitions (GtkStyleContext *context,
|
||||
return animate;
|
||||
}
|
||||
|
||||
GtkBitmask *
|
||||
_gtk_style_context_validate (GtkStyleContext *context,
|
||||
GtkCssNode *cssnode,
|
||||
gint64 timestamp,
|
||||
GtkCssChange change,
|
||||
const GtkBitmask *parent_changes)
|
||||
void
|
||||
gtk_style_context_validate (GtkStyleContext *context,
|
||||
const GtkBitmask *changes)
|
||||
{
|
||||
GtkStyleContextPrivate *priv;
|
||||
GtkCssStyle *current;
|
||||
GtkBitmask *changes;
|
||||
|
||||
priv = context->priv;
|
||||
|
||||
current = gtk_css_node_get_style (cssnode);
|
||||
if (current == NULL)
|
||||
current = gtk_css_static_style_get_default ();
|
||||
g_object_ref (current);
|
||||
|
||||
/* Try to avoid invalidating if we can */
|
||||
if (gtk_style_context_style_needs_full_revalidate (current, change))
|
||||
{
|
||||
GtkCssStyle *style, *static_style;
|
||||
|
||||
static_style = gtk_css_node_create_style (cssnode);
|
||||
style = gtk_css_animated_style_new (static_style,
|
||||
priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL,
|
||||
timestamp,
|
||||
gtk_css_node_get_style_provider (cssnode),
|
||||
gtk_style_context_should_create_transitions (context, current) ? current : NULL);
|
||||
|
||||
gtk_style_context_clear_cache (context);
|
||||
|
||||
gtk_css_node_set_style (cssnode, style);
|
||||
|
||||
g_object_unref (static_style);
|
||||
g_object_unref (style);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_gtk_bitmask_is_empty (parent_changes))
|
||||
{
|
||||
GtkCssStyle *new_values;
|
||||
|
||||
if (GTK_IS_CSS_ANIMATED_STYLE (current))
|
||||
{
|
||||
GtkCssStyle *new_base;
|
||||
|
||||
new_base = gtk_css_node_update_style (cssnode,
|
||||
GTK_CSS_ANIMATED_STYLE (current)->style,
|
||||
parent_changes);
|
||||
new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (current),
|
||||
new_base,
|
||||
timestamp);
|
||||
g_object_unref (new_base);
|
||||
}
|
||||
else
|
||||
{
|
||||
new_values = gtk_css_node_update_style (cssnode,
|
||||
current,
|
||||
parent_changes);
|
||||
}
|
||||
|
||||
gtk_css_node_set_style (cssnode, new_values);
|
||||
g_object_unref (new_values);
|
||||
}
|
||||
else if (change & GTK_CSS_CHANGE_ANIMATE &&
|
||||
gtk_style_context_is_animating (context))
|
||||
{
|
||||
GtkCssStyle *new_values;
|
||||
|
||||
new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (current),
|
||||
GTK_CSS_ANIMATED_STYLE (current)->style,
|
||||
timestamp);
|
||||
gtk_css_node_set_style (cssnode, new_values);
|
||||
g_object_unref (new_values);
|
||||
}
|
||||
}
|
||||
|
||||
_gtk_style_context_update_animating (context);
|
||||
|
||||
changes = gtk_css_style_get_difference (gtk_css_node_get_style (cssnode), current);
|
||||
g_object_unref (current);
|
||||
|
||||
if (!_gtk_bitmask_is_empty (changes))
|
||||
gtk_style_context_do_invalidate (context, changes);
|
||||
|
||||
gtk_style_context_clear_property_cache (context);
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,11 +46,10 @@ GtkCssValue * _gtk_style_context_peek_property (GtkStyleContext *c
|
||||
const GValue * _gtk_style_context_peek_style_property (GtkStyleContext *context,
|
||||
GType widget_type,
|
||||
GParamSpec *pspec);
|
||||
GtkBitmask * _gtk_style_context_validate (GtkStyleContext *context,
|
||||
GtkCssNode *cssnode,
|
||||
gint64 timestamp,
|
||||
GtkCssChange change,
|
||||
const GtkBitmask*parent_changes);
|
||||
gboolean gtk_style_context_should_create_transitions (GtkStyleContext *context,
|
||||
GtkCssStyle *previous_style);
|
||||
void gtk_style_context_validate (GtkStyleContext *context,
|
||||
const GtkBitmask*changes);
|
||||
gboolean _gtk_style_context_check_region_name (const gchar *str);
|
||||
|
||||
gboolean _gtk_style_context_resolve_color (GtkStyleContext *context,
|
||||
|
Loading…
Reference in New Issue
Block a user