summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--css/select.c57
-rw-r--r--css/select.h1
-rw-r--r--render/box_construct.c53
3 files changed, 54 insertions, 57 deletions
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,
diff --git a/render/box_construct.c b/render/box_construct.c
index 4ce2151cd..a72f918f8 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -1425,8 +1425,6 @@ css_select_results *box_get_style(html_content *c,
{
dom_string *s;
dom_exception err;
- int pseudo_element;
- css_error error;
css_stylesheet *inline_style = NULL;
css_select_results *styles;
nscss_select_ctx ctx;
@@ -1455,62 +1453,15 @@ css_select_results *box_get_style(html_content *c,
ctx.quirks = (c->quirks == DOM_DOCUMENT_QUIRKS_MODE_FULL);
ctx.base_url = c->base_url;
ctx.universal = c->universal;
+ ctx.parent_style = parent_style;
- /* Select partial style for element */
+ /* Select style for element */
styles = nscss_get_style(&ctx, n, CSS_MEDIA_SCREEN, inline_style);
/* No longer need inline style */
if (inline_style != NULL)
css_stylesheet_destroy(inline_style);
- /* Failed selecting partial style -- bail out */
- if (styles == NULL)
- return NULL;
-
- /* If there's a parent style, compose with partial to obtain
- * complete computed style for element */
- if (parent_style != NULL) {
- /* Complete the computed style, by composing with the parent
- * element's style */
- error = css_computed_style_compose(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;
}