tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit ab91e25575a5d89d0e62693e9d9cc5622241fd5e
parent 26ad5eb1cb7a252335a50a18812391c70946e589
Author: Serban Stanca <sstanca@mozilla.com>
Date:   Tue, 28 Oct 2025 16:13:36 +0200

Revert "Bug 1682439 - Add a basic WPT reftest for results of the contrast-color() function. r=firefox-style-system-reviewers,emilio" for causing mochitests failures in test_bug877690.html.

This reverts commit 69695ad2db5c218f4cc5b64ab22bc7553f1ecd15.

This reverts commit f4fa1425b081fd0fe8d11f4314cc409bf8d83ef9.

Diffstat:
Mmodules/libpref/init/StaticPrefList.yaml | 7-------
Mservo/components/style/values/computed/color.rs | 41-----------------------------------------
Mservo/components/style/values/generics/color.rs | 2--
Mservo/components/style/values/specified/color.rs | 26--------------------------
Mtesting/web-platform/meta/css/css-color/parsing/color-computed-contrast-color-function.html.ini | 27+++++++++++++++++++++++++++
Mtesting/web-platform/meta/css/css-color/parsing/color-valid-contrast-color-function.html.ini | 27+++++++++++++++++++++++++++
Dtesting/web-platform/tests/css/css-color/contrast-color-001-ref.html | 70----------------------------------------------------------------------
Dtesting/web-platform/tests/css/css-color/contrast-color-001.html | 86-------------------------------------------------------------------------------
8 files changed, 54 insertions(+), 232 deletions(-)

diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml @@ -9969,13 +9969,6 @@ mirror: always rust: true -# Is support for the contrast-color() function enabled? -- name: layout.css.contrast-color.enabled - type: RelaxedAtomicBool - value: true - mirror: always - rust: true - # Whether alt text in content is enabled. - name: layout.css.content.alt-text.enabled type: RelaxedAtomicBool diff --git a/servo/components/style/values/computed/color.rs b/servo/components/style/values/computed/color.rs @@ -34,11 +34,6 @@ impl ToCss for Color { Self::ColorFunction(ref color_function) => color_function.to_css(dest), Self::CurrentColor => dest.write_str("currentcolor"), Self::ColorMix(ref m) => m.to_css(dest), - Self::ContrastColor(ref c) => { - dest.write_str("contrast-color(")?; - c.to_css(dest)?; - dest.write_char(')') - }, } } } @@ -86,42 +81,6 @@ impl Color { mix.flags, ) }, - Self::ContrastColor(ref c) => { - let bg_color = c.resolve_to_absolute(current_color); - if Self::contrast_ratio(&bg_color, &AbsoluteColor::BLACK) - > Self::contrast_ratio(&bg_color, &AbsoluteColor::WHITE) - { - AbsoluteColor::BLACK - } else { - AbsoluteColor::WHITE - } - }, - } - } - - fn contrast_ratio(a: &AbsoluteColor, b: &AbsoluteColor) -> f32 { - // TODO: This just implements the WCAG 2.1 algorithm, - // https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio - // Consider using a more sophisticated contrast algorithm, e.g. see - // https://apcacontrast.com - let compute = |c| -> f32 { - if c <= 0.04045 { - c / 12.92 - } else { - f32::powf((c + 0.055) / 1.055, 2.4) - } - }; - let luminance = |r, g, b| -> f32 { 0.2126 * r + 0.7152 * g + 0.0722 * b }; - let a = a.into_srgb_legacy(); - let b = b.into_srgb_legacy(); - let a = a.raw_components(); - let b = b.raw_components(); - let la = luminance(compute(a[0]), compute(a[1]), compute(a[2])) + 0.05; - let lb = luminance(compute(b[0]), compute(b[1]), compute(b[2])) + 0.05; - if la > lb { - la / lb - } else { - lb / la } } } diff --git a/servo/components/style/values/generics/color.rs b/servo/components/style/values/generics/color.rs @@ -24,8 +24,6 @@ pub enum GenericColor<Percentage> { CurrentColor, /// The color-mix() function. ColorMix(Box<GenericColorMix<Self, Percentage>>), - /// The contrast-color() function. - ContrastColor(Box<Self>), } /// Flags used to modify the calculation of a color mix result. diff --git a/servo/components/style/values/specified/color.rs b/servo/components/style/values/specified/color.rs @@ -125,8 +125,6 @@ pub enum Color { ColorMix(Box<ColorMix>), /// A light-dark() color. LightDark(Box<GenericLightDark<Self>>), - /// The contrast-color function. - ContrastColor(Box<Color>), /// Quirksmode-only rule for inheriting color from the body #[cfg(feature = "gecko")] InheritFromBodyQuirk, @@ -457,17 +455,6 @@ impl Color { return Ok(Color::LightDark(Box::new(ld))); } - if static_prefs::pref!("layout.css.contrast-color.enabled") { - if let Ok(c) = input.try_parse(|i| { - i.expect_function_matching("contrast-color")?; - i.parse_nested_block(|i| { - Self::parse_internal(context, i, preserve_authored) - }) - }) { - return Ok(Color::ContrastColor(Box::new(c))); - } - } - match e.kind { ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(t)) => { Err(e.location.new_custom_error(StyleParseErrorKind::ValueError( @@ -542,11 +529,6 @@ impl ToCss for Color { Color::ColorFunction(ref color_function) => color_function.to_css(dest), Color::ColorMix(ref mix) => mix.to_css(dest), Color::LightDark(ref ld) => ld.to_css(dest), - Color::ContrastColor(ref c) => { - dest.write_str("contrast-color(")?; - c.to_css(dest)?; - dest.write_char(')') - }, #[cfg(feature = "gecko")] Color::System(system) => system.to_css(dest), #[cfg(feature = "gecko")] @@ -581,7 +563,6 @@ impl Color { mix.left.honored_in_forced_colors_mode(allow_transparent) && mix.right.honored_in_forced_colors_mode(allow_transparent) }, - Self::ContrastColor(ref c) => c.honored_in_forced_colors_mode(allow_transparent), } } @@ -787,9 +768,6 @@ impl Color { flags: mix.flags, }) }, - Color::ContrastColor(ref c) => { - ComputedColor::ContrastColor(Box::new(c.to_computed_color(context)?)) - }, #[cfg(feature = "gecko")] Color::System(system) => system.compute(context?), #[cfg(feature = "gecko")] @@ -825,9 +803,6 @@ impl ToComputedValue for Color { ComputedColor::ColorMix(ref mix) => { Color::ColorMix(Box::new(ToComputedValue::from_computed_value(&**mix))) }, - ComputedColor::ContrastColor(ref c) => { - Self::ContrastColor(Box::new(ToComputedValue::from_computed_value(&**c))) - }, } } } @@ -855,7 +830,6 @@ impl SpecifiedValueInfo for Color { "oklab", "oklch", "color-mix", - "contrast-color", "light-dark", ]); } diff --git a/testing/web-platform/meta/css/css-color/parsing/color-computed-contrast-color-function.html.ini b/testing/web-platform/meta/css/css-color/parsing/color-computed-contrast-color-function.html.ini @@ -1,3 +1,30 @@ [color-computed-contrast-color-function.html] + [Property background-color value 'contrast-color(white)'] + expected: FAIL + + [Property background-color value 'contrast-color(black)'] + expected: FAIL + + [Property background-color value 'contrast-color(pink)'] + expected: FAIL + + [Property background-color value 'contrast-color(color(srgb 1 0 1 / 0.5))'] + expected: FAIL + + [Property background-color value 'contrast-color(lab(0.2 0.5 0.2))'] + expected: FAIL + + [Property background-color value 'contrast-color(color(srgb 10 10 10))'] + expected: FAIL + + [Property background-color value 'contrast-color(color(srgb -10 -10 -10))'] + expected: FAIL + + [Property background-color value 'contrast-color(contrast-color(pink))'] + expected: FAIL + + [Property background-color value 'contrast-color(currentcolor)'] + expected: FAIL + [Property background-color value 'contrast-color(color(srgb calc(1 + (sign(20cqw - 10px) * 1)) calc(1 + (sign(20cqw - 10px) * 1)) calc(1 + (sign(20cqw - 10px) * 1))))'] expected: FAIL diff --git a/testing/web-platform/meta/css/css-color/parsing/color-valid-contrast-color-function.html.ini b/testing/web-platform/meta/css/css-color/parsing/color-valid-contrast-color-function.html.ini @@ -1,3 +1,30 @@ [color-valid-contrast-color-function.html] + [e.style['background-color'\] = "contrast-color(white)" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(black)" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(pink)" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(color(srgb 1 0 1 / 0.5))" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(lab(0.2 0.5 0.2))" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(color(srgb 10 10 10))" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(color(srgb -10 -10 -10))" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(contrast-color(pink))" should set the property value] + expected: FAIL + + [e.style['background-color'\] = "contrast-color(currentcolor)" should set the property value] + expected: FAIL + [e.style['background-color'\] = "contrast-color(color(srgb calc(0.5) calc(1 + (sign(20cqw - 10px) * 0.5)) 1 / .5))" should set the property value] expected: FAIL diff --git a/testing/web-platform/tests/css/css-color/contrast-color-001-ref.html b/testing/web-platform/tests/css/css-color/contrast-color-001-ref.html @@ -1,70 +0,0 @@ -<!D<!DOCTYPE html> -<meta charset="utf-8"> - -<title>CSS Color 5 reference: contrast-color</title> - -<link rel="help" href="https://drafts.csswg.org/css-color-5/#contrast-color"> -<link rel="author" title="Jonathan Kew" href="mailto:jkew@mozilla.com"> - -<style> -body { - background: ivory; - color: magenta; -} -p { - font: bold 16px sans-serif; - padding: .5em; -} -p.test1 { - background: white; - color: black; -} -p.test2 { - background: aliceblue; - color: black; -} -p.test3 { - background: mistyrose; - color: black; -} -p.test4 { - background: lightyellow; - color: black; -} -p.test5 { - background: palegreen; - color: black; -} -p.test6 { - background: darkblue; - color: white; -} -p.test7 { - background: maroon; - color: white; -} -p.test8 { - background: purple; - color: white; -} -p.test9 { - background: brown; - color: white; -} -p.test10 { - background: black; - color: white; -} -</style> - -<p class=test1>This text should be black</p> -<p class=test2>This text should be black</p> -<p class=test3>This text should be black</p> -<p class=test4>This text should be black</p> -<p class=test5>This text should be black</p> - -<p class=test6>This text should be white</p> -<p class=test7>This text should be white</p> -<p class=test8>This text should be white</p> -<p class=test9>This text should be white</p> -<p class=test10>This text should be white</p> diff --git a/testing/web-platform/tests/css/css-color/contrast-color-001.html b/testing/web-platform/tests/css/css-color/contrast-color-001.html @@ -1,86 +0,0 @@ -<!D<!DOCTYPE html> -<meta charset="utf-8"> - -<title>CSS Color 5: contrast-color</title> - -<link rel="help" href="https://drafts.csswg.org/css-color-5/#contrast-color"> -<link rel="author" title="Jonathan Kew" href="mailto:jkew@mozilla.com"> - -<link rel="match" href="contrast-color-001-ref.html"> - -<!-- -Although the spec says that - - "The precise color contrast algorithm for determining whether to output - a light or dark color is UA-defined", - -it does require that - - "contrast-color() resolves to either white or black, whichever produces - maximum color contrast..." - -so although the exact definition of "contrast" is unspecified, it is clear that -for very light colors, it must resolve to black, and for very dark ones, it must -resolve to white. It would only be for intermediate colors nearer the middle of -the lightness range that the result may be UA-dependent. - -Here, we check that contrast-color() resolves to black for a selection of very -light colors, and to white for some dark ones. ---> - -<style> -body { - background: ivory; - color: magenta; -} -p { - font: bold 16px sans-serif; - padding: .5em; - background: var(--bgcolor); - color: contrast-color(var(--bgcolor)); -} -/* light colors for which contrast-color() should be black: */ -p.test1 { - --bgcolor: white; -} -p.test2 { - --bgcolor: aliceblue; -} -p.test3 { - --bgcolor: mistyrose; -} -p.test4 { - --bgcolor: lightyellow; -} -p.test5 { - --bgcolor: palegreen; -} -/* dark colors for which contrast-color() should be white: */ -p.test6 { - --bgcolor: darkblue; -} -p.test7 { - --bgcolor: maroon; -} -p.test8 { - --bgcolor: purple; -} -p.test9 { - --bgcolor: brown; -} -p.test10 { - --bgcolor: black; -} -</style> - -<p class=test1>This text should be black</p> -<p class=test2>This text should be black</p> -<p class=test3>This text should be black</p> -<p class=test4>This text should be black</p> -<p class=test5>This text should be black</p> - -<p class=test6>This text should be white</p> -<p class=test7>This text should be white</p> -<p class=test8>This text should be white</p> -<p class=test9>This text should be white</p> -<p class=test10>This text should be white</p>