mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-15 14:50:06 +00:00
cssnode: Merge the 2 places that compute styles
Now that the widget node recomputes styles on update_style() we can just call it during validate(). That way, we don't need the widget node to manually compute its style.
This commit is contained in:
parent
df51bc836b
commit
092ff983f7
@ -35,7 +35,7 @@ gtk_css_node_get_style_provider_or_null (GtkCssNode *cssnode)
|
|||||||
return GTK_CSS_NODE_GET_CLASS (cssnode)->get_style_provider (cssnode);
|
return GTK_CSS_NODE_GET_CLASS (cssnode)->get_style_provider (cssnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gtk_css_node_set_invalid (GtkCssNode *node,
|
gtk_css_node_set_invalid (GtkCssNode *node,
|
||||||
gboolean invalid)
|
gboolean invalid)
|
||||||
{
|
{
|
||||||
@ -295,13 +295,9 @@ gtk_css_node_real_dequeue_validate (GtkCssNode *node)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkCssStyle *
|
static void
|
||||||
gtk_css_node_real_validate (GtkCssNode *cssnode,
|
gtk_css_node_real_validate (GtkCssNode *node)
|
||||||
GtkCssStyle *current_style,
|
|
||||||
gint64 timestamp,
|
|
||||||
GtkCssChange change)
|
|
||||||
{
|
{
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -876,8 +872,6 @@ gtk_css_node_validate_internal (GtkCssNode *cssnode,
|
|||||||
gint64 timestamp)
|
gint64 timestamp)
|
||||||
{
|
{
|
||||||
GtkCssNode *child;
|
GtkCssNode *child;
|
||||||
GtkCssStyle *new_style;
|
|
||||||
gboolean changed;
|
|
||||||
|
|
||||||
/* If you run your application with
|
/* If you run your application with
|
||||||
* GTK_DEBUG=no-css-cache
|
* GTK_DEBUG=no-css-cache
|
||||||
@ -894,27 +888,18 @@ gtk_css_node_validate_internal (GtkCssNode *cssnode,
|
|||||||
if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
|
if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
|
||||||
cssnode->pending_changes |= GTK_CSS_CHANGE_ANY;
|
cssnode->pending_changes |= GTK_CSS_CHANGE_ANY;
|
||||||
|
|
||||||
if (!cssnode->invalid && cssnode->pending_changes == 0)
|
if (!cssnode->invalid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
gtk_css_node_ensure_style (cssnode, timestamp);
|
||||||
|
|
||||||
|
/* need to set to FALSE then to TRUE here to make it chain up */
|
||||||
gtk_css_node_set_invalid (cssnode, FALSE);
|
gtk_css_node_set_invalid (cssnode, FALSE);
|
||||||
|
if (GTK_IS_CSS_ANIMATED_STYLE (cssnode->style) &&
|
||||||
|
!gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (cssnode->style)))
|
||||||
|
gtk_css_node_set_invalid (cssnode, TRUE);
|
||||||
|
|
||||||
cssnode->style_is_invalid = FALSE;
|
GTK_CSS_NODE_GET_CLASS (cssnode)->validate (cssnode);
|
||||||
|
|
||||||
new_style = GTK_CSS_NODE_GET_CLASS (cssnode)->validate (cssnode, cssnode->style, timestamp, cssnode->pending_changes);
|
|
||||||
if (new_style)
|
|
||||||
{
|
|
||||||
gtk_css_node_set_style (cssnode, new_style);
|
|
||||||
g_object_unref (new_style);
|
|
||||||
changed = TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
changed = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_css_node_propagate_pending_changes (cssnode, changed);
|
|
||||||
cssnode->pending_changes = 0;
|
|
||||||
|
|
||||||
for (child = gtk_css_node_get_first_child (cssnode);
|
for (child = gtk_css_node_get_first_child (cssnode);
|
||||||
child;
|
child;
|
||||||
|
@ -79,10 +79,7 @@ struct _GtkCssNodeClass
|
|||||||
void (* invalidate) (GtkCssNode *node);
|
void (* invalidate) (GtkCssNode *node);
|
||||||
void (* queue_validate) (GtkCssNode *node);
|
void (* queue_validate) (GtkCssNode *node);
|
||||||
void (* dequeue_validate) (GtkCssNode *node);
|
void (* dequeue_validate) (GtkCssNode *node);
|
||||||
GtkCssStyle * (* validate) (GtkCssNode *cssnode,
|
void (* validate) (GtkCssNode *node);
|
||||||
GtkCssStyle *current_style,
|
|
||||||
gint64 timestamp,
|
|
||||||
GtkCssChange change);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gtk_css_node_get_type (void) G_GNUC_CONST;
|
GType gtk_css_node_get_type (void) G_GNUC_CONST;
|
||||||
@ -147,8 +144,6 @@ void gtk_css_node_invalidate_frame_clock
|
|||||||
void gtk_css_node_invalidate (GtkCssNode *cssnode,
|
void gtk_css_node_invalidate (GtkCssNode *cssnode,
|
||||||
GtkCssChange change);
|
GtkCssChange change);
|
||||||
void gtk_css_node_validate (GtkCssNode *cssnode);
|
void gtk_css_node_validate (GtkCssNode *cssnode);
|
||||||
void gtk_css_node_set_invalid (GtkCssNode *node,
|
|
||||||
gboolean invalid);
|
|
||||||
|
|
||||||
gboolean gtk_css_node_init_matcher (GtkCssNode *cssnode,
|
gboolean gtk_css_node_init_matcher (GtkCssNode *cssnode,
|
||||||
GtkCssMatcher *matcher);
|
GtkCssMatcher *matcher);
|
||||||
|
@ -103,111 +103,20 @@ gtk_css_widget_node_dequeue_validate (GtkCssNode *node)
|
|||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
should_create_transitions (GtkCssChange change)
|
gtk_css_widget_node_validate (GtkCssNode *node)
|
||||||
{
|
|
||||||
return (change & GTK_CSS_CHANGE_ANIMATIONS) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gtk_css_static_style_needs_revalidate (GtkCssStaticStyle *style,
|
|
||||||
GtkCssChange change)
|
|
||||||
{
|
|
||||||
/* Try to avoid invalidating if we can */
|
|
||||||
if (change & GTK_CSS_RADICAL_CHANGE)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if (gtk_css_static_style_get_change (style) & change)
|
|
||||||
return TRUE;
|
|
||||||
else
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkCssStyle *
|
|
||||||
validate_static_style (GtkCssNode *node,
|
|
||||||
GtkCssStyle *style,
|
|
||||||
GtkCssChange change)
|
|
||||||
{
|
|
||||||
if (gtk_css_static_style_needs_revalidate (GTK_CSS_STATIC_STYLE (style), change))
|
|
||||||
{
|
|
||||||
return gtk_css_node_create_style (node);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return g_object_ref (style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkCssStyle *
|
|
||||||
gtk_css_widget_node_validate (GtkCssNode *node,
|
|
||||||
GtkCssStyle *style,
|
|
||||||
gint64 timestamp,
|
|
||||||
GtkCssChange change)
|
|
||||||
{
|
{
|
||||||
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GtkBitmask *changes;
|
|
||||||
GtkCssStyle *static_style, *new_style, *new_static_style;
|
|
||||||
|
|
||||||
if (widget_node->widget == NULL)
|
if (widget_node->widget == NULL)
|
||||||
return FALSE;
|
return;
|
||||||
|
|
||||||
context = gtk_widget_get_style_context (widget_node->widget);
|
context = gtk_widget_get_style_context (widget_node->widget);
|
||||||
if (style == NULL)
|
|
||||||
style = gtk_css_static_style_get_default ();
|
|
||||||
|
|
||||||
if (GTK_IS_CSS_ANIMATED_STYLE (style))
|
|
||||||
{
|
|
||||||
static_style = GTK_CSS_ANIMATED_STYLE (style)->style;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
static_style = style;
|
|
||||||
}
|
|
||||||
|
|
||||||
new_static_style = validate_static_style (node, static_style, change);
|
|
||||||
|
|
||||||
if (new_static_style != static_style || (change & GTK_CSS_CHANGE_ANIMATIONS))
|
|
||||||
{
|
|
||||||
GtkCssNode *parent = gtk_css_node_get_parent (node);
|
|
||||||
new_style = gtk_css_animated_style_new (new_static_style,
|
|
||||||
parent ? gtk_css_node_get_style (parent) : NULL,
|
|
||||||
timestamp,
|
|
||||||
gtk_css_node_get_style_provider (node),
|
|
||||||
should_create_transitions (change) ? style : NULL);
|
|
||||||
|
|
||||||
g_object_unref (new_static_style);
|
|
||||||
}
|
|
||||||
else if (GTK_IS_CSS_ANIMATED_STYLE (style) && (change & GTK_CSS_CHANGE_TIMESTAMP))
|
|
||||||
{
|
|
||||||
new_style = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (style),
|
|
||||||
static_style,
|
|
||||||
timestamp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
new_style = g_object_ref (style);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GTK_IS_CSS_ANIMATED_STYLE (new_style) &&
|
|
||||||
!gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (new_style)))
|
|
||||||
gtk_css_node_set_invalid (node, TRUE);
|
|
||||||
|
|
||||||
changes = gtk_css_style_get_difference (new_style, style);
|
|
||||||
widget_node->accumulated_changes = _gtk_bitmask_union (widget_node->accumulated_changes, changes);
|
|
||||||
_gtk_bitmask_free (changes);
|
|
||||||
|
|
||||||
gtk_style_context_validate (context, widget_node->accumulated_changes);
|
gtk_style_context_validate (context, widget_node->accumulated_changes);
|
||||||
_gtk_bitmask_free (widget_node->accumulated_changes);
|
_gtk_bitmask_free (widget_node->accumulated_changes);
|
||||||
widget_node->accumulated_changes = _gtk_bitmask_new ();
|
widget_node->accumulated_changes = _gtk_bitmask_new ();
|
||||||
|
|
||||||
if (_gtk_bitmask_is_empty (changes) && !GTK_IS_CSS_ANIMATED_STYLE (new_style))
|
|
||||||
{
|
|
||||||
g_object_unref (new_style);
|
|
||||||
new_style = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new_style;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef GtkWidgetPath * (* GetPathForChildFunc) (GtkContainer *, GtkWidget *);
|
typedef GtkWidgetPath * (* GetPathForChildFunc) (GtkContainer *, GtkWidget *);
|
||||||
|
Loading…
Reference in New Issue
Block a user