css: Introduce a struct for used values

The GtkCssUsedValues struct will hold the used values of those
css properties where that makes a difference. The new structs
are not used yet.
This commit is contained in:
Matthias Clasen 2024-05-19 18:28:40 -04:00
parent 36b55a8b57
commit 8814c00573
3 changed files with 90 additions and 1 deletions

View File

@ -74,6 +74,7 @@ gtk_css_style_finalize (GObject *object)
gtk_css_values_unref ((GtkCssValues *)style->transition);
gtk_css_values_unref ((GtkCssValues *)style->size);
gtk_css_values_unref ((GtkCssValues *)style->other);
gtk_css_values_unref ((GtkCssValues *)style->used);
if (style->variables)
gtk_css_variable_set_unref (style->variables);
@ -841,7 +842,8 @@ static const int values_size[] = {
sizeof (GtkCssAnimationValues),
sizeof (GtkCssTransitionValues),
sizeof (GtkCssSizeValues),
sizeof (GtkCssOtherValues)
sizeof (GtkCssOtherValues),
sizeof (GtkCssUsedValues)
};
#define TYPE_INDEX(type) ((type) - ((type) % 2))

View File

@ -59,6 +59,7 @@ typedef enum {
GTK_CSS_SIZE_INITIAL_VALUES,
GTK_CSS_OTHER_VALUES,
GTK_CSS_OTHER_INITIAL_VALUES,
GTK_CSS_USED_VALUES,
} GtkCssValuesType;
typedef struct _GtkCssValues GtkCssValues;
@ -73,6 +74,7 @@ typedef struct _GtkCssAnimationValues GtkCssAnimationValues;
typedef struct _GtkCssTransitionValues GtkCssTransitionValues;
typedef struct _GtkCssSizeValues GtkCssSizeValues;
typedef struct _GtkCssOtherValues GtkCssOtherValues;
typedef struct _GtkCssUsedValues GtkCssUsedValues;
struct _GtkCssValues {
int ref_count;
@ -227,6 +229,28 @@ struct _GtkCssOtherValues {
GtkCssValue *filter;
};
struct _GtkCssUsedValues {
GtkCssValues base;
GtkCssValue *color;
GtkCssValue *icon_palette;
GtkCssValue *background_color;
GtkCssValue *box_shadow;
GtkCssValue *background_image;
GtkCssValue *border_top_color;
GtkCssValue *border_right_color;
GtkCssValue *border_bottom_color;
GtkCssValue *border_left_color;
GtkCssValue *border_image_source;
GtkCssValue *icon_shadow;
GtkCssValue *outline_color;
GtkCssValue *caret_color;
GtkCssValue *secondary_caret_color;
GtkCssValue *text_shadow;
GtkCssValue *text_decoration_color;
GtkCssValue *icon_source;
};
/* typedef struct _GtkCssStyle GtkCssStyle; */
typedef struct _GtkCssStyleClass GtkCssStyleClass;
@ -245,6 +269,8 @@ struct _GtkCssStyle
GtkCssTransitionValues *transition;
GtkCssSizeValues *size;
GtkCssOtherValues *other;
GtkCssUsedValues *used;
GtkCssVariableSet *variables;
GtkCssValue *variable_values;

View File

@ -148,4 +148,65 @@ static const int other_props[] = {
GTK_CSS_PROPERTY_FILTER,
};
static const int used_props[] = {
GTK_CSS_PROPERTY_COLOR,
GTK_CSS_PROPERTY_ICON_PALETTE,
GTK_CSS_PROPERTY_BACKGROUND_COLOR,
GTK_CSS_PROPERTY_BOX_SHADOW,
GTK_CSS_PROPERTY_BACKGROUND_IMAGE,
GTK_CSS_PROPERTY_BORDER_TOP_COLOR,
GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR,
GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR,
GTK_CSS_PROPERTY_BORDER_LEFT_COLOR,
GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE,
GTK_CSS_PROPERTY_ICON_SHADOW,
GTK_CSS_PROPERTY_OUTLINE_COLOR,
GTK_CSS_PROPERTY_CARET_COLOR,
GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR,
GTK_CSS_PROPERTY_TEXT_SHADOW,
GTK_CSS_PROPERTY_TEXT_DECORATION_COLOR,
GTK_CSS_PROPERTY_ICON_SOURCE,
};
/* Maps back from css property ids to position in used_props.
* -1 means 'not present'.
*/
static const int used_props_map[] = {
0, /* color */
-1, -1,
1, /* icon-palette */
2, /* background-color */
-1, -1, -1, -1, -1, -1,
15, /* text-decoration-color */
-1, -1, -1, -1, -1, -1, -1, -1,
-1,
14, /* text-shadow */
3, /* box-shadow */
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1,
5, /* border-top-color */
6, /* border-right-color */
7, /* border-bottom-color */
8, /* border-left-color */
11, /* outline-color */
-1,
4, /* background-image */
-1,
9, /* border-image-source */
-1, -1, -1,
16, /* icon-source */
-1,
10, /* icon-shadow */
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1,
12, /* caret-color */
13, /* secondary-caret-color */
-1, -1, -1,
};
G_STATIC_ASSERT (G_N_ELEMENTS (used_props_map) == GTK_CSS_PROPERTY_N_PROPERTIES);
G_END_DECLS