From 3bee7b7e127be7b378a90569c63b82cde9fb20bc Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 9 Feb 2016 16:42:28 +0000 Subject: Layout: Don't generate :before and :after boxes for replaced elements. In CSS 2.1 this was undefined. CSS 2.1 -- 12.1 The :before and :after pseudo-elements Note. This specification does not fully define the interaction of :before and :after with replaced elements (such as IMG in HTML). This will be defined in more detail in a future specification. -- https://www.w3.org/TR/CSS21/generate.html#before-after-content In CSS 3 the :before and :after generated content boxes are not allowed on replaced elements. CSS 3 Generated and Replaced Content Module 12. Replaced content The box model defines different rules for the layout of replaced elements than normal elements. Replaced elements do not have '::before' and '::after' pseudo-elements; the 'content' property in the case of replaced content replaces the entire contents of the element's box. -- https://www.w3.org/TR/css3-content/#replacedContent --- render/box_construct.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'render/box_construct.c') diff --git a/render/box_construct.c b/render/box_construct.c index b3fc8f156..adb450946 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -852,10 +852,6 @@ bool box_construct_element(struct box_construct_ctx *ctx, props.node_is_root)]; } - /* Handle the :before pseudo element */ - box_construct_generate(ctx->n, ctx->content, box, - box->styles->styles[CSS_PSEUDO_ELEMENT_BEFORE]); - err = dom_node_get_node_name(ctx->n, &s); if (err != DOM_NO_ERR || s == NULL) return false; @@ -874,6 +870,12 @@ bool box_construct_element(struct box_construct_ctx *ctx, return false; } + /* Handle the :before pseudo element */ + if (!(box->flags & IS_REPLACED)) { + box_construct_generate(ctx->n, ctx->content, box, + box->styles->styles[CSS_PSEUDO_ELEMENT_BEFORE]); + } + if (box->type == BOX_NONE || (css_computed_display(box->style, props.node_is_root) == CSS_DISPLAY_NONE && props.node_is_root == false)) { @@ -1065,7 +1067,7 @@ void box_construct_element_after(dom_node *n, html_content *content) box->inline_end = inline_end; inline_end->inline_end = box; } - } else { + } else if (!(box->flags & IS_REPLACED)) { /* Handle the :after pseudo element */ box_construct_generate(n, content, box, box->styles->styles[CSS_PSEUDO_ELEMENT_AFTER]); @@ -1603,6 +1605,7 @@ bool box_image(BOX_SPECIAL_PARAMS) return true; /* start fetch */ + box->flags |= IS_REPLACED; ok = html_fetch_object(content, url, box, image_types, content->base.available_width, 1000, false); nsurl_unref(url); @@ -1879,6 +1882,7 @@ bool box_object(BOX_SPECIAL_PARAMS) box->object_params = params; /* start fetch (MIME type is ok or not specified) */ + box->flags |= IS_REPLACED; if (!html_fetch_object(content, params->data ? params->data : params->classid, box, CONTENT_ANY, content->base.available_width, 1000, @@ -2357,6 +2361,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) /* box */ assert(box->style); box->flags |= IFRAME; + box->flags |= IS_REPLACED; /* Showing iframe, so don't show alternate content */ if (convert_children) @@ -2415,6 +2420,7 @@ bool box_input(BOX_SPECIAL_PARAMS) if (gadget == NULL) goto no_memory; box->gadget = gadget; + box->flags |= IS_REPLACED; gadget->box = box; gadget->html = content; @@ -2554,6 +2560,7 @@ bool box_button(BOX_SPECIAL_PARAMS) gadget->html = content; box->gadget = gadget; + box->flags |= IS_REPLACED; gadget->box = box; box->type = BOX_INLINE_BLOCK; @@ -2676,6 +2683,7 @@ bool box_select(BOX_SPECIAL_PARAMS) box->type = BOX_INLINE_BLOCK; box->gadget = gadget; + box->flags |= IS_REPLACED; gadget->box = box; inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content->bctx); @@ -2797,6 +2805,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) if (box->gadget == NULL) return false; + box->flags |= IS_REPLACED; box->gadget->html = content; box->gadget->box = box; @@ -2930,6 +2939,7 @@ bool box_embed(BOX_SPECIAL_PARAMS) box->object_params = params; /* start fetch */ + box->flags |= IS_REPLACED; return html_fetch_object(content, params->data, box, CONTENT_ANY, content->base.available_width, 1000, false); } -- cgit v1.2.3