diff options
-rw-r--r-- | src/parse/css21props.c | 107 |
1 files changed, 74 insertions, 33 deletions
diff --git a/src/parse/css21props.c b/src/parse/css21props.c index 8574f82..593b8ce 100644 --- a/src/parse/css21props.c +++ b/src/parse/css21props.c @@ -328,6 +328,9 @@ static inline css_error parse_border_side_style(css_css21 *c, static inline css_error parse_border_side_width(css_css21 *c, const parserutils_vector *vector, int *ctx, uint16_t side, css_style **result); +static inline css_error parse_margin_side(css_css21 *c, + const parserutils_vector *vector, int *ctx, + uint16_t side, css_style **result); /** * Type of property handler function @@ -2163,48 +2166,28 @@ css_error parse_margin_bottom(css_css21 *c, const parserutils_vector *vector, int *ctx, css_style **result) { - UNUSED(c); - UNUSED(vector); - UNUSED(ctx); - UNUSED(result); - - return CSS_OK; + return parse_margin_side(c, vector, ctx, SIDE_BOTTOM, result); } css_error parse_margin_left(css_css21 *c, const parserutils_vector *vector, int *ctx, css_style **result) { - UNUSED(c); - UNUSED(vector); - UNUSED(ctx); - UNUSED(result); - - return CSS_OK; + return parse_margin_side(c, vector, ctx, SIDE_LEFT, result); } css_error parse_margin_right(css_css21 *c, const parserutils_vector *vector, int *ctx, css_style **result) { - UNUSED(c); - UNUSED(vector); - UNUSED(ctx); - UNUSED(result); - - return CSS_OK; + return parse_margin_side(c, vector, ctx, SIDE_RIGHT, result); } css_error parse_margin_top(css_css21 *c, const parserutils_vector *vector, int *ctx, css_style **result) { - UNUSED(c); - UNUSED(vector); - UNUSED(ctx); - UNUSED(result); - - return CSS_OK; + return parse_margin_side(c, vector, ctx, SIDE_TOP, result); } css_error parse_max_height(css_css21 *c, @@ -2973,13 +2956,11 @@ css_error parse_border_side_color(css_css21 *c, value = BORDER_COLOR_SET; } - value |= side; - error = parse_important(c, vector, ctx, &flags); if (error != CSS_OK) return error; - opv = buildOPV(OP_BORDER_TRBL_COLOR, flags, value); + opv = buildOPV(OP_BORDER_TRBL_COLOR, flags, value | side); required_size = sizeof(opv); if (value == BORDER_COLOR_SET) @@ -3045,9 +3026,7 @@ css_error parse_border_side_style(css_css21 *c, } else return CSS_INVALID; - value |= side; - - opv = buildOPV(OP_BORDER_TRBL_STYLE, flags, value); + opv = buildOPV(OP_BORDER_TRBL_STYLE, flags, value | side); /* Allocate result */ error = css_stylesheet_style_create(c->sheet, sizeof(opv), result); @@ -3106,13 +3085,11 @@ css_error parse_border_side_width(css_css21 *c, value = BORDER_WIDTH_SET; } - value |= side; - error = parse_important(c, vector, ctx, &flags); if (error != CSS_OK) return error; - opv = buildOPV(OP_BORDER_TRBL_WIDTH, flags, value); + opv = buildOPV(OP_BORDER_TRBL_WIDTH, flags, value | side); required_size = sizeof(opv); if (value == BORDER_WIDTH_SET) @@ -3136,4 +3113,68 @@ css_error parse_border_side_width(css_css21 *c, } +css_error parse_margin_side(css_css21 *c, + const parserutils_vector *vector, int *ctx, + uint16_t side, css_style **result) +{ + css_error error; + const css_token *token; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + fixed length = 0; + uint32_t unit = 0; + uint32_t required_size; + + /* length | percentage | IDENT(auto, inherit) */ + token = parserutils_vector_peek(vector, *ctx); + if (token == NULL) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT && + token->lower.ptr == c->strings[INHERIT]) { + parserutils_vector_iterate(vector, ctx); + flags = FLAG_INHERIT; + } else if (token->type == CSS_TOKEN_IDENT && + token->lower.ptr == c->strings[AUTO]) { + parserutils_vector_iterate(vector, ctx); + value = MARGIN_AUTO; + } else { + error = parse_unit_specifier(c, vector, ctx, &length, &unit); + if (error != CSS_OK) + return error; + + if (unit & UNIT_ANGLE || unit & UNIT_TIME || unit & UNIT_FREQ) + return CSS_INVALID; + + value = MARGIN_SET; + } + + error = parse_important(c, vector, ctx, &flags); + if (error != CSS_OK) + return error; + + opv = buildOPV(OP_MARGIN_TRBL, flags, value | side); + + required_size = sizeof(opv); + if (value == MARGIN_SET) + required_size += sizeof(length) + sizeof(unit); + + /* Allocate result */ + error = css_stylesheet_style_create(c->sheet, required_size, result); + if (error != CSS_OK) + return error; + + /* Copy the bytecode to it */ + memcpy((*result)->bytecode, &opv, sizeof(opv)); + if (value == MARGIN_SET) { + memcpy(((uint8_t *) (*result)->bytecode) + sizeof(opv), + &length, sizeof(length)); + memcpy(((uint8_t *) (*result)->bytecode) + sizeof(opv) + + sizeof(length), &unit, sizeof(unit)); + } + + return CSS_OK; +} + #endif |