diff options
Diffstat (limited to 'src/select/properties')
130 files changed, 2621 insertions, 844 deletions
diff --git a/src/select/properties/Makefile b/src/select/properties/Makefile index 6c6cf84..eee6cc3 100644 --- a/src/select/properties/Makefile +++ b/src/select/properties/Makefile @@ -50,6 +50,7 @@ direction.c \ display.c \ elevation.c \ empty_cells.c \ +fill_opacity.c \ flex_basis.c \ flex_direction.c \ flex_grow.c \ @@ -107,6 +108,7 @@ speak_header.c \ speak_numeral.c \ speak_punctuation.c \ stress.c \ +stroke_opacity.c \ table_layout.c \ text_align.c \ text_decoration.c \ diff --git a/src/select/properties/align_content.c b/src/select/properties/align_content.c index f43cd8e..d432879 100644 --- a/src/select/properties/align_content.c +++ b/src/select/properties/align_content.c @@ -21,7 +21,7 @@ css_error css__cascade_align_content(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case ALIGN_CONTENT_STRETCH: value = CSS_ALIGN_CONTENT_STRETCH; @@ -48,7 +48,7 @@ css_error css__cascade_align_content(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_align_content(state->computed, value); } @@ -66,16 +66,25 @@ css_error css__initial_align_content(css_select_state *state) return set_align_content(state->computed, CSS_ALIGN_CONTENT_STRETCH); } +css_error css__copy_align_content( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_align_content(to, get_align_content(from)); +} + css_error css__compose_align_content(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_align_content(child); - if (type == CSS_ALIGN_CONTENT_INHERIT) { - type = get_align_content(parent); - } - - return set_align_content(result, type); + return css__copy_align_content( + type == CSS_ALIGN_CONTENT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/align_items.c b/src/select/properties/align_items.c index ad69c81..52ca094 100644 --- a/src/select/properties/align_items.c +++ b/src/select/properties/align_items.c @@ -21,7 +21,7 @@ css_error css__cascade_align_items(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case ALIGN_ITEMS_STRETCH: value = CSS_ALIGN_ITEMS_STRETCH; @@ -42,7 +42,7 @@ css_error css__cascade_align_items(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_align_items(state->computed, value); } @@ -60,16 +60,25 @@ css_error css__initial_align_items(css_select_state *state) return set_align_items(state->computed, CSS_ALIGN_ITEMS_STRETCH); } +css_error css__copy_align_items( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_align_items(to, get_align_items(from)); +} + css_error css__compose_align_items(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_align_items(child); - if (type == CSS_ALIGN_ITEMS_INHERIT) { - type = get_align_items(parent); - } - - return set_align_items(result, type); + return css__copy_align_items( + type == CSS_ALIGN_ITEMS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/align_self.c b/src/select/properties/align_self.c index e8e469e..abdb3fe 100644 --- a/src/select/properties/align_self.c +++ b/src/select/properties/align_self.c @@ -21,7 +21,7 @@ css_error css__cascade_align_self(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case ALIGN_SELF_STRETCH: value = CSS_ALIGN_SELF_STRETCH; @@ -45,7 +45,7 @@ css_error css__cascade_align_self(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_align_self(state->computed, value); } @@ -63,16 +63,25 @@ css_error css__initial_align_self(css_select_state *state) return set_align_self(state->computed, CSS_ALIGN_SELF_AUTO); } +css_error css__copy_align_self( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_align_self(to, get_align_self(from)); +} + css_error css__compose_align_self(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_align_self(child); - if (type == CSS_ALIGN_SELF_INHERIT) { - type = get_align_self(parent); - } - - return set_align_self(result, type); + return css__copy_align_self( + type == CSS_ALIGN_SELF_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/azimuth.c b/src/select/properties/azimuth.c index d52110f..bbbb48d 100644 --- a/src/select/properties/azimuth.c +++ b/src/select/properties/azimuth.c @@ -18,7 +18,7 @@ css_error css__cascade_azimuth(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_DEG; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv) & ~AZIMUTH_BEHIND) { case AZIMUTH_ANGLE: val = *((css_fixed *) style->bytecode); @@ -47,7 +47,7 @@ css_error css__cascade_azimuth(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo set computed azimuth */ } @@ -70,6 +70,16 @@ css_error css__initial_azimuth(css_select_state *state) return CSS_OK; } +css_error css__copy_azimuth( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_azimuth(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/background_attachment.c b/src/select/properties/background_attachment.c index 834c830..49194cc 100644 --- a/src/select/properties/background_attachment.c +++ b/src/select/properties/background_attachment.c @@ -21,7 +21,7 @@ css_error css__cascade_background_attachment(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_ATTACHMENT_FIXED: value = CSS_BACKGROUND_ATTACHMENT_FIXED; @@ -33,7 +33,7 @@ css_error css__cascade_background_attachment(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_background_attachment(state->computed, value); } @@ -52,16 +52,25 @@ css_error css__initial_background_attachment(css_select_state *state) CSS_BACKGROUND_ATTACHMENT_SCROLL); } +css_error css__copy_background_attachment( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_background_attachment(to, get_background_attachment(from)); +} + css_error css__compose_background_attachment(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_background_attachment(child); - if (type == CSS_BACKGROUND_ATTACHMENT_INHERIT) { - type = get_background_attachment(parent); - } - - return set_background_attachment(result, type); + return css__copy_background_attachment( + type == CSS_BACKGROUND_ATTACHMENT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_color.c b/src/select/properties/background_color.c index bb90604..1ab61e6 100644 --- a/src/select/properties/background_color.c +++ b/src/select/properties/background_color.c @@ -32,6 +32,20 @@ css_error css__initial_background_color(css_select_state *state) CSS_BACKGROUND_COLOR_COLOR, 0); } +css_error css__copy_background_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_background_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_background_color(to, type, color); +} + css_error css__compose_background_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -39,10 +53,8 @@ css_error css__compose_background_color(const css_computed_style *parent, css_color color; uint8_t type = get_background_color(child, &color); - if (type == CSS_BACKGROUND_COLOR_INHERIT) { - type = get_background_color(parent, &color); - } - - return set_background_color(result, type, color); + return css__copy_background_color( + type == CSS_BACKGROUND_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_image.c b/src/select/properties/background_image.c index 96f7409..68b1e0f 100644 --- a/src/select/properties/background_image.c +++ b/src/select/properties/background_image.c @@ -39,6 +39,20 @@ css_error css__initial_background_image(css_select_state *state) CSS_BACKGROUND_IMAGE_NONE, NULL); } +css_error css__copy_background_image( + const css_computed_style *from, + css_computed_style *to) +{ + lwc_string *url; + uint8_t type = get_background_image(from, &url); + + if (from == to) { + return CSS_OK; + } + + return set_background_image(to, type, url); +} + css_error css__compose_background_image(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -46,10 +60,8 @@ css_error css__compose_background_image(const css_computed_style *parent, lwc_string *url; uint8_t type = get_background_image(child, &url); - if (type == CSS_BACKGROUND_IMAGE_INHERIT) { - type = get_background_image(parent, &url); - } - - return set_background_image(result, type, url); + return css__copy_background_image( + type == CSS_BACKGROUND_IMAGE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_position.c b/src/select/properties/background_position.c index d925b9c..f3fe47c 100644 --- a/src/select/properties/background_position.c +++ b/src/select/properties/background_position.c @@ -23,7 +23,7 @@ css_error css__cascade_background_position(uint32_t opv, css_style *style, uint32_t hunit = UNIT_PX; uint32_t vunit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { value = CSS_BACKGROUND_POSITION_SET; switch (getValue(opv) & 0xf0) { @@ -73,7 +73,7 @@ css_error css__cascade_background_position(uint32_t opv, css_style *style, vunit = css__to_css_unit(vunit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_background_position(state->computed, value, hlength, hunit, vlength, vunit); } @@ -96,6 +96,22 @@ css_error css__initial_background_position(css_select_state *state) 0, CSS_UNIT_PCT, 0, CSS_UNIT_PCT); } +css_error css__copy_background_position( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed hlength = 0, vlength = 0; + css_unit hunit = CSS_UNIT_PX, vunit = CSS_UNIT_PX; + uint8_t type = get_background_position(from, &hlength, &hunit, + &vlength, &vunit); + + if (from == to) { + return CSS_OK; + } + + return set_background_position(to, type, hlength, hunit, vlength, vunit); +} + css_error css__compose_background_position(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -105,12 +121,8 @@ css_error css__compose_background_position(const css_computed_style *parent, uint8_t type = get_background_position(child, &hlength, &hunit, &vlength, &vunit); - if (type == CSS_BACKGROUND_POSITION_INHERIT) { - type = get_background_position(parent, - &hlength, &hunit, &vlength, &vunit); - } - - return set_background_position(result, type, hlength, hunit, - vlength, vunit); + return css__copy_background_position( + type == CSS_BACKGROUND_POSITION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/background_repeat.c b/src/select/properties/background_repeat.c index 3881573..7104bfb 100644 --- a/src/select/properties/background_repeat.c +++ b/src/select/properties/background_repeat.c @@ -21,7 +21,7 @@ css_error css__cascade_background_repeat(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_REPEAT_NO_REPEAT: value = CSS_BACKGROUND_REPEAT_NO_REPEAT; @@ -39,7 +39,7 @@ css_error css__cascade_background_repeat(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_background_repeat(state->computed, value); } @@ -58,16 +58,25 @@ css_error css__initial_background_repeat(css_select_state *state) CSS_BACKGROUND_REPEAT_REPEAT); } +css_error css__copy_background_repeat( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_background_repeat(to, get_background_repeat(from)); +} + css_error css__compose_background_repeat(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_background_repeat(child); - if (type == CSS_BACKGROUND_REPEAT_INHERIT) { - type = get_background_repeat(parent); - } - - return set_background_repeat(result, type); + return css__copy_background_repeat( + type == CSS_BACKGROUND_REPEAT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_bottom_color.c b/src/select/properties/border_bottom_color.c index bdbecb7..1996d71 100644 --- a/src/select/properties/border_bottom_color.c +++ b/src/select/properties/border_bottom_color.c @@ -33,6 +33,20 @@ css_error css__initial_border_bottom_color(css_select_state *state) CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_bottom_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_bottom_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_bottom_color(to, type, color); +} + css_error css__compose_border_bottom_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +54,8 @@ css_error css__compose_border_bottom_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_bottom_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_bottom_color(parent, &color); - } - - return set_border_bottom_color(result, type, color); + return css__copy_border_bottom_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_bottom_style.c b/src/select/properties/border_bottom_style.c index b5caccb..3451c65 100644 --- a/src/select/properties/border_bottom_style.c +++ b/src/select/properties/border_bottom_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_bottom_style(css_select_state *state) return set_border_bottom_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_bottom_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_bottom_style(to, get_border_bottom_style(from)); +} + css_error css__compose_border_bottom_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_bottom_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_bottom_style(parent); - } - - return set_border_bottom_style(result, type); + return css__copy_border_bottom_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_bottom_width.c b/src/select/properties/border_bottom_width.c index b071fba..19f4304 100644 --- a/src/select/properties/border_bottom_width.c +++ b/src/select/properties/border_bottom_width.c @@ -14,16 +14,16 @@ #include "select/properties/properties.h" #include "select/properties/helpers.h" -css_error css__cascade_border_bottom_width(uint32_t opv, css_style *style, +css_error css__cascade_border_bottom_width(uint32_t opv, css_style *width, css_select_state *state) { - return css__cascade_border_width(opv, style, state, set_border_bottom_width); + return css__cascade_border_width(opv, width, state, set_border_bottom_width); } css_error css__set_border_bottom_width_from_hint(const css_hint *hint, - css_computed_style *style) + css_computed_style *width) { - return set_border_bottom_width(style, hint->status, + return set_border_bottom_width(width, hint->status, hint->data.length.value, hint->data.length.unit); } @@ -33,6 +33,21 @@ css_error css__initial_border_bottom_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_bottom_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_bottom_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_bottom_width(to, type, length, unit); +} + css_error css__compose_border_bottom_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_bottom_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_bottom_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_bottom_width(parent, &length, &unit); - } - - return set_border_bottom_width(result, type, length, unit); + return css__copy_border_bottom_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_collapse.c b/src/select/properties/border_collapse.c index 1363c7c..8868e6b 100644 --- a/src/select/properties/border_collapse.c +++ b/src/select/properties/border_collapse.c @@ -21,7 +21,7 @@ css_error css__cascade_border_collapse(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BORDER_COLLAPSE_SEPARATE: value = CSS_BORDER_COLLAPSE_SEPARATE; @@ -33,7 +33,7 @@ css_error css__cascade_border_collapse(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_border_collapse(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_border_collapse(css_select_state *state) return set_border_collapse(state->computed, CSS_BORDER_COLLAPSE_SEPARATE); } +css_error css__copy_border_collapse( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_collapse(to, get_border_collapse(from)); +} + css_error css__compose_border_collapse(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_collapse(child); - if (type == CSS_BORDER_COLLAPSE_INHERIT) { - type = get_border_collapse(parent); - } - - return set_border_collapse(result, type); + return css__copy_border_collapse( + type == CSS_BORDER_COLLAPSE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_left_color.c b/src/select/properties/border_left_color.c index 2880751..60b81ae 100644 --- a/src/select/properties/border_left_color.c +++ b/src/select/properties/border_left_color.c @@ -33,6 +33,20 @@ css_error css__initial_border_left_color(css_select_state *state) CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_left_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_left_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_left_color(to, type, color); +} + css_error css__compose_border_left_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +54,8 @@ css_error css__compose_border_left_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_left_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_left_color(parent, &color); - } - - return set_border_left_color(result, type, color); + return css__copy_border_left_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_left_style.c b/src/select/properties/border_left_style.c index e6472b3..99b5494 100644 --- a/src/select/properties/border_left_style.c +++ b/src/select/properties/border_left_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_left_style(css_select_state *state) return set_border_left_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_left_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_left_style(to, get_border_left_style(from)); +} + css_error css__compose_border_left_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_left_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_left_style(parent); - } - - return set_border_left_style(result, type); + return css__copy_border_left_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_left_width.c b/src/select/properties/border_left_width.c index 1278fa9..e1fc822 100644 --- a/src/select/properties/border_left_width.c +++ b/src/select/properties/border_left_width.c @@ -33,6 +33,21 @@ css_error css__initial_border_left_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_left_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_left_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_left_width(to, type, length, unit); +} + css_error css__compose_border_left_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_left_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_left_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_left_width(parent, &length, &unit); - } - - return set_border_left_width(result, type, length, unit); + return css__copy_border_left_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_right_color.c b/src/select/properties/border_right_color.c index b8563e6..815ca9c 100644 --- a/src/select/properties/border_right_color.c +++ b/src/select/properties/border_right_color.c @@ -33,6 +33,20 @@ css_error css__initial_border_right_color(css_select_state *state) CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_right_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_right_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_right_color(to, type, color); +} + css_error css__compose_border_right_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +54,8 @@ css_error css__compose_border_right_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_right_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_right_color(parent, &color); - } - - return set_border_right_color(result, type, color); + return css__copy_border_right_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_right_style.c b/src/select/properties/border_right_style.c index d75a99e..d14fbfb 100644 --- a/src/select/properties/border_right_style.c +++ b/src/select/properties/border_right_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_right_style(css_select_state *state) return set_border_right_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_right_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_right_style(to, get_border_right_style(from)); +} + css_error css__compose_border_right_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_right_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_right_style(parent); - } - - return set_border_right_style(result, type); + return css__copy_border_right_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_right_width.c b/src/select/properties/border_right_width.c index 18cacd2..93e8f19 100644 --- a/src/select/properties/border_right_width.c +++ b/src/select/properties/border_right_width.c @@ -33,6 +33,21 @@ css_error css__initial_border_right_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_right_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_right_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_right_width(to, type, length, unit); +} + css_error css__compose_border_right_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_right_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_right_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_right_width(parent, &length, &unit); - } - - return set_border_right_width(result, type, length, unit); + return css__copy_border_right_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_spacing.c b/src/select/properties/border_spacing.c index 0077aac..1f70aff 100644 --- a/src/select/properties/border_spacing.c +++ b/src/select/properties/border_spacing.c @@ -23,7 +23,7 @@ css_error css__cascade_border_spacing(uint32_t opv, css_style *style, uint32_t hunit = UNIT_PX; uint32_t vunit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { value = CSS_BORDER_SPACING_SET; hlength = *((css_fixed *) style->bytecode); advance_bytecode(style, sizeof(hlength)); @@ -40,7 +40,7 @@ css_error css__cascade_border_spacing(uint32_t opv, css_style *style, vunit = css__to_css_unit(vunit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_border_spacing(state->computed, value, hlength, hunit, vlength, vunit); } @@ -62,6 +62,22 @@ css_error css__initial_border_spacing(css_select_state *state) 0, CSS_UNIT_PX, 0, CSS_UNIT_PX); } +css_error css__copy_border_spacing( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed hlength = 0, vlength = 0; + css_unit hunit = CSS_UNIT_PX, vunit = CSS_UNIT_PX; + uint8_t type = get_border_spacing(from, &hlength, &hunit, + &vlength, &vunit); + + if (from == to) { + return CSS_OK; + } + + return set_border_spacing(to, type, hlength, hunit, vlength, vunit); +} + css_error css__compose_border_spacing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -71,10 +87,7 @@ css_error css__compose_border_spacing(const css_computed_style *parent, uint8_t type = get_border_spacing(child, &hlength, &hunit, &vlength, &vunit); - if (type == CSS_BORDER_SPACING_INHERIT) { - type = get_border_spacing(parent, - &hlength, &hunit, &vlength, &vunit); - } - - return set_border_spacing(result, type, hlength, hunit, vlength, vunit); + return css__copy_border_spacing( + type == CSS_BORDER_SPACING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_top_color.c b/src/select/properties/border_top_color.c index fd2ced4..ee3feb1 100644 --- a/src/select/properties/border_top_color.c +++ b/src/select/properties/border_top_color.c @@ -31,6 +31,20 @@ css_error css__initial_border_top_color(css_select_state *state) return set_border_top_color(state->computed, CSS_BORDER_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_border_top_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_border_top_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_border_top_color(to, type, color); +} + css_error css__compose_border_top_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -38,10 +52,8 @@ css_error css__compose_border_top_color(const css_computed_style *parent, css_color color; uint8_t type = get_border_top_color(child, &color); - if (type == CSS_BORDER_COLOR_INHERIT) { - type = get_border_top_color(parent, &color); - } - - return set_border_top_color(result, type, color); + return css__copy_border_top_color( + type == CSS_BORDER_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_top_style.c b/src/select/properties/border_top_style.c index 48d6b6d..1d2dc91 100644 --- a/src/select/properties/border_top_style.c +++ b/src/select/properties/border_top_style.c @@ -31,16 +31,25 @@ css_error css__initial_border_top_style(css_select_state *state) return set_border_top_style(state->computed, CSS_BORDER_STYLE_NONE); } +css_error css__copy_border_top_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_border_top_style(to, get_border_top_style(from)); +} + css_error css__compose_border_top_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_border_top_style(child); - if (type == CSS_BORDER_STYLE_INHERIT) { - type = get_border_top_style(parent); - } - - return set_border_top_style(result, type); + return css__copy_border_top_style( + type == CSS_BORDER_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/border_top_width.c b/src/select/properties/border_top_width.c index c0fb7da..18e60cb 100644 --- a/src/select/properties/border_top_width.c +++ b/src/select/properties/border_top_width.c @@ -33,6 +33,21 @@ css_error css__initial_border_top_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_border_top_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_border_top_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_border_top_width(to, type, length, unit); +} + css_error css__compose_border_top_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_border_top_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_border_top_width(child, &length, &unit); - if (type == CSS_BORDER_WIDTH_INHERIT) { - type = get_border_top_width(parent, &length, &unit); - } - - return set_border_top_width(result, type, length, unit); + return css__copy_border_top_width( + type == CSS_BORDER_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/bottom.c b/src/select/properties/bottom.c index 82754f1..fd65ed3 100644 --- a/src/select/properties/bottom.c +++ b/src/select/properties/bottom.c @@ -32,6 +32,21 @@ css_error css__initial_bottom(css_select_state *state) return set_bottom(state->computed, CSS_BOTTOM_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_bottom( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_bottom(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_bottom(to, type, length, unit); +} + css_error css__compose_bottom(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_bottom(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_bottom(child, &length, &unit); - if (type == CSS_BOTTOM_INHERIT) { - type = get_bottom(parent, &length, &unit); - } - - return set_bottom(result, type, length, unit); + return css__copy_bottom( + type == CSS_BOTTOM_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/box_sizing.c b/src/select/properties/box_sizing.c index 2d19c95..471f8a7 100644 --- a/src/select/properties/box_sizing.c +++ b/src/select/properties/box_sizing.c @@ -21,7 +21,7 @@ css_error css__cascade_box_sizing(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BOX_SIZING_CONTENT_BOX: value = CSS_BOX_SIZING_CONTENT_BOX; @@ -33,7 +33,7 @@ css_error css__cascade_box_sizing(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_box_sizing(state->computed, value); } @@ -51,17 +51,25 @@ css_error css__initial_box_sizing(css_select_state *state) return set_box_sizing(state->computed, CSS_BOX_SIZING_CONTENT_BOX); } -css_error css__compose_box_sizing( - const css_computed_style *parent, +css_error css__copy_box_sizing( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_box_sizing(to, get_box_sizing(from)); +} + +css_error css__compose_box_sizing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_box_sizing(child); - if (type == CSS_BOX_SIZING_INHERIT) { - type = get_box_sizing(parent); - } - - return set_box_sizing(result, type); + return css__copy_box_sizing( + type == CSS_BOX_SIZING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/break_after.c b/src/select/properties/break_after.c index 1f253aa..cb382e0 100644 --- a/src/select/properties/break_after.c +++ b/src/select/properties/break_after.c @@ -32,16 +32,25 @@ css_error css__initial_break_after(css_select_state *state) return set_break_after(state->computed, CSS_BREAK_AFTER_AUTO); } +css_error css__copy_break_after( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_break_after(to, get_break_after(from)); +} + css_error css__compose_break_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_break_after(child); - if (type == CSS_BREAK_AFTER_INHERIT) { - type = get_break_after(parent); - } - - return set_break_after(result, type); + return css__copy_break_after( + type == CSS_BREAK_AFTER_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/break_before.c b/src/select/properties/break_before.c index 3dcda76..91b0612 100644 --- a/src/select/properties/break_before.c +++ b/src/select/properties/break_before.c @@ -32,16 +32,25 @@ css_error css__initial_break_before(css_select_state *state) return set_break_before(state->computed, CSS_BREAK_BEFORE_AUTO); } +css_error css__copy_break_before( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_break_before(to, get_break_before(from)); +} + css_error css__compose_break_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_break_before(child); - if (type == CSS_BREAK_BEFORE_INHERIT) { - type = get_break_before(parent); - } - - return set_break_before(result, type); + return css__copy_break_before( + type == CSS_BREAK_BEFORE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/break_inside.c b/src/select/properties/break_inside.c index fdc44c1..d5b8aef 100644 --- a/src/select/properties/break_inside.c +++ b/src/select/properties/break_inside.c @@ -21,7 +21,7 @@ css_error css__cascade_break_inside(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BREAK_INSIDE_AUTO: value = CSS_BREAK_INSIDE_AUTO; @@ -39,7 +39,7 @@ css_error css__cascade_break_inside(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_break_inside(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_break_inside(css_select_state *state) return set_break_inside(state->computed, CSS_BREAK_INSIDE_AUTO); } +css_error css__copy_break_inside( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_break_inside(to, get_break_inside(from)); +} + css_error css__compose_break_inside(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_break_inside(child); - if (type == CSS_BREAK_INSIDE_INHERIT) { - type = get_break_inside(parent); - } - - return set_break_inside(result, type); + return css__copy_break_inside( + type == CSS_BREAK_INSIDE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/caption_side.c b/src/select/properties/caption_side.c index ecccc1d..f0e7693 100644 --- a/src/select/properties/caption_side.c +++ b/src/select/properties/caption_side.c @@ -21,7 +21,7 @@ css_error css__cascade_caption_side(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case CAPTION_SIDE_TOP: value = CSS_CAPTION_SIDE_TOP; @@ -33,7 +33,7 @@ css_error css__cascade_caption_side(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_caption_side(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_caption_side(css_select_state *state) return set_caption_side(state->computed, CSS_CAPTION_SIDE_TOP); } +css_error css__copy_caption_side( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_caption_side(to, get_caption_side(from)); +} + css_error css__compose_caption_side(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_caption_side(child); - if (type == CSS_CAPTION_SIDE_INHERIT) { - type = get_caption_side(parent); - } - - return set_caption_side(result, type); + return css__copy_caption_side( + type == CSS_CAPTION_SIDE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/clear.c b/src/select/properties/clear.c index bbb2673..1fbc48e 100644 --- a/src/select/properties/clear.c +++ b/src/select/properties/clear.c @@ -21,7 +21,7 @@ css_error css__cascade_clear(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case CLEAR_NONE: value = CSS_CLEAR_NONE; @@ -39,7 +39,7 @@ css_error css__cascade_clear(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_clear(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_clear(css_select_state *state) return set_clear(state->computed, CSS_CLEAR_NONE); } +css_error css__copy_clear( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_clear(to, get_clear(from)); +} + css_error css__compose_clear(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_clear(child); - if (type == CSS_CLEAR_INHERIT) { - type = get_clear(parent); - } - - return set_clear(result, type); + return css__copy_clear( + type == CSS_CLEAR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/clip.c b/src/select/properties/clip.c index 2785afb..c0b9c2b 100644 --- a/src/select/properties/clip.c +++ b/src/select/properties/clip.c @@ -22,7 +22,7 @@ css_error css__cascade_clip(uint32_t opv, css_style *style, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, false, false, false, false }; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv) & CLIP_SHAPE_MASK) { case CLIP_SHAPE_RECT: if (getValue(opv) & CLIP_RECT_TOP_AUTO) { @@ -71,7 +71,7 @@ css_error css__cascade_clip(uint32_t opv, css_style *style, rect.lunit = css__to_css_unit(rect.lunit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_clip(state->computed, value, &rect); } @@ -93,6 +93,22 @@ css_error css__initial_clip(css_select_state *state) return set_clip(state->computed, CSS_CLIP_AUTO, &rect); } +css_error css__copy_clip( + const css_computed_style *from, + css_computed_style *to) +{ + css_computed_clip_rect rect = { 0, 0, 0, 0, + CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, + false, false, false, false }; + uint8_t type = get_clip(from, &rect); + + if (from == to) { + return CSS_OK; + } + + return set_clip(to, type, &rect); +} + css_error css__compose_clip(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -102,9 +118,7 @@ css_error css__compose_clip(const css_computed_style *parent, false, false, false, false }; uint8_t type = get_clip(child, &rect); - if (type == CSS_CLIP_INHERIT) { - type = get_clip(parent, &rect); - } - - return set_clip(result, type, &rect); + return css__copy_clip( + type == CSS_CLIP_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/color.c b/src/select/properties/color.c index 806f2cc..6424436 100644 --- a/src/select/properties/color.c +++ b/src/select/properties/color.c @@ -17,11 +17,11 @@ css_error css__cascade_color(uint32_t opv, css_style *style, css_select_state *state) { - bool inherit = isInherit(opv); + enum flag_value flag_value = getFlagValue(opv); uint16_t value = CSS_COLOR_INHERIT; css_color color = 0; - if (inherit == false) { + if (flag_value == FLAG_VALUE__NONE) { switch (getValue(opv)) { case COLOR_TRANSPARENT: value = CSS_COLOR_COLOR; @@ -29,7 +29,7 @@ css_error css__cascade_color(uint32_t opv, css_style *style, case COLOR_CURRENT_COLOR: /* color: currentColor always computes to inherit */ value = CSS_COLOR_INHERIT; - inherit = true; + flag_value = FLAG_VALUE_INHERIT; break; case COLOR_SET: value = CSS_COLOR_COLOR; @@ -40,7 +40,7 @@ css_error css__cascade_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - inherit)) { + flag_value)) { return set_color(state->computed, value, color); } @@ -66,6 +66,20 @@ css_error css__initial_color(css_select_state *state) return css__set_color_from_hint(&hint, state->computed); } +css_error css__copy_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_color(to, type, color); +} + css_error css__compose_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -73,10 +87,8 @@ css_error css__compose_color(const css_computed_style *parent, css_color color; uint8_t type = get_color(child, &color); - if (type == CSS_COLOR_INHERIT) { - type = get_color(parent, &color); - } - - return set_color(result, type, color); + return css__copy_color( + type == CSS_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_count.c b/src/select/properties/column_count.c index efd1243..e502061 100644 --- a/src/select/properties/column_count.c +++ b/src/select/properties/column_count.c @@ -20,7 +20,7 @@ css_error css__cascade_column_count(uint32_t opv, css_style *style, uint16_t value = CSS_COLUMN_COUNT_INHERIT; css_fixed count = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COLUMN_COUNT_SET: value = CSS_COLUMN_COUNT_SET; @@ -30,11 +30,18 @@ css_error css__cascade_column_count(uint32_t opv, css_style *style, case COLUMN_COUNT_AUTO: value = CSS_COLUMN_COUNT_AUTO; break; + case COLUMN_COUNT_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_column_count(state->computed, value, count); } @@ -52,6 +59,20 @@ css_error css__initial_column_count(css_select_state *state) return set_column_count(state->computed, CSS_COLUMN_COUNT_AUTO, 0); } +css_error css__copy_column_count( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t count = 0; + uint8_t type = get_column_count(from, &count); + + if (from == to) { + return CSS_OK; + } + + return set_column_count(to, type, count); +} + css_error css__compose_column_count(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -59,9 +80,7 @@ css_error css__compose_column_count(const css_computed_style *parent, int32_t count = 0; uint8_t type = get_column_count(child, &count); - if (type == CSS_COLUMN_COUNT_INHERIT) { - type = get_column_count(parent, &count); - } - - return set_column_count(result, type, count); + return css__copy_column_count( + type == CSS_COLUMN_COUNT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_fill.c b/src/select/properties/column_fill.c index 31f19f0..f49946c 100644 --- a/src/select/properties/column_fill.c +++ b/src/select/properties/column_fill.c @@ -21,7 +21,7 @@ css_error css__cascade_column_fill(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COLUMN_FILL_BALANCE: value = CSS_COLUMN_FILL_BALANCE; @@ -33,7 +33,7 @@ css_error css__cascade_column_fill(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_column_fill(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_column_fill(css_select_state *state) return set_column_fill(state->computed, CSS_COLUMN_FILL_BALANCE); } +css_error css__copy_column_fill( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_column_fill(to, get_column_fill(from)); +} + css_error css__compose_column_fill(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_column_fill(child); - if (type == CSS_COLUMN_FILL_INHERIT) { - type = get_column_fill(parent); - } - - return set_column_fill(result, type); + return css__copy_column_fill( + type == CSS_COLUMN_FILL_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_gap.c b/src/select/properties/column_gap.c index 087eb0f..5776dc9 100644 --- a/src/select/properties/column_gap.c +++ b/src/select/properties/column_gap.c @@ -33,6 +33,21 @@ css_error css__initial_column_gap(css_select_state *state) INTTOFIX(1), CSS_UNIT_EM); } +css_error css__copy_column_gap( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = INTTOFIX(1); + css_unit unit = CSS_UNIT_EM; + uint8_t type = get_column_gap(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_column_gap(to, type, length, unit); +} + css_error css__compose_column_gap(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,9 +56,7 @@ css_error css__compose_column_gap(const css_computed_style *parent, css_unit unit = CSS_UNIT_EM; uint8_t type = get_column_gap(child, &length, &unit); - if (type == CSS_COLUMN_GAP_INHERIT) { - type = get_column_gap(parent, &length, &unit); - } - - return set_column_gap(result, type, length, unit); + return css__copy_column_gap( + type == CSS_COLUMN_GAP_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_rule_color.c b/src/select/properties/column_rule_color.c index f54c2ab..0b7ec9d 100644 --- a/src/select/properties/column_rule_color.c +++ b/src/select/properties/column_rule_color.c @@ -17,17 +17,18 @@ css_error css__cascade_column_rule_color(uint32_t opv, css_style *style, css_select_state *state) { - bool inherit = isInherit(opv); + enum flag_value flag_value = getFlagValue(opv); uint16_t value = CSS_COLUMN_RULE_COLOR_INHERIT; css_color color = 0; - if (isInherit(opv) == false) { + if (flag_value == FLAG_VALUE__NONE) { switch (getValue(opv)) { case COLUMN_RULE_COLOR_TRANSPARENT: value = CSS_COLUMN_RULE_COLOR_COLOR; break; case COLUMN_RULE_COLOR_CURRENT_COLOR: value = CSS_COLUMN_RULE_COLOR_CURRENT_COLOR; + flag_value = FLAG_VALUE_INHERIT; break; case COLUMN_RULE_COLOR_SET: value = CSS_COLUMN_RULE_COLOR_COLOR; @@ -38,7 +39,7 @@ css_error css__cascade_column_rule_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - inherit)) { + flag_value)) { return set_column_rule_color(state->computed, value, color); } @@ -57,6 +58,20 @@ css_error css__initial_column_rule_color(css_select_state *state) CSS_COLUMN_RULE_COLOR_CURRENT_COLOR, 0); } +css_error css__copy_column_rule_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color; + uint8_t type = get_column_rule_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_column_rule_color(to, type, color); +} + css_error css__compose_column_rule_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -64,10 +79,8 @@ css_error css__compose_column_rule_color(const css_computed_style *parent, css_color color; uint8_t type = get_column_rule_color(child, &color); - if (type == CSS_COLUMN_RULE_COLOR_INHERIT) { - type = get_column_rule_color(parent, &color); - } - - return set_column_rule_color(result, type, color); + return css__copy_column_rule_color( + type == CSS_COLUMN_RULE_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_rule_style.c b/src/select/properties/column_rule_style.c index 1d9a41e..be9579c 100644 --- a/src/select/properties/column_rule_style.c +++ b/src/select/properties/column_rule_style.c @@ -33,16 +33,25 @@ css_error css__initial_column_rule_style(css_select_state *state) CSS_COLUMN_RULE_STYLE_NONE); } +css_error css__copy_column_rule_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_column_rule_style(to, get_column_rule_style(from)); +} + css_error css__compose_column_rule_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_column_rule_style(child); - if (type == CSS_COLUMN_RULE_STYLE_INHERIT) { - type = get_column_rule_style(parent); - } - - return set_column_rule_style(result, type); + return css__copy_column_rule_style( + type == CSS_COLUMN_RULE_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_rule_width.c b/src/select/properties/column_rule_width.c index 3ca9367..c18f26c 100644 --- a/src/select/properties/column_rule_width.c +++ b/src/select/properties/column_rule_width.c @@ -34,6 +34,21 @@ css_error css__initial_column_rule_width(css_select_state *state) CSS_COLUMN_RULE_WIDTH_MEDIUM, 0, CSS_UNIT_PX); } +css_error css__copy_column_rule_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_column_rule_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_column_rule_width(to, type, length, unit); +} + css_error css__compose_column_rule_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -42,10 +57,8 @@ css_error css__compose_column_rule_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_column_rule_width(child, &length, &unit); - if (type == CSS_COLUMN_RULE_WIDTH_INHERIT) { - type = get_column_rule_width(parent, &length, &unit); - } - - return set_column_rule_width(result, type, length, unit); + return css__copy_column_rule_width( + type == CSS_COLUMN_RULE_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_span.c b/src/select/properties/column_span.c index 2c870d3..340150f 100644 --- a/src/select/properties/column_span.c +++ b/src/select/properties/column_span.c @@ -21,7 +21,7 @@ css_error css__cascade_column_span(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COLUMN_SPAN_NONE: value = CSS_COLUMN_SPAN_NONE; @@ -33,7 +33,7 @@ css_error css__cascade_column_span(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_column_span(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_column_span(css_select_state *state) return set_column_span(state->computed, CSS_COLUMN_SPAN_NONE); } +css_error css__copy_column_span( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_column_span(to, get_column_span(from)); +} + css_error css__compose_column_span(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_column_span(child); - if (type == CSS_COLUMN_SPAN_INHERIT) { - type = get_column_span(parent); - } - - return set_column_span(result, type); + return css__copy_column_span( + type == CSS_COLUMN_SPAN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/column_width.c b/src/select/properties/column_width.c index e739ade..d88d022 100644 --- a/src/select/properties/column_width.c +++ b/src/select/properties/column_width.c @@ -33,17 +33,30 @@ css_error css__initial_column_width(css_select_state *state) INTTOFIX(1), CSS_UNIT_EM); } +css_error css__copy_column_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_column_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_column_width(to, type, length, unit); +} + css_error css__compose_column_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { - css_fixed length = INTTOFIX(1); - css_unit unit = CSS_UNIT_EM; + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; uint8_t type = get_column_width(child, &length, &unit); - if (type == CSS_COLUMN_WIDTH_INHERIT) { - type = get_column_width(parent, &length, &unit); - } - - return set_column_width(result, type, length, unit); + return css__copy_column_width( + type == CSS_COLUMN_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/content.c b/src/select/properties/content.c index f75743d..32af49f 100644 --- a/src/select/properties/content.c +++ b/src/select/properties/content.c @@ -21,7 +21,7 @@ css_error css__cascade_content(uint32_t opv, css_style *style, css_computed_content_item *content = NULL; uint32_t n_contents = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); if (v == CONTENT_NORMAL) { @@ -140,7 +140,7 @@ css_error css__cascade_content(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_content(state->computed, value, content); @@ -199,39 +199,40 @@ css_error css__initial_content(css_select_state *state) return set_content(state->computed, CSS_CONTENT_NORMAL, NULL); } -css_error css__compose_content(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_content( + const css_computed_style *from, + css_computed_style *to) { css_error error; css_computed_content_item *copy = NULL; const css_computed_content_item *items = NULL; - uint8_t type = get_content(child, &items); + uint8_t type = get_content(from, &items); - if (type == CSS_CONTENT_INHERIT) { - type = get_content(parent, &items); + if (from == to) { + return CSS_OK; } - if (type == CSS_CONTENT_SET) { - size_t n_items = 0; - const css_computed_content_item *i; - - for (i = items; i->type != CSS_COMPUTED_CONTENT_NONE; - i++) - n_items++; - - copy = malloc((n_items + 1) * - sizeof(css_computed_content_item)); - if (copy == NULL) - return CSS_NOMEM; - - memcpy(copy, items, (n_items + 1) * - sizeof(css_computed_content_item)); + error = css__copy_computed_content_item_array(false, items, ©); + if (error != CSS_OK) { + return CSS_NOMEM; } - error = set_content(result, type, copy); - if (error != CSS_OK && copy != NULL) + error = set_content(to, type, copy); + if (error != CSS_OK) { free(copy); + } return error; } + +css_error css__compose_content(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + const css_computed_content_item *items = NULL; + uint8_t type = get_content(child, &items); + + return css__copy_content( + type == CSS_CONTENT_INHERIT ? parent : child, + result); +} diff --git a/src/select/properties/counter_increment.c b/src/select/properties/counter_increment.c index 1b75c25..2638838 100644 --- a/src/select/properties/counter_increment.c +++ b/src/select/properties/counter_increment.c @@ -48,38 +48,40 @@ css_error css__initial_counter_increment(css_select_state *state) CSS_COUNTER_INCREMENT_NONE, NULL); } -css_error css__compose_counter_increment(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_counter_increment( + const css_computed_style *from, + css_computed_style *to) { css_error error; css_computed_counter *copy = NULL; - const css_computed_counter *items = NULL; - uint8_t type = get_counter_increment(child, &items); + const css_computed_counter *counter_increment = NULL; + uint8_t type = get_counter_increment(from, &counter_increment); - if (type == CSS_COUNTER_INCREMENT_INHERIT) { - type = get_counter_increment(parent, &items); + if (from == to) { + return CSS_OK; } - if (type == CSS_COUNTER_INCREMENT_NAMED && items != NULL) { - size_t n_items = 0; - const css_computed_counter *i; - - for (i = items; i->name != NULL; i++) - n_items++; - - copy = malloc((n_items + 1) * - sizeof(css_computed_counter)); - if (copy == NULL) - return CSS_NOMEM; - - memcpy(copy, items, (n_items + 1) * - sizeof(css_computed_counter)); + error = css__copy_computed_counter_array(false, counter_increment, ©); + if (error != CSS_OK) { + return CSS_NOMEM; } - error = set_counter_increment(result, type, copy); - if (error != CSS_OK && copy != NULL) + error = set_counter_increment(to, type, copy); + if (error != CSS_OK) { free(copy); + } return error; } + +css_error css__compose_counter_increment(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + const css_computed_counter *counter_increment = NULL; + uint8_t type = get_counter_increment(child, &counter_increment); + + return css__copy_counter_increment( + type == CSS_COUNTER_INCREMENT_INHERIT ? parent : child, + result); +} diff --git a/src/select/properties/counter_reset.c b/src/select/properties/counter_reset.c index e4ec8bf..fcb39a3 100644 --- a/src/select/properties/counter_reset.c +++ b/src/select/properties/counter_reset.c @@ -47,38 +47,40 @@ css_error css__initial_counter_reset(css_select_state *state) return set_counter_reset(state->computed, CSS_COUNTER_RESET_NONE, NULL); } -css_error css__compose_counter_reset(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_counter_reset( + const css_computed_style *from, + css_computed_style *to) { css_error error; css_computed_counter *copy = NULL; - const css_computed_counter *items = NULL; - uint8_t type = get_counter_reset(child, &items); + const css_computed_counter *counter_reset = NULL; + uint8_t type = get_counter_reset(from, &counter_reset); - if (type == CSS_COUNTER_RESET_INHERIT) { - type = get_counter_reset(parent, &items); + if (from == to) { + return CSS_OK; } - if (type == CSS_COUNTER_RESET_NAMED && items != NULL) { - size_t n_items = 0; - const css_computed_counter *i; - - for (i = items; i->name != NULL; i++) - n_items++; - - copy = malloc((n_items + 1) * - sizeof(css_computed_counter)); - if (copy == NULL) - return CSS_NOMEM; - - memcpy(copy, items, (n_items + 1) * - sizeof(css_computed_counter)); + error = css__copy_computed_counter_array(false, counter_reset, ©); + if (error != CSS_OK) { + return CSS_NOMEM; } - error = set_counter_reset(result, type, copy); - if (error != CSS_OK && copy != NULL) + error = set_counter_reset(to, type, copy); + if (error != CSS_OK) { free(copy); + } return error; } + +css_error css__compose_counter_reset(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + const css_computed_counter *counter_reset = NULL; + uint8_t type = get_counter_reset(child, &counter_reset); + + return css__copy_counter_reset( + type == CSS_COUNTER_RESET_INHERIT ? parent : child, + result); +} diff --git a/src/select/properties/cue_after.c b/src/select/properties/cue_after.c index e1c09e8..67a2c73 100644 --- a/src/select/properties/cue_after.c +++ b/src/select/properties/cue_after.c @@ -37,6 +37,16 @@ css_error css__initial_cue_after(css_select_state *state) return CSS_OK; } +css_error css__copy_cue_after( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_cue_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/cue_before.c b/src/select/properties/cue_before.c index d562b3b..7c24822 100644 --- a/src/select/properties/cue_before.c +++ b/src/select/properties/cue_before.c @@ -37,6 +37,16 @@ css_error css__initial_cue_before(css_select_state *state) return CSS_OK; } +css_error css__copy_cue_before( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_cue_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/cursor.c b/src/select/properties/cursor.c index c5e50c6..09955c6 100644 --- a/src/select/properties/cursor.c +++ b/src/select/properties/cursor.c @@ -21,7 +21,7 @@ css_error css__cascade_cursor(uint32_t opv, css_style *style, lwc_string **uris = NULL; uint32_t n_uris = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); while (v == CURSOR_URI) { @@ -124,7 +124,7 @@ css_error css__cascade_cursor(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_cursor(state->computed, value, uris); @@ -164,38 +164,40 @@ css_error css__initial_cursor(css_select_state *state) return set_cursor(state->computed, CSS_CURSOR_AUTO, NULL); } -css_error css__compose_cursor(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_cursor( + const css_computed_style *from, + css_computed_style *to) { css_error error; lwc_string **copy = NULL; - lwc_string **urls = NULL; - uint8_t type = get_cursor(child, &urls); + lwc_string **cursor = NULL; + uint8_t type = get_cursor(from, &cursor); - if (type == CSS_CURSOR_INHERIT) { - type = get_cursor(parent, &urls); + if (from == to) { + return CSS_OK; } - if (urls != NULL) { - lwc_string **i; - size_t n_urls = 0; - - for (i = urls; (*i) != NULL; i++) - n_urls++; - - copy = malloc((n_urls + 1) * - sizeof(lwc_string *)); - if (copy == NULL) - return CSS_NOMEM; - - memcpy(copy, urls, (n_urls + 1) * - sizeof(lwc_string *)); + error = css__copy_lwc_string_array(false, cursor, ©); + if (error != CSS_OK) { + return CSS_NOMEM; } - error = set_cursor(result, type, copy); - if (error != CSS_OK && copy != NULL) + error = set_cursor(to, type, copy); + if (error != CSS_OK) { free(copy); + } return error; } + +css_error css__compose_cursor(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + lwc_string **cursor = NULL; + uint8_t type = get_cursor(child, &cursor); + + return css__copy_cursor( + type == CSS_CURSOR_INHERIT ? parent : child, + result); +} diff --git a/src/select/properties/direction.c b/src/select/properties/direction.c index f4a5c46..32bd31e 100644 --- a/src/select/properties/direction.c +++ b/src/select/properties/direction.c @@ -21,7 +21,7 @@ css_error css__cascade_direction(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case DIRECTION_LTR: value = CSS_DIRECTION_LTR; @@ -33,7 +33,7 @@ css_error css__cascade_direction(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_direction(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_direction(css_select_state *state) return set_direction(state->computed, CSS_DIRECTION_LTR); } +css_error css__copy_direction( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_direction(to, get_direction(from)); +} + css_error css__compose_direction(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_direction(child); - if (type == CSS_DIRECTION_INHERIT) { - type = get_direction(parent); - } - - return set_direction(result, type); + return css__copy_direction( + type == CSS_DIRECTION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/display.c b/src/select/properties/display.c index 510d24a..5455d20 100644 --- a/src/select/properties/display.c +++ b/src/select/properties/display.c @@ -21,7 +21,7 @@ css_error css__cascade_display(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case DISPLAY_INLINE: value = CSS_DISPLAY_INLINE; @@ -77,11 +77,17 @@ css_error css__cascade_display(uint32_t opv, css_style *style, case DISPLAY_INLINE_FLEX: value = CSS_DISPLAY_INLINE_FLEX; break; + case DISPLAY_GRID: + value = CSS_DISPLAY_GRID; + break; + case DISPLAY_INLINE_GRID: + value = CSS_DISPLAY_INLINE_GRID; + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_display(state->computed, value); } @@ -99,16 +105,25 @@ css_error css__initial_display(css_select_state *state) return set_display(state->computed, CSS_DISPLAY_INLINE); } +css_error css__copy_display( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_display(to, get_display(from)); +} + css_error css__compose_display(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_display(child); - if (type == CSS_DISPLAY_INHERIT) { - type = get_display(parent); - } - - return set_display(result, type); + return css__copy_display( + type == CSS_DISPLAY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/elevation.c b/src/select/properties/elevation.c index ee7d036..1368ef8 100644 --- a/src/select/properties/elevation.c +++ b/src/select/properties/elevation.c @@ -20,7 +20,7 @@ css_error css__cascade_elevation(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_DEG; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case ELEVATION_ANGLE: val = *((css_fixed *) style->bytecode); @@ -42,7 +42,7 @@ css_error css__cascade_elevation(uint32_t opv, css_style *style, unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo set computed elevation */ } @@ -65,6 +65,16 @@ css_error css__initial_elevation(css_select_state *state) return CSS_OK; } +css_error css__copy_elevation( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_elevation(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/empty_cells.c b/src/select/properties/empty_cells.c index fecdbdc..559fbde 100644 --- a/src/select/properties/empty_cells.c +++ b/src/select/properties/empty_cells.c @@ -21,7 +21,7 @@ css_error css__cascade_empty_cells(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case EMPTY_CELLS_SHOW: value = CSS_EMPTY_CELLS_SHOW; @@ -33,7 +33,7 @@ css_error css__cascade_empty_cells(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_empty_cells(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_empty_cells(css_select_state *state) return set_empty_cells(state->computed, CSS_EMPTY_CELLS_SHOW); } +css_error css__copy_empty_cells( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_empty_cells(to, get_empty_cells(from)); +} + css_error css__compose_empty_cells(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_empty_cells(child); - if (type == CSS_EMPTY_CELLS_INHERIT) { - type = get_empty_cells(parent); - } - - return set_empty_cells(result, type); + return css__copy_empty_cells( + type == CSS_EMPTY_CELLS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/fill_opacity.c b/src/select/properties/fill_opacity.c new file mode 100644 index 0000000..af0b52b --- /dev/null +++ b/src/select/properties/fill_opacity.c @@ -0,0 +1,73 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_fill_opacity(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_FILL_OPACITY_INHERIT; + css_fixed fill_opacity = 0; + + if (hasFlagValue(opv) == false) { + value = CSS_FILL_OPACITY_SET; + + fill_opacity = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(fill_opacity)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_fill_opacity(state->computed, value, fill_opacity); + } + + return CSS_OK; +} + +css_error css__set_fill_opacity_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_fill_opacity(style, hint->status, hint->data.fixed); +} + +css_error css__initial_fill_opacity(css_select_state *state) +{ + return set_fill_opacity(state->computed, CSS_FILL_OPACITY_SET, INTTOFIX(1)); +} + +css_error css__copy_fill_opacity( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed fill_opacity = 0; + uint8_t type = get_fill_opacity(from, &fill_opacity); + + if (from == to) { + return CSS_OK; + } + + return set_fill_opacity(to, type, fill_opacity); +} + +css_error css__compose_fill_opacity(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed fill_opacity = 0; + uint8_t type = get_fill_opacity(child, &fill_opacity); + + return css__copy_fill_opacity( + type == CSS_FILL_OPACITY_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/flex_basis.c b/src/select/properties/flex_basis.c index 1a92a6b..ed614c0 100644 --- a/src/select/properties/flex_basis.c +++ b/src/select/properties/flex_basis.c @@ -21,7 +21,7 @@ css_error css__cascade_flex_basis(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FLEX_BASIS_AUTO: value = CSS_FLEX_BASIS_AUTO; @@ -36,13 +36,20 @@ css_error css__cascade_flex_basis(uint32_t opv, css_style *style, unit = *((uint32_t *) style->bytecode); advance_bytecode(style, sizeof(unit)); break; + case FLEX_BASIS_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_flex_basis(state->computed, value, length, unit); } @@ -62,6 +69,21 @@ css_error css__initial_flex_basis(css_select_state *state) CSS_UNIT_PX); } +css_error css__copy_flex_basis( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_flex_basis(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_flex_basis(to, type, length, unit); +} + css_error css__compose_flex_basis(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -70,10 +92,8 @@ css_error css__compose_flex_basis(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_flex_basis(child, &length, &unit); - if (type == CSS_FLEX_BASIS_INHERIT) { - type = get_flex_basis(parent, &length, &unit); - } - - return set_flex_basis(result, type, length, unit); + return css__copy_flex_basis( + type == CSS_FLEX_BASIS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/flex_direction.c b/src/select/properties/flex_direction.c index 79703be..1d979be 100644 --- a/src/select/properties/flex_direction.c +++ b/src/select/properties/flex_direction.c @@ -21,7 +21,7 @@ css_error css__cascade_flex_direction(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FLEX_DIRECTION_ROW: value = CSS_FLEX_DIRECTION_ROW; @@ -39,7 +39,7 @@ css_error css__cascade_flex_direction(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_flex_direction(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_flex_direction(css_select_state *state) return set_flex_direction(state->computed, CSS_FLEX_DIRECTION_ROW); } +css_error css__copy_flex_direction( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_flex_direction(to, get_flex_direction(from)); +} + css_error css__compose_flex_direction(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_flex_direction(child); - if (type == CSS_FLEX_DIRECTION_INHERIT) { - type = get_flex_direction(parent); - } - - return set_flex_direction(result, type); + return css__copy_flex_direction( + type == CSS_FLEX_DIRECTION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/flex_grow.c b/src/select/properties/flex_grow.c index 7f37cfe..d4fbf5d 100644 --- a/src/select/properties/flex_grow.c +++ b/src/select/properties/flex_grow.c @@ -20,15 +20,26 @@ css_error css__cascade_flex_grow(uint32_t opv, css_style *style, uint16_t value = CSS_FLEX_GROW_INHERIT; css_fixed flex_grow = 0; - if (isInherit(opv) == false) { - value = CSS_FLEX_GROW_SET; + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case FLEX_GROW_SET: + value = CSS_FLEX_GROW_SET; - flex_grow = *((css_fixed *) style->bytecode); - advance_bytecode(style, sizeof(flex_grow)); + flex_grow = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(flex_grow)); + break; + case FLEX_GROW_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; + } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_flex_grow(state->computed, value, flex_grow); } @@ -46,6 +57,20 @@ css_error css__initial_flex_grow(css_select_state *state) return set_flex_grow(state->computed, CSS_FLEX_GROW_SET, INTTOFIX(0)); } +css_error css__copy_flex_grow( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed flex_grow = 0; + uint8_t type = get_flex_grow(from, &flex_grow); + + if (from == to) { + return CSS_OK; + } + + return set_flex_grow(to, type, flex_grow); +} + css_error css__compose_flex_grow(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -53,10 +78,8 @@ css_error css__compose_flex_grow(const css_computed_style *parent, css_fixed flex_grow = 0; uint8_t type = get_flex_grow(child, &flex_grow); - if (type == CSS_FLEX_GROW_INHERIT) { - type = get_flex_grow(parent, &flex_grow); - } - - return set_flex_grow(result, type, flex_grow); + return css__copy_flex_grow( + type == CSS_FLEX_GROW_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/flex_shrink.c b/src/select/properties/flex_shrink.c index d1acd2a..3075d7b 100644 --- a/src/select/properties/flex_shrink.c +++ b/src/select/properties/flex_shrink.c @@ -20,15 +20,26 @@ css_error css__cascade_flex_shrink(uint32_t opv, css_style *style, uint16_t value = CSS_FLEX_SHRINK_INHERIT; css_fixed flex_shrink = 0; - if (isInherit(opv) == false) { - value = CSS_FLEX_SHRINK_SET; + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case FLEX_SHRINK_SET: + value = CSS_FLEX_SHRINK_SET; - flex_shrink = *((css_fixed *) style->bytecode); - advance_bytecode(style, sizeof(flex_shrink)); + flex_shrink = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(flex_shrink)); + break; + case FLEX_SHRINK_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; + } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_flex_shrink(state->computed, value, flex_shrink); } @@ -46,6 +57,20 @@ css_error css__initial_flex_shrink(css_select_state *state) return set_flex_shrink(state->computed, CSS_FLEX_SHRINK_SET, INTTOFIX(1)); } +css_error css__copy_flex_shrink( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed flex_shrink = 0; + uint8_t type = get_flex_shrink(from, &flex_shrink); + + if (from == to) { + return CSS_OK; + } + + return set_flex_shrink(to, type, flex_shrink); +} + css_error css__compose_flex_shrink(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -53,10 +78,8 @@ css_error css__compose_flex_shrink(const css_computed_style *parent, css_fixed flex_shrink = 0; uint8_t type = get_flex_shrink(child, &flex_shrink); - if (type == CSS_FLEX_SHRINK_INHERIT) { - type = get_flex_shrink(parent, &flex_shrink); - } - - return set_flex_shrink(result, type, flex_shrink); + return css__copy_flex_shrink( + type == CSS_FLEX_SHRINK_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/flex_wrap.c b/src/select/properties/flex_wrap.c index 688a9b6..3ca9b74 100644 --- a/src/select/properties/flex_wrap.c +++ b/src/select/properties/flex_wrap.c @@ -21,7 +21,7 @@ css_error css__cascade_flex_wrap(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FLEX_WRAP_NOWRAP: value = CSS_FLEX_WRAP_NOWRAP; @@ -36,7 +36,7 @@ css_error css__cascade_flex_wrap(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_flex_wrap(state->computed, value); } @@ -54,16 +54,27 @@ css_error css__initial_flex_wrap(css_select_state *state) return set_flex_wrap(state->computed, CSS_FLEX_WRAP_NOWRAP); } +css_error css__copy_flex_wrap( + const css_computed_style *from, + css_computed_style *to) +{ + uint8_t type = get_flex_wrap(from); + + if (from == to) { + return CSS_OK; + } + + return set_flex_wrap(to, type); +} + css_error css__compose_flex_wrap(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_flex_wrap(child); - if (type == CSS_FLEX_WRAP_INHERIT) { - type = get_flex_wrap(parent); - } - - return set_flex_wrap(result, type); + return css__copy_flex_wrap( + type == CSS_FLEX_WRAP_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/float.c b/src/select/properties/float.c index c3ba909..6d009bb 100644 --- a/src/select/properties/float.c +++ b/src/select/properties/float.c @@ -21,7 +21,7 @@ css_error css__cascade_float(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FLOAT_LEFT: value = CSS_FLOAT_LEFT; @@ -36,7 +36,7 @@ css_error css__cascade_float(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_float(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_float(css_select_state *state) return set_float(state->computed, CSS_FLOAT_NONE); } +css_error css__copy_float( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_float(to, get_float(from)); +} + css_error css__compose_float(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_float(child); - if (type == CSS_FLOAT_INHERIT) { - type = get_float(parent); - } - - return set_float(result, type); + return css__copy_float( + type == CSS_FLOAT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_family.c b/src/select/properties/font_family.c index f853fcc..b0183e2 100644 --- a/src/select/properties/font_family.c +++ b/src/select/properties/font_family.c @@ -21,7 +21,7 @@ css_error css__cascade_font_family(uint32_t opv, css_style *style, lwc_string **fonts = NULL; uint32_t n_fonts = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); while (v != FONT_FAMILY_END) { @@ -134,7 +134,7 @@ css_error css__cascade_font_family(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_font_family(state->computed, value, fonts); @@ -182,42 +182,41 @@ css_error css__initial_font_family(css_select_state *state) return css__set_font_family_from_hint(&hint, state->computed); } -css_error css__compose_font_family(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_font_family( + const css_computed_style *from, + css_computed_style *to) { css_error error; - lwc_string **names = NULL; - uint8_t type = get_font_family(child, &names); - - if (type == CSS_FONT_FAMILY_INHERIT || result != child) { - size_t n_names = 0; - lwc_string **copy = NULL; - - if (type == CSS_FONT_FAMILY_INHERIT) - type = get_font_family(parent, &names); + lwc_string **copy = NULL; + lwc_string **font_family = NULL; + uint8_t type = get_font_family(from, &font_family); - if (names != NULL) { - lwc_string **i; - - for (i = names; (*i) != NULL; i++) - n_names++; + if (from == to) { + return CSS_OK; + } - copy = malloc((n_names + 1) * sizeof(lwc_string *)); - if (copy == NULL) - return CSS_NOMEM; + error = css__copy_lwc_string_array(false, font_family, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - memcpy(copy, names, (n_names + 1) * - sizeof(lwc_string *)); - } + error = set_font_family(to, type, copy); + if (error != CSS_OK) { + free(copy); + } - error = set_font_family(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + return error; +} - return error; - } +css_error css__compose_font_family(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + lwc_string **font_family = NULL; + uint8_t type = get_font_family(child, &font_family); - return CSS_OK; + return css__copy_font_family( + type == CSS_FONT_FAMILY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_size.c b/src/select/properties/font_size.c index a0269be..e4141d6 100644 --- a/src/select/properties/font_size.c +++ b/src/select/properties/font_size.c @@ -21,7 +21,7 @@ css_error css__cascade_font_size(uint32_t opv, css_style *style, css_fixed size = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_SIZE_DIMENSION: value = CSS_FONT_SIZE_DIMENSION; @@ -59,13 +59,20 @@ css_error css__cascade_font_size(uint32_t opv, css_style *style, case FONT_SIZE_SMALLER: value = CSS_FONT_SIZE_SMALLER; break; + case FONT_SIZE_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_size(state->computed, value, size, unit); } @@ -85,6 +92,21 @@ css_error css__initial_font_size(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_font_size( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed size = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_font_size(from, &size, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_font_size(to, type, size, unit); +} + css_error css__compose_font_size(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -93,10 +115,8 @@ css_error css__compose_font_size(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_font_size(child, &size, &unit); - if (type == CSS_FONT_SIZE_INHERIT) { - type = get_font_size(parent, &size, &unit); - } - - return set_font_size(result, type, size, unit); + return css__copy_font_size( + type == CSS_FONT_SIZE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_style.c b/src/select/properties/font_style.c index 0ba1fdd..fe605b8 100644 --- a/src/select/properties/font_style.c +++ b/src/select/properties/font_style.c @@ -21,7 +21,7 @@ css_error css__cascade_font_style(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_STYLE_NORMAL: value = CSS_FONT_STYLE_NORMAL; @@ -36,7 +36,7 @@ css_error css__cascade_font_style(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_style(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_font_style(css_select_state *state) return set_font_style(state->computed, CSS_FONT_STYLE_NORMAL); } +css_error css__copy_font_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_font_style(to, get_font_style(from)); +} + css_error css__compose_font_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_font_style(child); - if (type == CSS_FONT_STYLE_INHERIT) { - type= get_font_style(parent); - } - - return set_font_style(result, type); + return css__copy_font_style( + type == CSS_FONT_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_variant.c b/src/select/properties/font_variant.c index a9b6e56..9668fc3 100644 --- a/src/select/properties/font_variant.c +++ b/src/select/properties/font_variant.c @@ -21,7 +21,7 @@ css_error css__cascade_font_variant(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_VARIANT_NORMAL: value = CSS_FONT_VARIANT_NORMAL; @@ -33,7 +33,7 @@ css_error css__cascade_font_variant(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_variant(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_font_variant(css_select_state *state) return set_font_variant(state->computed, CSS_FONT_VARIANT_NORMAL); } +css_error css__copy_font_variant( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_font_variant(to, get_font_variant(from)); +} + css_error css__compose_font_variant(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_font_variant(child); - if (type == CSS_FONT_VARIANT_INHERIT) { - type = get_font_variant(parent); - } - - return set_font_variant(result, type); + return css__copy_font_variant( + type == CSS_FONT_VARIANT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/font_weight.c b/src/select/properties/font_weight.c index c0c2f2b..da918a1 100644 --- a/src/select/properties/font_weight.c +++ b/src/select/properties/font_weight.c @@ -21,7 +21,7 @@ css_error css__cascade_font_weight(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case FONT_WEIGHT_NORMAL: value = CSS_FONT_WEIGHT_NORMAL; @@ -66,7 +66,7 @@ css_error css__cascade_font_weight(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_font_weight(state->computed, value); } @@ -84,16 +84,25 @@ css_error css__initial_font_weight(css_select_state *state) return set_font_weight(state->computed, CSS_FONT_WEIGHT_NORMAL); } +css_error css__copy_font_weight( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_font_weight(to, get_font_weight(from)); +} + css_error css__compose_font_weight(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_font_weight(child); - if (type == CSS_FONT_WEIGHT_INHERIT) { - type = get_font_weight(parent); - } - - return set_font_weight(result, type); + return css__copy_font_weight( + type == CSS_FONT_WEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/height.c b/src/select/properties/height.c index 1d74c4a..d449e72 100644 --- a/src/select/properties/height.c +++ b/src/select/properties/height.c @@ -32,6 +32,21 @@ css_error css__initial_height(css_select_state *state) return set_height(state->computed, CSS_HEIGHT_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_height(to, type, length, unit); +} + css_error css__compose_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_height(child, &length, &unit); - if (type == CSS_HEIGHT_INHERIT) { - type = get_height(parent, &length, &unit); - } - - return set_height(result, type, length, unit); + return css__copy_height( + type == CSS_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/helpers.c b/src/select/properties/helpers.c index 40936dd..f1f1d9f 100644 --- a/src/select/properties/helpers.c +++ b/src/select/properties/helpers.c @@ -33,7 +33,7 @@ css_error css__cascade_bg_border_color(uint32_t opv, css_style *style, assert(CSS_BACKGROUND_COLOR_CURRENT_COLOR == (enum css_background_color_e)CSS_BORDER_COLOR_CURRENT_COLOR); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_COLOR_TRANSPARENT: value = CSS_BACKGROUND_COLOR_COLOR; @@ -50,7 +50,7 @@ css_error css__cascade_bg_border_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, color); } @@ -65,7 +65,7 @@ css_error css__cascade_uri_none(uint32_t opv, css_style *style, uint16_t value = CSS_BACKGROUND_IMAGE_INHERIT; lwc_string *uri = NULL; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BACKGROUND_IMAGE_NONE: value = CSS_BACKGROUND_IMAGE_NONE; @@ -80,7 +80,7 @@ css_error css__cascade_uri_none(uint32_t opv, css_style *style, /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value, uri); } @@ -95,7 +95,7 @@ css_error css__cascade_border_style(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BORDER_STYLE_NONE: value = CSS_BORDER_STYLE_NONE; @@ -131,7 +131,7 @@ css_error css__cascade_border_style(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value); } @@ -147,7 +147,7 @@ css_error css__cascade_border_width(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BORDER_WIDTH_SET: value = CSS_BORDER_WIDTH_WIDTH; @@ -165,13 +165,20 @@ css_error css__cascade_border_width(uint32_t opv, css_style *style, case BORDER_WIDTH_THICK: value = CSS_BORDER_WIDTH_THICK; break; + case BORDER_WIDTH_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -187,7 +194,7 @@ css_error css__cascade_length_auto(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BOTTOM_SET: value = CSS_BOTTOM_SET; @@ -199,13 +206,64 @@ css_error css__cascade_length_auto(uint32_t opv, css_style *style, case BOTTOM_AUTO: value = CSS_BOTTOM_AUTO; break; + case BOTTOM_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { + return fun(state->computed, value, length, unit); + } + + return CSS_OK; +} + +css_error css__cascade_length_auto_calc(uint32_t opv, css_style *style, + css_select_state *state, + css_error (*fun)(css_computed_style *, uint8_t, css_fixed_or_calc, + css_unit)) +{ + uint16_t value = CSS_BOTTOM_INHERIT; + css_fixed_or_calc length = (css_fixed_or_calc)0; + uint32_t unit = CSS_UNIT_PX; + uint32_t snum = 0; + + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case BOTTOM_SET: + value = CSS_BOTTOM_SET; + length.value = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(length.value)); + unit = css__to_css_unit(*((uint32_t *) style->bytecode)); + advance_bytecode(style, sizeof(unit)); + break; + case BOTTOM_AUTO: + value = CSS_BOTTOM_AUTO; + break; + case BOTTOM_CALC: + value = CSS_BOTTOM_SET; + advance_bytecode(style, sizeof(unit)); // TODO: Skip unit, not sure what to do + snum = *((uint32_t *) style->bytecode); + advance_bytecode(style, sizeof(snum)); + unit = CSS_UNIT_CALC; + css__stylesheet_string_get(style->sheet, snum, &length.calc); + break; + default: + assert(0 && "Invalid value"); + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -221,7 +279,7 @@ css_error css__cascade_length_normal(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LETTER_SPACING_SET: value = CSS_LETTER_SPACING_SET; @@ -233,13 +291,20 @@ css_error css__cascade_length_normal(uint32_t opv, css_style *style, case LETTER_SPACING_NORMAL: value = CSS_LETTER_SPACING_NORMAL; break; + case LETTER_SPACING_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -255,7 +320,7 @@ css_error css__cascade_length_none(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case MAX_HEIGHT_SET: value = CSS_MAX_HEIGHT_SET; @@ -267,13 +332,20 @@ css_error css__cascade_length_none(uint32_t opv, css_style *style, case MAX_HEIGHT_NONE: value = CSS_MAX_HEIGHT_NONE; break; + case MAX_HEIGHT_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -289,19 +361,30 @@ css_error css__cascade_length(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { - value = CSS_MIN_HEIGHT_SET; - length = *((css_fixed *) style->bytecode); - advance_bytecode(style, sizeof(length)); - unit = *((uint32_t *) style->bytecode); - advance_bytecode(style, sizeof(unit)); + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case MIN_HEIGHT_SET: + value = CSS_MIN_HEIGHT_SET; + length = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(length)); + unit = *((uint32_t *) style->bytecode); + advance_bytecode(style, sizeof(unit)); + break; + case MIN_HEIGHT_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; + } } unit = css__to_css_unit(unit); /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value, length, unit); } @@ -317,15 +400,26 @@ css_error css__cascade_number(uint32_t opv, css_style *style, /** \todo values */ - if (isInherit(opv) == false) { - value = 0; - length = *((css_fixed *) style->bytecode); - advance_bytecode(style, sizeof(length)); + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case ORPHANS_SET: + value = 0; + length = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(length)); + break; + case ORPHANS_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; + } } /** \todo lose fun != NULL once all properties have set routines */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value, length); } @@ -340,7 +434,7 @@ css_error css__cascade_page_break_after_before_inside(uint32_t opv, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case PAGE_BREAK_AFTER_AUTO: value = CSS_PAGE_BREAK_AFTER_AUTO; @@ -362,7 +456,7 @@ css_error css__cascade_page_break_after_before_inside(uint32_t opv, /** \todo lose fun != NULL */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value); } @@ -377,7 +471,7 @@ css_error css__cascade_break_after_before_inside(uint32_t opv, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case BREAK_AFTER_AUTO: value = CSS_BREAK_AFTER_AUTO; @@ -411,7 +505,7 @@ css_error css__cascade_break_after_before_inside(uint32_t opv, /** \todo lose fun != NULL */ if (fun != NULL && css__outranks_existing(getOpcode(opv), - isImportant(opv), state, isInherit(opv))) { + isImportant(opv), state, getFlagValue(opv))) { return fun(state->computed, value); } @@ -427,7 +521,7 @@ css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style, css_computed_counter *counters = NULL; uint32_t n_counters = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case COUNTER_INCREMENT_NAMED: { @@ -490,7 +584,7 @@ css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = fun(state->computed, value, counters); diff --git a/src/select/properties/helpers.h b/src/select/properties/helpers.h index 60e5b4c..d326856 100644 --- a/src/select/properties/helpers.h +++ b/src/select/properties/helpers.h @@ -9,6 +9,7 @@ #define css_select_properties_helpers_h_ #include "select/helpers.h" +#include "select/autogenerated_computed.h" uint32_t generic_destroy_color(void *bytecode); uint32_t generic_destroy_uri(void *bytecode); @@ -33,6 +34,10 @@ css_error css__cascade_length_auto(uint32_t opv, css_style *style, css_select_state *state, css_error (*fun)(css_computed_style *, uint8_t, css_fixed, css_unit)); +css_error css__cascade_length_auto_calc(uint32_t opv, css_style *style, + css_select_state *state, + css_error (*fun)(css_computed_style *, uint8_t, css_fixed_or_calc, + css_unit)); css_error css__cascade_length_normal(uint32_t opv, css_style *style, css_select_state *state, css_error (*fun)(css_computed_style *, uint8_t, css_fixed, @@ -59,4 +64,137 @@ css_error css__cascade_counter_increment_reset(uint32_t opv, css_style *style, css_error (*fun)(css_computed_style *, uint8_t, css_computed_counter *)); +/** Copy NULL terminated array of lwc_string pointers. */ +static inline css_error css__copy_lwc_string_array( + bool ref, + lwc_string *const*orig, + lwc_string ***copy_out) +{ + size_t count = 0; + lwc_string **copy = NULL; + + if (orig != NULL) { + for (lwc_string *const*i = orig; (*i) != NULL; i++) { + count++; + } + + copy = malloc((count + 1) * sizeof(*copy)); + if (copy == NULL) { + return CSS_NOMEM; + } + + if (ref) { + for (size_t i = 0; i < count; i++) { + copy[i] = lwc_string_ref(orig[i]); + } + copy[count] = NULL; + } else { + memcpy(copy, orig, (count + 1) * sizeof(*copy)); + } + } + + *copy_out = copy; + return CSS_OK; +} + +/** Copy NULL-name terminated array of css_computed_counter items. */ +static inline css_error css__copy_computed_counter_array( + bool ref, + const css_computed_counter *orig, + css_computed_counter **copy_out) +{ + size_t count = 0; + css_computed_counter *copy = NULL; + + if (orig != NULL) { + for (const css_computed_counter *i = orig; + i->name != NULL; i++) { + count++; + } + + copy = malloc((count + 1) * sizeof(*copy)); + if (copy == NULL) { + return CSS_NOMEM; + } + + if (ref) { + for (size_t i = 0; i < count; i++) { + copy[i].name = lwc_string_ref(orig[i].name); + copy[i].value = orig[i].value; + } + copy[count].name = NULL; + copy[count].value = 0; + } else { + memcpy(copy, orig, (count + 1) * sizeof(*copy)); + } + } + + *copy_out = copy; + return CSS_OK; +} + +/** Copy type:none terminated array of css_computed_content_item items. */ +static inline css_error css__copy_computed_content_item_array( + bool ref, + const css_computed_content_item *orig, + css_computed_content_item **copy_out) +{ + size_t count = 0; + css_computed_content_item *copy = NULL; + + if (orig != NULL) { + for (const css_computed_content_item *i = orig; + i->type != CSS_COMPUTED_CONTENT_NONE; i++) { + count++; + } + + copy = malloc((count + 1) * sizeof(*copy)); + if (copy == NULL) { + return CSS_NOMEM; + } + + if (ref) { + for (size_t i = 0; i < count; i++) { + switch (orig[i].type) { + case CSS_COMPUTED_CONTENT_STRING: + copy[i].data.string = lwc_string_ref( + orig[i].data.string); + break; + case CSS_COMPUTED_CONTENT_URI: + copy[i].data.uri = lwc_string_ref( + orig[i].data.uri); + break; + case CSS_COMPUTED_CONTENT_ATTR: + copy[i].data.attr = lwc_string_ref( + orig[i].data.attr); + break; + case CSS_COMPUTED_CONTENT_COUNTER: + copy[i].data.counter.name = lwc_string_ref( + orig[i].data.counter.name); + copy[i].data.counter.style = + orig[i].data.counter.style; + break; + case CSS_COMPUTED_CONTENT_COUNTERS: + copy[i].data.counters.name = lwc_string_ref( + orig[i].data.counters.name); + copy[i].data.counters.sep = lwc_string_ref( + orig[i].data.counters.sep); + copy[i].data.counters.style = + orig[i].data.counters.style; + break; + default: + break; + } + copy[i].type = orig[i].type; + } + copy[count].type = CSS_COMPUTED_CONTENT_NONE; + } else { + memcpy(copy, orig, (count + 1) * sizeof(*copy)); + } + } + + *copy_out = copy; + return CSS_OK; +} + #endif diff --git a/src/select/properties/justify_content.c b/src/select/properties/justify_content.c index 2e17ca5..385bab7 100644 --- a/src/select/properties/justify_content.c +++ b/src/select/properties/justify_content.c @@ -21,7 +21,7 @@ css_error css__cascade_justify_content(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case JUSTIFY_CONTENT_FLEX_START: value = CSS_JUSTIFY_CONTENT_FLEX_START; @@ -45,7 +45,7 @@ css_error css__cascade_justify_content(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_justify_content(state->computed, value); } @@ -64,16 +64,25 @@ css_error css__initial_justify_content(css_select_state *state) CSS_JUSTIFY_CONTENT_FLEX_START); } +css_error css__copy_justify_content( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_justify_content(to, get_justify_content(from)); +} + css_error css__compose_justify_content(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_justify_content(child); - if (type == CSS_JUSTIFY_CONTENT_INHERIT) { - type = get_justify_content(parent); - } - - return set_justify_content(result, type); + return css__copy_justify_content( + type == CSS_JUSTIFY_CONTENT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/left.c b/src/select/properties/left.c index 4baa324..ca8c844 100644 --- a/src/select/properties/left.c +++ b/src/select/properties/left.c @@ -32,6 +32,21 @@ css_error css__initial_left(css_select_state *state) return set_left(state->computed, CSS_LEFT_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_left( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_left(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_left(to, type, length, unit); +} + css_error css__compose_left(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_left(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_left(child, &length, &unit); - if (type == CSS_LEFT_INHERIT) { - type = get_left(parent, &length, &unit); - } - - return set_left(result, type, length, unit); + return css__copy_left( + type == CSS_LEFT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/letter_spacing.c b/src/select/properties/letter_spacing.c index 27ea04b..9c8e50c 100644 --- a/src/select/properties/letter_spacing.c +++ b/src/select/properties/letter_spacing.c @@ -33,6 +33,21 @@ css_error css__initial_letter_spacing(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_letter_spacing( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_letter_spacing(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_letter_spacing(to, type, length, unit); +} + css_error css__compose_letter_spacing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,9 +56,7 @@ css_error css__compose_letter_spacing(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_letter_spacing(child, &length, &unit); - if (type == CSS_LETTER_SPACING_INHERIT) { - type = get_letter_spacing(parent, &length, &unit); - } - - return set_letter_spacing(result, type, length, unit); + return css__copy_letter_spacing( + type == CSS_LETTER_SPACING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/line_height.c b/src/select/properties/line_height.c index 091a575..2cf2402 100644 --- a/src/select/properties/line_height.c +++ b/src/select/properties/line_height.c @@ -21,7 +21,7 @@ css_error css__cascade_line_height(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LINE_HEIGHT_NUMBER: value = CSS_LINE_HEIGHT_NUMBER; @@ -38,13 +38,20 @@ css_error css__cascade_line_height(uint32_t opv, css_style *style, case LINE_HEIGHT_NORMAL: value = CSS_LINE_HEIGHT_NORMAL; break; + case LINE_HEIGHT_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_line_height(state->computed, value, val, unit); } @@ -64,6 +71,21 @@ css_error css__initial_line_height(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_line_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_line_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_line_height(to, type, length, unit); +} + css_error css__compose_line_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -72,10 +94,8 @@ css_error css__compose_line_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_line_height(child, &length, &unit); - if (type == CSS_LINE_HEIGHT_INHERIT) { - type = get_line_height(parent, &length, &unit); - } - - return set_line_height(result, type, length, unit); + return css__copy_line_height( + type == CSS_LINE_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/list_style_image.c b/src/select/properties/list_style_image.c index cc77eb4..7a41c3a 100644 --- a/src/select/properties/list_style_image.c +++ b/src/select/properties/list_style_image.c @@ -39,6 +39,20 @@ css_error css__initial_list_style_image(css_select_state *state) CSS_LIST_STYLE_IMAGE_NONE, NULL); } +css_error css__copy_list_style_image( + const css_computed_style *from, + css_computed_style *to) +{ + lwc_string *url; + uint8_t type = get_list_style_image(from, &url); + + if (from == to) { + return CSS_OK; + } + + return set_list_style_image(to, type, url); +} + css_error css__compose_list_style_image(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -46,10 +60,8 @@ css_error css__compose_list_style_image(const css_computed_style *parent, lwc_string *url; uint8_t type = get_list_style_image(child, &url); - if (type == CSS_LIST_STYLE_IMAGE_INHERIT) { - type = get_list_style_image(parent, &url); - } - - return set_list_style_image(result, type, url); + return css__copy_list_style_image( + type == CSS_LIST_STYLE_IMAGE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/list_style_position.c b/src/select/properties/list_style_position.c index 02d7651..ca46850 100644 --- a/src/select/properties/list_style_position.c +++ b/src/select/properties/list_style_position.c @@ -21,7 +21,7 @@ css_error css__cascade_list_style_position(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LIST_STYLE_POSITION_INSIDE: value = CSS_LIST_STYLE_POSITION_INSIDE; @@ -33,7 +33,7 @@ css_error css__cascade_list_style_position(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_list_style_position(state->computed, value); } @@ -52,16 +52,25 @@ css_error css__initial_list_style_position(css_select_state *state) CSS_LIST_STYLE_POSITION_OUTSIDE); } +css_error css__copy_list_style_position( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_list_style_position(to, get_list_style_position(from)); +} + css_error css__compose_list_style_position(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_list_style_position(child); - if (type == CSS_LIST_STYLE_POSITION_INHERIT) { - type = get_list_style_position(parent); - } - - return set_list_style_position(result, type); + return css__copy_list_style_position( + type == CSS_LIST_STYLE_POSITION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/list_style_type.c b/src/select/properties/list_style_type.c index e32d1b1..9d809e6 100644 --- a/src/select/properties/list_style_type.c +++ b/src/select/properties/list_style_type.c @@ -21,7 +21,7 @@ css_error css__cascade_list_style_type(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case LIST_STYLE_TYPE_DISC: value = CSS_LIST_STYLE_TYPE_DISC; @@ -183,7 +183,7 @@ css_error css__cascade_list_style_type(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_list_style_type(state->computed, value); } @@ -201,15 +201,24 @@ css_error css__initial_list_style_type(css_select_state *state) return set_list_style_type(state->computed, CSS_LIST_STYLE_TYPE_DISC); } +css_error css__copy_list_style_type( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_list_style_type(to, get_list_style_type(from)); +} + css_error css__compose_list_style_type(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_list_style_type(child); - if (type == CSS_LIST_STYLE_TYPE_INHERIT) { - type = get_list_style_type(parent); - } - - return set_list_style_type(result, type); + return css__copy_list_style_type( + type == CSS_LIST_STYLE_TYPE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/margin_bottom.c b/src/select/properties/margin_bottom.c index 3b1d8a1..a0ffd89 100644 --- a/src/select/properties/margin_bottom.c +++ b/src/select/properties/margin_bottom.c @@ -32,6 +32,21 @@ css_error css__initial_margin_bottom(css_select_state *state) return set_margin_bottom(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_bottom( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_bottom(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_bottom(to, type, length, unit); +} + css_error css__compose_margin_bottom(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_bottom(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_bottom(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_bottom(parent, &length, &unit); - } - - return set_margin_bottom(result, type, length, unit); + return css__copy_margin_bottom( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/margin_left.c b/src/select/properties/margin_left.c index 240285a..b163fba 100644 --- a/src/select/properties/margin_left.c +++ b/src/select/properties/margin_left.c @@ -32,6 +32,21 @@ css_error css__initial_margin_left(css_select_state *state) return set_margin_left(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_left( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_left(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_left(to, type, length, unit); +} + css_error css__compose_margin_left(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_left(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_left(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_left(parent, &length, &unit); - } - - return set_margin_left(result, type, length, unit); + return css__copy_margin_left( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/margin_right.c b/src/select/properties/margin_right.c index 737fbee..2c15b54 100644 --- a/src/select/properties/margin_right.c +++ b/src/select/properties/margin_right.c @@ -32,6 +32,21 @@ css_error css__initial_margin_right(css_select_state *state) return set_margin_right(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_right( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_right(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_right(to, type, length, unit); +} + css_error css__compose_margin_right(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_right(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_right(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_right(parent, &length, &unit); - } - - return set_margin_right(result, type, length, unit); + return css__copy_margin_right( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/margin_top.c b/src/select/properties/margin_top.c index 5563a48..1df811d 100644 --- a/src/select/properties/margin_top.c +++ b/src/select/properties/margin_top.c @@ -32,6 +32,21 @@ css_error css__initial_margin_top(css_select_state *state) return set_margin_top(state->computed, CSS_MARGIN_SET, 0, CSS_UNIT_PX); } +css_error css__copy_margin_top( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_margin_top(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_margin_top(to, type, length, unit); +} + css_error css__compose_margin_top(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_margin_top(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_margin_top(child, &length, &unit); - if (type == CSS_MARGIN_INHERIT) { - type = get_margin_top(parent, &length, &unit); - } - - return set_margin_top(result, type, length, unit); + return css__copy_margin_top( + type == CSS_MARGIN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/max_height.c b/src/select/properties/max_height.c index e03c8da..1dcf09d 100644 --- a/src/select/properties/max_height.c +++ b/src/select/properties/max_height.c @@ -33,6 +33,21 @@ css_error css__initial_max_height(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_max_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_max_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_max_height(to, type, length, unit); +} + css_error css__compose_max_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_max_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_max_height(child, &length, &unit); - if (type == CSS_MAX_HEIGHT_INHERIT) { - type = get_max_height(parent, &length, &unit); - } - - return set_max_height(result, type, length, unit); + return css__copy_max_height( + type == CSS_MAX_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/max_width.c b/src/select/properties/max_width.c index ec98712..11d8ade 100644 --- a/src/select/properties/max_width.c +++ b/src/select/properties/max_width.c @@ -32,6 +32,21 @@ css_error css__initial_max_width(css_select_state *state) return set_max_width(state->computed, CSS_MAX_WIDTH_NONE, 0, CSS_UNIT_PX); } +css_error css__copy_max_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_max_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_max_width(to, type, length, unit); +} + css_error css__compose_max_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_max_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_max_width(child, &length, &unit); - if (type == CSS_MAX_WIDTH_INHERIT) { - type = get_max_width(parent, &length, &unit); - } - - return set_max_width(result, type, length, unit); + return css__copy_max_width( + type == CSS_MAX_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/min_height.c b/src/select/properties/min_height.c index a5389ce..d05655c 100644 --- a/src/select/properties/min_height.c +++ b/src/select/properties/min_height.c @@ -33,6 +33,21 @@ css_error css__initial_min_height(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_min_height( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_min_height(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_min_height(to, type, length, unit); +} + css_error css__compose_min_height(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_min_height(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_min_height(child, &length, &unit); - if (type == CSS_MIN_HEIGHT_INHERIT) { - type = get_min_height(parent, &length, &unit); - } - - return set_min_height(result, type, length, unit); + return css__copy_min_height( + type == CSS_MIN_HEIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/min_width.c b/src/select/properties/min_width.c index 8460e01..af709d3 100644 --- a/src/select/properties/min_width.c +++ b/src/select/properties/min_width.c @@ -33,6 +33,21 @@ css_error css__initial_min_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_min_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_min_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_min_width(to, type, length, unit); +} + css_error css__compose_min_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_min_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_min_width(child, &length, &unit); - if (type == CSS_MIN_WIDTH_INHERIT) { - type = get_min_width(parent, &length, &unit); - } - - return set_min_width(result, type, length, unit); + return css__copy_min_width( + type == CSS_MIN_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/opacity.c b/src/select/properties/opacity.c index aadab0b..3e875f9 100644 --- a/src/select/properties/opacity.c +++ b/src/select/properties/opacity.c @@ -20,15 +20,15 @@ css_error css__cascade_opacity(uint32_t opv, css_style *style, uint16_t value = CSS_OPACITY_INHERIT; css_fixed opacity = 0; - if (isInherit(opv) == false) { - value = CSS_Z_INDEX_SET; + if (hasFlagValue(opv) == false) { + value = CSS_OPACITY_SET; opacity = *((css_fixed *) style->bytecode); advance_bytecode(style, sizeof(opacity)); } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_opacity(state->computed, value, opacity); } @@ -46,6 +46,20 @@ css_error css__initial_opacity(css_select_state *state) return set_opacity(state->computed, CSS_OPACITY_SET, INTTOFIX(1)); } +css_error css__copy_opacity( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed opacity = 0; + uint8_t type = get_opacity(from, &opacity); + + if (from == to) { + return CSS_OK; + } + + return set_opacity(to, type, opacity); +} + css_error css__compose_opacity(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -53,10 +67,8 @@ css_error css__compose_opacity(const css_computed_style *parent, css_fixed opacity = 0; uint8_t type = get_opacity(child, &opacity); - if (type == CSS_OPACITY_INHERIT) { - type = get_opacity(parent, &opacity); - } - - return set_opacity(result, type, opacity); + return css__copy_opacity( + type == CSS_OPACITY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/order.c b/src/select/properties/order.c index 0366537..0164fd0 100644 --- a/src/select/properties/order.c +++ b/src/select/properties/order.c @@ -20,15 +20,26 @@ css_error css__cascade_order(uint32_t opv, css_style *style, uint16_t value = CSS_ORDER_INHERIT; css_fixed order = 0; - if (isInherit(opv) == false) { - value = CSS_ORDER_SET; + if (hasFlagValue(opv) == false) { + switch (getValue(opv)) { + case ORDER_SET: + value = CSS_ORDER_SET; - order = FIXTOINT(*((css_fixed *) style->bytecode)); - advance_bytecode(style, sizeof(order)); + order = FIXTOINT(*((css_fixed *) style->bytecode)); + advance_bytecode(style, sizeof(order)); + break; + case ORDER_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; + } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_order(state->computed, value, order); } @@ -46,6 +57,20 @@ css_error css__initial_order(css_select_state *state) return set_order(state->computed, CSS_ORDER_SET, 0); } +css_error css__copy_order( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t order = 0; + uint8_t type = get_order(from, &order); + + if (from == to) { + return CSS_OK; + } + + return set_order(to, type, order); +} + css_error css__compose_order(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -53,10 +78,8 @@ css_error css__compose_order(const css_computed_style *parent, int32_t order = 0; uint8_t type = get_order(child, &order); - if (type == CSS_ORDER_INHERIT) { - type = get_order(parent, &order); - } - - return set_order(result, type, order); + return css__copy_order( + type == CSS_ORDER_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/orphans.c b/src/select/properties/orphans.c index f169b81..b0fee43 100644 --- a/src/select/properties/orphans.c +++ b/src/select/properties/orphans.c @@ -31,6 +31,20 @@ css_error css__initial_orphans(css_select_state *state) return set_orphans(state->computed, CSS_ORPHANS_SET, 2); } +css_error css__copy_orphans( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t count = 0; + uint8_t type = get_orphans(from, &count); + + if (from == to) { + return CSS_OK; + } + + return set_orphans(to, type, count); +} + css_error css__compose_orphans(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -38,10 +52,8 @@ css_error css__compose_orphans(const css_computed_style *parent, int32_t count = 0; uint8_t type = get_orphans(child, &count); - if (type == CSS_ORPHANS_INHERIT) { - type = get_orphans(parent, &count); - } - - return set_orphans(result, type, count); + return css__copy_orphans( + type == CSS_ORPHANS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/outline_color.c b/src/select/properties/outline_color.c index 97846ac..359960f 100644 --- a/src/select/properties/outline_color.c +++ b/src/select/properties/outline_color.c @@ -20,7 +20,7 @@ css_error css__cascade_outline_color(uint32_t opv, css_style *style, uint16_t value = CSS_OUTLINE_COLOR_INHERIT; css_color color = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case OUTLINE_COLOR_TRANSPARENT: value = CSS_OUTLINE_COLOR_COLOR; @@ -40,7 +40,7 @@ css_error css__cascade_outline_color(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_outline_color(state->computed, value, color); } @@ -58,6 +58,20 @@ css_error css__initial_outline_color(css_select_state *state) return set_outline_color(state->computed, CSS_OUTLINE_COLOR_INVERT, 0); } +css_error css__copy_outline_color( + const css_computed_style *from, + css_computed_style *to) +{ + css_color color = 0; + uint8_t type = get_outline_color(from, &color); + + if (from == to) { + return CSS_OK; + } + + return set_outline_color(to, type, color); +} + css_error css__compose_outline_color(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -65,9 +79,7 @@ css_error css__compose_outline_color(const css_computed_style *parent, css_color color = 0; uint8_t type = get_outline_color(child, &color); - if (type == CSS_OUTLINE_COLOR_INHERIT) { - type = get_outline_color(parent, &color); - } - - return set_outline_color(result, type, color); + return css__copy_outline_color( + type == CSS_OUTLINE_COLOR_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/outline_style.c b/src/select/properties/outline_style.c index 5c30735..acdab03 100644 --- a/src/select/properties/outline_style.c +++ b/src/select/properties/outline_style.c @@ -31,16 +31,25 @@ css_error css__initial_outline_style(css_select_state *state) return set_outline_style(state->computed, CSS_OUTLINE_STYLE_NONE); } +css_error css__copy_outline_style( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_outline_style(to, get_outline_style(from)); +} + css_error css__compose_outline_style(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_outline_style(child); - if (type == CSS_OUTLINE_STYLE_INHERIT) { - type = get_outline_style(parent); - } - - return set_outline_style(result, type); + return css__copy_outline_style( + type == CSS_OUTLINE_STYLE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/outline_width.c b/src/select/properties/outline_width.c index 0289c57..dbc0298 100644 --- a/src/select/properties/outline_width.c +++ b/src/select/properties/outline_width.c @@ -33,6 +33,21 @@ css_error css__initial_outline_width(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_outline_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_outline_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_outline_width(to, type, length, unit); +} + css_error css__compose_outline_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_outline_width(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_outline_width(child, &length, &unit); - if (type == CSS_OUTLINE_WIDTH_INHERIT) { - type = get_outline_width(parent, &length, &unit); - } - - return set_outline_width(result, type, length, unit); + return css__copy_outline_width( + type == CSS_OUTLINE_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/overflow_x.c b/src/select/properties/overflow_x.c index 817d1d2..98dfba5 100644 --- a/src/select/properties/overflow_x.c +++ b/src/select/properties/overflow_x.c @@ -21,7 +21,7 @@ css_error css__cascade_overflow_x(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case OVERFLOW_VISIBLE: value = CSS_OVERFLOW_VISIBLE; @@ -39,7 +39,7 @@ css_error css__cascade_overflow_x(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_overflow_x(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_overflow_x(css_select_state *state) return set_overflow_x(state->computed, CSS_OVERFLOW_VISIBLE); } +css_error css__copy_overflow_x( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_overflow_x(to, get_overflow_x(from)); +} + css_error css__compose_overflow_x(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_overflow_x(child); - if (type == CSS_OVERFLOW_INHERIT) { - type = get_overflow_x(parent); - } - - return set_overflow_x(result, type); + return css__copy_overflow_x( + type == CSS_OVERFLOW_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/overflow_y.c b/src/select/properties/overflow_y.c index b54c4c8..d7795a2 100644 --- a/src/select/properties/overflow_y.c +++ b/src/select/properties/overflow_y.c @@ -21,7 +21,7 @@ css_error css__cascade_overflow_y(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case OVERFLOW_VISIBLE: value = CSS_OVERFLOW_VISIBLE; @@ -39,7 +39,7 @@ css_error css__cascade_overflow_y(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_overflow_y(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_overflow_y(css_select_state *state) return set_overflow_y(state->computed, CSS_OVERFLOW_VISIBLE); } +css_error css__copy_overflow_y( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_overflow_y(to, get_overflow_y(from)); +} + css_error css__compose_overflow_y(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_overflow_y(child); - if (type == CSS_OVERFLOW_INHERIT) { - type = get_overflow_y(parent); - } - - return set_overflow_y(result, type); + return css__copy_overflow_y( + type == CSS_OVERFLOW_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_bottom.c b/src/select/properties/padding_bottom.c index e3b36f7..53c749c 100644 --- a/src/select/properties/padding_bottom.c +++ b/src/select/properties/padding_bottom.c @@ -33,6 +33,21 @@ css_error css__initial_padding_bottom(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_padding_bottom( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_bottom(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_bottom(to, type, length, unit); +} + css_error css__compose_padding_bottom(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_padding_bottom(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_bottom(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_bottom(parent, &length, &unit); - } - - return set_padding_bottom(result, type, length, unit); + return css__copy_padding_bottom( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_left.c b/src/select/properties/padding_left.c index bdea11e..b61ca83 100644 --- a/src/select/properties/padding_left.c +++ b/src/select/properties/padding_left.c @@ -32,6 +32,21 @@ css_error css__initial_padding_left(css_select_state *state) return set_padding_left(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } +css_error css__copy_padding_left( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_left(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_left(to, type, length, unit); +} + css_error css__compose_padding_left(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_padding_left(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_left(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_left(parent, &length, &unit); - } - - return set_padding_left(result, type, length, unit); + return css__copy_padding_left( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_right.c b/src/select/properties/padding_right.c index 82c1ed3..35417d6 100644 --- a/src/select/properties/padding_right.c +++ b/src/select/properties/padding_right.c @@ -33,6 +33,21 @@ css_error css__initial_padding_right(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_padding_right( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_right(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_right(to, type, length, unit); +} + css_error css__compose_padding_right(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_padding_right(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_right(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_right(parent, &length, &unit); - } - - return set_padding_right(result, type, length, unit); + return css__copy_padding_right( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/padding_top.c b/src/select/properties/padding_top.c index f6d8b3e..a2cec95 100644 --- a/src/select/properties/padding_top.c +++ b/src/select/properties/padding_top.c @@ -32,6 +32,21 @@ css_error css__initial_padding_top(css_select_state *state) return set_padding_top(state->computed, CSS_PADDING_SET, 0, CSS_UNIT_PX); } +css_error css__copy_padding_top( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_padding_top(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_padding_top(to, type, length, unit); +} + css_error css__compose_padding_top(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_padding_top(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_padding_top(child, &length, &unit); - if (type == CSS_PADDING_INHERIT) { - type = get_padding_top(parent, &length, &unit); - } - - return set_padding_top(result, type, length, unit); + return css__copy_padding_top( + type == CSS_PADDING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/page_break_after.c b/src/select/properties/page_break_after.c index fdb6774..4065a17 100644 --- a/src/select/properties/page_break_after.c +++ b/src/select/properties/page_break_after.c @@ -33,16 +33,25 @@ css_error css__initial_page_break_after(css_select_state *state) CSS_PAGE_BREAK_AFTER_AUTO); } +css_error css__copy_page_break_after( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_page_break_after(to, get_page_break_after(from)); +} + css_error css__compose_page_break_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_page_break_after(child); - if (type == CSS_PAGE_BREAK_AFTER_INHERIT) { - type = get_page_break_after(parent); - } - - return set_page_break_after(result, type); + return css__copy_page_break_after( + type == CSS_PAGE_BREAK_AFTER_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/page_break_before.c b/src/select/properties/page_break_before.c index 1491997..d8fdd93 100644 --- a/src/select/properties/page_break_before.c +++ b/src/select/properties/page_break_before.c @@ -33,15 +33,24 @@ css_error css__initial_page_break_before(css_select_state *state) CSS_PAGE_BREAK_BEFORE_AUTO); } +css_error css__copy_page_break_before( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_page_break_before(to, get_page_break_before(from)); +} + css_error css__compose_page_break_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_page_break_before(child); - if (type == CSS_PAGE_BREAK_BEFORE_INHERIT) { - type = get_page_break_before(parent); - } - - return set_page_break_before(result, type); + return css__copy_page_break_before( + type == CSS_PAGE_BREAK_BEFORE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/page_break_inside.c b/src/select/properties/page_break_inside.c index ddcb19f..8655c40 100644 --- a/src/select/properties/page_break_inside.c +++ b/src/select/properties/page_break_inside.c @@ -33,16 +33,25 @@ css_error css__initial_page_break_inside(css_select_state *state) CSS_PAGE_BREAK_INSIDE_AUTO); } +css_error css__copy_page_break_inside( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_page_break_inside(to, get_page_break_inside(from)); +} + css_error css__compose_page_break_inside(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_page_break_inside(child); - if (type == CSS_PAGE_BREAK_INSIDE_INHERIT) { - type = get_page_break_inside(parent); - } - - return set_page_break_inside(result, type); + return css__copy_page_break_inside( + type == CSS_PAGE_BREAK_INSIDE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/pause_after.c b/src/select/properties/pause_after.c index 16bbefe..b8bf968 100644 --- a/src/select/properties/pause_after.c +++ b/src/select/properties/pause_after.c @@ -37,6 +37,16 @@ css_error css__initial_pause_after(css_select_state *state) return CSS_OK; } +css_error css__copy_pause_after( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pause_after(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/pause_before.c b/src/select/properties/pause_before.c index 7770615..74cb565 100644 --- a/src/select/properties/pause_before.c +++ b/src/select/properties/pause_before.c @@ -37,6 +37,16 @@ css_error css__initial_pause_before(css_select_state *state) return CSS_OK; } +css_error css__copy_pause_before( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pause_before(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/pitch.c b/src/select/properties/pitch.c index c5484d9..f665561 100644 --- a/src/select/properties/pitch.c +++ b/src/select/properties/pitch.c @@ -20,7 +20,7 @@ css_error css__cascade_pitch(uint32_t opv, css_style *style, css_fixed freq = 0; uint32_t unit = UNIT_HZ; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case PITCH_FREQUENCY: freq = *((css_fixed *) style->bytecode); @@ -35,13 +35,20 @@ css_error css__cascade_pitch(uint32_t opv, css_style *style, case PITCH_X_HIGH: /** \todo convert to public values */ break; + case PITCH_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo pitch */ } @@ -64,6 +71,16 @@ css_error css__initial_pitch(css_select_state *state) return CSS_OK; } +css_error css__copy_pitch( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pitch(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/pitch_range.c b/src/select/properties/pitch_range.c index 52a5751..c8f7526 100644 --- a/src/select/properties/pitch_range.c +++ b/src/select/properties/pitch_range.c @@ -37,6 +37,16 @@ css_error css__initial_pitch_range(css_select_state *state) return CSS_OK; } +css_error css__copy_pitch_range( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_pitch_range(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/play_during.c b/src/select/properties/play_during.c index 413d75a..0f38f74 100644 --- a/src/select/properties/play_during.c +++ b/src/select/properties/play_during.c @@ -19,7 +19,7 @@ css_error css__cascade_play_during(uint32_t opv, css_style *style, { lwc_string *uri = NULL; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case PLAY_DURING_URI: css__stylesheet_string_get(style->sheet, *((css_code_t *) style->bytecode), &uri); @@ -35,7 +35,7 @@ css_error css__cascade_play_during(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo play-during */ } @@ -58,6 +58,16 @@ css_error css__initial_play_during(css_select_state *state) return CSS_OK; } +css_error css__copy_play_during( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_play_during(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/position.c b/src/select/properties/position.c index 9f9658f..cc4b3e7 100644 --- a/src/select/properties/position.c +++ b/src/select/properties/position.c @@ -21,7 +21,7 @@ css_error css__cascade_position(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case POSITION_STATIC: value = CSS_POSITION_STATIC; @@ -35,11 +35,14 @@ css_error css__cascade_position(uint32_t opv, css_style *style, case POSITION_FIXED: value = CSS_POSITION_FIXED; break; + case POSITION_STICKY: + value = CSS_POSITION_STICKY; + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_position(state->computed, value); } @@ -57,16 +60,25 @@ css_error css__initial_position(css_select_state *state) return set_position(state->computed, CSS_POSITION_STATIC); } +css_error css__copy_position( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_position(to, get_position(from)); +} + css_error css__compose_position(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_position(child); - if (type == CSS_POSITION_INHERIT) { - type = get_position(parent); - } - - return set_position(result, type); + return css__copy_position( + type == CSS_POSITION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/properties.h b/src/select/properties/properties.h index 6eac397..cb0b213 100644 --- a/src/select/properties/properties.h +++ b/src/select/properties/properties.h @@ -18,6 +18,7 @@ css_error css__cascade_##pname (uint32_t opv, css_style *style, css_select_state *state); \ css_error css__set_##pname##_from_hint(const css_hint *hint, css_computed_style *style); \ css_error css__initial_##pname (css_select_state *state); \ + css_error css__copy_##pname (const css_computed_style *from, css_computed_style *to); \ css_error css__compose_##pname (const css_computed_style *parent, const css_computed_style *child, css_computed_style *result); \ uint32_t destroy_##pname (void *bytecode) @@ -71,6 +72,7 @@ PROPERTY_FUNCS(direction); PROPERTY_FUNCS(display); PROPERTY_FUNCS(elevation); PROPERTY_FUNCS(empty_cells); +PROPERTY_FUNCS(fill_opacity); PROPERTY_FUNCS(flex_basis); PROPERTY_FUNCS(flex_direction); PROPERTY_FUNCS(flex_grow); @@ -128,6 +130,7 @@ PROPERTY_FUNCS(speak_punctuation); PROPERTY_FUNCS(speak); PROPERTY_FUNCS(speech_rate); PROPERTY_FUNCS(stress); +PROPERTY_FUNCS(stroke_opacity); PROPERTY_FUNCS(table_layout); PROPERTY_FUNCS(text_align); PROPERTY_FUNCS(text_decoration); diff --git a/src/select/properties/quotes.c b/src/select/properties/quotes.c index 4144d8e..57fc48c 100644 --- a/src/select/properties/quotes.c +++ b/src/select/properties/quotes.c @@ -21,7 +21,7 @@ css_error css__cascade_quotes(uint32_t opv, css_style *style, lwc_string **quotes = NULL; uint32_t n_quotes = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); value = CSS_QUOTES_STRING; @@ -75,7 +75,7 @@ css_error css__cascade_quotes(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { css_error error; error = set_quotes(state->computed, value, quotes); @@ -123,43 +123,41 @@ css_error css__initial_quotes(css_select_state *state) return css__set_quotes_from_hint(&hint, state->computed); } -css_error css__compose_quotes(const css_computed_style *parent, - const css_computed_style *child, - css_computed_style *result) +css_error css__copy_quotes( + const css_computed_style *from, + css_computed_style *to) { css_error error; + lwc_string **copy = NULL; lwc_string **quotes = NULL; - uint8_t type = get_quotes(child, "es); - - if (type == CSS_QUOTES_INHERIT || result != child) { - size_t n_quotes = 0; - lwc_string **copy = NULL; - - if (type == CSS_QUOTES_INHERIT) { - type = get_quotes(parent, "es); - } - - if (quotes != NULL) { - lwc_string **i; + uint8_t type = get_quotes(from, "es); - for (i = quotes; (*i) != NULL; i++) - n_quotes++; + if (from == to) { + return CSS_OK; + } - copy = malloc((n_quotes + 1) * sizeof(lwc_string *)); - if (copy == NULL) - return CSS_NOMEM; + error = css__copy_lwc_string_array(false, quotes, ©); + if (error != CSS_OK) { + return CSS_NOMEM; + } - memcpy(copy, quotes, (n_quotes + 1) * - sizeof(lwc_string *)); - } + error = set_quotes(to, type, copy); + if (error != CSS_OK) { + free(copy); + } - error = set_quotes(result, type, copy); - if (error != CSS_OK && copy != NULL) - free(copy); + return error; +} - return error; - } +css_error css__compose_quotes(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + lwc_string **quotes = NULL; + uint8_t type = get_quotes(child, "es); - return CSS_OK; + return css__copy_quotes( + type == CSS_QUOTES_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/richness.c b/src/select/properties/richness.c index 9656486..cd62d5c 100644 --- a/src/select/properties/richness.c +++ b/src/select/properties/richness.c @@ -37,6 +37,16 @@ css_error css__initial_richness(css_select_state *state) return CSS_OK; } +css_error css__copy_richness( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_richness(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/right.c b/src/select/properties/right.c index 142e7e8..ee4f4a0 100644 --- a/src/select/properties/right.c +++ b/src/select/properties/right.c @@ -32,6 +32,21 @@ css_error css__initial_right(css_select_state *state) return set_right(state->computed, CSS_RIGHT_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_right( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_right(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_right(to, type, length, unit); +} + css_error css__compose_right(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_right(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_right(child, &length, &unit); - if (type == CSS_RIGHT_INHERIT) { - type = get_right(parent, &length, &unit); - } - - return set_right(result, type, length, unit); + return css__copy_right( + type == CSS_RIGHT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/speak.c b/src/select/properties/speak.c index eb5528b..7b0d014 100644 --- a/src/select/properties/speak.c +++ b/src/select/properties/speak.c @@ -19,7 +19,7 @@ css_error css__cascade_speak(uint32_t opv, css_style *style, { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_NORMAL: case SPEAK_NONE: @@ -30,7 +30,7 @@ css_error css__cascade_speak(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak */ } @@ -53,6 +53,16 @@ css_error css__initial_speak(css_select_state *state) return CSS_OK; } +css_error css__copy_speak( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speak_header.c b/src/select/properties/speak_header.c index 0935528..88ad0d7 100644 --- a/src/select/properties/speak_header.c +++ b/src/select/properties/speak_header.c @@ -19,7 +19,7 @@ css_error css__cascade_speak_header(uint32_t opv, css_style *style, { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_HEADER_ONCE: case SPEAK_HEADER_ALWAYS: @@ -29,7 +29,7 @@ css_error css__cascade_speak_header(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak-header */ } @@ -52,6 +52,16 @@ css_error css__initial_speak_header(css_select_state *state) return CSS_OK; } +css_error css__copy_speak_header( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak_header(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speak_numeral.c b/src/select/properties/speak_numeral.c index fc54caf..1cd6e98 100644 --- a/src/select/properties/speak_numeral.c +++ b/src/select/properties/speak_numeral.c @@ -19,7 +19,7 @@ css_error css__cascade_speak_numeral(uint32_t opv, css_style *style, { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_NUMERAL_DIGITS: case SPEAK_NUMERAL_CONTINUOUS: @@ -29,7 +29,7 @@ css_error css__cascade_speak_numeral(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak-numeral */ } @@ -52,6 +52,16 @@ css_error css__initial_speak_numeral(css_select_state *state) return CSS_OK; } +css_error css__copy_speak_numeral( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak_numeral(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speak_punctuation.c b/src/select/properties/speak_punctuation.c index 67cbdaf..916d530 100644 --- a/src/select/properties/speak_punctuation.c +++ b/src/select/properties/speak_punctuation.c @@ -19,7 +19,7 @@ css_error css__cascade_speak_punctuation( { UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEAK_PUNCTUATION_CODE: case SPEAK_PUNCTUATION_NONE: @@ -29,7 +29,7 @@ css_error css__cascade_speak_punctuation( } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speak-punctuation */ } @@ -52,6 +52,16 @@ css_error css__initial_speak_punctuation(css_select_state *state) return CSS_OK; } +css_error css__copy_speak_punctuation( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speak_punctuation(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/speech_rate.c b/src/select/properties/speech_rate.c index 5cec19b..98fbe84 100644 --- a/src/select/properties/speech_rate.c +++ b/src/select/properties/speech_rate.c @@ -19,7 +19,7 @@ css_error css__cascade_speech_rate(uint32_t opv, css_style *style, { css_fixed rate = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case SPEECH_RATE_SET: rate = *((css_fixed *) style->bytecode); @@ -34,11 +34,18 @@ css_error css__cascade_speech_rate(uint32_t opv, css_style *style, case SPEECH_RATE_SLOWER: /** \todo convert to public values */ break; + case SPEECH_RATE_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo speech-rate */ } @@ -61,6 +68,16 @@ css_error css__initial_speech_rate(css_select_state *state) return CSS_OK; } +css_error css__copy_speech_rate( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_speech_rate(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/stress.c b/src/select/properties/stress.c index c9d61dd..0320fd0 100644 --- a/src/select/properties/stress.c +++ b/src/select/properties/stress.c @@ -37,6 +37,16 @@ css_error css__initial_stress(css_select_state *state) return CSS_OK; } +css_error css__copy_stress( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_stress(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/stroke_opacity.c b/src/select/properties/stroke_opacity.c new file mode 100644 index 0000000..c27e127 --- /dev/null +++ b/src/select/properties/stroke_opacity.c @@ -0,0 +1,73 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_stroke_opacity(uint32_t opv, css_style *style, + css_select_state *state) +{ + uint16_t value = CSS_STROKE_OPACITY_INHERIT; + css_fixed stroke_opacity = 0; + + if (hasFlagValue(opv) == false) { + value = CSS_STROKE_OPACITY_SET; + + stroke_opacity = *((css_fixed *) style->bytecode); + advance_bytecode(style, sizeof(stroke_opacity)); + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + getFlagValue(opv))) { + return set_stroke_opacity(state->computed, value, stroke_opacity); + } + + return CSS_OK; +} + +css_error css__set_stroke_opacity_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_stroke_opacity(style, hint->status, hint->data.fixed); +} + +css_error css__initial_stroke_opacity(css_select_state *state) +{ + return set_stroke_opacity(state->computed, CSS_STROKE_OPACITY_SET, INTTOFIX(1)); +} + +css_error css__copy_stroke_opacity( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed stroke_opacity = 0; + uint8_t type = get_stroke_opacity(from, &stroke_opacity); + + if (from == to) { + return CSS_OK; + } + + return set_stroke_opacity(to, type, stroke_opacity); +} + +css_error css__compose_stroke_opacity(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + css_fixed stroke_opacity = 0; + uint8_t type = get_stroke_opacity(child, &stroke_opacity); + + return css__copy_stroke_opacity( + type == CSS_STROKE_OPACITY_INHERIT ? parent : child, + result); +} + diff --git a/src/select/properties/table_layout.c b/src/select/properties/table_layout.c index c911e10..255ce37 100644 --- a/src/select/properties/table_layout.c +++ b/src/select/properties/table_layout.c @@ -21,7 +21,7 @@ css_error css__cascade_table_layout(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case TABLE_LAYOUT_AUTO: value = CSS_TABLE_LAYOUT_AUTO; @@ -33,7 +33,7 @@ css_error css__cascade_table_layout(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_table_layout(state->computed, value); } @@ -51,16 +51,25 @@ css_error css__initial_table_layout(css_select_state *state) return set_table_layout(state->computed, CSS_TABLE_LAYOUT_AUTO); } +css_error css__copy_table_layout( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_table_layout(to, get_table_layout(from)); +} + css_error css__compose_table_layout(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_table_layout(child); - if (type == CSS_TABLE_LAYOUT_INHERIT) { - type = get_table_layout(parent); - } - - return set_table_layout(result, type); + return css__copy_table_layout( + type == CSS_TABLE_LAYOUT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_align.c b/src/select/properties/text_align.c index 808107f..303f8f5 100644 --- a/src/select/properties/text_align.c +++ b/src/select/properties/text_align.c @@ -21,7 +21,7 @@ css_error css__cascade_text_align(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case TEXT_ALIGN_LEFT: value = CSS_TEXT_ALIGN_LEFT; @@ -48,7 +48,7 @@ css_error css__cascade_text_align(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_text_align(state->computed, value); } @@ -66,15 +66,24 @@ css_error css__initial_text_align(css_select_state *state) return set_text_align(state->computed, CSS_TEXT_ALIGN_DEFAULT); } +css_error css__copy_text_align( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_text_align(to, get_text_align(from)); +} + css_error css__compose_text_align(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_text_align(child); - if (type == CSS_TEXT_ALIGN_INHERIT) { - type = get_text_align(parent); - } else if (type == CSS_TEXT_ALIGN_INHERIT_IF_NON_MAGIC) { + if (type == CSS_TEXT_ALIGN_INHERIT_IF_NON_MAGIC) { /* This is purely for the benefit of HTML tables */ type = get_text_align(parent); @@ -83,10 +92,15 @@ css_error css__compose_text_align(const css_computed_style *parent, * inherit as normal. */ if (type == CSS_TEXT_ALIGN_LIBCSS_LEFT || type == CSS_TEXT_ALIGN_LIBCSS_CENTER || - type == CSS_TEXT_ALIGN_LIBCSS_RIGHT) + type == CSS_TEXT_ALIGN_LIBCSS_RIGHT) { type = CSS_TEXT_ALIGN_DEFAULT; + } + + return set_text_align(result, type); } - return set_text_align(result, type); + return css__copy_text_align( + type == CSS_TEXT_ALIGN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_decoration.c b/src/select/properties/text_decoration.c index 0e7544d..bfea8a8 100644 --- a/src/select/properties/text_decoration.c +++ b/src/select/properties/text_decoration.c @@ -23,7 +23,7 @@ css_error css__cascade_text_decoration(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { if (getValue(opv) == TEXT_DECORATION_NONE) { value = CSS_TEXT_DECORATION_NONE; } else { @@ -41,7 +41,7 @@ css_error css__cascade_text_decoration(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_text_decoration(state->computed, value); } @@ -59,16 +59,25 @@ css_error css__initial_text_decoration(css_select_state *state) return set_text_decoration(state->computed, CSS_TEXT_DECORATION_NONE); } +css_error css__copy_text_decoration( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_text_decoration(to, get_text_decoration(from)); +} + css_error css__compose_text_decoration(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_text_decoration(child); - if (type == CSS_TEXT_DECORATION_INHERIT) { - type = get_text_decoration(parent); - } - - return set_text_decoration(result, type); + return css__copy_text_decoration( + type == CSS_TEXT_DECORATION_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_indent.c b/src/select/properties/text_indent.c index 787c0be..3708130 100644 --- a/src/select/properties/text_indent.c +++ b/src/select/properties/text_indent.c @@ -33,6 +33,21 @@ css_error css__initial_text_indent(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_text_indent( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_text_indent(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_text_indent(to, type, length, unit); +} + css_error css__compose_text_indent(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,10 +56,8 @@ css_error css__compose_text_indent(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_text_indent(child, &length, &unit); - if (type == CSS_TEXT_INDENT_INHERIT) { - type = get_text_indent(parent, &length, &unit); - } - - return set_text_indent(result, type, length, unit); + return css__copy_text_indent( + type == CSS_TEXT_INDENT_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/text_transform.c b/src/select/properties/text_transform.c index 38cb427..3bc5757 100644 --- a/src/select/properties/text_transform.c +++ b/src/select/properties/text_transform.c @@ -21,7 +21,7 @@ css_error css__cascade_text_transform(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case TEXT_TRANSFORM_CAPITALIZE: value = CSS_TEXT_TRANSFORM_CAPITALIZE; @@ -39,7 +39,7 @@ css_error css__cascade_text_transform(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_text_transform(state->computed, value); } @@ -57,16 +57,25 @@ css_error css__initial_text_transform(css_select_state *state) return set_text_transform(state->computed, CSS_TEXT_TRANSFORM_NONE); } +css_error css__copy_text_transform( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_text_transform(to, get_text_transform(from)); +} + css_error css__compose_text_transform(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_text_transform(child); - if (type == CSS_TEXT_TRANSFORM_INHERIT) { - type = get_text_transform(parent); - } - - return set_text_transform(result, type); + return css__copy_text_transform( + type == CSS_TEXT_TRANSFORM_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/top.c b/src/select/properties/top.c index 72129aa..473a105 100644 --- a/src/select/properties/top.c +++ b/src/select/properties/top.c @@ -32,6 +32,21 @@ css_error css__initial_top(css_select_state *state) return set_top(state->computed, CSS_TOP_AUTO, 0, CSS_UNIT_PX); } +css_error css__copy_top( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_top(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_top(to, type, length, unit); +} + css_error css__compose_top(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -40,10 +55,8 @@ css_error css__compose_top(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_top(child, &length, &unit); - if (type == CSS_TOP_INHERIT) { - type = get_top(parent, &length, &unit); - } - - return set_top(result, type, length, unit); + return css__copy_top( + type == CSS_TOP_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/unicode_bidi.c b/src/select/properties/unicode_bidi.c index 5b91df1..ae0f4ad 100644 --- a/src/select/properties/unicode_bidi.c +++ b/src/select/properties/unicode_bidi.c @@ -21,7 +21,7 @@ css_error css__cascade_unicode_bidi(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case UNICODE_BIDI_NORMAL: value = CSS_UNICODE_BIDI_NORMAL; @@ -36,7 +36,7 @@ css_error css__cascade_unicode_bidi(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_unicode_bidi(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_unicode_bidi(css_select_state *state) return set_unicode_bidi(state->computed, CSS_UNICODE_BIDI_NORMAL); } +css_error css__copy_unicode_bidi( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_unicode_bidi(to, get_unicode_bidi(from)); +} + css_error css__compose_unicode_bidi(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_unicode_bidi(child); - if (type == CSS_UNICODE_BIDI_INHERIT) { - type = get_unicode_bidi(parent); - } - - return set_unicode_bidi(result, type); + return css__copy_unicode_bidi( + type == CSS_UNICODE_BIDI_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/vertical_align.c b/src/select/properties/vertical_align.c index 9fb7143..790e5f0 100644 --- a/src/select/properties/vertical_align.c +++ b/src/select/properties/vertical_align.c @@ -21,7 +21,7 @@ css_error css__cascade_vertical_align(uint32_t opv, css_style *style, css_fixed length = 0; uint32_t unit = UNIT_PX; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case VERTICAL_ALIGN_SET: value = CSS_VERTICAL_ALIGN_SET; @@ -55,13 +55,20 @@ css_error css__cascade_vertical_align(uint32_t opv, css_style *style, case VERTICAL_ALIGN_TEXT_BOTTOM: value = CSS_VERTICAL_ALIGN_TEXT_BOTTOM; break; + case VERTICAL_ALIGN_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_vertical_align(state->computed, value, length, unit); } @@ -81,6 +88,21 @@ css_error css__initial_vertical_align(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_vertical_align( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_vertical_align(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_vertical_align(to, type, length, unit); +} + css_error css__compose_vertical_align(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -89,10 +111,8 @@ css_error css__compose_vertical_align(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_vertical_align(child, &length, &unit); - if (type == CSS_VERTICAL_ALIGN_INHERIT) { - type = get_vertical_align(parent, &length, &unit); - } - - return set_vertical_align(result, type, length, unit); + return css__copy_vertical_align( + type == CSS_VERTICAL_ALIGN_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/visibility.c b/src/select/properties/visibility.c index ef95252..674e433 100644 --- a/src/select/properties/visibility.c +++ b/src/select/properties/visibility.c @@ -21,7 +21,7 @@ css_error css__cascade_visibility(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case VISIBILITY_VISIBLE: value = CSS_VISIBILITY_VISIBLE; @@ -36,7 +36,7 @@ css_error css__cascade_visibility(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_visibility(state->computed, value); } @@ -54,16 +54,25 @@ css_error css__initial_visibility(css_select_state *state) return set_visibility(state->computed, CSS_VISIBILITY_VISIBLE); } +css_error css__copy_visibility( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_visibility(to, get_visibility(from)); +} + css_error css__compose_visibility(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_visibility(child); - if (type == CSS_VISIBILITY_INHERIT) { - type = get_visibility(parent); - } - - return set_visibility(result, type); + return css__copy_visibility( + type == CSS_VISIBILITY_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/voice_family.c b/src/select/properties/voice_family.c index b370a2b..66e3123 100644 --- a/src/select/properties/voice_family.c +++ b/src/select/properties/voice_family.c @@ -21,7 +21,7 @@ css_error css__cascade_voice_family(uint32_t opv, css_style *style, lwc_string **voices = NULL; uint32_t n_voices = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { uint32_t v = getValue(opv); while (v != VOICE_FAMILY_END) { @@ -92,7 +92,7 @@ css_error css__cascade_voice_family(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo voice-family */ if (n_voices > 0) free(voices); @@ -120,6 +120,16 @@ css_error css__initial_voice_family(css_select_state *state) return CSS_OK; } +css_error css__copy_voice_family( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_voice_family(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/volume.c b/src/select/properties/volume.c index 96787fa..64dd9a0 100644 --- a/src/select/properties/volume.c +++ b/src/select/properties/volume.c @@ -20,7 +20,7 @@ css_error css__cascade_volume(uint32_t opv, css_style *style, css_fixed val = 0; uint32_t unit = UNIT_PCT; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case VOLUME_NUMBER: val = *((css_fixed *) style->bytecode); @@ -40,13 +40,20 @@ css_error css__cascade_volume(uint32_t opv, css_style *style, case VOLUME_X_LOUD: /** \todo convert to public values */ break; + case VOLUME_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } unit = css__to_css_unit(unit); if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { /** \todo volume */ } @@ -69,6 +76,16 @@ css_error css__initial_volume(css_select_state *state) return CSS_OK; } +css_error css__copy_volume( + const css_computed_style *from, + css_computed_style *to) +{ + UNUSED(from); + UNUSED(to); + + return CSS_OK; +} + css_error css__compose_volume(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) diff --git a/src/select/properties/white_space.c b/src/select/properties/white_space.c index b8d2e02..edc35cd 100644 --- a/src/select/properties/white_space.c +++ b/src/select/properties/white_space.c @@ -21,7 +21,7 @@ css_error css__cascade_white_space(uint32_t opv, css_style *style, UNUSED(style); - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case WHITE_SPACE_NORMAL: value = CSS_WHITE_SPACE_NORMAL; @@ -42,7 +42,7 @@ css_error css__cascade_white_space(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_white_space(state->computed, value); } @@ -60,16 +60,25 @@ css_error css__initial_white_space(css_select_state *state) return set_white_space(state->computed, CSS_WHITE_SPACE_NORMAL); } +css_error css__copy_white_space( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_white_space(to, get_white_space(from)); +} + css_error css__compose_white_space(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { uint8_t type = get_white_space(child); - if (type == CSS_WHITE_SPACE_INHERIT) { - type = get_white_space(parent); - } - - return set_white_space(result, type); + return css__copy_white_space( + type == CSS_WHITE_SPACE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/widows.c b/src/select/properties/widows.c index 61126c2..853c08d 100644 --- a/src/select/properties/widows.c +++ b/src/select/properties/widows.c @@ -31,6 +31,20 @@ css_error css__initial_widows(css_select_state *state) return set_widows(state->computed, CSS_WIDOWS_SET, 2); } +css_error css__copy_widows( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t count = 0; + uint8_t type = get_widows(from, &count); + + if (from == to) { + return CSS_OK; + } + + return set_widows(to, type, count); +} + css_error css__compose_widows(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -38,10 +52,8 @@ css_error css__compose_widows(const css_computed_style *parent, int32_t count = 0; uint8_t type = get_widows(child, &count); - if (type == CSS_WIDOWS_INHERIT) { - type = get_widows(parent, &count); - } - - return set_widows(result, type, count); + return css__copy_widows( + type == CSS_WIDOWS_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/width.c b/src/select/properties/width.c index 829df91..b382bcc 100644 --- a/src/select/properties/width.c +++ b/src/select/properties/width.c @@ -17,33 +17,46 @@ css_error css__cascade_width(uint32_t opv, css_style *style, css_select_state *state) { - return css__cascade_length_auto(opv, style, state, set_width); + return css__cascade_length_auto_calc(opv, style, state, set_width); } css_error css__set_width_from_hint(const css_hint *hint, css_computed_style *style) { return set_width(style, hint->status, - hint->data.length.value, hint->data.length.unit); + (css_fixed_or_calc)(hint->data.length.value), hint->data.length.unit); } css_error css__initial_width(css_select_state *state) { - return set_width(state->computed, CSS_WIDTH_AUTO, 0, CSS_UNIT_PX); + return set_width(state->computed, CSS_WIDTH_AUTO, (css_fixed_or_calc)0, CSS_UNIT_PX); +} + +css_error css__copy_width( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed_or_calc length = (css_fixed_or_calc)0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_width(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_width(to, type, length, unit); } css_error css__compose_width(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { - css_fixed length = 0; + css_fixed_or_calc length = (css_fixed_or_calc)0; css_unit unit = CSS_UNIT_PX; uint8_t type = get_width(child, &length, &unit); - if (type == CSS_WIDTH_INHERIT) { - type = get_width(parent, &length, &unit); - } - - return set_width(result, type, length, unit); + return css__copy_width( + type == CSS_WIDTH_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/word_spacing.c b/src/select/properties/word_spacing.c index eb39b50..c1c6782 100644 --- a/src/select/properties/word_spacing.c +++ b/src/select/properties/word_spacing.c @@ -33,6 +33,21 @@ css_error css__initial_word_spacing(css_select_state *state) 0, CSS_UNIT_PX); } +css_error css__copy_word_spacing( + const css_computed_style *from, + css_computed_style *to) +{ + css_fixed length = 0; + css_unit unit = CSS_UNIT_PX; + uint8_t type = get_word_spacing(from, &length, &unit); + + if (from == to) { + return CSS_OK; + } + + return set_word_spacing(to, type, length, unit); +} + css_error css__compose_word_spacing(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -41,9 +56,7 @@ css_error css__compose_word_spacing(const css_computed_style *parent, css_unit unit = CSS_UNIT_PX; uint8_t type = get_word_spacing(child, &length, &unit); - if (type == CSS_WORD_SPACING_INHERIT) { - type = get_word_spacing(parent, &length, &unit); - } - - return set_word_spacing(result, type, length, unit); + return css__copy_word_spacing( + type == CSS_WORD_SPACING_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/writing_mode.c b/src/select/properties/writing_mode.c index bbd3753..05c0b26 100644 --- a/src/select/properties/writing_mode.c +++ b/src/select/properties/writing_mode.c @@ -17,11 +17,11 @@ css_error css__cascade_writing_mode(uint32_t opv, css_style *style, css_select_state *state) { - bool inherit = isInherit(opv); + enum flag_value flag_value = getFlagValue(opv); uint16_t writing_mode = CSS_WRITING_MODE_INHERIT; UNUSED(style); - if (inherit == false) { + if (flag_value == FLAG_VALUE__NONE) { switch (getValue(opv)) { case WRITING_MODE_HORIZONTAL_TB: writing_mode = CSS_WRITING_MODE_HORIZONTAL_TB; @@ -36,7 +36,7 @@ css_error css__cascade_writing_mode(uint32_t opv, css_style *style, } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - inherit)) { + flag_value)) { return set_writing_mode(state->computed, writing_mode); } @@ -55,16 +55,25 @@ css_error css__initial_writing_mode(css_select_state *state) CSS_WRITING_MODE_HORIZONTAL_TB); } +css_error css__copy_writing_mode( + const css_computed_style *from, + css_computed_style *to) +{ + if (from == to) { + return CSS_OK; + } + + return set_writing_mode(to, get_writing_mode(from)); +} + css_error css__compose_writing_mode(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) { - uint8_t writing_mode = get_writing_mode(child); - - if (writing_mode == CSS_WRITING_MODE_INHERIT) { - writing_mode = get_writing_mode(parent); - } + uint8_t type = get_writing_mode(child); - return set_writing_mode(result, writing_mode); + return css__copy_writing_mode( + type == CSS_WRITING_MODE_INHERIT ? parent : child, + result); } diff --git a/src/select/properties/z_index.c b/src/select/properties/z_index.c index 59cf242..23d0402 100644 --- a/src/select/properties/z_index.c +++ b/src/select/properties/z_index.c @@ -20,7 +20,7 @@ css_error css__cascade_z_index(uint32_t opv, css_style *style, uint16_t value = CSS_Z_INDEX_INHERIT; css_fixed index = 0; - if (isInherit(opv) == false) { + if (hasFlagValue(opv) == false) { switch (getValue(opv)) { case Z_INDEX_SET: value = CSS_Z_INDEX_SET; @@ -31,11 +31,18 @@ css_error css__cascade_z_index(uint32_t opv, css_style *style, case Z_INDEX_AUTO: value = CSS_Z_INDEX_AUTO; break; + case Z_INDEX_CALC: + advance_bytecode(style, sizeof(unit)); + advance_bytecode(style, sizeof(unit)); // TODO + return CSS_OK; + default: + assert(0 && "Invalid value"); + break; } } if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + getFlagValue(opv))) { return set_z_index(state->computed, value, index); } @@ -53,6 +60,20 @@ css_error css__initial_z_index(css_select_state *state) return set_z_index(state->computed, CSS_Z_INDEX_AUTO, 0); } +css_error css__copy_z_index( + const css_computed_style *from, + css_computed_style *to) +{ + int32_t index = 0; + uint8_t type = get_z_index(from, &index); + + if (from == to) { + return CSS_OK; + } + + return set_z_index(to, type, index); +} + css_error css__compose_z_index(const css_computed_style *parent, const css_computed_style *child, css_computed_style *result) @@ -60,10 +81,8 @@ css_error css__compose_z_index(const css_computed_style *parent, int32_t index = 0; uint8_t type = get_z_index(child, &index); - if (type == CSS_Z_INDEX_INHERIT) { - type = get_z_index(parent, &index); - } - - return set_z_index(result, type, index); + return css__copy_z_index( + type == CSS_Z_INDEX_INHERIT ? parent : child, + result); } |