Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
Bug 1658780 - Update the prefers-contrast media query to use the new …
Browse files Browse the repository at this point in the history
…more/less keywords r=emilio

Per the resolution here:
w3c/csswg-drafts#2943 (comment)

Differential Revision: https://phabricator.services.mozilla.com/D86848
  • Loading branch information
0xekez committed Aug 17, 2020
1 parent 7f61fd9 commit 1f69a14
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion layout/reftests/high-contrast/prefers-contrast-002.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
width: 100px;
height: 100px;
}
@media (prefers-contrast: high) {
@media (prefers-contrast: more) {
div {
outline: 2px solid #000000;
}
Expand Down
2 changes: 1 addition & 1 deletion layout/style/nsMediaFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ StyleContrastPref Gecko_MediaFeatures_PrefersContrast(
// https://github.com/w3c/csswg-drafts/issues/3856#issuecomment-642313572
// https://github.com/w3c/csswg-drafts/issues/2943
if (!!LookAndFeel::GetInt(LookAndFeel::IntID::UseAccessibilityTheme, 0)) {
return StyleContrastPref::High;
return StyleContrastPref::More;
}
return StyleContrastPref::NoPreference;
}
Expand Down
4 changes: 2 additions & 2 deletions layout/style/test/chrome/test_chrome_only_media_queries.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
expectParseable("(-moz-os-version: windows-win10)");
expectNonParseable("(-moz-os-version: )");

expectParseable("(prefers-contrast: low)")
expectParseable("(prefers-contrast: more)")
expectParseable("(prefers-contrast: forced)")
expectParseable("(prefers-contrast: no-preference)")
expectParseable("(prefers-contrast: high)");
expectParseable("(prefers-contrast: less)");
expectParseable("(prefers-contrast)")
</script>
17 changes: 8 additions & 9 deletions servo/components/style/gecko/media_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ fn eval_prefers_reduced_motion(device: &Device, query_value: Option<PrefersReduc
#[repr(u8)]
#[allow(missing_docs)]
enum PrefersContrast {
High,
Low,
More,
Less,
NoPreference,
Forced,
}
Expand All @@ -326,12 +326,11 @@ enum PrefersContrast {
#[derive(Clone, Copy, Debug, FromPrimitive, PartialEq)]
#[repr(u8)]
pub enum ContrastPref {
/// High contrast is prefered. Corresponds to an accessibility theme
/// More contrast is prefered. Corresponds to an accessibility theme
/// being enabled or firefox forcing high contrast colors.
High,
/// Low contrast is prefered. Corresponds to the
/// browser.display.prefers_low_contrast pref being true.
Low,
More,
/// Low contrast is prefered.
Less,
/// The default value if neither high or low contrast is enabled.
NoPreference,
}
Expand All @@ -344,8 +343,8 @@ fn eval_prefers_contrast(device: &Device, query_value: Option<PrefersContrast>)
if let Some(query_value) = query_value {
match query_value {
PrefersContrast::Forced => forced_colors,
PrefersContrast::High => contrast_pref == ContrastPref::High,
PrefersContrast::Low => contrast_pref == ContrastPref::Low,
PrefersContrast::More => contrast_pref == ContrastPref::More,
PrefersContrast::Less => contrast_pref == ContrastPref::Less,
PrefersContrast::NoPreference => contrast_pref == ContrastPref::NoPreference,
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<script>
query_should_be_css_parseable("(prefers-contrast)");
query_should_be_css_parseable("(prefers-contrast: no-preference)");
query_should_be_css_parseable("(prefers-contrast: high)");
query_should_be_css_parseable("(prefers-contrast: low)");
query_should_be_css_parseable("(prefers-contrast: more)");
query_should_be_css_parseable("(prefers-contrast: less)");
query_should_be_css_parseable("(prefers-contrast: forced)");

query_should_not_be_css_parseable("(prefers-contrast: increase)");
Expand All @@ -18,11 +18,13 @@
query_should_not_be_css_parseable("(prefers-contrast > increase)");
query_should_not_be_css_parseable("(prefers-increased-contrast)");
query_should_not_be_css_parseable("(prefers-decreased-contrast)");
query_should_not_be_css_parseable("(prefers-contrast: high)");
query_should_not_be_css_parseable("(prefers-contrast: low)");

query_should_be_js_parseable("(prefers-contrast)");
query_should_be_js_parseable("(prefers-contrast: no-preference)");
query_should_be_js_parseable("(prefers-contrast: high)");
query_should_be_js_parseable("(prefers-contrast: low)");
query_should_be_js_parseable("(prefers-contrast: more)");
query_should_be_js_parseable("(prefers-contrast: less)");
query_should_be_js_parseable("(prefers-contrast: forced)");

query_should_not_be_js_parseable("(prefers-contrast: increase)");
Expand All @@ -32,6 +34,8 @@
query_should_not_be_js_parseable("(prefers-contrast > increase)");
query_should_not_be_js_parseable("(prefers-increased-contrast)");
query_should_not_be_js_parseable("(prefers-decreased-contrast)");
query_should_not_be_js_parseable("(prefers-contrast: high)");
query_should_not_be_js_parseable("(prefers-contrast: low)");

test(() => {
// no-preference is the default and all other values evaluate to
Expand Down

0 comments on commit 1f69a14

Please sign in to comment.