Commit 27285f1f authored by Benjamin Otte's avatar Benjamin Otte

cssstyle: Have a default style

This way we can initialize the default style info with a style and
ddon't need to special case NULL everywhere.
parent ef9aa8b0
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "gtkcssstylepropertyprivate.h" #include "gtkcssstylepropertyprivate.h"
#include "gtkcsstransitionprivate.h" #include "gtkcsstransitionprivate.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtksettings.h"
#include "gtkstyleanimationprivate.h" #include "gtkstyleanimationprivate.h"
#include "gtkstylepropertyprivate.h" #include "gtkstylepropertyprivate.h"
#include "gtkstyleproviderprivate.h" #include "gtkstyleproviderprivate.h"
...@@ -180,6 +181,33 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *style, ...@@ -180,6 +181,33 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *style,
} }
} }
GtkCssStyle *
gtk_css_static_style_get_default (GdkScreen *screen)
{
static GQuark style_quark = 0;
GtkSettings *settings;
GtkCssStyle *result;
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
if (style_quark == 0)
style_quark = g_quark_from_string ("gtk-default-style");
settings = gtk_settings_get_for_screen (screen);
result = g_object_get_qdata (G_OBJECT (settings), style_quark);
if (result)
return result;
result = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (settings),
NULL,
gdk_screen_get_monitor_scale_factor (screen,
gdk_screen_get_primary_monitor (screen)),
NULL);
g_object_set_qdata_full (G_OBJECT (settings), style_quark, result, g_object_unref);
return result;
}
GtkCssStyle * GtkCssStyle *
gtk_css_static_style_new_compute (GtkStyleProviderPrivate *provider, gtk_css_static_style_new_compute (GtkStyleProviderPrivate *provider,
const GtkCssMatcher *matcher, const GtkCssMatcher *matcher,
......
...@@ -57,6 +57,7 @@ struct _GtkCssStaticStyleClass ...@@ -57,6 +57,7 @@ struct _GtkCssStaticStyleClass
GType gtk_css_static_style_get_type (void) G_GNUC_CONST; GType gtk_css_static_style_get_type (void) G_GNUC_CONST;
GtkCssStyle * gtk_css_static_style_get_default (GdkScreen *screen);
GtkCssStyle * gtk_css_static_style_new_compute (GtkStyleProviderPrivate *provider, GtkCssStyle * gtk_css_static_style_new_compute (GtkStyleProviderPrivate *provider,
const GtkCssMatcher *matcher, const GtkCssMatcher *matcher,
int scale, int scale,
......
...@@ -419,6 +419,7 @@ gtk_style_context_init (GtkStyleContext *style_context) ...@@ -419,6 +419,7 @@ gtk_style_context_init (GtkStyleContext *style_context)
/* Create default info store */ /* Create default info store */
priv->info = style_info_new (); priv->info = style_info_new ();
gtk_css_node_declaration_set_state (&priv->info->decl, GTK_STATE_FLAG_DIR_LTR); gtk_css_node_declaration_set_state (&priv->info->decl, GTK_STATE_FLAG_DIR_LTR);
priv->info->values = g_object_ref (gtk_css_static_style_get_default (priv->screen));
priv->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue)); priv->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
...@@ -779,26 +780,19 @@ style_values_lookup (GtkStyleContext *context) ...@@ -779,26 +780,19 @@ style_values_lookup (GtkStyleContext *context)
return info->values; return info->values;
g_assert (priv->widget != NULL || priv->widget_path != NULL); g_assert (priv->widget != NULL || priv->widget_path != NULL);
g_assert (gtk_style_context_is_saved (context));
if (gtk_style_context_is_saved (context)) values = g_hash_table_lookup (priv->style_values, info->decl);
{ if (values)
values = g_hash_table_lookup (priv->style_values, info->decl);
if (values)
{
style_info_set_values (info, values);
return values;
}
values = build_properties (context, info->decl, style_info_get_parent_style (context, info));
g_hash_table_insert (priv->style_values,
gtk_css_node_declaration_ref (info->decl),
g_object_ref (values));
}
else
{ {
values = build_properties (context, info->decl, style_info_get_parent_style (context, info)); style_info_set_values (info, values);
return values;
} }
values = build_properties (context, info->decl, style_info_get_parent_style (context, info));
g_hash_table_insert (priv->style_values,
gtk_css_node_declaration_ref (info->decl),
g_object_ref (values));
style_info_set_values (info, values); style_info_set_values (info, values);
g_object_unref (values); g_object_unref (values);
...@@ -2840,31 +2834,26 @@ _gtk_style_context_validate (GtkStyleContext *context, ...@@ -2840,31 +2834,26 @@ _gtk_style_context_validate (GtkStyleContext *context,
gtk_style_context_set_invalid (context, FALSE); gtk_style_context_set_invalid (context, FALSE);
info = priv->info; info = priv->info;
if (info->values) current = g_object_ref (info->values);
current = g_object_ref (info->values);
else
current = NULL;
/* Try to avoid invalidating if we can */ /* Try to avoid invalidating if we can */
if (current == NULL || if (gtk_style_context_style_needs_full_revalidate (current, change))
gtk_style_context_style_needs_full_revalidate (current, change))
{ {
GtkCssStyle *values; GtkCssStyle *style, *static_style;
style_info_set_values (info, NULL);
values = style_values_lookup (context);
values = gtk_css_animated_style_new (values, static_style = build_properties (context, info->decl, style_info_get_parent_style (context, info));
priv->parent ? style_values_lookup (priv->parent) : NULL, style = gtk_css_animated_style_new (static_style,
timestamp, priv->parent ? style_values_lookup (priv->parent) : NULL,
GTK_STYLE_PROVIDER_PRIVATE (priv->cascade), timestamp,
priv->scale, GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
gtk_style_context_should_create_transitions (context) ? current : NULL); priv->scale,
gtk_style_context_should_create_transitions (context) ? current : NULL);
style_info_set_values (info, values); style_info_set_values (info, style);
_gtk_style_context_update_animating (context); _gtk_style_context_update_animating (context);
g_object_unref (values); g_object_unref (static_style);
g_object_unref (style);
} }
else else
{ {
...@@ -2915,16 +2904,8 @@ _gtk_style_context_validate (GtkStyleContext *context, ...@@ -2915,16 +2904,8 @@ _gtk_style_context_validate (GtkStyleContext *context,
} }
} }
if (current) changes = gtk_css_style_get_difference (info->values, current);
{ g_object_unref (current);
changes = gtk_css_style_get_difference (info->values, current);
g_object_unref (current);
}
else
{
changes = _gtk_bitmask_new ();
changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
}
if (!_gtk_bitmask_is_empty (changes)) if (!_gtk_bitmask_is_empty (changes))
gtk_style_context_do_invalidate (context, changes); gtk_style_context_do_invalidate (context, changes);
...@@ -2981,12 +2962,18 @@ void ...@@ -2981,12 +2962,18 @@ void
gtk_style_context_invalidate (GtkStyleContext *context) gtk_style_context_invalidate (GtkStyleContext *context)
{ {
GtkBitmask *changes; GtkBitmask *changes;
GtkCssStyle *style;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
gtk_style_context_clear_cache (context); gtk_style_context_clear_cache (context);
style_info_set_values (context->priv->info, NULL); /* insta-recalculate the new style here */
style = build_properties (context,
context->priv->info->decl,
style_info_get_parent_style (context, context->priv->info));
style_info_set_values (context->priv->info, style);
g_object_unref (style);
changes = _gtk_bitmask_new (); changes = _gtk_bitmask_new ();
changes = _gtk_bitmask_invert_range (changes, changes = _gtk_bitmask_invert_range (changes,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment