mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Implement the color-gamut media feature
Differential Revision: https://phabricator.services.mozilla.com/D165385
This commit is contained in:
parent
65fbb16bb4
commit
a685297bf3
1 changed files with 40 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
use crate::gecko_bindings::bindings;
|
||||
use crate::gecko_bindings::structs;
|
||||
use crate::gecko_bindings::structs::ScreenColorGamut;
|
||||
use crate::media_queries::{Device, MediaType};
|
||||
use crate::queries::feature::{AllowsRanges, Evaluator, FeatureFlags, QueryFeatureDescription};
|
||||
use crate::queries::values::Orientation;
|
||||
|
@ -141,6 +142,38 @@ fn eval_monochrome(context: &Context) -> u32 {
|
|||
unsafe { bindings::Gecko_MediaFeatures_GetMonochromeBitsPerPixel(context.device().document()) }
|
||||
}
|
||||
|
||||
/// Values for the color-gamut media feature.
|
||||
/// This implements PartialOrd so that lower values will correctly match
|
||||
/// higher capabilities.
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, PartialOrd, ToCss)]
|
||||
#[repr(u8)]
|
||||
enum ColorGamut {
|
||||
/// The sRGB gamut.
|
||||
Srgb,
|
||||
/// The gamut specified by the Display P3 Color Space.
|
||||
P3,
|
||||
/// The gamut specified by the ITU-R Recommendation BT.2020 Color Space.
|
||||
Rec2020,
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/mediaqueries-4/#color-gamut
|
||||
fn eval_color_gamut(context: &Context, query_value: Option<ColorGamut>) -> bool {
|
||||
let query_value = match query_value {
|
||||
Some(v) => v,
|
||||
None => return false,
|
||||
};
|
||||
let color_gamut =
|
||||
unsafe { bindings::Gecko_MediaFeatures_ColorGamut(context.device().document()) };
|
||||
// Match if our color gamut is at least as wide as the query value
|
||||
query_value <=
|
||||
match color_gamut {
|
||||
// EndGuard_ is not a valid color gamut, so the default color-gamut is used.
|
||||
ScreenColorGamut::Srgb | ScreenColorGamut::EndGuard_ => ColorGamut::Srgb,
|
||||
ScreenColorGamut::P3 => ColorGamut::P3,
|
||||
ScreenColorGamut::Rec2020 => ColorGamut::Rec2020,
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/mediaqueries-4/#resolution
|
||||
fn eval_resolution(context: &Context) -> Resolution {
|
||||
let resolution_dppx =
|
||||
|
@ -585,7 +618,7 @@ macro_rules! bool_pref_feature {
|
|||
/// to support new types in these entries and (2) ensuring that either
|
||||
/// nsPresContext::MediaFeatureValuesChanged is called when the value that
|
||||
/// would be returned by the evaluator function could change.
|
||||
pub static MEDIA_FEATURES: [QueryFeatureDescription; 63] = [
|
||||
pub static MEDIA_FEATURES: [QueryFeatureDescription; 64] = [
|
||||
feature!(
|
||||
atom!("width"),
|
||||
AllowsRanges::Yes,
|
||||
|
@ -697,6 +730,12 @@ pub static MEDIA_FEATURES: [QueryFeatureDescription; 63] = [
|
|||
Evaluator::Integer(eval_monochrome),
|
||||
FeatureFlags::empty(),
|
||||
),
|
||||
feature!(
|
||||
atom!("color-gamut"),
|
||||
AllowsRanges::No,
|
||||
keyword_evaluator!(eval_color_gamut, ColorGamut),
|
||||
FeatureFlags::empty(),
|
||||
),
|
||||
feature!(
|
||||
atom!("prefers-reduced-motion"),
|
||||
AllowsRanges::No,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue