From b2b89f6c5765bc3731b83b4951b4603a70689437 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 12 Jan 2020 22:44:58 -0500 Subject: [PATCH] css: Add gtk_css_style_get_static_style This lets us avoid poking directly at the GtkCssAnimatedStyle struct in gtkcssnode.c. --- gtk/gtkcssanimatedstyle.c | 10 ++++++++++ gtk/gtkcssnode.c | 11 ++--------- gtk/gtkcssstyle.c | 15 +++++++++++++++ gtk/gtkcssstyleprivate.h | 3 +++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c index 4aa82c0fe9..56a5e7b476 100644 --- a/gtk/gtkcssanimatedstyle.c +++ b/gtk/gtkcssanimatedstyle.c @@ -79,6 +79,15 @@ gtk_css_animated_style_is_static (GtkCssStyle *style) return TRUE; } +static GtkCssStyle * +gtk_css_animated_style_get_static_style (GtkCssStyle *style) +{ + /* This is called a lot, so we avoid a dynamic type check here */ + GtkCssAnimatedStyle *animated = (GtkCssAnimatedStyle *) style; + + return animated->style; +} + static void gtk_css_animated_style_dispose (GObject *object) { @@ -123,6 +132,7 @@ gtk_css_animated_style_class_init (GtkCssAnimatedStyleClass *klass) style_class->get_value = gtk_css_animated_style_get_value; style_class->get_section = gtk_css_animated_style_get_section; style_class->is_static = gtk_css_animated_style_is_static; + style_class->get_static_style = gtk_css_animated_style_get_static_style; } static void diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c index 7af6c7ab93..3dfb8e5a83 100644 --- a/gtk/gtkcssnode.c +++ b/gtk/gtkcssnode.c @@ -407,14 +407,7 @@ gtk_css_node_real_update_style (GtkCssNode *cssnode, { GtkCssStyle *static_style, *new_static_style, *new_style; - if (GTK_IS_CSS_ANIMATED_STYLE (style)) - { - static_style = GTK_CSS_ANIMATED_STYLE (style)->style; - } - else - { - static_style = style; - } + static_style = gtk_css_style_get_static_style (style); if (gtk_css_style_needs_recreation (static_style, change)) new_static_style = gtk_css_node_create_style (cssnode); @@ -436,7 +429,7 @@ gtk_css_node_real_update_style (GtkCssNode *cssnode, } else if (static_style != style && (change & GTK_CSS_CHANGE_TIMESTAMP)) { - new_style = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (style), + new_style = gtk_css_animated_style_new_advance ((GtkCssAnimatedStyle *)style, static_style, timestamp); } diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c index 835a2b4213..53561657cb 100644 --- a/gtk/gtkcssstyle.c +++ b/gtk/gtkcssstyle.c @@ -53,11 +53,18 @@ gtk_css_style_real_is_static (GtkCssStyle *style) return TRUE; } +static GtkCssStyle * +gtk_css_style_real_get_static_style (GtkCssStyle *style) +{ + return style; +} + static void gtk_css_style_class_init (GtkCssStyleClass *klass) { klass->get_section = gtk_css_style_real_get_section; klass->is_static = gtk_css_style_real_is_static; + klass->get_static_style = gtk_css_style_real_get_static_style; } static void @@ -89,6 +96,14 @@ gtk_css_style_is_static (GtkCssStyle *style) return GTK_CSS_STYLE_GET_CLASS (style)->is_static (style); } +GtkCssStyle * +gtk_css_style_get_static_style (GtkCssStyle *style) +{ + gtk_internal_return_val_if_fail (GTK_IS_CSS_STYLE (style), NULL); + + return GTK_CSS_STYLE_GET_CLASS (style)->get_static_style (style); +} + /* * gtk_css_style_print: * @style: a #GtkCssStyle diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h index c0add354ad..6c4fcd035b 100644 --- a/gtk/gtkcssstyleprivate.h +++ b/gtk/gtkcssstyleprivate.h @@ -56,6 +56,8 @@ struct _GtkCssStyleClass guint id); /* TRUE if this style will require changes based on timestamp */ gboolean (* is_static) (GtkCssStyle *style); + + GtkCssStyle * (* get_static_style) (GtkCssStyle *style); }; GType gtk_css_style_get_type (void) G_GNUC_CONST; @@ -74,6 +76,7 @@ gboolean gtk_css_style_print (GtkCssStyle PangoAttrList * gtk_css_style_get_pango_attributes (GtkCssStyle *style); PangoFontDescription * gtk_css_style_get_pango_font (GtkCssStyle *style); +GtkCssStyle * gtk_css_style_get_static_style (GtkCssStyle *style); G_END_DECLS