mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Implement inverted-colors media feature
Implemented the inverted-colors media feature from Media Queries Level 5 for all platforms. Spec: https://drafts.csswg.org/mediaqueries-5/#inverted Platform specific implementations: - Windows: Checks system color filter setting, and if it is inverted (note: Windows does not live update due to having to read a reg key) - Mac: Checks dedicated inverted accessibility system setting - Android: Checks dedicated inverted system setting - Linux: No GTK API exposes anything like it so always none Locked behind new pref `layout.css.inverted-colors.enabled`, always off by default for now. Also added new WPT tests (none previously). Other browsers: - WebKit: shipped since Safari 9.1 (Jan 2017) - Blink: no signal Test page: https://goose.icu/inverted-colors Differential Revision: https://phabricator.services.mozilla.com/D173201
This commit is contained in:
parent
dcfef6cdbb
commit
13e2d10474
2 changed files with 43 additions and 1 deletions
|
@ -297,6 +297,35 @@ fn eval_forced_colors(context: &Context, query_value: Option<ForcedColors>) -> b
|
|||
}
|
||||
}
|
||||
|
||||
/// Possible values for the inverted-colors media query.
|
||||
/// https://drafts.csswg.org/mediaqueries-5/#inverted
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
|
||||
#[repr(u8)]
|
||||
enum InvertedColors {
|
||||
/// Colors are displayed normally.
|
||||
None,
|
||||
/// All pixels within the displayed area have been inverted.
|
||||
Inverted,
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/mediaqueries-5/#inverted
|
||||
fn eval_inverted_colors(
|
||||
context: &Context,
|
||||
query_value: Option<InvertedColors>,
|
||||
) -> bool {
|
||||
let inverted_colors =
|
||||
unsafe { bindings::Gecko_MediaFeatures_InvertedColors(context.device().document()) };
|
||||
let query_value = match query_value {
|
||||
Some(v) => v,
|
||||
None => return inverted_colors,
|
||||
};
|
||||
|
||||
match query_value {
|
||||
InvertedColors::None => !inverted_colors,
|
||||
InvertedColors::Inverted => inverted_colors,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
|
||||
#[repr(u8)]
|
||||
enum OverflowBlock {
|
||||
|
@ -669,7 +698,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; 66] = [
|
||||
pub static MEDIA_FEATURES: [QueryFeatureDescription; 67] = [
|
||||
feature!(
|
||||
atom!("width"),
|
||||
AllowsRanges::Yes,
|
||||
|
@ -816,6 +845,12 @@ pub static MEDIA_FEATURES: [QueryFeatureDescription; 66] = [
|
|||
keyword_evaluator!(eval_forced_colors, ForcedColors),
|
||||
FeatureFlags::empty(),
|
||||
),
|
||||
feature!(
|
||||
atom!("inverted-colors"),
|
||||
AllowsRanges::No,
|
||||
keyword_evaluator!(eval_inverted_colors, InvertedColors),
|
||||
FeatureFlags::empty(),
|
||||
),
|
||||
feature!(
|
||||
atom!("overflow-block"),
|
||||
AllowsRanges::No,
|
||||
|
|
|
@ -329,6 +329,13 @@ fn disabled_by_pref(feature: &Atom, context: &ParserContext) -> bool {
|
|||
return !context.in_ua_or_chrome_sheet() &&
|
||||
!static_prefs::pref!("layout.css.prefers-reduced-transparency.enabled");
|
||||
}
|
||||
|
||||
// inverted-colors is always enabled in the ua and chrome. On
|
||||
// the web it is hidden behind a preferenc.
|
||||
if *feature == atom!("inverted-colors") {
|
||||
return !context.in_ua_or_chrome_sheet() &&
|
||||
!static_prefs::pref!("layout.css.inverted-colors.enabled");
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue