1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 04:27:40 +00:00

LibWeb: Support media queries with the resolution feature

The resolution is simply 1dppx * device pixel ratio.

This makes high resolution images show up on https://apple.com/
when running on a high-DPI display. :^)
This commit is contained in:
Andreas Kling 2023-08-25 18:07:11 +02:00
parent b63e393cef
commit da8692572a
3 changed files with 45 additions and 1 deletions

View file

@ -0,0 +1,31 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
BlockContainer <body> at (8,16) content-size 784x68.875 children: not-inline
BlockContainer <p> at (8,16) content-size 784x35.40625 children: inline
line 0 width: 746.890625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 88, rect: [8,16 746.890625x17.46875]
"NOTE: This test assumes that you're running with 1x pixels (which our test runner always"
line 1 width: 40.625, height: 17.9375, bottom: 35.40625, baseline: 13.53125
frag 0 from TextNode start: 89, length: 5, rect: [8,33 40.625x17.46875]
"does."
TextNode <#text>
BlockContainer <(anonymous)> at (8,67.40625) content-size 784x0 children: inline
TextNode <#text>
BlockContainer <div.pass> at (8,67.40625) content-size 784x17.46875 children: inline
line 0 width: 49.734375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 4, rect: [8,67.40625 49.734375x17.46875]
"PASS"
TextNode <#text>
BlockContainer <(anonymous)> at (8,84.875) content-size 784x0 children: inline
TextNode <#text>
TextNode <#text>
ViewportPaintable (Viewport<#document>) [0,0 800x600]
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
PaintableWithLines (BlockContainer<BODY>) [8,16 784x68.875]
PaintableWithLines (BlockContainer<P>) [8,16 784x35.40625]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer(anonymous)) [8,67.40625 784x0]
PaintableWithLines (BlockContainer<DIV>.pass) [8,67.40625 784x17.46875]
TextPaintable (TextNode<#text>)
PaintableWithLines (BlockContainer(anonymous)) [8,84.875 784x0]

View file

@ -0,0 +1,12 @@
<style>
div { display: none; }
@media (min-resolution: 96dpi) {
div.pass { display: block; }
}
@media (min-resolution: 97dpi) {
div.fail { display: block; }
}
</style>
<p>NOTE: This test assumes that you're running with 1x pixels (which our test runner always does.</p>
<div class="pass">PASS</div>
<div class="fail">FAIL</div>

View file

@ -546,7 +546,8 @@ Optional<CSS::MediaFeatureValue> Window::query_media_feature(CSS::MediaFeatureID
case CSS::MediaFeatureID::PrefersReducedTransparency:
// FIXME: Make this a preference
return CSS::MediaFeatureValue(CSS::ValueID::NoPreference);
// FIXME: resolution
case CSS::MediaFeatureID::Resolution:
return CSS::MediaFeatureValue(CSS::Resolution(device_pixel_ratio(), CSS::Resolution::Type::Dppx));
case CSS::MediaFeatureID::Scan:
return CSS::MediaFeatureValue(CSS::ValueID::Progressive);
case CSS::MediaFeatureID::Scripting: