mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
style: Add support for CSS prefers-color-scheme media feature.
Bug: 1494034 Reviewed-by: emilio
This commit is contained in:
parent
71d9fe5d60
commit
d6750de0c3
2 changed files with 28 additions and 1 deletions
|
@ -57,6 +57,7 @@ include = [
|
||||||
"CursorKind",
|
"CursorKind",
|
||||||
"Display",
|
"Display",
|
||||||
"DisplayMode",
|
"DisplayMode",
|
||||||
|
"PrefersColorScheme",
|
||||||
"ExtremumLength",
|
"ExtremumLength",
|
||||||
"FillRule",
|
"FillRule",
|
||||||
"FontDisplay",
|
"FontDisplay",
|
||||||
|
|
|
@ -280,6 +280,16 @@ enum PrefersReducedMotion {
|
||||||
Reduce,
|
Reduce,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Values for the prefers-color-scheme media feature.
|
||||||
|
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
|
||||||
|
#[repr(u8)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub enum PrefersColorScheme {
|
||||||
|
Light,
|
||||||
|
Dark,
|
||||||
|
NoPreference,
|
||||||
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion
|
/// https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion
|
||||||
fn eval_prefers_reduced_motion(device: &Device, query_value: Option<PrefersReducedMotion>) -> bool {
|
fn eval_prefers_reduced_motion(device: &Device, query_value: Option<PrefersReducedMotion>) -> bool {
|
||||||
let prefers_reduced =
|
let prefers_reduced =
|
||||||
|
@ -348,6 +358,16 @@ fn eval_overflow_inline(device: &Device, query_value: Option<OverflowInline>) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme
|
||||||
|
fn eval_prefers_color_scheme(device: &Device, query_value: Option<PrefersColorScheme>) -> bool {
|
||||||
|
let prefers_color_scheme =
|
||||||
|
unsafe { bindings::Gecko_MediaFeatures_PrefersColorScheme(device.document()) };
|
||||||
|
match query_value {
|
||||||
|
Some(v) => prefers_color_scheme == v,
|
||||||
|
None => prefers_color_scheme != PrefersColorScheme::NoPreference,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/mediaqueries-4/#mf-interaction
|
/// https://drafts.csswg.org/mediaqueries-4/#mf-interaction
|
||||||
bitflags! {
|
bitflags! {
|
||||||
struct PointerCapabilities: u8 {
|
struct PointerCapabilities: u8 {
|
||||||
|
@ -526,7 +546,7 @@ lazy_static! {
|
||||||
/// to support new types in these entries and (2) ensuring that either
|
/// to support new types in these entries and (2) ensuring that either
|
||||||
/// nsPresContext::MediaFeatureValuesChanged is called when the value that
|
/// nsPresContext::MediaFeatureValuesChanged is called when the value that
|
||||||
/// would be returned by the evaluator function could change.
|
/// would be returned by the evaluator function could change.
|
||||||
pub static ref MEDIA_FEATURES: [MediaFeatureDescription; 52] = [
|
pub static ref MEDIA_FEATURES: [MediaFeatureDescription; 53] = [
|
||||||
feature!(
|
feature!(
|
||||||
atom!("width"),
|
atom!("width"),
|
||||||
AllowsRanges::Yes,
|
AllowsRanges::Yes,
|
||||||
|
@ -657,6 +677,12 @@ lazy_static! {
|
||||||
keyword_evaluator!(eval_overflow_inline, OverflowInline),
|
keyword_evaluator!(eval_overflow_inline, OverflowInline),
|
||||||
ParsingRequirements::empty(),
|
ParsingRequirements::empty(),
|
||||||
),
|
),
|
||||||
|
feature!(
|
||||||
|
atom!("prefers-color-scheme"),
|
||||||
|
AllowsRanges::No,
|
||||||
|
keyword_evaluator!(eval_prefers_color_scheme, PrefersColorScheme),
|
||||||
|
ParsingRequirements::empty(),
|
||||||
|
),
|
||||||
feature!(
|
feature!(
|
||||||
atom!("pointer"),
|
atom!("pointer"),
|
||||||
AllowsRanges::No,
|
AllowsRanges::No,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue