summaryrefslogtreecommitdiff
path: root/src/select
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2022-08-27 21:21:52 +0100
committerMichael Drake <mdrake.unique@gmail.com>2022-08-29 13:49:20 +0100
commit7e21db9a7a7e4b27f2423cca182f189599269315 (patch)
tree94b094189070c849258a6ee50d1d80ee5d315302 /src/select
parent9cf3fc5bf2e20de413c15db04cf83c49601638d4 (diff)
downloadlibcss-7e21db9a7a7e4b27f2423cca182f189599269315.tar.gz
libcss-7e21db9a7a7e4b27f2423cca182f189599269315.tar.bz2
Select: Split out duplicated revert handling
Diffstat (limited to 'src/select')
-rw-r--r--src/select/select.c99
1 files changed, 47 insertions, 52 deletions
diff --git a/src/select/select.c b/src/select/select.c
index bd2af96..e1f7883 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -1144,8 +1144,7 @@ failed:
return error;
}
-
-static css_error css__select_revert_property(
+static css_error css__select_revert_property_to_origin(
css_select_state *select_state,
prop_state *prop_state,
css_origin origin,
@@ -1165,6 +1164,44 @@ static css_error css__select_revert_property(
return CSS_OK;
}
+static css_error css__select_revert_property(
+ css_select_state *select_state,
+ prop_state *prop_state,
+ enum css_pseudo_element pseudo,
+ enum css_properties_e property)
+{
+ css_error error;
+
+ switch (prop_state->origin) {
+ case CSS_ORIGIN_AUTHOR:
+ error = css__select_revert_property_to_origin(
+ select_state, prop_state, CSS_ORIGIN_USER,
+ pseudo, property);
+ if (error != CSS_OK) {
+ return error;
+ }
+ if (prop_state->explicit_default != FLAG_VALUE_REVERT) {
+ break;
+ }
+ /* Fall-through */
+ case CSS_ORIGIN_USER:
+ error = css__select_revert_property_to_origin(
+ select_state, prop_state, CSS_ORIGIN_UA,
+ pseudo, property);
+ if (error != CSS_OK) {
+ return error;
+ }
+ if (prop_state->explicit_default != FLAG_VALUE_REVERT) {
+ break;
+ }
+ /* Fall-through */
+ case CSS_ORIGIN_UA:
+ prop_state->explicit_default = FLAG_VALUE_UNSET;
+ break;
+ }
+
+ return CSS_OK;
+}
/**
* Select a style for the given node
@@ -1340,30 +1377,10 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
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;
+ error = css__select_revert_property(&state, prop,
+ CSS_PSEUDO_ELEMENT_NONE, i);
+ if (error != CSS_OK) {
+ goto cleanup;
}
}
@@ -1402,32 +1419,10 @@ css_error css_select_style(css_select_ctx *ctx, void *node,
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;
+ error = css__select_revert_property(&state,
+ prop, j, i);
+ if (error != CSS_OK) {
+ goto cleanup;
}
}