Compare commits

...

4 Commits

Author SHA1 Message Date
Matthias Clasen
8a14144658 Replace generic setter code
Instead of going through a big switch of all properties,
make the new_compute() functions for each values struct
directly set its members. This way, we can also avoid the
border-width special case for more properties.
2020-01-26 23:50:52 -05:00
Matthias Clasen
0ff6176525 Add some checking for the group splitup
Verify that we don't miss properties or have them
more than once.
2020-01-26 22:29:55 -05:00
Matthias Clasen
c30befed1e Add accounting for styles 2020-01-26 22:29:55 -05:00
Matthias Clasen
9d38806ced css: Split style into groups 2020-01-26 22:29:55 -05:00
5 changed files with 1100 additions and 162 deletions

View File

@@ -28,11 +28,14 @@ void
_gtk_css_lookup_init (GtkCssLookup *lookup)
{
memset (lookup, 0, sizeof (*lookup));
lookup->set_values = _gtk_bitmask_new ();
}
void
_gtk_css_lookup_destroy (GtkCssLookup *lookup)
{
_gtk_bitmask_free (lookup->set_values);
}
gboolean
@@ -41,13 +44,7 @@ _gtk_css_lookup_is_missing (const GtkCssLookup *lookup,
{
gtk_internal_return_val_if_fail (lookup != NULL, FALSE);
return lookup->values[id].value == NULL;
}
gboolean
_gtk_css_lookup_all_set (const GtkCssLookup *lookup)
{
return lookup->n_set_values == GTK_CSS_PROPERTY_N_PROPERTIES;
return !_gtk_bitmask_get (lookup->set_values, id);
}
/**
@@ -75,41 +72,5 @@ _gtk_css_lookup_set (GtkCssLookup *lookup,
lookup->values[id].value = value;
lookup->values[id].section = section;
lookup->n_set_values ++;
}
/**
* _gtk_css_lookup_resolve:
* @lookup: the lookup
* @context: the context the values are resolved for
* @values: a new #GtkCssStyle to be filled with the new properties
*
* Resolves the current lookup into a styleproperties object. This is done
* by converting from the “winning declaration” to the “computed value”.
*
* XXX: This bypasses the notion of “specified value”. If this ever becomes
* an issue, go fix it.
**/
void
_gtk_css_lookup_resolve (GtkCssLookup *lookup,
GtkStyleProvider *provider,
GtkCssStaticStyle *style,
GtkCssStyle *parent_style)
{
guint i;
gtk_internal_return_if_fail (lookup != NULL);
gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
gtk_internal_return_if_fail (GTK_IS_CSS_STATIC_STYLE (style));
gtk_internal_return_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style));
for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++)
{
gtk_css_static_style_compute_value (style,
provider,
parent_style,
i,
lookup->values[i].value,
lookup->values[i].section);
}
lookup->set_values = _gtk_bitmask_set (lookup->set_values, id, TRUE);
}

View File

@@ -36,7 +36,7 @@ typedef struct {
} GtkCssLookupValue;
struct _GtkCssLookup {
guint n_set_values;
GtkBitmask *set_values;
GtkCssLookupValue values[GTK_CSS_PROPERTY_N_PROPERTIES];
};
@@ -44,15 +44,16 @@ void _gtk_css_lookup_init (GtkCssLookup
void _gtk_css_lookup_destroy (GtkCssLookup *lookup);
gboolean _gtk_css_lookup_is_missing (const GtkCssLookup *lookup,
guint id);
gboolean _gtk_css_lookup_all_set (const GtkCssLookup *lookup);
void _gtk_css_lookup_set (GtkCssLookup *lookup,
guint id,
GtkCssSection *section,
GtkCssValue *value);
void _gtk_css_lookup_resolve (GtkCssLookup *lookup,
GtkStyleProvider *provider,
GtkCssStaticStyle *style,
GtkCssStyle *parent_style);
static inline const GtkBitmask *
_gtk_css_lookup_get_set_values (const GtkCssLookup *lookup)
{
return lookup->set_values;
}
G_END_DECLS

View File

@@ -489,9 +489,6 @@ gtk_css_style_provider_lookup (GtkStyleProvider *provider,
ruleset->styles[j].section,
ruleset->styles[j].value);
}
if (_gtk_css_lookup_all_set (lookup))
break;
}
g_ptr_array_free (tree_rules, TRUE);

File diff suppressed because it is too large Load Diff

View File

