From 1b13f81b8259f4416df7b3063cb280cb977722d7 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 29 Jan 2011 17:53:22 +0000 Subject: Centralise handling of transparent colours. Add support for currentColor svn path=/trunk/libcss/; revision=11525 --- docs/Bytecode | 20 +- include/libcss/properties.h | 14 +- src/bytecode/opcodes.h | 14 +- src/parse/properties/border_color.c | 14 +- src/parse/properties/css_property_parser_gen.c | 13 +- src/parse/properties/properties.gen | 4 +- src/parse/properties/utils.c | 33 ++-- src/parse/properties/utils.h | 2 +- src/parse/propstrings.c | 1 + src/parse/propstrings.h | 2 +- src/select/computed.c | 58 +++++- src/select/properties/background_color.c | 2 +- src/select/properties/border_bottom_color.c | 2 +- src/select/properties/border_left_color.c | 2 +- src/select/properties/border_right_color.c | 2 +- src/select/properties/border_top_color.c | 2 +- src/select/properties/color.c | 25 ++- src/select/properties/helpers.c | 9 +- src/select/properties/outline_color.c | 6 + test/data/parse/colours.dat | 10 +- test/data/parse/properties.dat | 34 +++- test/data/parse2/bg.dat | 24 +++ test/data/parse2/border.dat | 38 ++++ test/data/parse2/outline.dat | 20 ++ test/data/select/tests1.dat | 262 ++++++++++++++++--------- test/dump.h | 17 ++ test/dump_computed.h | 33 +--- 27 files changed, 471 insertions(+), 192 deletions(-) diff --git a/docs/Bytecode b/docs/Bytecode index da6256e..5d7d431 100644 --- a/docs/Bytecode +++ b/docs/Bytecode @@ -149,8 +149,9 @@ Opcodes bit 7 set => colour follows. bits 0-6: MBZ bit 7 clear => keyword colour: - bits 1-6: MBZ - bit 0 : clear => transparent, set => rffe. + bits 0-6: 0000000 => transparent, + 0000001 => currentColor, + other => rffe. 03 - background-image (14bits) : @@ -214,8 +215,9 @@ Opcodes bit 7 set => colour follows. bits 0-6: MBZ bit 7 clear => keyword colour: - bits 1-6: MBZ - bit 0 : clear => transparent, set => rffe. + bits 0-6: 0000000 => transparent, + 0000001 => currentColor, + other => rffe. 0c - border-top-style 0d - border-right-style @@ -310,8 +312,10 @@ Opcodes bits 0-7: bit 7: set => colour follows. bits 0-6: MBZ. - clear => Reserved for future expansion. - bits 0-6: MBZ. + clear => keywords: + bits 0-6: 0000000 => transparent, + 0000001 => currentColor, + other => rffe. 19 - content (14bits) : @@ -707,7 +711,9 @@ Opcodes bit 7 set => colour follows bits 0-6: MBZ bit 7 clear => keywords: - bits 0-6: 0000000 => invert, + bits 0-6: 0000000 => transparent, + 0000001 => currentColor, + 0000010 => invert, other => rffe. 3a - outline-style diff --git a/include/libcss/properties.h b/include/libcss/properties.h index 0c139a3..11fb04d 100644 --- a/include/libcss/properties.h +++ b/include/libcss/properties.h @@ -126,8 +126,8 @@ enum css_background_attachment_e { enum css_background_color_e { CSS_BACKGROUND_COLOR_INHERIT = 0x0, - CSS_BACKGROUND_COLOR_TRANSPARENT = 0x1, - CSS_BACKGROUND_COLOR_COLOR = 0x2 + CSS_BACKGROUND_COLOR_COLOR = 0x1, + CSS_BACKGROUND_COLOR_CURRENT_COLOR = 0x2 }; enum css_background_image_e { @@ -163,9 +163,8 @@ enum css_border_spacing_e { enum css_border_color_e { CSS_BORDER_COLOR_INHERIT = CSS_BACKGROUND_COLOR_INHERIT, - CSS_BORDER_COLOR_TRANSPARENT = CSS_BACKGROUND_COLOR_TRANSPARENT, CSS_BORDER_COLOR_COLOR = CSS_BACKGROUND_COLOR_COLOR, - CSS_BORDER_COLOR_INITIAL = 0x3 + CSS_BORDER_COLOR_CURRENT_COLOR = CSS_BACKGROUND_COLOR_CURRENT_COLOR, }; enum css_border_style_e { @@ -443,9 +442,10 @@ enum css_min_width_e { }; enum css_outline_color_e { - CSS_OUTLINE_COLOR_INHERIT = 0x0, - CSS_OUTLINE_COLOR_COLOR = 0x1, - CSS_OUTLINE_COLOR_INVERT = 0x2 + CSS_OUTLINE_COLOR_INHERIT = CSS_BACKGROUND_COLOR_INHERIT, + CSS_OUTLINE_COLOR_COLOR = CSS_BACKGROUND_COLOR_COLOR, + CSS_OUTLINE_COLOR_CURRENT_COLOR = CSS_BACKGROUND_COLOR_CURRENT_COLOR, + CSS_OUTLINE_COLOR_INVERT = 0x3 }; enum css_outline_style_e { diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h index 3fad172..991d099 100644 --- a/src/bytecode/opcodes.h +++ b/src/bytecode/opcodes.h @@ -35,6 +35,7 @@ enum op_background_attachment { enum op_background_color { BACKGROUND_COLOR_TRANSPARENT = 0x0000, + BACKGROUND_COLOR_CURRENT_COLOR = 0x0001, BACKGROUND_COLOR_SET = 0x0080 }; @@ -72,8 +73,9 @@ enum op_border_spacing { }; enum op_border_color { - BORDER_COLOR_SET = 0x0080, - BORDER_COLOR_TRANSPARENT = 0x0000 + BORDER_COLOR_TRANSPARENT = 0x0000, + BORDER_COLOR_CURRENT_COLOR = 0x0001, + BORDER_COLOR_SET = 0x0080 }; enum op_border_style { @@ -126,6 +128,8 @@ enum op_clip { }; enum op_color { + COLOR_TRANSPARENT = 0x0000, + COLOR_CURRENT_COLOR = 0x0001, COLOR_SET = 0x0080 }; @@ -366,8 +370,10 @@ enum op_orphans { }; enum op_outline_color { - OUTLINE_COLOR_SET = 0x0080, - OUTLINE_COLOR_INVERT = 0x0000 + OUTLINE_COLOR_TRANSPARENT = 0x0000, + OUTLINE_COLOR_CURRENT_COLOR = 0x0001, + OUTLINE_COLOR_INVERT = 0x0002, + OUTLINE_COLOR_SET = 0x0080 }; enum op_outline_style { diff --git a/src/parse/properties/border_color.c b/src/parse/properties/border_color.c index 074b457..7495ffc 100644 --- a/src/parse/properties/border_color.c +++ b/src/parse/properties/border_color.c @@ -37,7 +37,6 @@ css_error css__parse_border_color(css_language *c, uint16_t side_val[4]; uint32_t side_color[4]; uint32_t side_count = 0; - bool match; css_error error; /* Firstly, handle inherit */ @@ -74,18 +73,7 @@ css_error css__parse_border_color(css_language *c, return CSS_INVALID; } - if ((token->type == CSS_TOKEN_IDENT) && - (lwc_string_caseless_isequal(token->idata, - c->strings[TRANSPARENT], - &match) == lwc_error_ok && match)) { - side_val[side_count] = BORDER_COLOR_TRANSPARENT; - parserutils_vector_iterate(vector, ctx); - error = CSS_OK; - } else { - side_val[side_count] = BORDER_COLOR_SET; - error = css__parse_colour_specifier(c, vector, ctx, &side_color[side_count]); - } - + error = css__parse_colour_specifier(c, vector, ctx, &side_val[side_count], &side_color[side_count]); if (error == CSS_OK) { side_count++; diff --git a/src/parse/properties/css_property_parser_gen.c b/src/parse/properties/css_property_parser_gen.c index ae1fa04..dec4745 100644 --- a/src/parse/properties/css_property_parser_gen.c +++ b/src/parse/properties/css_property_parser_gen.c @@ -268,27 +268,26 @@ void output_number(FILE *outputf, struct keyval *parseid, struct keyval_list *kv void output_color(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist) { - struct keyval *ckv = kvlist->item[0]; - fprintf(outputf, "{\n" + "\t\tuint16_t value = 0;\n" "\t\tuint32_t color = 0;\n" "\t\t*ctx = orig_ctx;\n\n" - "\t\terror = css__parse_colour_specifier(c, vector, ctx, &color);\n" + "\t\terror = css__parse_colour_specifier(c, vector, ctx, &value, &color);\n" "\t\tif (error != CSS_OK) {\n" "\t\t\t*ctx = orig_ctx;\n" "\t\t\treturn error;\n" "\t\t}\n\n" - "\t\terror = css__stylesheet_style_appendOPV(result, %s, 0, %s);\n" + "\t\terror = css__stylesheet_style_appendOPV(result, %s, 0, value);\n" "\t\tif (error != CSS_OK) {\n" "\t\t\t*ctx = orig_ctx;\n" "\t\t\treturn error;\n" "\t\t}\n" "\n" - "\t\terror = css__stylesheet_style_append(result, color);\n" + "\t\tif (value == COLOR_SET)\n" + "\t\t\terror = css__stylesheet_style_append(result, color);\n" "\t}\n\n", - parseid->val, - ckv->val); + parseid->val); } void output_length_unit(FILE *outputf, struct keyval *parseid, struct keyval_list *kvlist) diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen index b0e84b8..016d7a0 100644 --- a/src/parse/properties/properties.gen +++ b/src/parse/properties/properties.gen @@ -93,7 +93,7 @@ border_left_style:CSS_PROP_BORDER_LEFT_STYLE WRAP:css__parse_border_side_style border_right_style:CSS_PROP_BORDER_RIGHT_STYLE WRAP:css__parse_border_side_style #generic for border_{top, bottom, left, right}_color.c -border_side_color:op GENERIC: IDENT:( INHERIT: TRANSPARENT:0,BORDER_COLOR_TRANSPARENT IDENT:) COLOR:BORDER_COLOR_SET +border_side_color:op GENERIC: IDENT:( INHERIT: IDENT:) COLOR:BORDER_COLOR_SET border_top_color:CSS_PROP_BORDER_TOP_COLOR WRAP:css__parse_border_side_color border_bottom_color:CSS_PROP_BORDER_BOTTOM_COLOR WRAP:css__parse_border_side_color @@ -108,7 +108,7 @@ counter_reset:CSS_PROP_COUNTER_RESET IDENT:( INHERIT: NONE:0,COUNTER_RESET_NONE background_attachment:CSS_PROP_BACKGROUND_ATTACHMENT IDENT:( INHERIT: FIXED:0,BACKGROUND_ATTACHMENT_FIXED SCROLL:0,BACKGROUND_ATTACHMENT_SCROLL IDENT:) -background_color:CSS_PROP_BACKGROUND_COLOR IDENT:( INHERIT: TRANSPARENT:0,BACKGROUND_COLOR_TRANSPARENT IDENT:) COLOR:BACKGROUND_COLOR_SET +background_color:CSS_PROP_BACKGROUND_COLOR IDENT:( INHERIT: IDENT:) COLOR:BACKGROUND_COLOR_SET caption_side:CSS_PROP_CAPTION_SIDE IDENT:( INHERIT: TOP:0,CAPTION_SIDE_TOP BOTTOM:0,CAPTION_SIDE_BOTTOM IDENT:) diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c index 860712d..934b3f6 100644 --- a/src/parse/properties/utils.c +++ b/src/parse/properties/utils.c @@ -342,6 +342,7 @@ static void HSL_to_RGB(css_fixed hue, css_fixed sat, css_fixed lit, uint8_t *r, * \param c Parsing context * \param vector Vector of tokens to process * \param ctx Pointer to vector iteration context + * \param value Pointer to location to receive value * \param result Pointer to location to receive result (AARRGGBB) * \return CSS_OK on success, * CSS_INVALID if the input is invalid @@ -351,11 +352,10 @@ static void HSL_to_RGB(css_fixed hue, css_fixed sat, css_fixed lit, uint8_t *r, */ css_error css__parse_colour_specifier(css_language *c, const parserutils_vector *vector, int *ctx, - uint32_t *result) + uint16_t *value, uint32_t *result) { int orig_ctx = *ctx; const css_token *token; - uint8_t r = 0, g = 0, b = 0, a = 0xff; bool match; css_error error; @@ -386,9 +386,17 @@ css_error css__parse_colour_specifier(css_language *c, if ((lwc_string_caseless_isequal( token->idata, c->strings[TRANSPARENT], &match) == lwc_error_ok && match)) { + *value = COLOR_TRANSPARENT; *result = 0; /* black transparent */ return CSS_OK; + } else if ((lwc_string_caseless_isequal( + token->idata, c->strings[CURRENTCOLOR], + &match) == lwc_error_ok && match)) { + *value = COLOR_CURRENT_COLOR; + *result = 0; + return CSS_OK; } + error = css__parse_named_colour(c, token->idata, result); if (error != CSS_OK && c->sheet->quirks_allowed) { error = css__parse_hash_colour(token->idata, result); @@ -397,34 +405,27 @@ css_error css__parse_colour_specifier(css_language *c, } if (error != CSS_OK) - *ctx = orig_ctx; - - return error; + goto invalid; } else if (token->type == CSS_TOKEN_HASH) { error = css__parse_hash_colour(token->idata, result); if (error != CSS_OK) - *ctx = orig_ctx; - - return error; + goto invalid; } else if (c->sheet->quirks_allowed && token->type == CSS_TOKEN_NUMBER) { error = css__parse_hash_colour(token->idata, result); if (error == CSS_OK) c->sheet->quirks_used = true; else - *ctx = orig_ctx; - - return error; + goto invalid; } else if (c->sheet->quirks_allowed && token->type == CSS_TOKEN_DIMENSION) { error = css__parse_hash_colour(token->idata, result); if (error == CSS_OK) c->sheet->quirks_used = true; else - *ctx = orig_ctx; - - return error; + goto invalid; } else if (token->type == CSS_TOKEN_FUNCTION) { + uint8_t r = 0, g = 0, b = 0, a = 0xff; int colour_channels = 0; if ((lwc_string_caseless_isequal( @@ -641,9 +642,11 @@ css_error css__parse_colour_specifier(css_language *c, } else { goto invalid; } + + *result = (a << 24) | (r << 16) | (g << 8) | b; } - *result = (a << 24) | (r << 16) | (g << 8) | b; + *value = COLOR_SET; return CSS_OK; diff --git a/src/parse/properties/utils.h b/src/parse/properties/utils.h index e5315bb..ab045bd 100644 --- a/src/parse/properties/utils.h +++ b/src/parse/properties/utils.h @@ -166,7 +166,7 @@ css_error css__parse_list_style_type_value(css_language *c, css_error css__parse_colour_specifier(css_language *c, const parserutils_vector *vector, int *ctx, - uint32_t *result); + uint16_t *value, uint32_t *result); css_error css__parse_named_colour(css_language *c, lwc_string *data, uint32_t *result); diff --git a/src/parse/propstrings.c b/src/parse/propstrings.c index 354c794..9e81300 100644 --- a/src/parse/propstrings.c +++ b/src/parse/propstrings.c @@ -336,6 +336,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = { { "-libcss-left", SLEN("-libcss-left") }, { "-libcss-center", SLEN("-libcss-center") }, { "-libcss-right", SLEN("-libcss-right") }, + { "currentColor", SLEN("currentColor") }, { "aliceblue", SLEN("aliceblue") }, { "antiquewhite", SLEN("antiquewhite") }, diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h index d3b7208..5a1662d 100644 --- a/src/parse/propstrings.h +++ b/src/parse/propstrings.h @@ -85,7 +85,7 @@ enum { W_RESIZE, LIBCSS_TEXT, WAIT, HELP, PROGRESS, SERIF, SANS_SERIF, CURSIVE, FANTASY, MONOSPACE, MALE, FEMALE, CHILD, MIX, UNDERLINE, OVERLINE, LINE_THROUGH, BLINK, RGB, RGBA, HSL, HSLA, LIBCSS_LEFT, LIBCSS_CENTER, - LIBCSS_RIGHT, + LIBCSS_RIGHT, CURRENTCOLOR, /* Named colours */ FIRST_COLOUR, diff --git a/src/select/computed.c b/src/select/computed.c index 5479d2f..ee667e2 100644 --- a/src/select/computed.c +++ b/src/select/computed.c @@ -13,6 +13,11 @@ #include "select/propset.h" #include "utils/utils.h" +static css_error compute_absolute_color(css_computed_style *style, + uint8_t (*get)(const css_computed_style *style, + css_color *color), + css_error (*set)(css_computed_style *style, + uint8_t type, css_color color)); static css_error compute_border_colors(css_computed_style *style); static css_error compute_absolute_border_width(css_computed_style *style, @@ -375,6 +380,13 @@ css_error css__compute_absolute_values(const css_computed_style *parent, if (error != CSS_OK) return error; + /* Fix up background-color */ + error = compute_absolute_color(style, + get_background_color, + set_background_color); + if (error != CSS_OK) + return error; + /* Fix up border-{top,right,bottom,left}-color */ error = compute_border_colors(style); if (error != CSS_OK) @@ -475,6 +487,13 @@ css_error css__compute_absolute_values(const css_computed_style *parent, if (error != CSS_OK) return error; + /* Fix up outline-color */ + error = compute_absolute_color(style, + get_outline_color, + set_outline_color); + if (error != CSS_OK) + return error; + /* Fix up outline-width */ error = compute_absolute_border_side_width(style, &ex_size.data.length, @@ -500,7 +519,36 @@ css_error css__compute_absolute_values(const css_computed_style *parent, ******************************************************************************/ /** - * Compute border colours, replacing any set to initial with + * Compute colour values, replacing any set to currentColor with + * the computed value of color. + * + * \param style The style to process + * \param get Accessor for colour value + * \param set Mutator for colour value + * \return CSS_OK on success + */ +css_error compute_absolute_color(css_computed_style *style, + uint8_t (*get)(const css_computed_style *style, + css_color *color), + css_error (*set)(css_computed_style *style, + uint8_t type, css_color color)) +{ + css_color color; + css_error error = CSS_OK; + + if (get(style, &color) == CSS_BACKGROUND_COLOR_CURRENT_COLOR) { + css_color computed_color; + + css_computed_color(style, &computed_color); + + error = set(style, CSS_BACKGROUND_COLOR_COLOR, computed_color); + } + + return error; +} + +/** + * Compute border colours, replacing any set to currentColor with * the computed value of color. * * \param style The style to process @@ -513,28 +561,28 @@ css_error compute_border_colors(css_computed_style *style) css_computed_color(style, &color); - if (get_border_top_color(style, &bcol) == CSS_BORDER_COLOR_INITIAL) { + if (get_border_top_color(style, &bcol) == CSS_BORDER_COLOR_CURRENT_COLOR) { error = set_border_top_color(style, CSS_BORDER_COLOR_COLOR, color); if (error != CSS_OK) return error; } - if (get_border_right_color(style, &bcol) == CSS_BORDER_COLOR_INITIAL) { + if (get_border_right_color(style, &bcol) == CSS_BORDER_COLOR_CURRENT_COLOR) { error = set_border_right_color(style, CSS_BORDER_COLOR_COLOR, color); if (error != CSS_OK) return error; } - if (get_border_bottom_color(style, &bcol) == CSS_BORDER_COLOR_INITIAL) { + if (get_border_bottom_color(style, &bcol) == CSS_BORDER_COLOR_CURRENT_COLOR) { error = set_border_bottom_color(style, CSS_BORDER_COLOR_COLOR, color); if (error != CSS_OK) return error; } - if (get_border_left_color(style, &bcol) == CSS_BORDER_COLOR_INITIAL) { + if (get_border_left_color(style, &bcol) == CSS_BORDER_COLOR_CURRENT_COLOR) { error = set_border_left_color(style, CSS_BORDER_COLOR_COLOR, color); if (error != CSS_OK) diff --git a/src/select/properties/background_color.c b/src/select/properties/background_color.c index e71fc7d..07ba82e 100644 --- a/src/select/properties/background_color.c +++ b/src/select/properties/background_color.c @@ -29,7 +29,7 @@ css_error css__set_background_color_from_hint(const css_hint *hint, css_error css__initial_background_color(css_select_state *state) { return set_background_color(state->computed, - CSS_BACKGROUND_COLOR_TRANSPARENT, 0); + CSS_BACKGROUND_COLOR_COLOR, 0); } css_error css__compose_background_color(const css_computed_style *parent, diff --git a/src/select/properties/border_bottom_color.c b/src/select/properties/border_bottom_color.c index 0df95cc..2e63982 100644 --- a/src/select/properties/border_bottom_color.c +++ b/src/select/properties/border_bottom_color.c @@ -30,7 +30,7 @@ css_error css__set_border_bottom_color_from_hint(const css_hint *hint, css_error css__initial_border_bottom_color(css_select_state *state) { return set_border_bottom_color(state->computed, - CSS_BORDER_COLOR_INITIAL, 0); + CSS_BORDER_COLOR_CURRENT_COLOR, 0); } css_error css__compose_border_bottom_color(const css_computed_style *parent, diff --git a/src/select/properties/border_left_color.c b/src/select/properties/border_left_color.c index ea631ee..cf08257 100644 --- a/src/select/properties/border_left_color.c +++ b/src/select/properties/border_left_color.c @@ -30,7 +30,7 @@ css_error css__set_border_left_color_from_hint(const css_hint *hint, css_error css__initial_border_left_color(css_select_state *state) { return set_border_left_color(state->computed, - CSS_BORDER_COLOR_INITIAL, 0); + CSS_BORDER_COLOR_CURRENT_COLOR, 0); } css_error css__compose_border_left_color(const css_computed_style *parent, diff --git a/src/select/properties/border_right_color.c b/src/select/properties/border_right_color.c index 5f9b6ca..1829784 100644 --- a/src/select/properties/border_right_color.c +++ b/src/select/properties/border_right_color.c @@ -30,7 +30,7 @@ css_error css__set_border_right_color_from_hint(const css_hint *hint, css_error css__initial_border_right_color(css_select_state *state) { return set_border_right_color(state->computed, - CSS_BORDER_COLOR_INITIAL, 0); + CSS_BORDER_COLOR_CURRENT_COLOR, 0); } css_error css__compose_border_right_color(const css_computed_style *parent, diff --git a/src/select/properties/border_top_color.c b/src/select/properties/border_top_color.c index 328ce67..1517eea 100644 --- a/src/select/properties/border_top_color.c +++ b/src/select/properties/border_top_color.c @@ -28,7 +28,7 @@ css_error css__set_border_top_color_from_hint(const css_hint *hint, css_error css__initial_border_top_color(css_select_state *state) { - return set_border_top_color(state->computed, CSS_BORDER_COLOR_INITIAL, 0); + return set_border_top_color(state->computed, CSS_BORDER_COLOR_CURRENT_COLOR, 0); } css_error css__compose_border_top_color(const css_computed_style *parent, diff --git a/src/select/properties/color.c b/src/select/properties/color.c index 3cd1e3d..dad2b9d 100644 --- a/src/select/properties/color.c +++ b/src/select/properties/color.c @@ -17,17 +17,30 @@ css_error css__cascade_color(uint32_t opv, css_style *style, css_select_state *state) { + bool inherit = isInherit(opv); uint16_t value = CSS_COLOR_INHERIT; css_color color = 0; - if (isInherit(opv) == false) { - value = CSS_COLOR_COLOR; - color = *((css_color *) style->bytecode); - advance_bytecode(style, sizeof(color)); + if (inherit == false) { + switch (getValue(opv)) { + case COLOR_TRANSPARENT: + value = CSS_COLOR_COLOR; + break; + case COLOR_CURRENT_COLOR: + /* color: currentColor always computes to inherit */ + value = CSS_COLOR_INHERIT; + inherit = true; + break; + case COLOR_SET: + value = CSS_COLOR_COLOR; + color = *((css_color *) style->bytecode); + advance_bytecode(style, sizeof(color)); + break; + } } - if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, - isInherit(opv))) { + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + inherit)) { return set_color(state->computed, value, color); } diff --git a/src/select/properties/helpers.c b/src/select/properties/helpers.c index 9635dd8..3851b36 100644 --- a/src/select/properties/helpers.c +++ b/src/select/properties/helpers.c @@ -53,14 +53,17 @@ css_error css__cascade_bg_border_color(uint32_t opv, css_style *style, css_color color = 0; assert(CSS_BACKGROUND_COLOR_INHERIT == CSS_BORDER_COLOR_INHERIT); - assert(CSS_BACKGROUND_COLOR_TRANSPARENT == - CSS_BORDER_COLOR_TRANSPARENT); assert(CSS_BACKGROUND_COLOR_COLOR == CSS_BORDER_COLOR_COLOR); + assert(CSS_BACKGROUND_COLOR_CURRENT_COLOR == + CSS_BORDER_COLOR_CURRENT_COLOR); if (isInherit(opv) == false) { switch (getValue(opv)) { case BACKGROUND_COLOR_TRANSPARENT: - value = CSS_BACKGROUND_COLOR_TRANSPARENT; + value = CSS_BACKGROUND_COLOR_COLOR; + break; + case BACKGROUND_COLOR_CURRENT_COLOR: + value = CSS_BACKGROUND_COLOR_CURRENT_COLOR; break; case BACKGROUND_COLOR_SET: value = CSS_BACKGROUND_COLOR_COLOR; diff --git a/src/select/properties/outline_color.c b/src/select/properties/outline_color.c index dced1d8..36aafd7 100644 --- a/src/select/properties/outline_color.c +++ b/src/select/properties/outline_color.c @@ -22,6 +22,12 @@ css_error css__cascade_outline_color(uint32_t opv, css_style *style, if (isInherit(opv) == false) { switch (getValue(opv)) { + case OUTLINE_COLOR_TRANSPARENT: + value = CSS_OUTLINE_COLOR_COLOR; + break; + case OUTLINE_COLOR_CURRENT_COLOR: + value = CSS_OUTLINE_COLOR_CURRENT_COLOR; + break; case OUTLINE_COLOR_SET: value = CSS_OUTLINE_COLOR_COLOR; color = *((css_color *) style->bytecode); diff --git a/test/data/parse/colours.dat b/test/data/parse/colours.dat index 67d5427..0ca7a31 100644 --- a/test/data/parse/colours.dat +++ b/test/data/parse/colours.dat @@ -45,7 +45,15 @@ #errors #expected | 1 * -| 0x02000018 0x00000000 +| 0x00000018 +#reset + +#data +* { color: currentColor } +#errors +#expected +| 1 * +| 0x00040018 #reset ## Out-of-range rgb() parameters diff --git a/test/data/parse/properties.dat b/test/data/parse/properties.dat index ac038e5..29b5eb6 100644 --- a/test/data/parse/properties.dat +++ b/test/data/parse/properties.dat @@ -233,6 +233,14 @@ | 0x00000002 #reset +#data +* { background-color: currentColor } +#errors +#expected +| 1 * +| 0x00040002 +#reset + ## ## 03 - background-image ## @@ -493,6 +501,14 @@ | 0x0000000b #reset +#data +* { border-left-color: currentColor } +#errors +#expected +| 1 * +| 0x0004000b +#reset + ## ## 0c - border-top-style ## 0d - border-right-style @@ -2283,7 +2299,7 @@ p:before { content: open-quote url('http://picodrive.acornarcade.com/') " : " at #errors #expected | 1 * -| 0x00000039 +| 0x00080039 #reset #data @@ -2294,6 +2310,22 @@ p:before { content: open-quote url('http://picodrive.acornarcade.com/') " : " at | 0x02000039 0xffbbbbcc #reset +#data +* { outline-color: currentColor } +#errors +#expected +| 1 * +| 0x00040039 +#reset + +#data +* { outline-color: transparent } +#errors +#expected +| 1 * +| 0x00000039 +#reset + ## ## 3a - outline-style ## diff --git a/test/data/parse2/bg.dat b/test/data/parse2/bg.dat index 50c7340..0ad6444 100644 --- a/test/data/parse2/bg.dat +++ b/test/data/parse2/bg.dat @@ -10,6 +10,30 @@ | background-repeat: repeat #reset +#data +* { background: transparent } +#errors +#expected +| * +| background-attachment: scroll +| background-color: transparent +| background-image: none +| background-position: left top +| background-repeat: repeat +#reset + +#data +* { background: currentColor } +#errors +#expected +| * +| background-attachment: scroll +| background-color: currentColor +| background-image: none +| background-position: left top +| background-repeat: repeat +#reset + #data * { background: url("chess.png") gray 40% repeat fixed; } #errors diff --git a/test/data/parse2/border.dat b/test/data/parse2/border.dat index daecf3b..cd9ab13 100644 --- a/test/data/parse2/border.dat +++ b/test/data/parse2/border.dat @@ -36,6 +36,44 @@ | border-left-width: medium #reset +#data +* { border: transparent; } +#errors +#expected +| * +| border-top-color: transparent +| border-top-style: none +| border-top-width: medium +| border-right-color: transparent +| border-right-style: none +| border-right-width: medium +| border-bottom-color: transparent +| border-bottom-style: none +| border-bottom-width: medium +| border-left-color: transparent +| border-left-style: none +| border-left-width: medium +#reset + +#data +* { border: currentColor; } +#errors +#expected +| * +| border-top-color: currentColor +| border-top-style: none +| border-top-width: medium +| border-right-color: currentColor +| border-right-style: none +| border-right-width: medium +| border-bottom-color: currentColor +| border-bottom-style: none +| border-bottom-width: medium +| border-left-color: currentColor +| border-left-style: none +| border-left-width: medium +#reset + #data * { border: solid; } #errors diff --git a/test/data/parse2/outline.dat b/test/data/parse2/outline.dat index e39fa41..363b5d9 100644 --- a/test/data/parse2/outline.dat +++ b/test/data/parse2/outline.dat @@ -18,6 +18,26 @@ | outline-width: medium #reset +#data +* { outline: transparent; } +#errors +#expected +| * +| outline-color: transparent +| outline-style: none +| outline-width: medium +#reset + +#data +* { outline: currentColor; } +#errors +#expected +| * +| outline-color: currentColor +| outline-style: none +| outline-width: medium +#reset + #data * { outline: solid; } #errors diff --git a/test/data/select/tests1.dat b/test/data/select/tests1.dat index e25ac82..0e44641 100644 --- a/test/data/select/tests1.dat +++ b/test/data/select/tests1.dat @@ -14,15 +14,15 @@ div#foo { float: right; } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -89,15 +89,15 @@ div p.green { float: left !important; } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -164,15 +164,15 @@ div.moose > div + div { border-top-style: solid; } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -238,15 +238,15 @@ div.moose > div + div { border-top-style: solid; } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: solid border-right-style: none border-bottom-style: none @@ -304,7 +304,7 @@ div { display: inline; } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat @@ -381,6 +381,90 @@ word-spacing: normal z-index: auto #reset +#tree all +| div* +#author +div { color: currentColor; } +#errors +#expected +background-attachment: scroll +background-color: #00000000 +background-image: none +background-position: 0% 0% +background-repeat: repeat +border-collapse: separate +border-spacing: 0px 0px +border-top-color: #ff000000 +border-right-color: #ff000000 +border-bottom-color: #ff000000 +border-left-color: #ff000000 +border-top-style: none +border-right-style: none +border-bottom-style: none +border-left-style: none +border-top-width: 2px +border-right-width: 2px +border-bottom-width: 2px +border-left-width: 2px +bottom: auto +caption_side: top +clear: none +clip: auto +color: #ff000000 +content: normal +counter-increment: none +counter-reset: none +cursor: auto +direction: ltr +display: inline +empty-cells: show +float: none +font-family: sans-serif +font-size: 12pt +font-style: normal +font-variant: normal +font-weight: normal +height: auto +left: auto +letter-spacing: normal +line-height: normal +list-style-image: none +list-style-position: outside +list-style-type: disc +margin-top: 0px +margin-right: 0px +margin-bottom: 0px +margin-left: 0px +max-height: none +max-width: none +min-height: 0px +min-width: 0px +outline-color: invert +outline-style: none +outline-width: 2px +overflow: visible +padding-top: 0px +padding-right: 0px +padding-bottom: 0px +padding-left: 0px +position: static +quotes: none +right: auto +table-layout: auto +text-align: default +text-decoration: none +text-indent: 0px +text-transform: none +top: auto +unicode-bidi: normal +vertical-align: baseline +visibility: visible +white-space: normal +width: auto +word-spacing: normal +z-index: auto +#reset + #tree all | div* #author @@ -479,10 +563,10 @@ background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -538,7 +622,7 @@ div { quotes: "a" "b" } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat @@ -627,15 +711,15 @@ div p + p { background-attachment: fixed; } #errors #expected background-attachment: fixed -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -696,15 +780,15 @@ div p + p { background-attachment: fixed; } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -766,15 +850,15 @@ div p + p { background-attachment: fixed; } #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -839,15 +923,15 @@ div p + p { background-image: url("Sonic_the_Hedgehog.png"); background-position #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: url('Sonic_the_Hedgehog.png') background-position: 100% 100% background-repeat: repeat-y border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -911,15 +995,15 @@ div p + p { background-image: url("Sonic_the_Hedgehog.png"); background-repeat: #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: url('Sonic_the_Hedgehog.png') background-position: 50% 20% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -989,15 +1073,15 @@ td,th {display:table-cell;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -1067,15 +1151,15 @@ td,th {display:table-cell;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -1145,15 +1229,15 @@ td,th {display:table-cell;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -1220,14 +1304,14 @@ tr {display:table-row;} td,th {display:table-cell;} #user #author -.hedgehog tr > td {border-color:transparent;} +.hedgehog tr > td {border-color:#00000000;} #sonic tr > td {border-top-color:#fff;border-right-color:#8040ff;border-bottom-color:black;border-left-color:rgb(255,0,255);} td,th {border-top-style: none;border-right-style: hidden;border-bottom-style: dotted;border-left-style: dashed} tr > td {border-top-width: thin;border-right-width: medium;border-bottom-width: thick;border-left-width: 2px;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat @@ -1302,21 +1386,21 @@ tr {display:table-row;} td,th {display:table-cell;} #user #author -.hedgehog tr > td {border-color:transparent;} +.hedgehog tr > td {border-color:#000000;} td,th {border-top-style: solid;border-right-style: double;border-bottom-style: groove;border-left-style: ridge} tr > td {border-top-width: 0;border-right-width: 2em;border-bottom-width: thick;border-left-width: -2px;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: transparent -border-right-color: transparent -border-bottom-color: transparent -border-left-color: transparent +border-top-color: #ff000000 +border-right-color: #ff000000 +border-bottom-color: #ff000000 +border-left-color: #ff000000 border-top-style: solid border-right-style: double border-bottom-style: groove @@ -1387,15 +1471,15 @@ td,th {display:table-cell;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 0px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: inset border-right-style: outset border-bottom-style: inset @@ -1465,15 +1549,15 @@ td,th {display:table-cell;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 2px 2px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none @@ -1543,15 +1627,15 @@ td,th {display:table-cell;} #errors #expected background-attachment: scroll -background-color: transparent +background-color: #00000000 background-image: none background-position: 0% 0% background-repeat: repeat border-spacing: 2px 0px -border-top-color: initial -border-right-color: initial -border-bottom-color: initial -border-left-color: initial +border-top-color: currentColor +border-right-color: currentColor +border-bottom-color: currentColor +border-left-color: currentColor border-top-style: none border-right-style: none border-bottom-style: none diff --git a/test/dump.h b/test/dump.h index 36f4278..b35832c 100644 --- a/test/dump.h +++ b/test/dump.h @@ -723,6 +723,8 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) case CSS_PROP_BACKGROUND_COLOR: assert(BACKGROUND_COLOR_TRANSPARENT == BORDER_COLOR_TRANSPARENT); + assert(BACKGROUND_COLOR_CURRENT_COLOR == + BORDER_COLOR_CURRENT_COLOR); assert(BACKGROUND_COLOR_SET == BORDER_COLOR_SET); @@ -730,6 +732,9 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) case BACKGROUND_COLOR_TRANSPARENT: *ptr += sprintf(*ptr, "transparent"); break; + case BACKGROUND_COLOR_CURRENT_COLOR: + *ptr += sprintf(*ptr, "currentColor"); + break; case BACKGROUND_COLOR_SET: { uint32_t colour = @@ -1076,6 +1081,12 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) break; case CSS_PROP_COLOR: switch (value) { + case COLOR_TRANSPARENT: + *ptr += sprintf(*ptr, "transparent"); + break; + case COLOR_CURRENT_COLOR: + *ptr += sprintf(*ptr, "currentColor"); + break; case COLOR_SET: { uint32_t colour = @@ -1706,6 +1717,12 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) break; case CSS_PROP_OUTLINE_COLOR: switch (value) { + case OUTLINE_COLOR_TRANSPARENT: + *ptr += sprintf(*ptr, "transparent"); + break; + case OUTLINE_COLOR_CURRENT_COLOR: + *ptr += sprintf(*ptr, "currentColor"); + break; case OUTLINE_COLOR_SET: { uint32_t colour = diff --git a/test/dump_computed.h b/test/dump_computed.h index d6a45ba..c76b17b 100644 --- a/test/dump_computed.h +++ b/test/dump_computed.h @@ -172,9 +172,6 @@ static void dump_computed_style(const css_computed_style *style, char *buf, /* background-color */ val = css_computed_background_color(style, &color); switch (val) { - case CSS_BACKGROUND_COLOR_TRANSPARENT: - wrote = snprintf(ptr, *len, "background-color: transparent\n"); - break; case CSS_BACKGROUND_COLOR_COLOR: wrote = snprintf(ptr, *len, "background-color: #%08x\n", color); break; @@ -289,11 +286,8 @@ static void dump_computed_style(const css_computed_style *style, char *buf, /* border-top-color */ val = css_computed_border_top_color(style, &color); switch (val) { - case CSS_BORDER_COLOR_INITIAL: - wrote = snprintf(ptr, *len, "border-top-color: initial\n"); - break; - case CSS_BORDER_COLOR_TRANSPARENT: - wrote = snprintf(ptr, *len, "border-top-color: transparent\n"); + case CSS_BORDER_COLOR_CURRENT_COLOR: + wrote = snprintf(ptr, *len, "border-top-color: currentColor\n"); break; case CSS_BORDER_COLOR_COLOR: wrote = snprintf(ptr, *len, "border-top-color: #%08x\n", color); @@ -308,12 +302,8 @@ static void dump_computed_style(const css_computed_style *style, char *buf, /* border-right-color */ val = css_computed_border_right_color(style, &color); switch (val) { - case CSS_BORDER_COLOR_INITIAL: - wrote = snprintf(ptr, *len, "border-right-color: initial\n"); - break; - case CSS_BORDER_COLOR_TRANSPARENT: - wrote = snprintf(ptr, *len, - "border-right-color: transparent\n"); + case CSS_BORDER_COLOR_CURRENT_COLOR: + wrote = snprintf(ptr, *len, "border-right-color: currentColor\n"); break; case CSS_BORDER_COLOR_COLOR: wrote = snprintf(ptr, *len, @@ -329,12 +319,8 @@ static void dump_computed_style(const css_computed_style *style, char *buf, /* border-bottom-color */ val = css_computed_border_bottom_color(style, &color); switch (val) { - case CSS_BORDER_COLOR_INITIAL: - wrote = snprintf(ptr, *len, "border-bottom-color: initial\n"); - break; - case CSS_BORDER_COLOR_TRANSPARENT: - wrote = snprintf(ptr, *len, - "border-bottom-color: transparent\n"); + case CSS_BORDER_COLOR_CURRENT_COLOR: + wrote = snprintf(ptr, *len, "border-bottom-color: currentColor\n"); break; case CSS_BORDER_COLOR_COLOR: wrote = snprintf(ptr, *len, @@ -350,11 +336,8 @@ static void dump_computed_style(const css_computed_style *style, char *buf, /* border-left-color */ val = css_computed_border_left_color(style, &color); switch (val) { - case CSS_BORDER_COLOR_INITIAL: - wrote = snprintf(ptr, *len, "border-left-color: initial\n"); - break; - case CSS_BORDER_COLOR_TRANSPARENT: - wrote = snprintf(ptr, *len, "border-left-color: transparent\n"); + case CSS_BORDER_COLOR_CURRENT_COLOR: + wrote = snprintf(ptr, *len, "border-left-color: currentColor\n"); break; case CSS_BORDER_COLOR_COLOR: wrote = snprintf(ptr, *len, -- cgit v1.2.3