Media query resolution (#30406)

* Add resolution and device-pixel-ratio media query

* Update expectations
This commit is contained in:
Samson 2023-09-22 18:18:00 +02:00 committed by GitHub
parent 5d8d7c79c2
commit aa41fbd8f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 37 deletions

View file

@ -1,4 +1,5 @@
-moz-content-preferred-color-scheme
-moz-device-pixel-ratio
-moz-gtk-csd-close-button-position
-moz-gtk-csd-maximize-button-position
-moz-gtk-csd-menu-radius
@ -37,6 +38,7 @@ datachannel
date
datetime-local
dir
device-pixel-ratio
durationchange
email
emptied
@ -108,6 +110,7 @@ rejectionhandled
removetrack
reset
resize
resolution
resourcetimingbufferfull
right
rtl

View file

@ -12,6 +12,7 @@ use crate::media_queries::MediaType;
use crate::properties::ComputedValues;
use crate::values::computed::CSSPixelLength;
use crate::values::computed::Context;
use crate::values::computed::Resolution;
use crate::values::specified::font::FONT_MEDIUM_PX;
use crate::values::specified::ViewportVariant;
use crate::values::KeyframesName;
@ -252,9 +253,19 @@ fn eval_scan(_: &Context, _: Option<Scan>) -> bool {
false
}
/// https://drafts.csswg.org/mediaqueries-4/#resolution
fn eval_resolution(context: &Context) -> Resolution {
Resolution::from_dppx(context.device().device_pixel_ratio.0)
}
/// https://compat.spec.whatwg.org/#css-media-queries-webkit-device-pixel-ratio
fn eval_device_pixel_ratio(context: &Context) -> f32 {
eval_resolution(context).dppx()
}
lazy_static! {
/// A list with all the media features that Servo supports.
pub static ref MEDIA_FEATURES: [QueryFeatureDescription; 2] = [
pub static ref MEDIA_FEATURES: [QueryFeatureDescription; 5] = [
feature!(
atom!("width"),
AllowsRanges::Yes,
@ -267,5 +278,23 @@ lazy_static! {
keyword_evaluator!(eval_scan, Scan),
FeatureFlags::empty(),
),
feature!(
atom!("resolution"),
AllowsRanges::Yes,
Evaluator::Resolution(eval_resolution),
FeatureFlags::empty(),
),
feature!(
atom!("device-pixel-ratio"),
AllowsRanges::Yes,
Evaluator::Float(eval_device_pixel_ratio),
FeatureFlags::WEBKIT_PREFIX,
),
feature!(
atom!("-moz-device-pixel-ratio"),
AllowsRanges::Yes,
Evaluator::Float(eval_device_pixel_ratio),
FeatureFlags::empty(),
),
];
}

View file

@ -17,24 +17,6 @@
[Test parsing ' color ), ( color' with matchMedia]
expected: FAIL
[Test parsing '(min-resolution: 1x)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 2x)' with matchMedia]
expected: FAIL
[Test parsing '(max-resolution: 7x)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 2dppx)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 600dpi)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 77dpcm)' with matchMedia]
expected: FAIL
[Test parsing '(min-resolution: calc(1x))' with matchMedia]
expected: FAIL

View file

@ -17,33 +17,15 @@
[Test parsing ' color ), ( color' with matchMedia]
expected: FAIL
[Test parsing '(min-resolution: 1x)' with matchMedia]
expected: FAIL
[Test parsing '(min-resolution: calc(1x))' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 2x)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: calc(2x))' with matchMedia]
expected: FAIL
[Test parsing '(max-resolution: 7x)' with matchMedia]
expected: FAIL
[Test parsing '(max-resolution: calc(7x))' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 2dppx)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 600dpi)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: 77dpcm)' with matchMedia]
expected: FAIL
[Test parsing '(resolution: calc(1x + 2x))' with matchMedia]
expected: FAIL