[gtk+] cssstyle: Have a default style
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] cssstyle: Have a default style
- Date: Wed, 7 Jan 2015 13:57:28 +0000 (UTC)
commit 27285f1f0fb00bb4507a8bf3e426bef940ae41af
Author: Benjamin Otte <otte redhat com>
Date: Mon Jan 5 16:13:18 2015 +0100
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.
gtk/gtkcssstaticstyle.c | 28 ++++++++++++++
gtk/gtkcssstaticstyleprivate.h | 1 +
gtk/gtkstylecontext.c | 79 +++++++++++++++++-----------------------
3 files changed, 62 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index 1a1671c..446935a 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -33,6 +33,7 @@
#include "gtkcssstylepropertyprivate.h"
#include "gtkcsstransitionprivate.h"
#include "gtkprivate.h"
+#include "gtksettings.h"
#include "gtkstyleanimationprivate.h"
#include "gtkstylepropertyprivate.h"
#include "gtkstyleproviderprivate.h"
@@ -181,6 +182,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 *
gtk_css_static_style_new_compute (GtkStyleProviderPrivate *provider,
const GtkCssMatcher *matcher,
int scale,
diff --git a/gtk/gtkcssstaticstyleprivate.h b/gtk/gtkcssstaticstyleprivate.h
index e7b32d1..04b68d7 100644
--- a/gtk/gtkcssstaticstyleprivate.h
+++ b/gtk/gtkcssstaticstyleprivate.h
@@ -57,6 +57,7 @@ struct _GtkCssStaticStyleClass
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,
const GtkCssMatcher *matcher,
int scale,
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 15fe437..d7c4fd0 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -419,6 +419,7 @@ gtk_style_context_init (GtkStyleContext *style_context)
/* Create default info store */
priv->info = style_info_new ();
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));
@@ -779,26 +780,19 @@ style_values_lookup (GtkStyleContext *context)
return info->values;
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)
- {
- 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 = g_hash_table_lookup (priv->style_values, info->decl);
+ if (values)
{
- 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);
g_object_unref (values);
@@ -2840,31 +2834,26 @@ _gtk_style_context_validate (GtkStyleContext *context,
gtk_style_context_set_invalid (context, FALSE);
info = priv->info;
- if (info->values)
- current = g_object_ref (info->values);
- else
- current = NULL;
+ current = g_object_ref (info->values);
/* Try to avoid invalidating if we can */
- if (current == NULL ||
- gtk_style_context_style_needs_full_revalidate (current, change))
+ if (gtk_style_context_style_needs_full_revalidate (current, change))
{
- GtkCssStyle *values;
-
- style_info_set_values (info, NULL);
- values = style_values_lookup (context);
+ GtkCssStyle *style, *static_style;
- values = gtk_css_animated_style_new (values,
- priv->parent ? style_values_lookup (priv->parent) : NULL,
- timestamp,
- GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
- priv->scale,
- gtk_style_context_should_create_transitions (context) ? current :
NULL);
+ static_style = build_properties (context, info->decl, style_info_get_parent_style (context, info));
+ style = gtk_css_animated_style_new (static_style,
+ priv->parent ? style_values_lookup (priv->parent) : NULL,
+ timestamp,
+ GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+ 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);
- g_object_unref (values);
+ g_object_unref (static_style);
+ g_object_unref (style);
}
else
{
@@ -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);
- }
- else
- {
- changes = _gtk_bitmask_new ();
- changes = _gtk_bitmask_invert_range (changes, 0, _gtk_css_style_property_get_n_properties ());
- }
+ changes = gtk_css_style_get_difference (info->values, current);
+ g_object_unref (current);
if (!_gtk_bitmask_is_empty (changes))
gtk_style_context_do_invalidate (context, changes);
@@ -2981,12 +2962,18 @@ void
gtk_style_context_invalidate (GtkStyleContext *context)
{
GtkBitmask *changes;
+ GtkCssStyle *style;
g_return_if_fail (GTK_IS_STYLE_CONTEXT (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_invert_range (changes,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]