summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
Diffstat (limited to 'gtk')
-rw-r--r--gtk/Makefile.am2
-rw-r--r--gtk/gtkcssanimatedstyle.c113
-rw-r--r--gtk/gtkcssanimatedstyleprivate.h8
-rw-r--r--gtk/gtkcssstaticstyle.c225
-rw-r--r--gtk/gtkcssstaticstyleprivate.h69
5 files changed, 307 insertions, 110 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 0573e3e378..4052bb7d01 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -406,6 +406,7 @@ gtk_private_h_sources = \
gtkcssshadowsvalueprivate.h \
gtkcssshadowvalueprivate.h \
gtkcssshorthandpropertyprivate.h \
+ gtkcssstaticstyleprivate.h \
gtkcssstringvalueprivate.h \
gtkcssstylefuncsprivate.h \
gtkcssstyleprivate.h \
@@ -634,6 +635,7 @@ gtk_base_c_sources = \
gtkcssshadowvalue.c \
gtkcssshorthandproperty.c \
gtkcssshorthandpropertyimpl.c \
+ gtkcssstaticstyle.c \
gtkcssstylefuncs.c \
gtkcssstyleproperty.c \
gtkcssstylepropertyimpl.c \
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 4ced8d1e5d..1d20c146d4 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -29,6 +29,7 @@
#include "gtkcssnumbervalueprivate.h"
#include "gtkcsssectionprivate.h"
#include "gtkcssshorthandpropertyprivate.h"
+#include "gtkcssstaticstyleprivate.h"
#include "gtkcssstringvalueprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtkcsstransitionprivate.h"
@@ -59,11 +60,7 @@ gtk_css_animated_style_get_section (GtkCssStyle *style,
{
GtkCssAnimatedStyle *animated = GTK_CSS_ANIMATED_STYLE (style);
- if (animated->sections == NULL ||
- id >= animated->sections->len)
- return NULL;
-
- return g_ptr_array_index (animated->sections, id);
+ return gtk_css_style_get_section (animated->style, id);
}
static GtkBitmask *
@@ -71,16 +68,9 @@ gtk_css_animated_style_compute_dependencies (GtkCssStyle *style,
const GtkBitmask *parent_changes)
{
GtkCssAnimatedStyle *animated = GTK_CSS_ANIMATED_STYLE (style);
- GtkBitmask *changes;
-
- changes = _gtk_bitmask_copy (parent_changes);
- changes = _gtk_bitmask_intersect (changes, animated->depends_on_parent);
- if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_COLOR))
- changes = _gtk_bitmask_union (changes, animated->depends_on_color);
- if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_FONT_SIZE))
- changes = _gtk_bitmask_union (changes, animated->depends_on_font_size);
- return changes;
+ /* XXX: This misses dependencies due to animations */
+ return gtk_css_style_compute_dependencies (animated->style, parent_changes);
}
static void
@@ -88,16 +78,6 @@ gtk_css_animated_style_dispose (GObject *object)
{
GtkCssAnimatedStyle *style = GTK_CSS_ANIMATED_STYLE (object);
- if (style->values)
- {
- g_ptr_array_unref (style->values);
- style->values = NULL;
- }
- if (style->sections)
- {
- g_ptr_array_unref (style->sections);
- style->sections = NULL;
- }
if (style->animated_values)
{
g_ptr_array_unref (style->animated_values);
@@ -115,10 +95,7 @@ gtk_css_animated_style_finalize (GObject *object)
{
GtkCssAnimatedStyle *style = GTK_CSS_ANIMATED_STYLE (object);
- _gtk_bitmask_free (style->depends_on_parent);
- _gtk_bitmask_free (style->equals_parent);
- _gtk_bitmask_free (style->depends_on_color);
- _gtk_bitmask_free (style->depends_on_font_size);
+ g_object_unref (style->style);
G_OBJECT_CLASS (gtk_css_animated_style_parent_class)->finalize (object);
}
@@ -140,10 +117,7 @@ gtk_css_animated_style_class_init (GtkCssAnimatedStyleClass *klass)
static void
gtk_css_animated_style_init (GtkCssAnimatedStyle *style)
{
- style->depends_on_parent = _gtk_bitmask_new ();
- style->equals_parent = _gtk_bitmask_new ();
- style->depends_on_color = _gtk_bitmask_new ();
- style->depends_on_font_size = _gtk_bitmask_new ();
+ style->style = gtk_css_static_style_new ();
}
GtkCssStyle *
@@ -152,13 +126,6 @@ gtk_css_animated_style_new (void)
return g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
}
-static void
-maybe_unref_section (gpointer section)
-{
- if (section)
- gtk_css_section_unref (section);
-}
-
void
gtk_css_animated_style_compute_value (GtkCssAnimatedStyle *style,
GtkStyleProviderPrivate *provider,
@@ -168,69 +135,13 @@ gtk_css_animated_style_compute_value (GtkCssAnimatedStyle *style,
GtkCssValue *specified,
GtkCssSection *section)
{
- GtkCssDependencies dependencies;
- GtkCssValue *value;
-
gtk_internal_return_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style));
gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
gtk_internal_return_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style));
- /* http://www.w3.org/TR/css3-cascade/#cascade
- * Then, for every element, the value for each property can be found
- * by following this pseudo-algorithm:
- * 1) Identify all declarations that apply to the element
- */
- if (specified == NULL)
- {
- GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id);
-
- if (_gtk_css_style_property_is_inherit (prop))
- specified = _gtk_css_inherit_value_new ();
- else
- specified = _gtk_css_initial_value_new ();
- }
- else
- _gtk_css_value_ref (specified);
-
- value = _gtk_css_value_compute (specified, id, provider, scale, GTK_CSS_STYLE (style), parent_style, &dependencies);
-
- if (style->values == NULL)
- style->values = g_ptr_array_new_full (_gtk_css_style_property_get_n_properties (),
- (GDestroyNotify)_gtk_css_value_unref);
- if (id >= style->values->len)
- g_ptr_array_set_size (style->values, id + 1);
-
- if (g_ptr_array_index (style->values, id))
- _gtk_css_value_unref (g_ptr_array_index (style->values, id));
- g_ptr_array_index (style->values, id) = _gtk_css_value_ref (value);
-
- if (dependencies & (GTK_CSS_DEPENDS_ON_PARENT | GTK_CSS_EQUALS_PARENT))
- style->depends_on_parent = _gtk_bitmask_set (style->depends_on_parent, id, TRUE);
- if (dependencies & (GTK_CSS_EQUALS_PARENT))
- style->equals_parent = _gtk_bitmask_set (style->equals_parent, id, TRUE);
- if (dependencies & (GTK_CSS_DEPENDS_ON_COLOR))
- style->depends_on_color = _gtk_bitmask_set (style->depends_on_color, id, TRUE);
- if (dependencies & (GTK_CSS_DEPENDS_ON_FONT_SIZE))
- style->depends_on_font_size = _gtk_bitmask_set (style->depends_on_font_size, id, TRUE);
-
- if (style->sections && style->sections->len > id && g_ptr_array_index (style->sections, id))
- {
- gtk_css_section_unref (g_ptr_array_index (style->sections, id));
- g_ptr_array_index (style->sections, id) = NULL;
- }
-
- if (section)
- {
- if (style->sections == NULL)
- style->sections = g_ptr_array_new_with_free_func (maybe_unref_section);
- if (style->sections->len <= id)
- g_ptr_array_set_size (style->sections, id + 1);
-
- g_ptr_array_index (style->sections, id) = gtk_css_section_ref (section);
- }
-
- _gtk_css_value_unref (value);
- _gtk_css_value_unref (specified);
+ gtk_css_static_style_compute_value (GTK_CSS_STATIC_STYLE (style->style),
+ provider, scale, parent_style,
+ id, specified, section);
}
void
@@ -258,11 +169,7 @@ gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style,
{
gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), NULL);
- if (style->values == NULL ||
- id >= style->values->len)
- return NULL;
-
- return g_ptr_array_index (style->values, id);
+ return gtk_css_style_get_value (style->style, id);
}
/* TRANSITIONS */
diff --git a/gtk/gtkcssanimatedstyleprivate.h b/gtk/gtkcssanimatedstyleprivate.h
index 07b094b2ea..141050f82d 100644
--- a/gtk/gtkcssanimatedstyleprivate.h
+++ b/gtk/gtkcssanimatedstyleprivate.h
@@ -38,17 +38,11 @@ struct _GtkCssAnimatedStyle
{
GtkCssStyle parent;
- GPtrArray *values; /* the unanimated (aka intrinsic) values */
- GPtrArray *sections; /* sections the values are defined in */
+ GtkCssStyle *style; /* the style if we weren't animating */
GPtrArray *animated_values; /* NULL or array of animated values/NULL if not animated */
gint64 current_time; /* the current time in our world */
GSList *animations; /* the running animations, least important one first */
-
- GtkBitmask *depends_on_parent; /* for intrinsic values */
- GtkBitmask *equals_parent; /* dito */
- GtkBitmask *depends_on_color; /* dito */
- GtkBitmask *depends_on_font_size; /* dito */
};
struct _GtkCssAnimatedStyleClass
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
new file mode 100644
index 0000000000..bcb37a025f
--- /dev/null
+++ b/gtk/gtkcssstaticstyle.c
@@ -0,0 +1,225 @@
+/*
+ * Copyright © 2012 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#include "config.h"
+
+#include "gtkcssstaticstyleprivate.h"
+
+#include "gtkcssanimationprivate.h"
+#include "gtkcssarrayvalueprivate.h"
+#include "gtkcssenumvalueprivate.h"
+#include "gtkcssinheritvalueprivate.h"
+#include "gtkcssinitialvalueprivate.h"
+#include "gtkcssnumbervalueprivate.h"
+#include "gtkcsssectionprivate.h"
+#include "gtkcssshorthandpropertyprivate.h"
+#include "gtkcssstringvalueprivate.h"
+#include "gtkcssstylepropertyprivate.h"
+#include "gtkcsstransitionprivate.h"
+#include "gtkprivate.h"
+#include "gtkstyleanimationprivate.h"
+#include "gtkstylepropertyprivate.h"
+#include "gtkstyleproviderprivate.h"
+
+G_DEFINE_TYPE (GtkCssStaticStyle, gtk_css_static_style, GTK_TYPE_CSS_STYLE)
+
+static GtkCssValue *
+gtk_css_static_style_get_value (GtkCssStyle *style,
+ guint id)
+{
+ GtkCssStaticStyle *sstyle = GTK_CSS_STATIC_STYLE (style);
+
+ if (sstyle->values == NULL ||
+ id >= sstyle->values->len)
+ return NULL;
+
+ return g_ptr_array_index (sstyle->values, id);
+}
+
+static GtkCssSection *
+gtk_css_static_style_get_section (GtkCssStyle *style,
+ guint id)
+{
+ GtkCssStaticStyle *sstyle = GTK_CSS_STATIC_STYLE (style);
+
+ if (sstyle->sections == NULL ||
+ id >= sstyle->sections->len)
+ return NULL;
+
+ return g_ptr_array_index (sstyle->sections, id);
+}
+
+static GtkBitmask *
+gtk_css_static_style_compute_dependencies (GtkCssStyle *style,
+ const GtkBitmask *parent_changes)
+{
+ GtkCssStaticStyle *sstyle = GTK_CSS_STATIC_STYLE (style);
+ GtkBitmask *changes;
+
+ changes = _gtk_bitmask_copy (parent_changes);
+ changes = _gtk_bitmask_intersect (changes, sstyle->depends_on_parent);
+ if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_COLOR))
+ changes = _gtk_bitmask_union (changes, sstyle->depends_on_color);
+ if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_FONT_SIZE))
+ changes = _gtk_bitmask_union (changes, sstyle->depends_on_font_size);
+
+ return changes;
+}
+
+static void
+gtk_css_static_style_dispose (GObject *object)
+{
+ GtkCssStaticStyle *style = GTK_CSS_STATIC_STYLE (object);
+
+ if (style->values)
+ {
+ g_ptr_array_unref (style->values);
+ style->values = NULL;
+ }
+ if (style->sections)
+ {
+ g_ptr_array_unref (style->sections);
+ style->sections = NULL;
+ }
+
+ G_OBJECT_CLASS (gtk_css_static_style_parent_class)->dispose (object);
+}
+
+static void
+gtk_css_static_style_finalize (GObject *object)
+{
+ GtkCssStaticStyle *style = GTK_CSS_STATIC_STYLE (object);
+
+ _gtk_bitmask_free (style->depends_on_parent);
+ _gtk_bitmask_free (style->equals_parent);
+ _gtk_bitmask_free (style->depends_on_color);
+ _gtk_bitmask_free (style->depends_on_font_size);
+
+ G_OBJECT_CLASS (gtk_css_static_style_parent_class)->finalize (object);
+}
+
+static void
+gtk_css_static_style_class_init (GtkCssStaticStyleClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkCssStyleClass *style_class = GTK_CSS_STYLE_CLASS (klass);
+
+ object_class->dispose = gtk_css_static_style_dispose;
+ object_class->finalize = gtk_css_static_style_finalize;
+
+ style_class->get_value = gtk_css_static_style_get_value;
+ style_class->get_section = gtk_css_static_style_get_section;
+ style_class->compute_dependencies = gtk_css_static_style_compute_dependencies;
+}
+
+static void
+gtk_css_static_style_init (GtkCssStaticStyle *style)
+{
+ style->depends_on_parent = _gtk_bitmask_new ();
+ style->equals_parent = _gtk_bitmask_new ();
+ style->depends_on_color = _gtk_bitmask_new ();
+ style->depends_on_font_size = _gtk_bitmask_new ();
+}
+
+GtkCssStyle *
+gtk_css_static_style_new (void)
+{
+ return g_object_new (GTK_TYPE_CSS_STATIC_STYLE, NULL);
+}
+
+static void
+maybe_unref_section (gpointer section)
+{
+ if (section)
+ gtk_css_section_unref (section);
+}
+
+void
+gtk_css_static_style_compute_value (GtkCssStaticStyle *style,
+ GtkStyleProviderPrivate *provider,
+ int scale,
+ GtkCssStyle *parent_style,
+ guint id,
+ GtkCssValue *specified,
+ GtkCssSection *section)
+{
+ GtkCssDependencies dependencies;
+ GtkCssValue *value;
+
+ gtk_internal_return_if_fail (GTK_IS_CSS_STATIC_STYLE (style));
+ gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
+ gtk_internal_return_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style));
+
+ /* http://www.w3.org/TR/css3-cascade/#cascade
+ * Then, for every element, the value for each property can be found
+ * by following this pseudo-algorithm:
+ * 1) Identify all declarations that apply to the element
+ */
+ if (specified == NULL)
+ {
+ GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id);
+
+ if (_gtk_css_style_property_is_inherit (prop))
+ specified = _gtk_css_inherit_value_new ();
+ else
+ specified = _gtk_css_initial_value_new ();
+ }
+ else
+ _gtk_css_value_ref (specified);
+
+ value = _gtk_css_value_compute (specified, id, provider, scale, GTK_CSS_STYLE (style), parent_style, &dependencies);
+
+ if (style->values == NULL)
+ style->values = g_ptr_array_new_with_free_func ((GDestroyNotify)_gtk_css_value_unref);
+ if (id >= style->values->len)
+ g_ptr_array_set_size (style->values, id + 1);
+
+ if (g_ptr_array_index (style->values, id))
+ _gtk_css_value_unref (g_ptr_array_index (style->values, id));
+ g_ptr_array_index (style->values, id) = _gtk_css_value_ref (value);
+
+ if (dependencies & (GTK_CSS_DEPENDS_ON_PARENT | GTK_CSS_EQUALS_PARENT))
+ style->depends_on_parent = _gtk_bitmask_set (style->depends_on_parent, id, TRUE);
+ if (dependencies & (GTK_CSS_EQUALS_PARENT))
+ style->equals_parent = _gtk_bitmask_set (style->equals_parent, id, TRUE);
+ if (dependencies & (GTK_CSS_DEPENDS_ON_COLOR))
+ style->depends_on_color = _gtk_bitmask_set (style->depends_on_color, id, TRUE);
+ if (dependencies & (GTK_CSS_DEPENDS_ON_FONT_SIZE))
+ style->depends_on_font_size = _gtk_bitmask_set (style->depends_on_font_size, id, TRUE);
+
+ if (style->sections && style->sections->len > id && g_ptr_array_index (style->sections, id))
+ {
+ gtk_css_section_unref (g_ptr_array_index (style->sections, id));
+ g_ptr_array_index (style->sections, id) = NULL;
+ }
+
+ if (section)
+ {
+ if (style->sections == NULL)
+ style->sections = g_ptr_array_new_with_free_func (maybe_unref_section);
+ if (style->sections->len <= id)
+ g_ptr_array_set_size (style->sections, id + 1);
+
+ g_ptr_array_index (style->sections, id) = gtk_css_section_ref (section);
+ }
+
+ _gtk_css_value_unref (value);
+ _gtk_css_value_unref (specified);
+}
+
diff --git a/gtk/gtkcssstaticstyleprivate.h b/gtk/gtkcssstaticstyleprivate.h
new file mode 100644
index 0000000000..390a9116f0
--- /dev/null
+++ b/gtk/gtkcssstaticstyleprivate.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2012 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#ifndef __GTK_CSS_STATIC_STYLE_PRIVATE_H__
+#define __GTK_CSS_STATIC_STYLE_PRIVATE_H__
+
+#include "gtk/gtkcssstyleprivate.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CSS_STATIC_STYLE (gtk_css_static_style_get_type ())
+#define GTK_CSS_STATIC_STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_STATIC_STYLE, GtkCssStaticStyle))
+#define GTK_CSS_STATIC_STYLE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_STATIC_STYLE, GtkCssStaticStyleClass))
+#define GTK_IS_CSS_STATIC_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_STATIC_STYLE))
+#define GTK_IS_CSS_STATIC_STYLE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_STATIC_STYLE))
+#define GTK_CSS_STATIC_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_STATIC_STYLE, GtkCssStaticStyleClass))
+
+typedef struct _GtkCssStaticStyle GtkCssStaticStyle;
+typedef struct _GtkCssStaticStyleClass GtkCssStaticStyleClass;
+
+struct _GtkCssStaticStyle
+{
+ GtkCssStyle parent;
+
+ GPtrArray *values; /* the values */
+ GPtrArray *sections; /* sections the values are defined in */
+
+ GtkBitmask *depends_on_parent; /* values that depend on parent values */
+ GtkBitmask *equals_parent; /* values that equal their parent values */
+ GtkBitmask *depends_on_color; /* values that depend on the color property */
+ GtkBitmask *depends_on_font_size; /* values that depend on the font-size property */
+};
+
+struct _GtkCssStaticStyleClass
+{
+ GtkCssStyleClass parent_class;
+};
+
+GType gtk_css_static_style_get_type (void) G_GNUC_CONST;
+
+GtkCssStyle * gtk_css_static_style_new (void);
+
+void gtk_css_static_style_compute_value (GtkCssStaticStyle *style,
+ GtkStyleProviderPrivate*provider,
+ int scale,
+ GtkCssStyle *parent_style,
+ guint id,
+ GtkCssValue *specified,
+ GtkCssSection *section);
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_STATIC_STYLE_PRIVATE_H__ */