From 9cf3fc5bf2e20de413c15db04cf83c49601638d4 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 27 Aug 2022 17:15:26 +0100 Subject: Select: Support CSS property-wide 'revert' value --- src/select/select.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'src/select/select.c') diff --git a/src/select/select.c b/src/select/select.c index c7d59b7..bd2af96 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -1145,6 +1145,27 @@ failed: } +static css_error css__select_revert_property( + css_select_state *select_state, + prop_state *prop_state, + css_origin origin, + enum css_pseudo_element pseudo, + enum css_properties_e property) +{ + css_error error; + + error = prop_dispatch[property].copy( + select_state->revert[origin].style[pseudo], + select_state->results->styles[pseudo]); + if (error != CSS_OK) { + return error; + } + + *prop_state = select_state->revert[origin].props[property][pseudo]; + return CSS_OK; +} + + /** * Select a style for the given node * @@ -1318,6 +1339,34 @@ css_error css_select_style(css_select_ctx *ctx, void *node, for (i = 0; i < CSS_N_PROPERTIES; i++) { prop_state *prop = &state.props[i][CSS_PSEUDO_ELEMENT_NONE]; + if (prop->explicit_default == FLAG_VALUE_REVERT) { + switch (prop->origin) { + case CSS_ORIGIN_AUTHOR: + error = css__select_revert_property(&state, + prop, CSS_ORIGIN_USER, 0, i); + if (error != CSS_OK) { + goto cleanup; + } + if (prop->explicit_default != FLAG_VALUE_REVERT) { + break; + } + /* Fall-through */ + case CSS_ORIGIN_USER: + error = css__select_revert_property(&state, + prop, CSS_ORIGIN_UA, 0, i); + if (error != CSS_OK) { + goto cleanup; + } + if (prop->explicit_default != FLAG_VALUE_REVERT) { + break; + } + /* Fall-through */ + case CSS_ORIGIN_UA: + prop->explicit_default = FLAG_VALUE_UNSET; + break; + } + } + if (prop->explicit_default == FLAG_VALUE_UNSET) { if (prop_dispatch[i].inherited == true) { prop->explicit_default = FLAG_VALUE_INHERIT; @@ -1352,6 +1401,36 @@ css_error css_select_style(css_select_ctx *ctx, void *node, for (i = 0; i < CSS_N_PROPERTIES; i++) { prop_state *prop = &state.props[i][j]; + if (prop->explicit_default == FLAG_VALUE_REVERT) { + switch (prop->origin) { + case CSS_ORIGIN_AUTHOR: + error = css__select_revert_property( + &state, prop, + CSS_ORIGIN_USER, j, i); + if (error != CSS_OK) { + goto cleanup; + } + if (prop->explicit_default != FLAG_VALUE_REVERT) { + break; + } + /* Fall-through */ + case CSS_ORIGIN_USER: + error = css__select_revert_property( + &state, prop, + CSS_ORIGIN_UA, j, i); + if (error != CSS_OK) { + goto cleanup; + } + if (prop->explicit_default != FLAG_VALUE_REVERT) { + break; + } + /* Fall-through */ + case CSS_ORIGIN_UA: + prop->explicit_default = FLAG_VALUE_UNSET; + break; + } + } + if (prop->explicit_default == FLAG_VALUE_UNSET) { if (prop_dispatch[i].inherited == true) { prop->explicit_default = FLAG_VALUE_INHERIT; -- cgit v1.2.3