From 1970fb7bdaa30454115777122a238b4931839f0b Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 19 Dec 2013 14:21:15 +0000 Subject: Make nscss_get_style return completed computed styles. Now matches nscss_get_blank_style, and no need for anything outside css/select.c to see partial computed styles. --- css/select.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++------ css/select.h | 1 + 2 files changed, 52 insertions(+), 6 deletions(-) (limited to 'css') diff --git a/css/select.c b/css/select.c index 1e1b47f54..a69c77033 100644 --- a/css/select.c +++ b/css/select.c @@ -108,8 +108,6 @@ static bool parse_number(const char *data, bool non_negative, bool real, static bool parse_font_size(const char *size, uint8_t *val, css_fixed *len, css_unit *unit); -static css_computed_style *nscss_get_initial_style(nscss_select_ctx *ctx); - static bool isWhitespace(char c); static bool isHex(char c); static uint8_t charToHex(char c); @@ -263,28 +261,75 @@ static void nscss_dom_user_data_handler(dom_node_operation operation, } /** - * Get a style selection results (partial computed styles) for an element + * Get style selection results for an element * * \param ctx CSS selection context * \param n Element to select for * \param media Permitted media types * \param inline_style Inline style associated with element, or NULL - * \return Pointer to selection results (containing partial computed styles), + * \return Pointer to selection results (containing computed styles), * or NULL on failure */ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n, uint64_t media, const css_stylesheet *inline_style) { css_select_results *styles; + int pseudo_element; css_error error; /* Select style for node */ error = css_select_style(ctx->ctx, n, media, inline_style, &selection_handler, ctx, &styles); - if (error != CSS_OK) { + + if (error != CSS_OK || styles == NULL) { + /* Failed selecting partial style -- bail out */ return NULL; } + /* If there's a parent style, compose with partial to obtain + * complete computed style for element */ + if (ctx->parent_style != NULL) { + /* Complete the computed style, by composing with the parent + * element's style */ + error = css_computed_style_compose(ctx->parent_style, + styles->styles[CSS_PSEUDO_ELEMENT_NONE], + nscss_compute_font_size, NULL, + styles->styles[CSS_PSEUDO_ELEMENT_NONE]); + if (error != CSS_OK) { + css_select_results_destroy(styles); + return NULL; + } + } + + for (pseudo_element = CSS_PSEUDO_ELEMENT_NONE + 1; + pseudo_element < CSS_PSEUDO_ELEMENT_COUNT; + pseudo_element++) { + + if (pseudo_element == CSS_PSEUDO_ELEMENT_FIRST_LETTER || + pseudo_element == CSS_PSEUDO_ELEMENT_FIRST_LINE) + /* TODO: Handle first-line and first-letter pseudo + * element computed style completion */ + continue; + + if (styles->styles[pseudo_element] == NULL) + /* There were no rules concerning this pseudo element */ + continue; + + /* Complete the pseudo element's computed style, by composing + * with the base element's style */ + error = css_computed_style_compose( + styles->styles[CSS_PSEUDO_ELEMENT_NONE], + styles->styles[pseudo_element], + nscss_compute_font_size, NULL, + styles->styles[pseudo_element]); + if (error != CSS_OK) { + /* TODO: perhaps this shouldn't be quite so + * catastrophic? */ + css_select_results_destroy(styles); + return NULL; + } + } + return styles; } @@ -294,7 +339,7 @@ css_select_results *nscss_get_style(nscss_select_ctx *ctx, dom_node *n, * \param ctx CSS selection context * \return Pointer to partial computed style, or NULL on failure */ -css_computed_style *nscss_get_initial_style(nscss_select_ctx *ctx) +static css_computed_style *nscss_get_initial_style(nscss_select_ctx *ctx) { css_computed_style *style; css_error error; diff --git a/css/select.h b/css/select.h index 7488ab94a..083fd91b6 100644 --- a/css/select.h +++ b/css/select.h @@ -37,6 +37,7 @@ typedef struct nscss_select_ctx bool quirks; nsurl *base_url; lwc_string *universal; + const css_computed_style *parent_style; } nscss_select_ctx; css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len, -- cgit v1.2.3