diff --git a/Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes-ref.html b/Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes-ref.html new file mode 100644 index 0000000000..7c314bf765 --- /dev/null +++ b/Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes-ref.html @@ -0,0 +1,6 @@ + + diff --git a/Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes.html b/Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes.html new file mode 100644 index 0000000000..feba6ab258 --- /dev/null +++ b/Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes.html @@ -0,0 +1,10 @@ + + diff --git a/Tests/LibWeb/Ref/manifest.json b/Tests/LibWeb/Ref/manifest.json index 8c52f9f608..aad9eb7542 100644 --- a/Tests/LibWeb/Ref/manifest.json +++ b/Tests/LibWeb/Ref/manifest.json @@ -1,4 +1,5 @@ { + "img-srcset-viewport-relative-sizes.html": "img-srcset-viewport-relative-sizes-ref.html", "square-flex.html": "square-ref.html", "separate-borders-inline-table.html": "separate-borders-ref.html", "opacity-stacking.html": "opacity-stacking-ref.html", diff --git a/Userland/Libraries/LibWeb/HTML/SourceSet.cpp b/Userland/Libraries/LibWeb/HTML/SourceSet.cpp index 5ccefead56..03c9de56ad 100644 --- a/Userland/Libraries/LibWeb/HTML/SourceSet.cpp +++ b/Userland/Libraries/LibWeb/HTML/SourceSet.cpp @@ -388,8 +388,15 @@ void SourceSet::normalize_source_densities(DOM::Element const& element) { // 1. Let source size be source set's source size. auto source_size = [&] { - if (!m_source_size.is_calculated()) + if (!m_source_size.is_calculated()) { + // If the source size is viewport-relative, resolve it against the viewport right now. + if (m_source_size.value().is_viewport_relative()) { + return CSS::Length::make_px(m_source_size.value().viewport_relative_length_to_px(element.document().viewport_rect())); + } + + // FIXME: Resolve font-relative lengths against the relevant font size. return m_source_size.value(); + } // HACK: Flush any pending layouts here so we get an up-to-date length resolution context. // FIXME: We should have a way to build a LengthResolutionContext for any DOM node without going through the layout tree.