Commit 30eb2608 authored by Benjamin Otte's avatar Benjamin Otte

css: Feed sections to CSS lookup code

parent 79a171de
...@@ -26,9 +26,14 @@ ...@@ -26,9 +26,14 @@
#include "gtkcssstylepropertyprivate.h" #include "gtkcssstylepropertyprivate.h"
#include "gtkstylepropertiesprivate.h" #include "gtkstylepropertiesprivate.h"
typedef struct {
GtkCssSection *section;
const GValue *value;
} GtkCssLookupValue;
struct _GtkCssLookup { struct _GtkCssLookup {
GtkBitmask *missing; GtkBitmask *missing;
const GValue *values[1]; GtkCssLookupValue values[1];
}; };
GtkCssLookup * GtkCssLookup *
...@@ -37,7 +42,7 @@ _gtk_css_lookup_new (void) ...@@ -37,7 +42,7 @@ _gtk_css_lookup_new (void)
GtkCssLookup *lookup; GtkCssLookup *lookup;
guint n = _gtk_css_style_property_get_n_properties (); guint n = _gtk_css_style_property_get_n_properties ();
lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (const GValue *) * n); lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n);
lookup->missing = _gtk_bitmask_new (); lookup->missing = _gtk_bitmask_new ();
_gtk_bitmask_invert_range (lookup->missing, 0, n); _gtk_bitmask_invert_range (lookup->missing, 0, n);
...@@ -67,30 +72,35 @@ _gtk_css_lookup_is_missing (const GtkCssLookup *lookup, ...@@ -67,30 +72,35 @@ _gtk_css_lookup_is_missing (const GtkCssLookup *lookup,
{ {
g_return_val_if_fail (lookup != NULL, FALSE); g_return_val_if_fail (lookup != NULL, FALSE);
return lookup->values[id] == NULL; return lookup->values[id].value == NULL;
} }
/** /**
* _gtk_css_lookup_set: * _gtk_css_lookup_set:
* @lookup: the lookup * @lookup: the lookup
* @id: id of the property to set, see _gtk_style_property_get_id() * @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 "cascading value" to use * @value: the "cascading value" to use
* *
* Sets the @value for a given @id. No value may have been set for @id * 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 * before. See _gtk_css_lookup_is_missing(). This function is used to
* set the "winning declaration" of a lookup. * 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.
**/ **/
void void
_gtk_css_lookup_set (GtkCssLookup *lookup, _gtk_css_lookup_set (GtkCssLookup *lookup,
guint id, guint id,
const GValue *value) GtkCssSection *section,
const GValue *value)
{ {
g_return_if_fail (lookup != NULL); g_return_if_fail (lookup != NULL);
g_return_if_fail (_gtk_bitmask_get (lookup->missing, id)); g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
g_return_if_fail (value != NULL); g_return_if_fail (value != NULL);
_gtk_bitmask_set (lookup->missing, id, FALSE); _gtk_bitmask_set (lookup->missing, id, FALSE);
lookup->values[id] = value; lookup->values[id].value = value;
lookup->values[id].section = section;
} }
/** /**
...@@ -130,20 +140,20 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup, ...@@ -130,20 +140,20 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup,
* 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 (lookup->values[i] != NULL) if (lookup->values[i].value != NULL)
{ {
/* 2) If the cascading process (described below) yields a winning /* 2) If the cascading process (described below) yields a winning
* declaration and the value of the winning declaration is not * declaration and the value of the winning declaration is not
* ‘initial’ or ‘inherit’, the value of the winning declaration * ‘initial’ or ‘inherit’, the value of the winning declaration
* becomes the specified value. * becomes the specified value.
*/ */
if (!G_VALUE_HOLDS (lookup->values[i], GTK_TYPE_CSS_SPECIAL_VALUE)) if (!G_VALUE_HOLDS (lookup->values[i].value, GTK_TYPE_CSS_SPECIAL_VALUE))
{ {
result = lookup->values[i]; result = lookup->values[i].value;
} }
else else
{ {
switch (g_value_get_enum (lookup->values[i])) switch (g_value_get_enum (lookup->values[i].value))
{ {
case GTK_CSS_INHERIT: case GTK_CSS_INHERIT:
/* 3) if the value of the winning declaration is ‘inherit’, /* 3) if the value of the winning declaration is ‘inherit’,
...@@ -159,7 +169,7 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup, ...@@ -159,7 +169,7 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup,
break; break;
default: default:
/* This is part of (2) above */ /* This is part of (2) above */
result = lookup->values[i]; result = lookup->values[i].value;
break; break;
} }
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <glib-object.h> #include <glib-object.h>
#include "gtk/gtkbitmaskprivate.h" #include "gtk/gtkbitmaskprivate.h"
#include "gtk/gtkcsssection.h"
#include "gtk/gtkstylecontext.h" #include "gtk/gtkstylecontext.h"
#include "gtk/gtkstyleproperties.h" #include "gtk/gtkstyleproperties.h"
...@@ -38,6 +39,7 @@ gboolean _gtk_css_lookup_is_missing (const GtkCssLoo ...@@ -38,6 +39,7 @@ gboolean _gtk_css_lookup_is_missing (const GtkCssLoo
guint id); guint id);
void _gtk_css_lookup_set (GtkCssLookup *lookup, void _gtk_css_lookup_set (GtkCssLookup *lookup,
guint id, guint id,
GtkCssSection *section,
const GValue *value); const GValue *value);
GtkStyleProperties * _gtk_css_lookup_resolve (GtkCssLookup *lookup, GtkStyleProperties * _gtk_css_lookup_resolve (GtkCssLookup *lookup,
GtkStyleContext *context); GtkStyleContext *context);
......
...@@ -1560,7 +1560,7 @@ gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider, ...@@ -1560,7 +1560,7 @@ gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider,
if (!_gtk_css_lookup_is_missing (lookup, id)) if (!_gtk_css_lookup_is_missing (lookup, id))
continue; continue;
_gtk_css_lookup_set (lookup, id, &value->value); _gtk_css_lookup_set (lookup, id, value->section, &value->value);
} }
} }
} }
......
...@@ -618,7 +618,8 @@ pack_border_color (GValue *value, ...@@ -618,7 +618,8 @@ pack_border_color (GValue *value,
} }
static void static void
_gtk_css_shorthand_property_register (GParamSpec *pspec, _gtk_css_shorthand_property_register (const char *name,
GType value_type,
const char **subproperties, const char **subproperties,
GtkStyleUnpackFunc unpack_func, GtkStyleUnpackFunc unpack_func,
GtkStylePackFunc pack_func, GtkStylePackFunc pack_func,
...@@ -630,12 +631,11 @@ _gtk_css_shorthand_property_register (GParamSpec *pspec, ...@@ -630,12 +631,11 @@ _gtk_css_shorthand_property_register (GParamSpec *pspec,
g_return_if_fail (unpack_func != NULL); g_return_if_fail (unpack_func != NULL);
node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY, node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
"name", pspec->name, "name", name,
"value-type", pspec->value_type, "value-type", value_type,
"subproperties", subproperties, "subproperties", subproperties,
NULL); NULL);
node->pspec = pspec;
node->pack_func = pack_func; node->pack_func = pack_func;
node->unpack_func = unpack_func; node->unpack_func = unpack_func;
node->parse_func = parse_func; node->parse_func = parse_func;
...@@ -653,58 +653,44 @@ _gtk_css_shorthand_property_init_properties (void) ...@@ -653,58 +653,44 @@ _gtk_css_shorthand_property_init_properties (void)
const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL }; const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL }; const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
_gtk_css_shorthand_property_register (g_param_spec_boxed ("font", _gtk_css_shorthand_property_register ("font",
"Font Description", PANGO_TYPE_FONT_DESCRIPTION,
"Font Description",
PANGO_TYPE_FONT_DESCRIPTION, 0),
font_subproperties, font_subproperties,
unpack_font_description, unpack_font_description,
pack_font_description, pack_font_description,
NULL); NULL);
_gtk_css_shorthand_property_register (g_param_spec_boxed ("margin", _gtk_css_shorthand_property_register ("margin",
"Margin", GTK_TYPE_BORDER,
"Margin",
GTK_TYPE_BORDER, 0),
margin_subproperties, margin_subproperties,
unpack_margin, unpack_margin,
pack_margin, pack_margin,
NULL); NULL);
_gtk_css_shorthand_property_register (g_param_spec_boxed ("padding", _gtk_css_shorthand_property_register ("padding",
"Padding", GTK_TYPE_BORDER,
"Padding",
GTK_TYPE_BORDER, 0),
padding_subproperties, padding_subproperties,
unpack_padding, unpack_padding,
pack_padding, pack_padding,
NULL); NULL);
_gtk_css_shorthand_property_register (g_param_spec_boxed ("border-width", _gtk_css_shorthand_property_register ("border-width",
"Border width", GTK_TYPE_BORDER,
"Border width, in pixels",
GTK_TYPE_BORDER, 0),
border_width_subproperties, border_width_subproperties,
unpack_border_width, unpack_border_width,
pack_border_width, pack_border_width,
NULL); NULL);
_gtk_css_shorthand_property_register (g_param_spec_int ("border-radius", _gtk_css_shorthand_property_register ("border-radius",
"Border radius", G_TYPE_INT,
"Border radius, in pixels",
0, G_MAXINT, 0, 0),
border_radius_subproperties, border_radius_subproperties,
unpack_border_radius, unpack_border_radius,
pack_border_radius, pack_border_radius,
border_radius_value_parse); border_radius_value_parse);
_gtk_css_shorthand_property_register (g_param_spec_boxed ("border-color", _gtk_css_shorthand_property_register ("border-color",
"Border color", GDK_TYPE_RGBA,
"Border color",
GDK_TYPE_RGBA, 0),
border_color_subproperties, border_color_subproperties,
unpack_border_color, unpack_border_color,
pack_border_color, pack_border_color,
border_color_shorthand_value_parse); border_color_shorthand_value_parse);
_gtk_css_shorthand_property_register (g_param_spec_boxed ("border-image", _gtk_css_shorthand_property_register ("border-image",
"Border Image", GTK_TYPE_BORDER_IMAGE,
"Border Image",
GTK_TYPE_BORDER_IMAGE, 0),
border_image_subproperties, border_image_subproperties,
_gtk_border_image_unpack, _gtk_border_image_unpack,
_gtk_border_image_pack, _gtk_border_image_pack,
......
...@@ -341,7 +341,7 @@ gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider, ...@@ -341,7 +341,7 @@ gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider,
if (value == NULL) if (value == NULL)
continue; continue;
_gtk_css_lookup_set (lookup, id, value); _gtk_css_lookup_set (lookup, id, NULL, value);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment