From c14f3c4e05d3a6f38fbd84a2bee78895d8120619 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 27 Aug 2022 16:07:40 +0100 Subject: Select: Clone UA and author styles for revert --- src/select/select.c | 30 ++++++++++++++++++++++++++++++ src/select/select.h | 8 ++++++++ 2 files changed, 38 insertions(+) (limited to 'src') diff --git a/src/select/select.c b/src/select/select.c index 7b5b71a..c7d59b7 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -1019,6 +1019,15 @@ static void css_select__finalise_selection_state( if (state->element.name != NULL){ lwc_string_unref(state->element.name); } + + for (size_t i = 0; i < CSS_ORIGIN_AUTHOR; i++) { + for (size_t j = 0; j < CSS_PSEUDO_ELEMENT_COUNT; j++) { + if (state->revert[i].style[j] == NULL) { + continue; + } + css_computed_style_destroy(state->revert[i].style[j]); + } + } } @@ -1164,6 +1173,7 @@ css_error css_select_style(css_select_ctx *ctx, void *node, css_select_handler *handler, void *pw, css_select_results **result) { + css_origin origin = CSS_ORIGIN_UA; uint32_t i, j, nhints; css_error error; css_select_state state; @@ -1242,9 +1252,29 @@ css_error css_select_style(css_select_ctx *ctx, void *node, /* Iterate through the top-level stylesheets, selecting styles * from those which apply to our current media requirements and * are not disabled */ + if (ctx->n_sheets > 0) { + origin = ctx->sheets[0].origin; + } for (i = 0; i < ctx->n_sheets; i++) { const css_select_sheet s = ctx->sheets[i]; + if (s.origin != origin) { + for (j = 0; j < CSS_PSEUDO_ELEMENT_COUNT; j++) { + if (state.results->styles[j] == NULL) { + continue; + } + error = css__computed_style_clone( + state.results->styles[j], + &state.revert[origin].style[j]); + if (error != CSS_OK) { + goto cleanup; + } + memcpy(state.revert[origin].props, + state.props, sizeof(state.props)); + } + origin = s.origin; + } + if (mq__list_match(s.media, unit_ctx, media, &ctx->str) && s.sheet->disabled == false) { error = select_from_sheet(ctx, s.sheet, diff --git a/src/select/select.h b/src/select/select.h index f449534..69bf4d8 100644 --- a/src/select/select.h +++ b/src/select/select.h @@ -58,6 +58,11 @@ struct css_node_data { css_node_flags flags; }; +struct revert_data { + prop_state props[CSS_N_PROPERTIES][CSS_PSEUDO_ELEMENT_COUNT]; + css_computed_style *style[CSS_PSEUDO_ELEMENT_COUNT]; +}; + /** * Selection state */ @@ -67,6 +72,9 @@ typedef struct css_select_state { const css_unit_ctx *unit_ctx; /* Unit conversion context. */ css_select_results *results; /* Result set to populate */ + /** UA and user styles for handling revert property value. */ + struct revert_data revert[CSS_ORIGIN_AUTHOR]; + css_pseudo_element current_pseudo; /* Current pseudo element */ css_computed_style *computed; /* Computed style to populate */ -- cgit v1.2.3