mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Resolve viewport-relative <img sizes> values
We still don't know how to resolve font-relative lengths in <img sizes> since we don't always have font size information available at this stage in the pipeline, but we can at least handle viewport-relative lengths. This fixes an issue on many websites where low-resolution images were loaded (appropriate for a small viewport) even when the viewport is big.
This commit is contained in:
parent
ae5313d33c
commit
0103940cee
Notes:
sideshowbarker
2024-07-17 11:34:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0103940cee Pull-request: https://github.com/SerenityOS/serenity/pull/20698
4 changed files with 25 additions and 1 deletions
|
@ -0,0 +1,6 @@
|
||||||
|
<!doctype html>
|
||||||
|
<img
|
||||||
|
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NgaGD4DwAChAGAZM0bBgAAAABJRU5ErkJggg=="
|
||||||
|
width="400"
|
||||||
|
height="400"
|
||||||
|
/>
|
10
Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes.html
Normal file
10
Tests/LibWeb/Ref/img-srcset-viewport-relative-sizes.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<!doctype html>
|
||||||
|
<img
|
||||||
|
sizes="100vw"
|
||||||
|
srcset="
|
||||||
|
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2P4z8DwHwAFAAH/F1FwBgAAAABJRU5ErkJggg== 100w,
|
||||||
|
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NgaGD4DwAChAGAZM0bBgAAAABJRU5ErkJggg== 200w
|
||||||
|
"
|
||||||
|
width="400"
|
||||||
|
height="400"
|
||||||
|
/>
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"img-srcset-viewport-relative-sizes.html": "img-srcset-viewport-relative-sizes-ref.html",
|
||||||
"square-flex.html": "square-ref.html",
|
"square-flex.html": "square-ref.html",
|
||||||
"separate-borders-inline-table.html": "separate-borders-ref.html",
|
"separate-borders-inline-table.html": "separate-borders-ref.html",
|
||||||
"opacity-stacking.html": "opacity-stacking-ref.html",
|
"opacity-stacking.html": "opacity-stacking-ref.html",
|
||||||
|
|
|
@ -388,8 +388,15 @@ void SourceSet::normalize_source_densities(DOM::Element const& element)
|
||||||
{
|
{
|
||||||
// 1. Let source size be source set's source size.
|
// 1. Let source size be source set's source size.
|
||||||
auto 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();
|
return m_source_size.value();
|
||||||
|
}
|
||||||
|
|
||||||
// HACK: Flush any pending layouts here so we get an up-to-date length resolution context.
|
// 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.
|
// FIXME: We should have a way to build a LengthResolutionContext for any DOM node without going through the layout tree.
|
||||||
|
|
Loading…
Reference in a new issue