@@ -34,11 +34,164 @@ G_BEGIN_DECLS
typedef struct _GtkCssStaticStyleClass GtkCssStaticStyleClass;
/* inherited */
typedef struct {
int ref_count;
GtkCssValue *color;
GtkCssValue *dpi;
GtkCssValue *font_size;
GtkCssValue *icon_theme;
GtkCssValue *icon_palette;
} GtkCssCoreValues;
typedef struct {
int ref_count;
GtkCssValue *background_color;
GtkCssValue *box_shadow;
GtkCssValue *background_clip;
GtkCssValue *background_origin;
GtkCssValue *background_size;
GtkCssValue *background_position;
GtkCssValue *background_repeat;
GtkCssValue *background_image;
GtkCssValue *background_blend_mode;
} GtkCssBackgroundValues;
typedef struct {
int ref_count;
GtkCssValue *border_top_style;
GtkCssValue *border_top_width;
GtkCssValue *border_left_style;
GtkCssValue *border_left_width;
GtkCssValue *border_bottom_style;
GtkCssValue *border_bottom_width;
GtkCssValue *border_right_style;
GtkCssValue *border_right_width;
GtkCssValue *border_top_left_radius;
GtkCssValue *border_top_right_radius;
GtkCssValue *border_bottom_right_radius;
GtkCssValue *border_bottom_left_radius;
GtkCssValue *border_top_color;
GtkCssValue *border_right_color;
GtkCssValue *border_bottom_color;
GtkCssValue *border_left_color;
GtkCssValue *border_image_source;
GtkCssValue *border_image_repeat;
GtkCssValue *border_image_slice;
GtkCssValue *border_image_width;
} GtkCssBorderValues;
/* inherited */
typedef struct {
int ref_count;
GtkCssValue *icon_size;
GtkCssValue *icon_shadow;
GtkCssValue *icon_style;
} GtkCssIconValues;
typedef struct {
int ref_count;
GtkCssValue *outline_style;
GtkCssValue *outline_width;
GtkCssValue *outline_offset;
GtkCssValue *outline_top_left_radius;
GtkCssValue *outline_top_right_radius;
GtkCssValue *outline_bottom_right_radius;
GtkCssValue *outline_bottom_left_radius;
GtkCssValue *outline_color;
} GtkCssOutlineValues;
/* inherited */
typedef struct {
int ref_count;
GtkCssValue *font_family;
GtkCssValue *font_style;
GtkCssValue *font_weight;
GtkCssValue *font_stretch;
GtkCssValue *letter_spacing;
GtkCssValue *text_shadow;
GtkCssValue *caret_color;
GtkCssValue *secondary_caret_color;
GtkCssValue *font_feature_settings;
GtkCssValue *font_variation_settings;
} GtkCssFontValues;
typedef struct {
int ref_count;
GtkCssValue *text_decoration_line;
GtkCssValue *text_decoration_color;
GtkCssValue *text_decoration_style;
GtkCssValue *font_kerning;
GtkCssValue *font_variant_ligatures;
GtkCssValue *font_variant_position;
GtkCssValue *font_variant_caps;
GtkCssValue *font_variant_numeric;
GtkCssValue *font_variant_alternates;
GtkCssValue *font_variant_east_asian;
} GtkCssFontVariantValues;
typedef struct {
int ref_count;
GtkCssValue *animation_name;
GtkCssValue *animation_duration;
GtkCssValue *animation_timing_function;
GtkCssValue *animation_iteration_count;
GtkCssValue *animation_direction;
GtkCssValue *animation_play_state;
GtkCssValue *animation_delay;
GtkCssValue *animation_fill_mode;
} GtkCssAnimationValues;
typedef struct {
int ref_count;
GtkCssValue *transition_property;
GtkCssValue *transition_duration;
GtkCssValue *transition_timing_function;
GtkCssValue *transition_delay;
} GtkCssTransitionValues;
typedef struct {
int ref_count;
GtkCssValue *margin_top;
GtkCssValue *margin_left;
GtkCssValue *margin_bottom;
GtkCssValue *margin_right;
GtkCssValue *padding_top;
GtkCssValue *padding_left;
GtkCssValue *padding_bottom;
GtkCssValue *padding_right;
GtkCssValue *border_spacing;
GtkCssValue *min_width;
GtkCssValue *min_height;
} GtkCssSizeValues;
typedef struct {
int ref_count;
GtkCssValue *icon_source;
GtkCssValue *icon_transform;
GtkCssValue *icon_filter;
GtkCssValue *transform;
GtkCssValue *opacity;
GtkCssValue *filter;
} GtkCssOtherValues;
struct _GtkCssStaticStyle
{
GtkCssStyle parent;
GtkCssValue *values[GTK_CSS_PROPERTY_N_PROPERTIES]; /* the values */
GtkCssCoreValues *core;
GtkCssBackgroundValues *background;
GtkCssBorderValues *border;
GtkCssIconValues *icon;
GtkCssOutlineValues *outline;
GtkCssFontValues *font;
GtkCssFontVariantValues *font_variant;
GtkCssAnimationValues *animation;
GtkCssTransitionValues *transition;
GtkCssSizeValues *size;
GtkCssOtherValues *other;
GPtrArray *sections; /* sections the values are defined in */
GtkCssChange change; /* change as returned by value lookup */
@@ -57,13 +210,6 @@ GtkCssStyle * gtk_css_static_style_new_compute (GtkStyleProvide
GtkCssStyle *parent,
GtkCssChange change);
void gtk_css_static_style_compute_value (GtkCssStaticStyle *style,
GtkStyleProvider *provider,
GtkCssStyle *parent_style,
guint id,
GtkCssValue *specified,
GtkCssSection *section);
GtkCssChange gtk_css_static_style_get_change (GtkCssStaticStyle *style);
G_END_DECLS