From 29d29134baa95e772b07aad2eac0b91970205af8 Mon Sep 17 00:00:00 2001 From: Andi Gallo Date: Sun, 28 May 2023 04:40:27 +0000 Subject: [PATCH] LibWeb: Skip children based on media when updating the source set If child has a media attribute and its value does not match the environment, continue to the next child. --- .../expected/picture-source-media-query.txt | 13 +++++++++++++ Tests/LibWeb/Layout/input/120.png | Bin 0 -> 572 bytes Tests/LibWeb/Layout/input/400.png | Bin 0 -> 592 bytes .../Layout/input/picture-source-media-query.html | 11 +++++++++++ .../Libraries/LibWeb/HTML/HTMLImageElement.cpp | 9 ++++++++- 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/picture-source-media-query.txt create mode 100644 Tests/LibWeb/Layout/input/120.png create mode 100644 Tests/LibWeb/Layout/input/400.png create mode 100644 Tests/LibWeb/Layout/input/picture-source-media-query.html diff --git a/Tests/LibWeb/Layout/expected/picture-source-media-query.txt b/Tests/LibWeb/Layout/expected/picture-source-media-query.txt new file mode 100644 index 0000000000..7049945dd6 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/picture-source-media-query.txt @@ -0,0 +1,13 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x416 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x400 children: inline + line 0 width: 400, height: 400, bottom: 400, baseline: 400 + frag 0 from ImageBox start: 0, length: 0, rect: [8,8 400x400] + TextNode <#text> + InlineNode + TextNode <#text> + InlineNode + TextNode <#text> + ImageBox at (8,8) content-size 400x400 children: not-inline + TextNode <#text> + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/120.png b/Tests/LibWeb/Layout/input/120.png new file mode 100644 index 0000000000000000000000000000000000000000..c021943f7fa1c93e405f4afc02950d7308e13c45 GIT binary patch literal 572 zcmeAS@N?(olHy`uVBq!ia0y~yV5k6LMrH;E2If^uCNeNEwq`mz2Y5O=D-;yvr)B1( zGB9XNtet4*+$xYkWBjz1hO@p<3%?hYv@$*}FAd(7TXz4@nF=d-^j6N{zdbrjR&I_*+$xYkWBjz1hO@p<3%?hYv@$*}FAd(7TXz4@nF=d-^j6N{zdbrjR&I_S@IMkb@Cl^_XES3j3^P6 + + + + + + + + + + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index b496137212..363cd05687 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -741,7 +741,14 @@ static void update_the_source_set(DOM::Element& element) if (source_set.is_empty()) continue; - // FIXME: 6. If child has a media attribute, and its value does not match the environment, continue to the next child. + // 6. If child has a media attribute, and its value does not match the environment, continue to the next child. + if (child->has_attribute(HTML::AttributeNames::media)) { + auto media_query = parse_media_query(CSS::Parser::ParsingContext { element.document() }, + child->attribute(HTML::AttributeNames::media)); + if (!media_query || !media_query->evaluate(element.document().window())) { + continue; + } + } // 7. Parse child's sizes attribute, and let source set's source size be the returned value. source_set.m_source_size = parse_a_sizes_attribute(element.document(), child->attribute(HTML::AttributeNames::sizes));