diff options
83 files changed, 414 insertions, 315 deletions
diff --git a/include/libcss/select.h b/include/libcss/select.h index a5d6111..76c226b 100644 --- a/include/libcss/select.h +++ b/include/libcss/select.h @@ -19,14 +19,34 @@ extern "C" #include <libcss/functypes.h> #include <libcss/hint.h> #include <libcss/types.h> +#include <libcss/computed.h> -enum css_pseudo_element { +typedef enum css_pseudo_element { CSS_PSEUDO_ELEMENT_NONE = 0, CSS_PSEUDO_ELEMENT_FIRST_LINE = 1, CSS_PSEUDO_ELEMENT_FIRST_LETTER = 2, CSS_PSEUDO_ELEMENT_BEFORE = 3, - CSS_PSEUDO_ELEMENT_AFTER = 4 -}; + CSS_PSEUDO_ELEMENT_AFTER = 4, + + CSS_PSEUDO_ELEMENT_COUNT = 5 /**< Number of pseudo elements */ +} css_pseudo_element; + +/** + * Style selection result set + */ +typedef struct css_select_results { + css_allocator_fn alloc; + void *pw; + + /** + * Array of pointers to computed styles, + * indexed by css_pseudo_element. If there + * was no styling for a given pseudo element, + * then no computed style will be created and + * the corresponding pointer will be set to NULL + */ + css_computed_style *styles[]; +} css_select_results; typedef struct css_select_handler { css_error (*node_name)(void *pw, void *node, @@ -102,10 +122,11 @@ css_error css_select_ctx_get_sheet(css_select_ctx *ctx, uint32_t index, const css_stylesheet **sheet); css_error css_select_style(css_select_ctx *ctx, void *node, - uint32_t pseudo_element, uint64_t media, - const css_stylesheet *inline_style, - css_computed_style *result, - css_select_handler *handler, void *pw); + uint64_t media, const css_stylesheet *inline_style, + css_select_handler *handler, void *pw, + css_select_results **result); + +css_error css_select_results_destroy(css_select_results *results); #ifdef __cplusplus } diff --git a/src/select/computed.c b/src/select/computed.c index 57f50cb..16c6b9f 100644 --- a/src/select/computed.c +++ b/src/select/computed.c @@ -239,9 +239,9 @@ css_error css_computed_style_initialise(css_computed_style *style, return CSS_BADPARM; state.node = NULL; - state.pseudo_element = CSS_PSEUDO_ELEMENT_NONE; state.media = CSS_MEDIA_ALL; - state.result = style; + state.results = NULL; + state.computed = style; state.handler = handler; state.pw = pw; diff --git a/src/select/properties/background_attachment.c b/src/select/properties/background_attachment.c index 807c533..b5bf732 100644 --- a/src/select/properties/background_attachment.c +++ b/src/select/properties/background_attachment.c @@ -34,7 +34,7 @@ css_error cascade_background_attachment(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_background_attachment(state->result, value); + return set_background_attachment(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_background_attachment_from_hint(const css_hint *hint, css_error initial_background_attachment(css_select_state *state) { - return set_background_attachment(state->result, + return set_background_attachment(state->computed, CSS_BACKGROUND_ATTACHMENT_SCROLL); } diff --git a/src/select/properties/background_color.c b/src/select/properties/background_color.c index 322af83..0867ce2 100644 --- a/src/select/properties/background_color.c +++ b/src/select/properties/background_color.c @@ -28,7 +28,7 @@ css_error set_background_color_from_hint(const css_hint *hint, css_error initial_background_color(css_select_state *state) { - return set_background_color(state->result, + return set_background_color(state->computed, CSS_BACKGROUND_COLOR_TRANSPARENT, 0); } diff --git a/src/select/properties/background_image.c b/src/select/properties/background_image.c index df39e30..501f4fe 100644 --- a/src/select/properties/background_image.c +++ b/src/select/properties/background_image.c @@ -35,7 +35,7 @@ css_error set_background_image_from_hint(const css_hint *hint, css_error initial_background_image(css_select_state *state) { - return set_background_image(state->result, + return set_background_image(state->computed, CSS_BACKGROUND_IMAGE_NONE, NULL); } diff --git a/src/select/properties/background_position.c b/src/select/properties/background_position.c index 56125e3..6bcaa7f 100644 --- a/src/select/properties/background_position.c +++ b/src/select/properties/background_position.c @@ -74,7 +74,7 @@ css_error cascade_background_position(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_background_position(state->result, value, + return set_background_position(state->computed, value, hlength, hunit, vlength, vunit); } @@ -91,7 +91,7 @@ css_error set_background_position_from_hint(const css_hint *hint, css_error initial_background_position(css_select_state *state) { - return set_background_position(state->result, + return set_background_position(state->computed, CSS_BACKGROUND_POSITION_SET, 0, CSS_UNIT_PCT, 0, CSS_UNIT_PCT); } diff --git a/src/select/properties/background_repeat.c b/src/select/properties/background_repeat.c index d288259..c700730 100644 --- a/src/select/properties/background_repeat.c +++ b/src/select/properties/background_repeat.c @@ -40,7 +40,7 @@ css_error cascade_background_repeat(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_background_repeat(state->result, value); + return set_background_repeat(state->computed, value); } return CSS_OK; @@ -54,7 +54,7 @@ css_error set_background_repeat_from_hint(const css_hint *hint, css_error initial_background_repeat(css_select_state *state) { - return set_background_repeat(state->result, + return set_background_repeat(state->computed, CSS_BACKGROUND_REPEAT_REPEAT); } diff --git a/src/select/properties/border_bottom_color.c b/src/select/properties/border_bottom_color.c index 74fb65e..e2cc535 100644 --- a/src/select/properties/border_bottom_color.c +++ b/src/select/properties/border_bottom_color.c @@ -29,7 +29,7 @@ css_error set_border_bottom_color_from_hint(const css_hint *hint, css_error initial_border_bottom_color(css_select_state *state) { - return set_border_bottom_color(state->result, + return set_border_bottom_color(state->computed, CSS_BORDER_COLOR_INITIAL, 0); } diff --git a/src/select/properties/border_bottom_style.c b/src/select/properties/border_bottom_style.c index 0789018..6857630 100644 --- a/src/select/properties/border_bottom_style.c +++ b/src/select/properties/border_bottom_style.c @@ -28,7 +28,7 @@ css_error set_border_bottom_style_from_hint(const css_hint *hint, css_error initial_border_bottom_style(css_select_state *state) { - return set_border_bottom_style(state->result, CSS_BORDER_STYLE_NONE); + return set_border_bottom_style(state->computed, CSS_BORDER_STYLE_NONE); } css_error compose_border_bottom_style(const css_computed_style *parent, diff --git a/src/select/properties/border_bottom_width.c b/src/select/properties/border_bottom_width.c index b9c217e..b65ed5e 100644 --- a/src/select/properties/border_bottom_width.c +++ b/src/select/properties/border_bottom_width.c @@ -29,7 +29,7 @@ css_error set_border_bottom_width_from_hint(const css_hint *hint, css_error initial_border_bottom_width(css_select_state *state) { - return set_border_bottom_width(state->result, CSS_BORDER_WIDTH_MEDIUM, + return set_border_bottom_width(state->computed, CSS_BORDER_WIDTH_MEDIUM, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/border_collapse.c b/src/select/properties/border_collapse.c index 1a23346..108caa7 100644 --- a/src/select/properties/border_collapse.c +++ b/src/select/properties/border_collapse.c @@ -34,7 +34,7 @@ css_error cascade_border_collapse(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_border_collapse(state->result, value); + return set_border_collapse(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_border_collapse_from_hint(const css_hint *hint, css_error initial_border_collapse(css_select_state *state) { - return set_border_collapse(state->result, CSS_BORDER_COLLAPSE_SEPARATE); + return set_border_collapse(state->computed, CSS_BORDER_COLLAPSE_SEPARATE); } css_error compose_border_collapse(const css_computed_style *parent, diff --git a/src/select/properties/border_left_color.c b/src/select/properties/border_left_color.c index 44a9231..b745553 100644 --- a/src/select/properties/border_left_color.c +++ b/src/select/properties/border_left_color.c @@ -29,7 +29,7 @@ css_error set_border_left_color_from_hint(const css_hint *hint, css_error initial_border_left_color(css_select_state *state) { - return set_border_left_color(state->result, + return set_border_left_color(state->computed, CSS_BORDER_COLOR_INITIAL, 0); } diff --git a/src/select/properties/border_left_style.c b/src/select/properties/border_left_style.c index cf5a938..18e8604 100644 --- a/src/select/properties/border_left_style.c +++ b/src/select/properties/border_left_style.c @@ -28,7 +28,7 @@ css_error set_border_left_style_from_hint(const css_hint *hint, css_error initial_border_left_style(css_select_state *state) { - return set_border_left_style(state->result, CSS_BORDER_STYLE_NONE); + return set_border_left_style(state->computed, CSS_BORDER_STYLE_NONE); } css_error compose_border_left_style(const css_computed_style *parent, diff --git a/src/select/properties/border_left_width.c b/src/select/properties/border_left_width.c index 8113c2d..3247784 100644 --- a/src/select/properties/border_left_width.c +++ b/src/select/properties/border_left_width.c @@ -29,7 +29,7 @@ css_error set_border_left_width_from_hint(const css_hint *hint, css_error initial_border_left_width(css_select_state *state) { - return set_border_left_width(state->result, CSS_BORDER_WIDTH_MEDIUM, + return set_border_left_width(state->computed, CSS_BORDER_WIDTH_MEDIUM, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/border_right_color.c b/src/select/properties/border_right_color.c index e70345c..d2cd95d 100644 --- a/src/select/properties/border_right_color.c +++ b/src/select/properties/border_right_color.c @@ -29,7 +29,7 @@ css_error set_border_right_color_from_hint(const css_hint *hint, css_error initial_border_right_color(css_select_state *state) { - return set_border_right_color(state->result, + return set_border_right_color(state->computed, CSS_BORDER_COLOR_INITIAL, 0); } diff --git a/src/select/properties/border_right_style.c b/src/select/properties/border_right_style.c index 18670b3..c11b49a 100644 --- a/src/select/properties/border_right_style.c +++ b/src/select/properties/border_right_style.c @@ -28,7 +28,7 @@ css_error set_border_right_style_from_hint(const css_hint *hint, css_error initial_border_right_style(css_select_state *state) { - return set_border_right_style(state->result, CSS_BORDER_STYLE_NONE); + return set_border_right_style(state->computed, CSS_BORDER_STYLE_NONE); } css_error compose_border_right_style(const css_computed_style *parent, diff --git a/src/select/properties/border_right_width.c b/src/select/properties/border_right_width.c index b45bcae..e7fe775 100644 --- a/src/select/properties/border_right_width.c +++ b/src/select/properties/border_right_width.c @@ -29,7 +29,7 @@ css_error set_border_right_width_from_hint(const css_hint *hint, css_error initial_border_right_width(css_select_state *state) { - return set_border_right_width(state->result, CSS_BORDER_WIDTH_MEDIUM, + return set_border_right_width(state->computed, CSS_BORDER_WIDTH_MEDIUM, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/border_spacing.c b/src/select/properties/border_spacing.c index 3fff485..caf6f2e 100644 --- a/src/select/properties/border_spacing.c +++ b/src/select/properties/border_spacing.c @@ -41,7 +41,7 @@ css_error cascade_border_spacing(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_border_spacing(state->result, value, + return set_border_spacing(state->computed, value, hlength, hunit, vlength, vunit); } @@ -58,7 +58,7 @@ css_error set_border_spacing_from_hint(const css_hint *hint, css_error initial_border_spacing(css_select_state *state) { - return set_border_spacing(state->result, CSS_BORDER_SPACING_SET, + return set_border_spacing(state->computed, CSS_BORDER_SPACING_SET, 0, CSS_UNIT_PX, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/border_top_color.c b/src/select/properties/border_top_color.c index 8038720..f13df9e 100644 --- a/src/select/properties/border_top_color.c +++ b/src/select/properties/border_top_color.c @@ -28,7 +28,7 @@ css_error set_border_top_color_from_hint(const css_hint *hint, css_error initial_border_top_color(css_select_state *state) { - return set_border_top_color(state->result, CSS_BORDER_COLOR_INITIAL, 0); + return set_border_top_color(state->computed, CSS_BORDER_COLOR_INITIAL, 0); } css_error compose_border_top_color(const css_computed_style *parent, diff --git a/src/select/properties/border_top_style.c b/src/select/properties/border_top_style.c index 3585df5..7cdbf1b 100644 --- a/src/select/properties/border_top_style.c +++ b/src/select/properties/border_top_style.c @@ -28,7 +28,7 @@ css_error set_border_top_style_from_hint(const css_hint *hint, css_error initial_border_top_style(css_select_state *state) { - return set_border_top_style(state->result, CSS_BORDER_STYLE_NONE); + return set_border_top_style(state->computed, CSS_BORDER_STYLE_NONE); } css_error compose_border_top_style(const css_computed_style *parent, diff --git a/src/select/properties/border_top_width.c b/src/select/properties/border_top_width.c index d1d1888..d8c4547 100644 --- a/src/select/properties/border_top_width.c +++ b/src/select/properties/border_top_width.c @@ -29,7 +29,7 @@ css_error set_border_top_width_from_hint(const css_hint *hint, css_error initial_border_top_width(css_select_state *state) { - return set_border_top_width(state->result, CSS_BORDER_WIDTH_MEDIUM, + return set_border_top_width(state->computed, CSS_BORDER_WIDTH_MEDIUM, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/bottom.c b/src/select/properties/bottom.c index 115cdf2..455dca9 100644 --- a/src/select/properties/bottom.c +++ b/src/select/properties/bottom.c @@ -29,7 +29,7 @@ css_error set_bottom_from_hint(const css_hint *hint, css_error initial_bottom(css_select_state *state) { - return set_bottom(state->result, CSS_BOTTOM_AUTO, 0, CSS_UNIT_PX); + return set_bottom(state->computed, CSS_BOTTOM_AUTO, 0, CSS_UNIT_PX); } css_error compose_bottom(const css_computed_style *parent, diff --git a/src/select/properties/caption_side.c b/src/select/properties/caption_side.c index a6c2c17..c751dba 100644 --- a/src/select/properties/caption_side.c +++ b/src/select/properties/caption_side.c @@ -34,7 +34,7 @@ css_error cascade_caption_side(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_caption_side(state->result, value); + return set_caption_side(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_caption_side_from_hint(const css_hint *hint, css_error initial_caption_side(css_select_state *state) { - return set_caption_side(state->result, CSS_CAPTION_SIDE_TOP); + return set_caption_side(state->computed, CSS_CAPTION_SIDE_TOP); } css_error compose_caption_side(const css_computed_style *parent, diff --git a/src/select/properties/clear.c b/src/select/properties/clear.c index 03cf4f0..e29521b 100644 --- a/src/select/properties/clear.c +++ b/src/select/properties/clear.c @@ -40,7 +40,7 @@ css_error cascade_clear(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_clear(state->result, value); + return set_clear(state->computed, value); } return CSS_OK; @@ -54,7 +54,7 @@ css_error set_clear_from_hint(const css_hint *hint, css_error initial_clear(css_select_state *state) { - return set_clear(state->result, CSS_CLEAR_NONE); + return set_clear(state->computed, CSS_CLEAR_NONE); } css_error compose_clear(const css_computed_style *parent, diff --git a/src/select/properties/clip.c b/src/select/properties/clip.c index e2ebdca..b87da03 100644 --- a/src/select/properties/clip.c +++ b/src/select/properties/clip.c @@ -71,7 +71,7 @@ css_error cascade_clip(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_clip(state->result, value, &rect); + return set_clip(state->computed, value, &rect); } return CSS_OK; @@ -89,7 +89,7 @@ css_error initial_clip(css_select_state *state) CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, false, false, false, false }; - return set_clip(state->result, CSS_CLIP_AUTO, &rect); + return set_clip(state->computed, CSS_CLIP_AUTO, &rect); } css_error compose_clip(const css_computed_style *parent, diff --git a/src/select/properties/color.c b/src/select/properties/color.c index ae3e814..f727b60 100644 --- a/src/select/properties/color.c +++ b/src/select/properties/color.c @@ -28,7 +28,7 @@ css_error cascade_color(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_color(state->result, value, color); + return set_color(state->computed, value, color); } return CSS_OK; @@ -50,7 +50,7 @@ css_error initial_color(css_select_state *state) if (error != CSS_OK) return error; - return set_color_from_hint(&hint, state->result); + return set_color_from_hint(&hint, state->computed); } css_error compose_color(const css_computed_style *parent, diff --git a/src/select/properties/content.c b/src/select/properties/content.c index 99cd09e..40fb018 100644 --- a/src/select/properties/content.c +++ b/src/select/properties/content.c @@ -35,14 +35,14 @@ css_error cascade_content(uint32_t opv, css_style *style, lwc_string *he = *((lwc_string **) style->bytecode); css_computed_content_item *temp; - temp = state->result->alloc(content, + temp = state->computed->alloc(content, (n_contents + 1) * sizeof(css_computed_content_item), - state->result->pw); + state->computed->pw); if (temp == NULL) { if (content != NULL) { - state->result->alloc(content, - 0, state->result->pw); + state->computed->alloc(content, + 0, state->computed->pw); } return CSS_NOMEM; } @@ -126,11 +126,11 @@ css_error cascade_content(uint32_t opv, css_style *style, if (n_contents > 0) { css_computed_content_item *temp; - temp = state->result->alloc(content, + temp = state->computed->alloc(content, (n_contents + 1) * sizeof(css_computed_content_item), - state->result->pw); + state->computed->pw); if (temp == NULL) { - state->result->alloc(content, 0, state->result->pw); + state->computed->alloc(content, 0, state->computed->pw); return CSS_NOMEM; } @@ -143,13 +143,13 @@ css_error cascade_content(uint32_t opv, css_style *style, isInherit(opv))) { css_error error; - error = set_content(state->result, value, content); + error = set_content(state->computed, value, content); if (error != CSS_OK && content != NULL) - state->result->alloc(content, 0, state->result->pw); + state->computed->alloc(content, 0, state->computed->pw); return error; } else if (content != NULL) { - state->result->alloc(content, 0, state->result->pw); + state->computed->alloc(content, 0, state->computed->pw); } return CSS_OK; @@ -196,7 +196,7 @@ css_error set_content_from_hint(const css_hint *hint, css_error initial_content(css_select_state *state) { - return set_content(state->result, CSS_CONTENT_NORMAL, NULL); + return set_content(state->computed, CSS_CONTENT_NORMAL, NULL); } css_error compose_content(const css_computed_style *parent, diff --git a/src/select/properties/counter_increment.c b/src/select/properties/counter_increment.c index 9697028..e17be9f 100644 --- a/src/select/properties/counter_increment.c +++ b/src/select/properties/counter_increment.c @@ -44,7 +44,7 @@ css_error set_counter_increment_from_hint(const css_hint *hint, css_error initial_counter_increment(css_select_state *state) { - return set_counter_increment(state->result, + return set_counter_increment(state->computed, CSS_COUNTER_INCREMENT_NONE, NULL); } diff --git a/src/select/properties/counter_reset.c b/src/select/properties/counter_reset.c index be78605..8bcd462 100644 --- a/src/select/properties/counter_reset.c +++ b/src/select/properties/counter_reset.c @@ -44,7 +44,7 @@ css_error set_counter_reset_from_hint(const css_hint *hint, css_error initial_counter_reset(css_select_state *state) { - return set_counter_reset(state->result, CSS_COUNTER_RESET_NONE, NULL); + return set_counter_reset(state->computed, CSS_COUNTER_RESET_NONE, NULL); } css_error compose_counter_reset(const css_computed_style *parent, diff --git a/src/select/properties/cursor.c b/src/select/properties/cursor.c index 6269744..249d8b4 100644 --- a/src/select/properties/cursor.c +++ b/src/select/properties/cursor.c @@ -31,13 +31,13 @@ css_error cascade_cursor(uint32_t opv, css_style *style, uri = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(uri)); - temp = state->result->alloc(uris, + temp = state->computed->alloc(uris, (n_uris + 1) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { if (uris != NULL) { - state->result->alloc(uris, 0, - state->result->pw); + state->computed->alloc(uris, 0, + state->computed->pw); } return CSS_NOMEM; } @@ -111,11 +111,11 @@ css_error cascade_cursor(uint32_t opv, css_style *style, if (n_uris > 0) { lwc_string **temp; - temp = state->result->alloc(uris, + temp = state->computed->alloc(uris, (n_uris + 1) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { - state->result->alloc(uris, 0, state->result->pw); + state->computed->alloc(uris, 0, state->computed->pw); return CSS_NOMEM; } @@ -128,14 +128,14 @@ css_error cascade_cursor(uint32_t opv, css_style *style, isInherit(opv))) { css_error error; - error = set_cursor(state->result, value, uris); + error = set_cursor(state->computed, value, uris); if (error != CSS_OK && n_uris > 0) - state->result->alloc(uris, 0, state->result->pw); + state->computed->alloc(uris, 0, state->computed->pw); return error; } else { if (n_uris > 0) - state->result->alloc(uris, 0, state->result->pw); + state->computed->alloc(uris, 0, state->computed->pw); } return CSS_OK; @@ -162,7 +162,7 @@ css_error set_cursor_from_hint(const css_hint *hint, css_error initial_cursor(css_select_state *state) { - return set_cursor(state->result, CSS_CURSOR_AUTO, NULL); + return set_cursor(state->computed, CSS_CURSOR_AUTO, NULL); } css_error compose_cursor(const css_computed_style *parent, diff --git a/src/select/properties/direction.c b/src/select/properties/direction.c index 12f6ee6..2cc91c8 100644 --- a/src/select/properties/direction.c +++ b/src/select/properties/direction.c @@ -34,7 +34,7 @@ css_error cascade_direction(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_direction(state->result, value); + return set_direction(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_direction_from_hint(const css_hint *hint, css_error initial_direction(css_select_state *state) { - return set_direction(state->result, CSS_DIRECTION_LTR); + return set_direction(state->computed, CSS_DIRECTION_LTR); } css_error compose_direction(const css_computed_style *parent, diff --git a/src/select/properties/display.c b/src/select/properties/display.c index 6f19501..34f0b20 100644 --- a/src/select/properties/display.c +++ b/src/select/properties/display.c @@ -76,7 +76,7 @@ css_error cascade_display(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_display(state->result, value); + return set_display(state->computed, value); } return CSS_OK; @@ -90,7 +90,7 @@ css_error set_display_from_hint(const css_hint *hint, css_error initial_display(css_select_state *state) { - return set_display(state->result, CSS_DISPLAY_INLINE); + return set_display(state->computed, CSS_DISPLAY_INLINE); } css_error compose_display(const css_computed_style *parent, diff --git a/src/select/properties/empty_cells.c b/src/select/properties/empty_cells.c index 09a86b2..dc43f87 100644 --- a/src/select/properties/empty_cells.c +++ b/src/select/properties/empty_cells.c @@ -34,7 +34,7 @@ css_error cascade_empty_cells(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_empty_cells(state->result, value); + return set_empty_cells(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_empty_cells_from_hint(const css_hint *hint, css_error initial_empty_cells(css_select_state *state) { - return set_empty_cells(state->result, CSS_EMPTY_CELLS_SHOW); + return set_empty_cells(state->computed, CSS_EMPTY_CELLS_SHOW); } css_error compose_empty_cells(const css_computed_style *parent, diff --git a/src/select/properties/float.c b/src/select/properties/float.c index f073419..24377af 100644 --- a/src/select/properties/float.c +++ b/src/select/properties/float.c @@ -37,7 +37,7 @@ css_error cascade_float(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_float(state->result, value); + return set_float(state->computed, value); } return CSS_OK; @@ -51,7 +51,7 @@ css_error set_float_from_hint(const css_hint *hint, css_error initial_float(css_select_state *state) { - return set_float(state->result, CSS_FLOAT_NONE); + return set_float(state->computed, CSS_FLOAT_NONE); } css_error compose_float(const css_computed_style *parent, diff --git a/src/select/properties/font_family.c b/src/select/properties/font_family.c index fd2fa3c..a0c7609 100644 --- a/src/select/properties/font_family.c +++ b/src/select/properties/font_family.c @@ -62,13 +62,13 @@ css_error cascade_font_family(uint32_t opv, css_style *style, * first generic-family are ignored. */ /** \todo Do this at bytecode generation time? */ if (value == CSS_FONT_FAMILY_INHERIT && font != NULL) { - temp = state->result->alloc(fonts, + temp = state->computed->alloc(fonts, (n_fonts + 1) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { if (fonts != NULL) { - state->result->alloc(fonts, 0, - state->result->pw); + state->computed->alloc(fonts, 0, + state->computed->pw); } return CSS_NOMEM; } @@ -89,11 +89,11 @@ css_error cascade_font_family(uint32_t opv, css_style *style, if (n_fonts > 0) { lwc_string **temp; - temp = state->result->alloc(fonts, + temp = state->computed->alloc(fonts, (n_fonts + 1) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { - state->result->alloc(fonts, 0, state->result->pw); + state->computed->alloc(fonts, 0, state->computed->pw); return CSS_NOMEM; } @@ -106,14 +106,14 @@ css_error cascade_font_family(uint32_t opv, css_style *style, isInherit(opv))) { css_error error; - error = set_font_family(state->result, value, fonts); + error = set_font_family(state->computed, value, fonts); if (error != CSS_OK && n_fonts > 0) - state->result->alloc(fonts, 0, state->result->pw); + state->computed->alloc(fonts, 0, state->computed->pw); return error; } else { if (n_fonts > 0) - state->result->alloc(fonts, 0, state->result->pw); + state->computed->alloc(fonts, 0, state->computed->pw); } return CSS_OK; @@ -148,7 +148,7 @@ css_error initial_font_family(css_select_state *state) if (error != CSS_OK) return error; - return set_font_family_from_hint(&hint, state->result); + return set_font_family_from_hint(&hint, state->computed); } css_error compose_font_family(const css_computed_style *parent, diff --git a/src/select/properties/font_size.c b/src/select/properties/font_size.c index 49c9130..8b52626 100644 --- a/src/select/properties/font_size.c +++ b/src/select/properties/font_size.c @@ -66,7 +66,7 @@ css_error cascade_font_size(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_font_size(state->result, value, size, unit); + return set_font_size(state->computed, value, size, unit); } return CSS_OK; @@ -81,7 +81,7 @@ css_error set_font_size_from_hint(const css_hint *hint, css_error initial_font_size(css_select_state *state) { - return set_font_size(state->result, CSS_FONT_SIZE_MEDIUM, + return set_font_size(state->computed, CSS_FONT_SIZE_MEDIUM, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/font_style.c b/src/select/properties/font_style.c index f7c648a..0683bfa 100644 --- a/src/select/properties/font_style.c +++ b/src/select/properties/font_style.c @@ -37,7 +37,7 @@ css_error cascade_font_style(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_font_style(state->result, value); + return set_font_style(state->computed, value); } return CSS_OK; @@ -51,7 +51,7 @@ css_error set_font_style_from_hint(const css_hint *hint, css_error initial_font_style(css_select_state *state) { - return set_font_style(state->result, CSS_FONT_STYLE_NORMAL); + return set_font_style(state->computed, CSS_FONT_STYLE_NORMAL); } css_error compose_font_style(const css_computed_style *parent, diff --git a/src/select/properties/font_variant.c b/src/select/properties/font_variant.c index 085469a..f1240cc 100644 --- a/src/select/properties/font_variant.c +++ b/src/select/properties/font_variant.c @@ -34,7 +34,7 @@ css_error cascade_font_variant(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_font_variant(state->result, value); + return set_font_variant(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_font_variant_from_hint(const css_hint *hint, css_error initial_font_variant(css_select_state *state) { - return set_font_variant(state->result, CSS_FONT_VARIANT_NORMAL); + return set_font_variant(state->computed, CSS_FONT_VARIANT_NORMAL); } css_error compose_font_variant(const css_computed_style *parent, diff --git a/src/select/properties/font_weight.c b/src/select/properties/font_weight.c index 4fc59e2..39bb473 100644 --- a/src/select/properties/font_weight.c +++ b/src/select/properties/font_weight.c @@ -67,7 +67,7 @@ css_error cascade_font_weight(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_font_weight(state->result, value); + return set_font_weight(state->computed, value); } return CSS_OK; @@ -81,7 +81,7 @@ css_error set_font_weight_from_hint(const css_hint *hint, css_error initial_font_weight(css_select_state *state) { - return set_font_weight(state->result, CSS_FONT_WEIGHT_NORMAL); + return set_font_weight(state->computed, CSS_FONT_WEIGHT_NORMAL); } css_error compose_font_weight(const css_computed_style *parent, diff --git a/src/select/properties/height.c b/src/select/properties/height.c index dc90c4f..6a0cfae 100644 --- a/src/select/properties/height.c +++ b/src/select/properties/height.c @@ -29,7 +29,7 @@ css_error set_height_from_hint(const css_hint *hint, css_error initial_height(css_select_state *state) { - return set_height(state->result, CSS_HEIGHT_AUTO, 0, CSS_UNIT_PX); + return set_height(state->computed, CSS_HEIGHT_AUTO, 0, CSS_UNIT_PX); } css_error compose_height(const css_computed_style *parent, diff --git a/src/select/properties/helpers.c b/src/select/properties/helpers.c index edc098c..8ce5fc6 100644 --- a/src/select/properties/helpers.c +++ b/src/select/properties/helpers.c @@ -107,7 +107,7 @@ css_error cascade_bg_border_color(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, color); + return fun(state->computed, value, color); } return CSS_OK; @@ -137,7 +137,7 @@ css_error cascade_uri_none(uint32_t opv, css_style *style, /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, uri); + return fun(state->computed, value, uri); } return CSS_OK; @@ -188,7 +188,7 @@ css_error cascade_border_style(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value); + return fun(state->computed, value); } return CSS_OK; @@ -228,7 +228,7 @@ css_error cascade_border_width(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, length, unit); + return fun(state->computed, value, length, unit); } return CSS_OK; @@ -262,7 +262,7 @@ css_error cascade_length_auto(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, length, unit); + return fun(state->computed, value, length, unit); } return CSS_OK; @@ -296,7 +296,7 @@ css_error cascade_length_normal(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, length, unit); + return fun(state->computed, value, length, unit); } return CSS_OK; @@ -330,7 +330,7 @@ css_error cascade_length_none(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, length, unit); + return fun(state->computed, value, length, unit); } return CSS_OK; @@ -358,7 +358,7 @@ css_error cascade_length(uint32_t opv, css_style *style, /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, length, unit); + return fun(state->computed, value, length, unit); } return CSS_OK; @@ -382,7 +382,7 @@ css_error cascade_number(uint32_t opv, css_style *style, /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value, length); + return fun(state->computed, value, length); } return CSS_OK; @@ -411,7 +411,7 @@ css_error cascade_page_break_after_before(uint32_t opv, css_style *style, /** \todo lose fun != NULL */ if (fun != NULL && outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return fun(state->result, value); + return fun(state->computed, value); } return CSS_OK; @@ -444,14 +444,14 @@ css_error cascade_counter_increment_reset(uint32_t opv, css_style *style, val = *((css_fixed *) style->bytecode); advance_bytecode(style, sizeof(val)); - temp = state->result->alloc(counters, + temp = state->computed->alloc(counters, (n_counters + 1) * sizeof(css_computed_counter), - state->result->pw); + state->computed->pw); if (temp == NULL) { if (counters != NULL) { - state->result->alloc(counters, - 0, state->result->pw); + state->computed->alloc(counters, + 0, state->computed->pw); } return CSS_NOMEM; } @@ -478,11 +478,11 @@ css_error cascade_counter_increment_reset(uint32_t opv, css_style *style, if (n_counters > 0) { css_computed_counter *temp; - temp = state->result->alloc(counters, + temp = state->computed->alloc(counters, (n_counters + 1) * sizeof(css_computed_counter), - state->result->pw); + state->computed->pw); if (temp == NULL) { - state->result->alloc(counters, 0, state->result->pw); + state->computed->alloc(counters, 0, state->computed->pw); return CSS_NOMEM; } @@ -496,13 +496,13 @@ css_error cascade_counter_increment_reset(uint32_t opv, css_style *style, isInherit(opv))) { css_error error; - error = fun(state->result, value, counters); + error = fun(state->computed, value, counters); if (error != CSS_OK && n_counters > 0) - state->result->alloc(counters, 0, state->result->pw); + state->computed->alloc(counters, 0, state->computed->pw); return error; } else if (n_counters > 0) { - state->result->alloc(counters, 0, state->result->pw); + state->computed->alloc(counters, 0, state->computed->pw); } return CSS_OK; diff --git a/src/select/properties/left.c b/src/select/properties/left.c index a5c3832..5e0035d 100644 --- a/src/select/properties/left.c +++ b/src/select/properties/left.c @@ -29,7 +29,7 @@ css_error set_left_from_hint(const css_hint *hint, css_error initial_left(css_select_state *state) { - return set_left(state->result, CSS_LEFT_AUTO, 0, CSS_UNIT_PX); + return set_left(state->computed, CSS_LEFT_AUTO, 0, CSS_UNIT_PX); } css_error compose_left(const css_computed_style *parent, diff --git a/src/select/properties/letter_spacing.c b/src/select/properties/letter_spacing.c index 10b1258..f466b69 100644 --- a/src/select/properties/letter_spacing.c +++ b/src/select/properties/letter_spacing.c @@ -29,7 +29,7 @@ css_error set_letter_spacing_from_hint(const css_hint *hint, css_error initial_letter_spacing(css_select_state *state) { - return set_letter_spacing(state->result, CSS_LETTER_SPACING_NORMAL, + return set_letter_spacing(state->computed, CSS_LETTER_SPACING_NORMAL, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/line_height.c b/src/select/properties/line_height.c index b292ddb..8e20bd5 100644 --- a/src/select/properties/line_height.c +++ b/src/select/properties/line_height.c @@ -45,7 +45,7 @@ css_error cascade_line_height(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_line_height(state->result, value, val, unit); + return set_line_height(state->computed, value, val, unit); } return CSS_OK; @@ -60,7 +60,7 @@ css_error set_line_height_from_hint(const css_hint *hint, css_error initial_line_height(css_select_state *state) { - return set_line_height(state->result, CSS_LINE_HEIGHT_NORMAL, + return set_line_height(state->computed, CSS_LINE_HEIGHT_NORMAL, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/list_style_image.c b/src/select/properties/list_style_image.c index 624ef0b..4ebfb28 100644 --- a/src/select/properties/list_style_image.c +++ b/src/select/properties/list_style_image.c @@ -35,7 +35,7 @@ css_error set_list_style_image_from_hint(const css_hint *hint, css_error initial_list_style_image(css_select_state *state) { - return set_list_style_image(state->result, + return set_list_style_image(state->computed, CSS_LIST_STYLE_IMAGE_NONE, NULL); } diff --git a/src/select/properties/list_style_position.c b/src/select/properties/list_style_position.c index d8eb646..17c5eed 100644 --- a/src/select/properties/list_style_position.c +++ b/src/select/properties/list_style_position.c @@ -34,7 +34,7 @@ css_error cascade_list_style_position(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_list_style_position(state->result, value); + return set_list_style_position(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_list_style_position_from_hint(const css_hint *hint, css_error initial_list_style_position(css_select_state *state) { - return set_list_style_position(state->result, + return set_list_style_position(state->computed, CSS_LIST_STYLE_POSITION_OUTSIDE); } diff --git a/src/select/properties/list_style_type.c b/src/select/properties/list_style_type.c index ce9f0a0..37a2bad 100644 --- a/src/select/properties/list_style_type.c +++ b/src/select/properties/list_style_type.c @@ -73,7 +73,7 @@ css_error cascade_list_style_type(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_list_style_type(state->result, value); + return set_list_style_type(state->computed, value); } return CSS_OK; @@ -87,7 +87,7 @@ css_error set_list_style_type_from_hint(const css_hint *hint, css_error initial_list_style_type(css_select_state *state) { - return set_list_style_type(state->result, CSS_LIST_STYLE_TYPE_DISC); + return set_list_style_type(state->computed, CSS_LIST_STYLE_TYPE_DISC); } css_error compose_list_style_type(const css_computed_style *parent, diff --git a/src/select/properties/margin_bottom.c b/src/select/properties/margin_bottom.c index 4d82475..e1be53c 100644 --- a/src/select/properties/margin_bottom.c +++ b/src/select/properties/margin_bottom.c @@ -29,7 +29,7 @@ css_error set_margin_bottom_from_hint(const css_hint *hint, css_error initial_margin_bottom(css_select_state *state) { - return set_margin_bottom(state->result, CSS_MARGIN_SET, 0, CSS_UNIT_PX); + return set_margin_bottom(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } css_error compose_margin_bottom(const css_computed_style *parent, diff --git a/src/select/properties/margin_left.c b/src/select/properties/margin_left.c index 5b3d9f0..bd39871 100644 --- a/src/select/properties/margin_left.c +++ b/src/select/properties/margin_left.c @@ -29,7 +29,7 @@ css_error set_margin_left_from_hint(const css_hint *hint, css_error initial_margin_left(css_select_state *state) { - return set_margin_left(state->result, CSS_MARGIN_SET, 0, CSS_UNIT_PX); + return set_margin_left(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } css_error compose_margin_left(const css_computed_style *parent, diff --git a/src/select/properties/margin_right.c b/src/select/properties/margin_right.c index 2eb3610..8a03165 100644 --- a/src/select/properties/margin_right.c +++ b/src/select/properties/margin_right.c @@ -29,7 +29,7 @@ css_error set_margin_right_from_hint(const css_hint *hint, css_error initial_margin_right(css_select_state *state) { - return set_margin_right(state->result, CSS_MARGIN_SET, 0, CSS_UNIT_PX); + return set_margin_right(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } css_error compose_margin_right(const css_computed_style *parent, diff --git a/src/select/properties/margin_top.c b/src/select/properties/margin_top.c index e2cb23e..878cf27 100644 --- a/src/select/properties/margin_top.c +++ b/src/select/properties/margin_top.c @@ -29,7 +29,7 @@ css_error set_margin_top_from_hint(const css_hint *hint, css_error initial_margin_top(css_select_state *state) { - return set_margin_top(state->result, CSS_MARGIN_SET, 0, CSS_UNIT_PX); + return set_margin_top(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } css_error compose_margin_top(const css_computed_style *parent, diff --git a/src/select/properties/max_height.c b/src/select/properties/max_height.c index 372a62c..cdbc0a0 100644 --- a/src/select/properties/max_height.c +++ b/src/select/properties/max_height.c @@ -29,7 +29,7 @@ css_error set_max_height_from_hint(const css_hint *hint, css_error initial_max_height(css_select_state *state) { - return set_max_height(state->result, CSS_MAX_HEIGHT_NONE, + return set_max_height(state->computed, CSS_MAX_HEIGHT_NONE, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/max_width.c b/src/select/properties/max_width.c index 62f33f9..a8472aa 100644 --- a/src/select/properties/max_width.c +++ b/src/select/properties/max_width.c @@ -29,7 +29,7 @@ css_error set_max_width_from_hint(const css_hint *hint, css_error initial_max_width(css_select_state *state) { - return set_max_width(state->result, CSS_MAX_WIDTH_NONE, 0, CSS_UNIT_PX); + return set_max_width(state->computed, CSS_MAX_WIDTH_NONE, 0, CSS_UNIT_PX); } css_error compose_max_width(const css_computed_style *parent, diff --git a/src/select/properties/min_height.c b/src/select/properties/min_height.c index 0b8221a..8fb1f2b 100644 --- a/src/select/properties/min_height.c +++ b/src/select/properties/min_height.c @@ -29,7 +29,7 @@ css_error set_min_height_from_hint(const css_hint *hint, css_error initial_min_height(css_select_state *state) { - return set_min_height(state->result, CSS_MIN_HEIGHT_SET, + return set_min_height(state->computed, CSS_MIN_HEIGHT_SET, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/min_width.c b/src/select/properties/min_width.c index 438b9dc..9166fba 100644 --- a/src/select/properties/min_width.c +++ b/src/select/properties/min_width.c @@ -29,7 +29,7 @@ css_error set_min_width_from_hint(const css_hint *hint, css_error initial_min_width(css_select_state *state) { - return set_min_width(state->result, CSS_MIN_WIDTH_SET, 0, CSS_UNIT_PX); + return set_min_width(state->computed, CSS_MIN_WIDTH_SET, 0, CSS_UNIT_PX); } css_error compose_min_width(const css_computed_style *parent, diff --git a/src/select/properties/outline_color.c b/src/select/properties/outline_color.c index 10592a7..c444816 100644 --- a/src/select/properties/outline_color.c +++ b/src/select/properties/outline_color.c @@ -35,7 +35,7 @@ css_error cascade_outline_color(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_outline_color(state->result, value, color); + return set_outline_color(state->computed, value, color); } return CSS_OK; @@ -49,7 +49,7 @@ css_error set_outline_color_from_hint(const css_hint *hint, css_error initial_outline_color(css_select_state *state) { - return set_outline_color(state->result, CSS_OUTLINE_COLOR_INVERT, 0); + return set_outline_color(state->computed, CSS_OUTLINE_COLOR_INVERT, 0); } css_error compose_outline_color(const css_computed_style *parent, diff --git a/src/select/properties/outline_style.c b/src/select/properties/outline_style.c index b203ae9..5e80a34 100644 --- a/src/select/properties/outline_style.c +++ b/src/select/properties/outline_style.c @@ -28,7 +28,7 @@ css_error set_outline_style_from_hint(const css_hint *hint, css_error initial_outline_style(css_select_state *state) { - return set_outline_style(state->result, CSS_OUTLINE_STYLE_NONE); + return set_outline_style(state->computed, CSS_OUTLINE_STYLE_NONE); } css_error compose_outline_style(const css_computed_style *parent, diff --git a/src/select/properties/outline_width.c b/src/select/properties/outline_width.c index 07f2107..08b6945 100644 --- a/src/select/properties/outline_width.c +++ b/src/select/properties/outline_width.c @@ -29,7 +29,7 @@ css_error set_outline_width_from_hint(const css_hint *hint, css_error initial_outline_width(css_select_state *state) { - return set_outline_width(state->result, CSS_OUTLINE_WIDTH_MEDIUM, + return set_outline_width(state->computed, CSS_OUTLINE_WIDTH_MEDIUM, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/overflow.c b/src/select/properties/overflow.c index 74adf45..6318d31 100644 --- a/src/select/properties/overflow.c +++ b/src/select/properties/overflow.c @@ -40,7 +40,7 @@ css_error cascade_overflow(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_overflow(state->result, value); + return set_overflow(state->computed, value); } return CSS_OK; @@ -54,7 +54,7 @@ css_error set_overflow_from_hint(const css_hint *hint, css_error initial_overflow(css_select_state *state) { - return set_overflow(state->result, CSS_OVERFLOW_VISIBLE); + return set_overflow(state->computed, CSS_OVERFLOW_VISIBLE); } css_error compose_overflow(const css_computed_style *parent, diff --git a/src/select/properties/padding_bottom.c b/src/select/properties/padding_bottom.c index 1cb4fb2..cbc47d6 100644 --- a/src/select/properties/padding_bottom.c +++ b/src/select/properties/padding_bottom.c @@ -29,7 +29,7 @@ css_error set_padding_bottom_from_hint(const css_hint *hint, css_error initial_padding_bottom(css_select_state *state) { - return set_padding_bottom(state->result, CSS_PADDING_SET, + return set_padding_bottom(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/padding_left.c b/src/select/properties/padding_left.c index b1a01c8..4a4e602 100644 --- a/src/select/properties/padding_left.c +++ b/src/select/properties/padding_left.c @@ -29,7 +29,7 @@ css_error set_padding_left_from_hint(const css_hint *hint, css_error initial_padding_left(css_select_state *state) { - return set_padding_left(state->result, CSS_PADDING_SET, 0, CSS_UNIT_PX); + return set_padding_left(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } css_error compose_padding_left(const css_computed_style *parent, diff --git a/src/select/properties/padding_right.c b/src/select/properties/padding_right.c index 9fffefa..c9dbf07 100644 --- a/src/select/properties/padding_right.c +++ b/src/select/properties/padding_right.c @@ -29,7 +29,7 @@ css_error set_padding_right_from_hint(const css_hint *hint, css_error initial_padding_right(css_select_state *state) { - return set_padding_right(state->result, CSS_PADDING_SET, + return set_padding_right(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/padding_top.c b/src/select/properties/padding_top.c index dfc5b39..7ab62ae 100644 --- a/src/select/properties/padding_top.c +++ b/src/select/properties/padding_top.c @@ -29,7 +29,7 @@ css_error set_padding_top_from_hint(const css_hint *hint, css_error initial_padding_top(css_select_state *state) { - return set_padding_top(state->result, CSS_PADDING_SET, 0, CSS_UNIT_PX); + return set_padding_top(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } css_error compose_padding_top(const css_computed_style *parent, diff --git a/src/select/properties/position.c b/src/select/properties/position.c index c5c882e..1bef4e3 100644 --- a/src/select/properties/position.c +++ b/src/select/properties/position.c @@ -40,7 +40,7 @@ css_error cascade_position(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_position(state->result, value); + return set_position(state->computed, value); } return CSS_OK; @@ -54,7 +54,7 @@ css_error set_position_from_hint(const css_hint *hint, css_error initial_position(css_select_state *state) { - return set_position(state->result, CSS_POSITION_STATIC); + return set_position(state->computed, CSS_POSITION_STATIC); } css_error compose_position(const css_computed_style *parent, diff --git a/src/select/properties/quotes.c b/src/select/properties/quotes.c index da3b737..8d4fcbc 100644 --- a/src/select/properties/quotes.c +++ b/src/select/properties/quotes.c @@ -36,13 +36,13 @@ css_error cascade_quotes(uint32_t opv, css_style *style, close = *((lwc_string **) style->bytecode); advance_bytecode(style, sizeof(lwc_string *)); - temp = state->result->alloc(quotes, + temp = state->computed->alloc(quotes, (n_quotes + 2) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { if (quotes != NULL) { - state->result->alloc(quotes, 0, - state->result->pw); + state->computed->alloc(quotes, 0, + state->computed->pw); } return CSS_NOMEM; } @@ -61,11 +61,11 @@ css_error cascade_quotes(uint32_t opv, css_style *style, if (n_quotes > 0) { lwc_string **temp; - temp = state->result->alloc(quotes, + temp = state->computed->alloc(quotes, (n_quotes + 1) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { - state->result->alloc(quotes, 0, state->result->pw); + state->computed->alloc(quotes, 0, state->computed->pw); return CSS_NOMEM; } @@ -78,14 +78,14 @@ css_error cascade_quotes(uint32_t opv, css_style *style, isInherit(opv))) { css_error error; - error = set_quotes(state->result, value, quotes); + error = set_quotes(state->computed, value, quotes); if (error != CSS_OK && quotes != NULL) - state->result->alloc(quotes, 0, state->result->pw); + state->computed->alloc(quotes, 0, state->computed->pw); return error; } else { if (quotes != NULL) - state->result->alloc(quotes, 0, state->result->pw); + state->computed->alloc(quotes, 0, state->computed->pw); } return CSS_OK; @@ -120,7 +120,7 @@ css_error initial_quotes(css_select_state *state) if (error != CSS_OK) return error; - return set_quotes_from_hint(&hint, state->result); + return set_quotes_from_hint(&hint, state->computed); } css_error compose_quotes(const css_computed_style *parent, diff --git a/src/select/properties/right.c b/src/select/properties/right.c index 9b3a127..2dfdb2f 100644 --- a/src/select/properties/right.c +++ b/src/select/properties/right.c @@ -29,7 +29,7 @@ css_error set_right_from_hint(const css_hint *hint, css_error initial_right(css_select_state *state) { - return set_right(state->result, CSS_RIGHT_AUTO, 0, CSS_UNIT_PX); + return set_right(state->computed, CSS_RIGHT_AUTO, 0, CSS_UNIT_PX); } css_error compose_right(const css_computed_style *parent, diff --git a/src/select/properties/table_layout.c b/src/select/properties/table_layout.c index 04c2141..7cc8792 100644 --- a/src/select/properties/table_layout.c +++ b/src/select/properties/table_layout.c @@ -34,7 +34,7 @@ css_error cascade_table_layout(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_table_layout(state->result, value); + return set_table_layout(state->computed, value); } return CSS_OK; @@ -48,7 +48,7 @@ css_error set_table_layout_from_hint(const css_hint *hint, css_error initial_table_layout(css_select_state *state) { - return set_table_layout(state->result, CSS_TABLE_LAYOUT_AUTO); + return set_table_layout(state->computed, CSS_TABLE_LAYOUT_AUTO); } css_error compose_table_layout(const css_computed_style *parent, diff --git a/src/select/properties/text_align.c b/src/select/properties/text_align.c index b108c7b..2281079 100644 --- a/src/select/properties/text_align.c +++ b/src/select/properties/text_align.c @@ -49,7 +49,7 @@ css_error cascade_text_align(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_text_align(state->result, value); + return set_text_align(state->computed, value); } return CSS_OK; @@ -63,7 +63,7 @@ css_error set_text_align_from_hint(const css_hint *hint, css_error initial_text_align(css_select_state *state) { - return set_text_align(state->result, CSS_TEXT_ALIGN_DEFAULT); + return set_text_align(state->computed, CSS_TEXT_ALIGN_DEFAULT); } css_error compose_text_align(const css_computed_style *parent, diff --git a/src/select/properties/text_decoration.c b/src/select/properties/text_decoration.c index 244b9e1..96ce877 100644 --- a/src/select/properties/text_decoration.c +++ b/src/select/properties/text_decoration.c @@ -42,7 +42,7 @@ css_error cascade_text_decoration(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_text_decoration(state->result, value); + return set_text_decoration(state->computed, value); } return CSS_OK; @@ -56,7 +56,7 @@ css_error set_text_decoration_from_hint(const css_hint *hint, css_error initial_text_decoration(css_select_state *state) { - return set_text_decoration(state->result, CSS_TEXT_DECORATION_NONE); + return set_text_decoration(state->computed, CSS_TEXT_DECORATION_NONE); } css_error compose_text_decoration(const css_computed_style *parent, diff --git a/src/select/properties/text_indent.c b/src/select/properties/text_indent.c index d4221fa..623f88d 100644 --- a/src/select/properties/text_indent.c +++ b/src/select/properties/text_indent.c @@ -29,7 +29,7 @@ css_error set_text_indent_from_hint(const css_hint *hint, css_error initial_text_indent(css_select_state *state) { - return set_text_indent(state->result, CSS_TEXT_INDENT_SET, + return set_text_indent(state->computed, CSS_TEXT_INDENT_SET, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/text_transform.c b/src/select/properties/text_transform.c index 74cded5..80ec86e 100644 --- a/src/select/properties/text_transform.c +++ b/src/select/properties/text_transform.c @@ -40,7 +40,7 @@ css_error cascade_text_transform(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_text_transform(state->result, value); + return set_text_transform(state->computed, value); } return CSS_OK; @@ -54,7 +54,7 @@ css_error set_text_transform_from_hint(const css_hint *hint, css_error initial_text_transform(css_select_state *state) { - return set_text_transform(state->result, CSS_TEXT_TRANSFORM_NONE); + return set_text_transform(state->computed, CSS_TEXT_TRANSFORM_NONE); } css_error compose_text_transform(const css_computed_style *parent, diff --git a/src/select/properties/top.c b/src/select/properties/top.c index 7fe31e7..f982fc9 100644 --- a/src/select/properties/top.c +++ b/src/select/properties/top.c @@ -29,7 +29,7 @@ css_error set_top_from_hint(const css_hint *hint, css_error initial_top(css_select_state *state) { - return set_top(state->result, CSS_TOP_AUTO, 0, CSS_UNIT_PX); + return set_top(state->computed, CSS_TOP_AUTO, 0, CSS_UNIT_PX); } css_error compose_top(const css_computed_style *parent, diff --git a/src/select/properties/unicode_bidi.c b/src/select/properties/unicode_bidi.c index eceee2d..d858b7f 100644 --- a/src/select/properties/unicode_bidi.c +++ b/src/select/properties/unicode_bidi.c @@ -37,7 +37,7 @@ css_error cascade_unicode_bidi(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_unicode_bidi(state->result, value); + return set_unicode_bidi(state->computed, value); } return CSS_OK; @@ -51,7 +51,7 @@ css_error set_unicode_bidi_from_hint(const css_hint *hint, css_error initial_unicode_bidi(css_select_state *state) { - return set_unicode_bidi(state->result, CSS_UNICODE_BIDI_NORMAL); + return set_unicode_bidi(state->computed, CSS_UNICODE_BIDI_NORMAL); } css_error compose_unicode_bidi(const css_computed_style *parent, diff --git a/src/select/properties/vertical_align.c b/src/select/properties/vertical_align.c index eb64b5d..e26dee9 100644 --- a/src/select/properties/vertical_align.c +++ b/src/select/properties/vertical_align.c @@ -62,7 +62,7 @@ css_error cascade_vertical_align(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_vertical_align(state->result, value, length, unit); + return set_vertical_align(state->computed, value, length, unit); } return CSS_OK; @@ -77,7 +77,7 @@ css_error set_vertical_align_from_hint(const css_hint *hint, css_error initial_vertical_align(css_select_state *state) { - return set_vertical_align(state->result, CSS_VERTICAL_ALIGN_BASELINE, + return set_vertical_align(state->computed, CSS_VERTICAL_ALIGN_BASELINE, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/visibility.c b/src/select/properties/visibility.c index 892ecb4..9d5fd9a 100644 --- a/src/select/properties/visibility.c +++ b/src/select/properties/visibility.c @@ -37,7 +37,7 @@ css_error cascade_visibility(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_visibility(state->result, value); + return set_visibility(state->computed, value); } return CSS_OK; @@ -51,7 +51,7 @@ css_error set_visibility_from_hint(const css_hint *hint, css_error initial_visibility(css_select_state *state) { - return set_visibility(state->result, CSS_VISIBILITY_VISIBLE); + return set_visibility(state->computed, CSS_VISIBILITY_VISIBLE); } css_error compose_visibility(const css_computed_style *parent, diff --git a/src/select/properties/voice_family.c b/src/select/properties/voice_family.c index efe60b4..cc1833c 100644 --- a/src/select/properties/voice_family.c +++ b/src/select/properties/voice_family.c @@ -54,13 +54,13 @@ css_error cascade_voice_family(uint32_t opv, css_style *style, * first generic-family are ignored. */ /** \todo Do this at bytecode generation time? */ if (value == 0 && voice != NULL) { - temp = state->result->alloc(voices, + temp = state->computed->alloc(voices, (n_voices + 1) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { if (voices != NULL) { - state->result->alloc(voices, 0, - state->result->pw); + state->computed->alloc(voices, 0, + state->computed->pw); } return CSS_NOMEM; } @@ -81,11 +81,11 @@ css_error cascade_voice_family(uint32_t opv, css_style *style, if (n_voices > 0) { lwc_string **temp; - temp = state->result->alloc(voices, + temp = state->computed->alloc(voices, (n_voices + 1) * sizeof(lwc_string *), - state->result->pw); + state->computed->pw); if (temp == NULL) { - state->result->alloc(voices, 0, state->result->pw); + state->computed->alloc(voices, 0, state->computed->pw); return CSS_NOMEM; } @@ -98,10 +98,10 @@ css_error cascade_voice_family(uint32_t opv, css_style *style, isInherit(opv))) { /** \todo voice-family */ if (n_voices > 0) - state->result->alloc(voices, 0, state->result->pw); + state->computed->alloc(voices, 0, state->computed->pw); } else { if (n_voices > 0) - state->result->alloc(voices, 0, state->result->pw); + state->computed->alloc(voices, 0, state->computed->pw); } return CSS_OK; diff --git a/src/select/properties/white_space.c b/src/select/properties/white_space.c index 9485b69..4fb9caa 100644 --- a/src/select/properties/white_space.c +++ b/src/select/properties/white_space.c @@ -43,7 +43,7 @@ css_error cascade_white_space(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_white_space(state->result, value); + return set_white_space(state->computed, value); } return CSS_OK; @@ -57,7 +57,7 @@ css_error set_white_space_from_hint(const css_hint *hint, css_error initial_white_space(css_select_state *state) { - return set_white_space(state->result, CSS_WHITE_SPACE_NORMAL); + return set_white_space(state->computed, CSS_WHITE_SPACE_NORMAL); } css_error compose_white_space(const css_computed_style *parent, diff --git a/src/select/properties/width.c b/src/select/properties/width.c index add09a4..68e27b3 100644 --- a/src/select/properties/width.c +++ b/src/select/properties/width.c @@ -29,7 +29,7 @@ css_error set_width_from_hint(const css_hint *hint, css_error initial_width(css_select_state *state) { - return set_width(state->result, CSS_WIDTH_AUTO, 0, CSS_UNIT_PX); + return set_width(state->computed, CSS_WIDTH_AUTO, 0, CSS_UNIT_PX); } css_error compose_width(const css_computed_style *parent, diff --git a/src/select/properties/word_spacing.c b/src/select/properties/word_spacing.c index 2e7b505..58a2674 100644 --- a/src/select/properties/word_spacing.c +++ b/src/select/properties/word_spacing.c @@ -29,7 +29,7 @@ css_error set_word_spacing_from_hint(const css_hint *hint, css_error initial_word_spacing(css_select_state *state) { - return set_word_spacing(state->result, CSS_WORD_SPACING_NORMAL, + return set_word_spacing(state->computed, CSS_WORD_SPACING_NORMAL, 0, CSS_UNIT_PX); } diff --git a/src/select/properties/z_index.c b/src/select/properties/z_index.c index aeb01db..343a3f3 100644 --- a/src/select/properties/z_index.c +++ b/src/select/properties/z_index.c @@ -36,7 +36,7 @@ css_error cascade_z_index(uint32_t opv, css_style *style, if (outranks_existing(getOpcode(opv), isImportant(opv), state, isInherit(opv))) { - return set_z_index(state->result, value, index); + return set_z_index(state->computed, value, index); } return CSS_OK; @@ -50,7 +50,7 @@ css_error set_z_index_from_hint(const css_hint *hint, css_error initial_z_index(css_select_state *state) { - return set_z_index(state->result, CSS_Z_INDEX_AUTO, 0); + return set_z_index(state->computed, CSS_Z_INDEX_AUTO, 0); } css_error compose_z_index(const css_computed_style *parent, diff --git a/src/select/select.c b/src/select/select.c index 48062d7..5c68699 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -45,8 +45,10 @@ struct css_select_ctx { void *pw; /**< Client-specific private data */ }; -static css_error set_hint(css_select_state *state, uint32_t i); -static css_error set_initial(css_select_state *state, uint32_t i, void *parent); +static css_error set_hint(css_select_state *state, uint32_t prop); +static css_error set_initial(css_select_state *state, + uint32_t prop, css_pseudo_element pseudo, + void *parent); static css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_origin origin, @@ -65,10 +67,10 @@ static css_error match_universal_combinator(css_select_ctx *ctx, css_select_state *state, void *node, void **next_node); static css_error match_details(css_select_ctx *ctx, void *node, const css_selector_detail *detail, css_select_state *state, - bool *match); + bool *match, css_pseudo_element *pseudo_element); static css_error match_detail(css_select_ctx *ctx, void *node, const css_selector_detail *detail, css_select_state *state, - bool *match, bool *match_pseudo_element); + bool *match, css_pseudo_element *pseudo_element); static css_error cascade_style(const css_style *style, css_select_state *state); #ifdef DEBUG_CHAIN_MATCHING @@ -272,12 +274,11 @@ css_error css_select_ctx_get_sheet(css_select_ctx *ctx, uint32_t index, * * \param ctx Selection context to use * \param node Node to select style for - * \param pseudo_element Pseudo element to select for, instead * \param media Currently active media types * \param inline_style Corresponding inline style for node, or NULL - * \param result Pointer to style to populate (assumed clean) * \param handler Dispatch table of handler functions * \param pw Client-specific private data for handler functions + * \param result Pointer to location to receive result set * \return CSS_OK on success, appropriate error otherwise. * * In computing the style, no reference is made to the parent node's @@ -290,12 +291,11 @@ css_error css_select_ctx_get_sheet(css_select_ctx *ctx, uint32_t index, * update the fully computed style for a node when layout changes. */ css_error css_select_style(css_select_ctx *ctx, void *node, - uint32_t pseudo_element, uint64_t media, - const css_stylesheet *inline_style, - css_computed_style *result, - css_select_handler *handler, void *pw) + uint64_t media, const css_stylesheet *inline_style, + css_select_handler *handler, void *pw, + css_select_results **result) { - uint32_t i; + uint32_t i, j; css_error error; css_select_state state; void *parent = NULL; @@ -303,22 +303,37 @@ css_error css_select_style(css_select_ctx *ctx, void *node, if (ctx == NULL || node == NULL || result == NULL || handler == NULL) return CSS_BADPARM; - /* Inline style has no meaning if selecting for a pseudo element */ - if (pseudo_element != CSS_PSEUDO_ELEMENT_NONE && inline_style != NULL) - return CSS_BADPARM; - /* Set up the selection state */ memset(&state, 0, sizeof(css_select_state)); state.node = node; - state.pseudo_element = pseudo_element; state.media = media; - state.result = result; state.handler = handler; state.pw = pw; - error = handler->parent_node(pw, node, &parent); - if (error) + /* Allocate the result set */ + state.results = ctx->alloc(NULL, sizeof(css_select_results) + + CSS_PSEUDO_ELEMENT_COUNT * + sizeof(css_computed_style *), ctx->pw); + if (state.results == NULL) + return CSS_NOMEM; + + state.results->alloc = ctx->alloc; + state.results->pw = ctx->pw; + + for (i = 0; i < CSS_PSEUDO_ELEMENT_COUNT; i++) + state.results->styles[i] = NULL; + + /* Base element style is guaranteed to exist */ + error = css_computed_style_create(ctx->alloc, ctx->pw, + &state.results->styles[CSS_PSEUDO_ELEMENT_NONE]); + if (error != CSS_OK) { + ctx->alloc(state.results, 0, ctx->pw); return error; + } + + error = handler->parent_node(pw, node, &parent); + if (error != CSS_OK) + goto cleanup; /* Iterate through the top-level stylesheets, selecting styles * from those which apply to our current media requirements and @@ -348,6 +363,11 @@ css_error css_select_style(css_select_ctx *ctx, void *node, /* No bytecode if input was empty or wholly invalid */ if (sel->style != NULL) { + /* Inline style applies to base element only */ + state.current_pseudo = CSS_PSEUDO_ELEMENT_NONE; + state.computed = state.results->styles[ + CSS_PSEUDO_ELEMENT_NONE]; + error = cascade_style(sel->style, &state); if (error != CSS_OK) goto cleanup; @@ -357,26 +377,44 @@ css_error css_select_style(css_select_ctx *ctx, void *node, /* Take account of presentational hints and fix up any remaining * unset properties. */ for (i = 0; i < CSS_N_PROPERTIES; i++) { - /* Apply presentational hints if we're not selecting for - * a pseudo element, and the property is unset or the - * existing property value did not come from an author - * stylesheet or a user sheet using !important. */ - if (pseudo_element == CSS_PSEUDO_ELEMENT_NONE && - (state.props[i].set == false || - (state.props[i].origin != CSS_ORIGIN_AUTHOR && - state.props[i].important == false))) { - error = set_hint(&state, i); - if (error != CSS_OK) - goto cleanup; - } + for (j = 0; j < CSS_PSEUDO_ELEMENT_COUNT; j++) { + prop_state *prop = &state.props[i][j]; + + /* Skip non-existent pseudo elements */ + if (state.results->styles[j] == NULL) + continue; + + /* Apply presentational hints if we're not selecting for + * a pseudo element, and the property is unset or the + * existing property value did not come from an author + * stylesheet or a user sheet using !important. */ + if (j == CSS_PSEUDO_ELEMENT_NONE && + (prop->set == false || + (prop->origin != CSS_ORIGIN_AUTHOR && + prop->important == false))) { + state.current_pseudo = j; + state.computed = state.results->styles[j]; + + error = set_hint(&state, i); + if (error != CSS_OK) + goto cleanup; + } - /* If the property is still unset or it's set to inherit and - * we're the root element, then set it to its initial value. */ - if (state.props[i].set == false || (parent == NULL && - state.props[i].inherit == true)) { - error = set_initial(&state, i, parent); - if (error != CSS_OK) - goto cleanup; + /* If the property is still unset or we're not selecting + * for a pseudo element and it's set to inherit and + * we're the root element, then set it to its initial + * value. */ + if (prop->set == false || + (j == CSS_PSEUDO_ELEMENT_NONE && + parent == NULL && + prop->inherit == true)) { + state.current_pseudo = j; + state.computed = state.results->styles[j]; + + error = set_initial(&state, i, j, parent); + if (error != CSS_OK) + goto cleanup; + } } } @@ -385,14 +423,25 @@ css_error css_select_style(css_select_ctx *ctx, void *node, * computed, and the default border-{top,right,bottom,left}-color * is set to the computed value of color. */ if (parent == NULL) { - error = compute_absolute_values(NULL, result, + /* Only compute absolute values for the base element */ + error = compute_absolute_values(NULL, + state.results->styles[CSS_PSEUDO_ELEMENT_NONE], handler->compute_font_size, pw); if (error != CSS_OK) goto cleanup; } + *result = state.results; error = CSS_OK; + cleanup: + /* Only clean up the results if there's an error. + * If there is no error, we're going to pass ownership of + * the results to the client */ + if (error != CSS_OK && state.results != NULL) { + css_select_results_destroy(state.results); + } + if (ctx->n_sheets > 0 && ctx->sheets[0].sheet != NULL) { if (state.universal != NULL) lwc_string_unref(state.universal); @@ -417,14 +466,40 @@ cleanup: if (state.after != NULL) lwc_string_unref(state.after); } + return error; } +/** + * Destroy a selection result set + * + * \param results Result set to destroy + * \return CSS_OK on success, appropriate error otherwise + */ +css_error css_select_results_destroy(css_select_results *results) +{ + uint32_t i; + + if (results == NULL) + return CSS_BADPARM; + + if (results->styles != NULL) { + for (i = 0; i < CSS_PSEUDO_ELEMENT_COUNT; i++) { + if (results->styles[i] != NULL) + css_computed_style_destroy(results->styles[i]); + } + } + + results->alloc(results, 0, results->pw); + + return CSS_OK; +} + /****************************************************************************** * Selection engine internals below here * ******************************************************************************/ -css_error set_hint(css_select_state *state, uint32_t i) +css_error set_hint(css_select_state *state, uint32_t prop) { css_hint hint; css_error error; @@ -434,35 +509,40 @@ css_error set_hint(css_select_state *state, uint32_t i) /* Retrieve this property's hint from the client */ error = state->handler->node_presentational_hint(state->pw, - state->node, i, &hint); + state->node, prop, &hint); if (error != CSS_OK) return (error == CSS_PROPERTY_NOT_SET) ? CSS_OK : error; /* Hint defined -- set it in the result */ - error = prop_dispatch[i].set_from_hint(&hint, state->result); + error = prop_dispatch[prop].set_from_hint(&hint, state->computed); if (error != CSS_OK) return error; /* Keep selection state in sync with reality */ - state->props[i].set = 1; - state->props[i].specificity = 0; - state->props[i].origin = CSS_ORIGIN_AUTHOR; - state->props[i].important = 0; - state->props[i].inherit = (hint.status == 0); + state->props[prop][CSS_PSEUDO_ELEMENT_NONE].set = 1; + state->props[prop][CSS_PSEUDO_ELEMENT_NONE].specificity = 0; + state->props[prop][CSS_PSEUDO_ELEMENT_NONE].origin = CSS_ORIGIN_AUTHOR; + state->props[prop][CSS_PSEUDO_ELEMENT_NONE].important = 0; + state->props[prop][CSS_PSEUDO_ELEMENT_NONE].inherit = + (hint.status == 0); return CSS_OK; } -css_error set_initial(css_select_state *state, uint32_t i, void *parent) +css_error set_initial(css_select_state *state, + uint32_t prop, css_pseudo_element pseudo, + void *parent) { css_error error; /* Do nothing if this property is inherited (the default state * of a clean computed style is for everything to be set to inherit) * - * If the node is tree root, everything should be defaulted. + * If the node is tree root and we're dealing with the base element, + * everything should be defaulted. */ - if (prop_dispatch[i].inherited == false || parent == NULL) { + if (prop_dispatch[prop].inherited == false || + (pseudo == CSS_PSEUDO_ELEMENT_NONE && parent == NULL)) { /* Remaining properties are neither inherited nor * already set. Thus, we set them to their initial * values here. Except, however, if the property in @@ -472,23 +552,23 @@ css_error set_initial(css_select_state *state, uint32_t i, void *parent) * accessors to return the initial values for the * property. */ - if (prop_dispatch[i].group == GROUP_NORMAL) { - error = prop_dispatch[i].initial(state); + if (prop_dispatch[prop].group == GROUP_NORMAL) { + error = prop_dispatch[prop].initial(state); if (error != CSS_OK) return error; - } else if (prop_dispatch[i].group == GROUP_UNCOMMON && - state->result->uncommon != NULL) { - error = prop_dispatch[i].initial(state); + } else if (prop_dispatch[prop].group == GROUP_UNCOMMON && + state->computed->uncommon != NULL) { + error = prop_dispatch[prop].initial(state); if (error != CSS_OK) return error; - } else if (prop_dispatch[i].group == GROUP_PAGE && - state->result->page != NULL) { - error = prop_dispatch[i].initial(state); + } else if (prop_dispatch[prop].group == GROUP_PAGE && + state->computed->page != NULL) { + error = prop_dispatch[prop].initial(state); if (error != CSS_OK) return error; - } else if (prop_dispatch[i].group == GROUP_AURAL && - state->result->aural != NULL) { - error = prop_dispatch[i].initial(state); + } else if (prop_dispatch[prop].group == GROUP_AURAL && + state->computed->aural != NULL) { + error = prop_dispatch[prop].initial(state); if (error != CSS_OK) return error; } @@ -541,6 +621,8 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, state->sheet = s; state->current_origin = origin; + /** \todo This can be hoisted into css_select_style: + * the lwc context is global now */ error = intern_strings_for_sheet(ctx, s, state); if (error != CSS_OK) return error; @@ -882,6 +964,9 @@ css_error match_selector_chain(css_select_ctx *ctx, { const css_selector *s = selector; void *node = state->node; + const css_selector_detail *detail = &s->data; + bool match = false; + css_pseudo_element pseudo; css_error error; #ifdef DEBUG_CHAIN_MATCHING @@ -890,31 +975,24 @@ css_error match_selector_chain(css_select_ctx *ctx, fprintf(stderr, "\n"); #endif - do { - void *next_node = NULL; - const css_selector_detail *detail = &s->data; - bool match = false; - - /* If this is the first selector in the chain, we must match - * its details. The details of subsequent selectors will be - * matched when processing the combinator. - * - * Note that pseudo elements will only appear as details of - * the first selector in the chain, as the parser will reject - * any selector chains containing pseudo elements anywhere - * else. - */ - if (s == selector) { - /* Match details on this selector */ - error = match_details(ctx, node, detail, state, &match); - if (error != CSS_OK) - return error; + /* Match the details of the first selector in the chain. + * + * Note that pseudo elements will only appear as details of + * the first selector in the chain, as the parser will reject + * any selector chains containing pseudo elements anywhere + * else. + */ + error = match_details(ctx, node, detail, state, &match, &pseudo); + if (error != CSS_OK) + return error; - /* Details don't match, so reject selector chain */ - if (match == false) - return CSS_OK; + /* Details don't match, so reject selector chain */ + if (match == false) + return CSS_OK; - } + /* Iterate up the selector chain, matching combinators */ + do { + void *next_node = NULL; /* Consider any combinator on this selector */ if (s->data.comb != CSS_COMBINATOR_NONE && @@ -953,6 +1031,17 @@ css_error match_selector_chain(css_select_ctx *ctx, if (((css_rule_selector *) selector->rule)->style == NULL) return CSS_OK; + /* Ensure that the appropriate computed style exists */ + if (state->results->styles[pseudo] == NULL) { + error = css_computed_style_create(ctx->alloc, ctx->pw, + &state->results->styles[pseudo]); + if (error != CSS_OK) + return error; + } + + state->current_pseudo = pseudo; + state->computed = state->results->styles[pseudo]; + return cascade_style(((css_rule_selector *) selector->rule)->style, state); } @@ -994,7 +1083,8 @@ css_error match_named_combinator(css_select_ctx *ctx, css_combinator type, if (n != NULL) { /* Match its details */ - error = match_details(ctx, n, detail, state, &match); + error = match_details(ctx, n, detail, state, + &match, NULL); if (error != CSS_OK) return error; @@ -1046,7 +1136,8 @@ css_error match_universal_combinator(css_select_ctx *ctx, css_combinator type, if (n != NULL) { /* Match its details */ - error = match_details(ctx, n, detail, state, &match); + error = match_details(ctx, n, detail, state, + &match, NULL); if (error != CSS_OK) return error; @@ -1070,10 +1161,10 @@ css_error match_universal_combinator(css_select_ctx *ctx, css_combinator type, css_error match_details(css_select_ctx *ctx, void *node, const css_selector_detail *detail, css_select_state *state, - bool *match) + bool *match, css_pseudo_element *pseudo_element) { css_error error; - bool match_pseudo_element = false; + css_pseudo_element pseudo = CSS_PSEUDO_ELEMENT_NONE; /* We match by default (if there are no details than the element * selector, then we must match) */ @@ -1086,8 +1177,7 @@ css_error match_details(css_select_ctx *ctx, void *node, * can be avoided unless absolutely necessary)? */ do { - error = match_detail(ctx, node, detail, state, match, - &match_pseudo_element); + error = match_detail(ctx, node, detail, state, match, &pseudo); if (error != CSS_OK) return error; @@ -1101,19 +1191,16 @@ css_error match_details(css_select_ctx *ctx, void *node, detail = NULL; } while (detail != NULL); - /* If we're selecting for a pseudo element and the selector chain did - * not match the pseudo element, it's not a match; reject the selector - * chain */ - if (state->pseudo_element != CSS_PSEUDO_ELEMENT_NONE && - match_pseudo_element == false) - *match = false; + /* Return the applicable pseudo element, if required */ + if (pseudo_element != NULL) + *pseudo_element = pseudo; return CSS_OK; } css_error match_detail(css_select_ctx *ctx, void *node, const css_selector_detail *detail, css_select_state *state, - bool *match, bool *match_pseudo_element) + bool *match, css_pseudo_element *pseudo_element) { css_error error = CSS_OK; @@ -1160,26 +1247,16 @@ css_error match_detail(css_select_ctx *ctx, void *node, *match = false; break; case CSS_SELECTOR_PSEUDO_ELEMENT: - if (detail->name == state->first_line && - state->pseudo_element == - CSS_PSEUDO_ELEMENT_FIRST_LINE) { - *match = true; - *match_pseudo_element = true; - } else if (detail->name == state->first_letter && - state->pseudo_element == - CSS_PSEUDO_ELEMENT_FIRST_LETTER) { - *match = true; - *match_pseudo_element = true; - } else if (detail->name == state->before && - state->pseudo_element == - CSS_PSEUDO_ELEMENT_BEFORE) { - *match = true; - *match_pseudo_element = true; - } else if (detail->name == state->after && - state->pseudo_element == - CSS_PSEUDO_ELEMENT_AFTER) { - *match = true; - *match_pseudo_element = true; + *match = true; + + if (detail->name == state->first_line) { + *pseudo_element = CSS_PSEUDO_ELEMENT_FIRST_LINE; + } else if (detail->name == state->first_letter) { + *pseudo_element = CSS_PSEUDO_ELEMENT_FIRST_LETTER; + } else if (detail->name == state->before) { + *pseudo_element = CSS_PSEUDO_ELEMENT_BEFORE; + } else if (detail->name == state->after) { + *pseudo_element = CSS_PSEUDO_ELEMENT_AFTER; } else *match = false; break; @@ -1228,7 +1305,7 @@ css_error cascade_style(const css_style *style, css_select_state *state) bool outranks_existing(uint16_t op, bool important, css_select_state *state, bool inherit) { - prop_state *existing = &state->props[op]; + prop_state *existing = &state->props[op][state->current_pseudo]; bool outranks = false; /* Sorting on origin & importance gives the following: diff --git a/src/select/select.h b/src/select/select.h index 8d940a0..e66743e 100644 --- a/src/select/select.h +++ b/src/select/select.h @@ -28,9 +28,11 @@ typedef struct prop_state { */ typedef struct css_select_state { void *node; /* Node we're selecting for */ - uint32_t pseudo_element; /* Pseudo element to select for */ uint64_t media; /* Currently active media types */ - css_computed_style *result; /* Style to populate */ + css_select_results *results; /* Result set to populate */ + + css_pseudo_element current_pseudo; /* Current pseudo element */ + css_computed_style *computed; /* Computed style to populate */ css_select_handler *handler; /* Handler functions */ void *pw; /* Client data for handlers */ @@ -53,7 +55,7 @@ typedef struct css_select_state { lwc_string *before; lwc_string *after; - prop_state props[CSS_N_PROPERTIES]; + prop_state props[CSS_N_PROPERTIES][CSS_PSEUDO_ELEMENT_COUNT]; } css_select_state; static inline void advance_bytecode(css_style *style, uint32_t n_bytes) diff --git a/test/select-auto.c b/test/select-auto.c index 8642cfd..6cefbf8 100644 --- a/test/select-auto.c +++ b/test/select-auto.c @@ -651,7 +651,7 @@ void parse_expected(line_ctx *ctx, const char *data, size_t len) void run_test(line_ctx *ctx, const char *exp, size_t explen) { css_select_ctx *select; - css_computed_style *computed; + css_select_results *results; uint32_t i; char *buf; size_t buflen; @@ -673,15 +673,14 @@ void run_test(line_ctx *ctx, const char *exp, size_t explen) ctx->sheets[i].media) == CSS_OK); } - assert(css_computed_style_create(myrealloc, NULL, &computed) == CSS_OK); - testnum++; - assert(css_select_style(select, ctx->target, ctx->pseudo_element, - ctx->media, NULL, computed, &select_handler, ctx) == - CSS_OK); + assert(css_select_style(select, ctx->target, ctx->media, NULL, + &select_handler, ctx, &results) == CSS_OK); + + assert(results->styles[ctx->pseudo_element] != NULL); - dump_computed_style(computed, buf, &buflen); + dump_computed_style(results->styles[ctx->pseudo_element], buf, &buflen); if (8192 - buflen != explen || memcmp(buf, exp, explen) != 0) { printf("Expected (%u):\n%.*s\n", @@ -692,7 +691,7 @@ void run_test(line_ctx *ctx, const char *exp, size_t explen) } /* Clean up */ - css_computed_style_destroy(computed); + css_select_results_destroy(results); css_select_ctx_destroy(select); destroy_tree(ctx->tree); |