mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 22:20:24 +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);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
gtk_css_node_set_invalid (GtkCssNode *node,
|
||||
gboolean invalid)
|
||||
{
|
||||
@ -295,13 +295,9 @@ gtk_css_node_real_dequeue_validate (GtkCssNode *node)
|
||||
{
|
||||
}
|
||||
|
||||
static GtkCssStyle *
|
||||
gtk_css_node_real_validate (GtkCssNode *cssnode,
|
||||
GtkCssStyle *current_style,
|
||||
gint64 timestamp,
|
||||
GtkCssChange change)
|
||||
static void
|
||||
gtk_css_node_real_validate (GtkCssNode *node)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -876,8 +872,6 @@ gtk_css_node_validate_internal (GtkCssNode *cssnode,
|
||||
gint64 timestamp)
|
||||
{
|
||||
GtkCssNode *child;
|
||||
GtkCssStyle *new_style;
|
||||
gboolean changed;
|
||||
|
||||
/* If you run your application with
|
||||
* 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))
|
||||
cssnode->pending_changes |= GTK_CSS_CHANGE_ANY;
|
||||
|
||||
if (!cssnode->invalid && cssnode->pending_changes == 0)
|
||||
if (!cssnode->invalid)
|
||||
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);
|
||||
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;
|
||||
|
||||
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;
|
||||
GTK_CSS_NODE_GET_CLASS (cssnode)->validate (cssnode);
|
||||
|
||||
for (child = gtk_css_node_get_first_child (cssnode);
|
||||
child;
|
||||
|
@ -79,10 +79,7 @@ struct _GtkCssNodeClass
|
||||
void (* invalidate) (GtkCssNode *node);
|
||||
void (* queue_validate) (GtkCssNode *node);
|
||||
void (* dequeue_validate) (GtkCssNode *node);
|
||||
GtkCssStyle * (* validate) (GtkCssNode *cssnode,
|
||||
GtkCssStyle *current_style,
|
||||
gint64 timestamp,
|
||||
GtkCssChange change);
|
||||
void (* validate) (GtkCssNode *node);
|
||||
};
|
||||
|
||||
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,
|
||||
GtkCssChange change);
|
||||
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,
|
||||
GtkCssMatcher *matcher);
|
||||
|
@ -103,111 +103,20 @@ gtk_css_widget_node_dequeue_validate (GtkCssNode *node)
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static gboolean
|
||||
should_create_transitions (GtkCssChange change)
|
||||
{
|
||||
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)
|
||||
static void
|
||||
gtk_css_widget_node_validate (GtkCssNode *node)
|
||||
{
|
||||
GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
|
||||
GtkStyleContext *context;
|
||||
GtkBitmask *changes;
|
||||
GtkCssStyle *static_style, *new_style, *new_static_style;
|
||||
|
||||
if (widget_node->widget == NULL)
|
||||
return FALSE;
|
||||
return;
|
||||
|
||||
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_bitmask_free (widget_node->accumulated_changes);
|
||||
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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user