mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 14:20:21 +00:00
css: Move computing of initial and inherit values
... to the compute vfunc. Simplifies code quite a bit. But makes the code no longer a simple step-by-step implementation of the spec.
This commit is contained in:
parent
6dc3113edc
commit
9e7e65ca6e
@ -90,15 +90,10 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values,
|
|||||||
GtkCssValue *specified,
|
GtkCssValue *specified,
|
||||||
GtkCssSection *section)
|
GtkCssSection *section)
|
||||||
{
|
{
|
||||||
GtkCssStyleProperty *prop;
|
|
||||||
GtkStyleContext *parent;
|
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
|
g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
|
||||||
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||||
|
|
||||||
prop = _gtk_css_style_property_lookup_by_id (id);
|
|
||||||
parent = gtk_style_context_get_parent (context);
|
|
||||||
|
|
||||||
gtk_css_computed_values_ensure_array (values, id + 1);
|
gtk_css_computed_values_ensure_array (values, id + 1);
|
||||||
|
|
||||||
/* http://www.w3.org/TR/css3-cascade/#cascade
|
/* http://www.w3.org/TR/css3-cascade/#cascade
|
||||||
@ -106,65 +101,19 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values,
|
|||||||
* by following this pseudo-algorithm:
|
* by following this pseudo-algorithm:
|
||||||
* 1) Identify all declarations that apply to the element
|
* 1) Identify all declarations that apply to the element
|
||||||
*/
|
*/
|
||||||
if (specified != NULL)
|
if (specified == NULL)
|
||||||
{
|
{
|
||||||
if (_gtk_css_value_is_inherit (specified))
|
GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id);
|
||||||
{
|
|
||||||
/* 3) if the value of the winning declaration is ‘inherit’,
|
|
||||||
* the inherited value (see below) becomes the specified value.
|
|
||||||
*/
|
|
||||||
specified = NULL;
|
|
||||||
}
|
|
||||||
else if (_gtk_css_value_is_initial (specified))
|
|
||||||
{
|
|
||||||
/* if the value of the winning declaration is ‘initial’,
|
|
||||||
* the initial value (see below) becomes the specified value.
|
|
||||||
*/
|
|
||||||
specified = _gtk_css_style_property_get_initial_value (prop);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 2) If the cascading process (described below) yields a winning
|
|
||||||
* declaration and the value of the winning declaration is not
|
|
||||||
* ‘initial’ or ‘inherit’, the value of the winning declaration
|
|
||||||
* becomes the specified value.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_gtk_css_style_property_is_inherit (prop))
|
if (_gtk_css_style_property_is_inherit (prop))
|
||||||
{
|
specified = _gtk_css_inherit_value_new ();
|
||||||
/* 4) if the property is inherited, the inherited value becomes
|
|
||||||
* the specified value.
|
|
||||||
*/
|
|
||||||
specified = NULL;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
specified = _gtk_css_initial_value_new ();
|
||||||
/* 5) Otherwise, the initial value becomes the specified value.
|
|
||||||
*/
|
|
||||||
specified = _gtk_css_style_property_get_initial_value (prop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (specified == NULL && parent == NULL)
|
|
||||||
{
|
|
||||||
/* If the ‘inherit’ value is set on the root element, the property is
|
|
||||||
* assigned its initial value. */
|
|
||||||
specified = _gtk_css_style_property_get_initial_value (prop);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (specified)
|
|
||||||
{
|
|
||||||
g_ptr_array_index (values->values, id) = _gtk_css_value_compute (specified, id, context);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
_gtk_css_value_ref (specified);
|
||||||
GtkCssValue *parent_value;
|
|
||||||
/* Set NULL here and do the inheritance upon lookup? */
|
|
||||||
parent_value = _gtk_style_context_peek_property (parent, id);
|
|
||||||
|
|
||||||
g_ptr_array_index (values->values, id) = _gtk_css_value_ref (parent_value);
|
g_ptr_array_index (values->values, id) = _gtk_css_value_compute (specified, id, context);
|
||||||
}
|
|
||||||
|
|
||||||
if (section)
|
if (section)
|
||||||
{
|
{
|
||||||
@ -175,6 +124,8 @@ _gtk_css_computed_values_compute_value (GtkCssComputedValues *values,
|
|||||||
|
|
||||||
g_ptr_array_index (values->sections, id) = gtk_css_section_ref (section);
|
g_ptr_array_index (values->sections, id) = gtk_css_section_ref (section);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_gtk_css_value_unref (specified);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
#include "gtkcssinheritvalueprivate.h"
|
#include "gtkcssinheritvalueprivate.h"
|
||||||
|
|
||||||
|
#include "gtkcssstylepropertyprivate.h"
|
||||||
|
#include "gtkstylecontextprivate.h"
|
||||||
|
|
||||||
struct _GtkCssValue {
|
struct _GtkCssValue {
|
||||||
GTK_CSS_VALUE_BASE
|
GTK_CSS_VALUE_BASE
|
||||||
};
|
};
|
||||||
@ -35,8 +38,14 @@ gtk_css_value_inherit_compute (GtkCssValue *value,
|
|||||||
guint property_id,
|
guint property_id,
|
||||||
GtkStyleContext *context)
|
GtkStyleContext *context)
|
||||||
{
|
{
|
||||||
/* This value should be caught further up */
|
GtkStyleContext *parent = gtk_style_context_get_parent (context);
|
||||||
g_return_val_if_reached (_gtk_css_value_ref (value));
|
|
||||||
|
if (parent)
|
||||||
|
return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, property_id));
|
||||||
|
else
|
||||||
|
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
|
||||||
|
property_id,
|
||||||
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -76,11 +85,3 @@ _gtk_css_inherit_value_new (void)
|
|||||||
{
|
{
|
||||||
return _gtk_css_value_ref (&inherit);
|
return _gtk_css_value_ref (&inherit);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
_gtk_css_value_is_inherit (const GtkCssValue *value)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (value != NULL, FALSE);
|
|
||||||
|
|
||||||
return value == &inherit;
|
|
||||||
}
|
|
||||||
|
@ -26,8 +26,6 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
GtkCssValue * _gtk_css_inherit_value_new (void);
|
GtkCssValue * _gtk_css_inherit_value_new (void);
|
||||||
|
|
||||||
gboolean _gtk_css_value_is_inherit (const GtkCssValue *value);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GTK_CSS_INHERIT_VALUE_PRIVATE_H__ */
|
#endif /* __GTK_CSS_INHERIT_VALUE_PRIVATE_H__ */
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "gtkcssinitialvalueprivate.h"
|
#include "gtkcssinitialvalueprivate.h"
|
||||||
|
|
||||||
|
#include "gtkcssstylepropertyprivate.h"
|
||||||
|
|
||||||
struct _GtkCssValue {
|
struct _GtkCssValue {
|
||||||
GTK_CSS_VALUE_BASE
|
GTK_CSS_VALUE_BASE
|
||||||
};
|
};
|
||||||
@ -35,8 +37,9 @@ gtk_css_value_initial_compute (GtkCssValue *value,
|
|||||||
guint property_id,
|
guint property_id,
|
||||||
GtkStyleContext *context)
|
GtkStyleContext *context)
|
||||||
{
|
{
|
||||||
/* This value should be caught further up */
|
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
|
||||||
g_return_val_if_reached (_gtk_css_value_ref (value));
|
property_id,
|
||||||
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -76,11 +79,3 @@ _gtk_css_initial_value_new (void)
|
|||||||
{
|
{
|
||||||
return _gtk_css_value_ref (&initial);
|
return _gtk_css_value_ref (&initial);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
_gtk_css_value_is_initial (const GtkCssValue *value)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (value != NULL, FALSE);
|
|
||||||
|
|
||||||
return value == &initial;
|
|
||||||
}
|
|
||||||
|
@ -26,8 +26,6 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
GtkCssValue * _gtk_css_initial_value_new (void);
|
GtkCssValue * _gtk_css_initial_value_new (void);
|
||||||
|
|
||||||
gboolean _gtk_css_value_is_initial (const GtkCssValue *value);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GTK_CSS_INITIAL_VALUE_PRIVATE_H__ */
|
#endif /* __GTK_CSS_INITIAL_VALUE_PRIVATE_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user