[gtk+/wip/css: 10/22] css: Allow bypassing the compute_value() stage
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 10/22] css: Allow bypassing the compute_value() stage
- Date: Tue, 17 Jan 2012 00:10:33 +0000 (UTC)
commit 6c83291f582289a2111d08d66ed0154504a9203b
Author: Benjamin Otte <otte redhat com>
Date: Sat Jan 14 17:04:00 2012 +0100
css: Allow bypassing the compute_value() stage
This is useful when overriding values.
gtk/gtkcsscomputedvalues.c | 31 ++++++++++++++++++++++++++
gtk/gtkcsslookup.c | 51 +++++++++++++++++++++++++++++++++++++++----
gtk/gtkcsslookupprivate.h | 4 +++
gtk/gtkstyleproperties.c | 2 +-
4 files changed, 82 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcsscomputedvalues.c b/gtk/gtkcsscomputedvalues.c
index 8423be7..877f9cc 100644
--- a/gtk/gtkcsscomputedvalues.c
+++ b/gtk/gtkcsscomputedvalues.c
@@ -184,6 +184,37 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values,
}
}
+void
+_gtk_css_computed_values_set_value (GtkCssComputedValues *values,
+ guint id,
+ const GValue *value,
+ GtkCssSection *section)
+{
+ GValue *set;
+
+ g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
+ g_return_if_fail (value == NULL || G_IS_VALUE (value));
+
+ if (values->values == NULL)
+ values->values = g_value_array_new (id + 1);
+ while (values->values->n_values <= id)
+ g_value_array_append (values->values, NULL);
+
+ set = g_value_array_get_nth (values->values, id);
+ g_value_init (set, G_VALUE_TYPE (value));
+ g_value_copy (value, set);
+
+ if (section)
+ {
+ if (values->sections == NULL)
+ values->sections = g_ptr_array_new_with_free_func (maybe_unref_section);
+ if (values->sections->len <= id)
+ g_ptr_array_set_size (values->sections, id + 1);
+
+ g_ptr_array_index (values->sections, id) = gtk_css_section_ref (section);
+ }
+}
+
const GValue *
_gtk_css_computed_values_get_value (GtkCssComputedValues *values,
guint id)
diff --git a/gtk/gtkcsslookup.c b/gtk/gtkcsslookup.c
index fce8528..c3dd7d0 100644
--- a/gtk/gtkcsslookup.c
+++ b/gtk/gtkcsslookup.c
@@ -29,6 +29,7 @@
typedef struct {
GtkCssSection *section;
const GValue *value;
+ const GValue *computed;
} GtkCssLookupValue;
struct _GtkCssLookup {
@@ -104,6 +105,40 @@ _gtk_css_lookup_set (GtkCssLookup *lookup,
}
/**
+ * _gtk_css_lookup_set_computed:
+ * @lookup: the lookup
+ * @id: id of the property to set, see _gtk_style_property_get_id()
+ * @section: (allow-none): The @section the value was defined in or %NULL
+ * @value: the "computed value" to use
+ *
+ * Sets the @value for a given @id. No value may have been set for @id
+ * before. See _gtk_css_lookup_is_missing(). This function is used to
+ * set the "winning declaration" of a lookup. Note that for performance
+ * reasons @value and @section are not copied. It is your responsibility
+ * to ensure they are kept alive until _gtk_css_lookup_free() is called.
+ *
+ * As opposed to _gtk_css_lookup_set(), this function forces a computed
+ * value and will not cause computation to happen. In particular, with this
+ * method relative lengths or symbolic colors can not be used. This is
+ * usually only useful for doing overrides. It should not be used for proper
+ * CSS.
+ **/
+void
+_gtk_css_lookup_set_computed (GtkCssLookup *lookup,
+ guint id,
+ GtkCssSection *section,
+ const GValue *value)
+{
+ g_return_if_fail (lookup != NULL);
+ g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
+ g_return_if_fail (value != NULL);
+
+ _gtk_bitmask_set (lookup->missing, id, FALSE);
+ lookup->values[id].computed = value;
+ lookup->values[id].section = section;
+}
+
+/**
* _gtk_css_lookup_resolve:
* @lookup: the lookup
* @context: the context the values are resolved for
@@ -130,10 +165,16 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup,
for (i = 0; i < n; i++)
{
- _gtk_css_computed_values_compute_value (values,
- context,
- i,
- lookup->values[i].value,
- lookup->values[i].section);
+ if (lookup->values[i].computed)
+ _gtk_css_computed_values_set_value (values,
+ i,
+ lookup->values[i].computed,
+ lookup->values[i].section);
+ else
+ _gtk_css_computed_values_compute_value (values,
+ context,
+ i,
+ lookup->values[i].value,
+ lookup->values[i].section);
}
}
diff --git a/gtk/gtkcsslookupprivate.h b/gtk/gtkcsslookupprivate.h
index f966902..d50cb8f 100644
--- a/gtk/gtkcsslookupprivate.h
+++ b/gtk/gtkcsslookupprivate.h
@@ -41,6 +41,10 @@ void _gtk_css_lookup_set (GtkCssLookup
guint id,
GtkCssSection *section,
const GValue *value);
+void _gtk_css_lookup_set_computed (GtkCssLookup *lookup,
+ guint id,
+ GtkCssSection *section,
+ const GValue *value);
void _gtk_css_lookup_resolve (GtkCssLookup *lookup,
GtkStyleContext *context,
GtkCssComputedValues *values);
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index ecb79f5..a92d722 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -339,7 +339,7 @@ gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider,
if (value == NULL)
continue;
- _gtk_css_lookup_set (lookup, id, NULL, value);
+ _gtk_css_lookup_set_computed (lookup, id, NULL, value);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]