From 70f9124b438d59343c818565d3fa7efe4a8490ba Mon Sep 17 00:00:00 2001 From: Alexandru Marc Date: Sat, 17 May 2025 20:03:37 +0300 Subject: [PATCH] Revert "Bug 1966890 - Fix build bustage. try #2" for causing build bustages This reverts commit 61ae6ce046ea3433251383dc3942d7c5fa82e49d. Revert "Bug 1966890 - Fix build bustage" This reverts commit 35542218b35f94e6433653d6f0a3e67b7660bc55. Revert "Bug 1966890 - Expand light-dark() to support images. r=dshin" This reverts commit 6a6842df06409e413d9cda8270248f1b9a1f6683. Revert "Bug 1966890 - Factor out the light-dark() function. r=dshin" This reverts commit f9b667bdc0bb91add46c6df8bd32b3eaad1b5bff. Revert "Bug 1966890 - Allow unnecessary transmutes in rust bindings. r=dshin" This reverts commit 88ed80b1eee5249c291af4a30e2222975d6a2c49. --- layout/painting/nsImageRenderer.cpp | 8 +-- modules/libpref/init/StaticPrefList.yaml | 6 +-- servo/components/style/gecko_bindings/mod.rs | 4 +- .../components/style/values/computed/image.rs | 34 ------------- .../components/style/values/generics/color.rs | 49 +------------------ .../components/style/values/generics/image.rs | 12 ++--- .../style/values/specified/color.rs | 48 ++++++++++++++++-- .../style/values/specified/image.rs | 32 ++++++------ .../mozilla/meta/css/css-images/__dir__.ini | 1 - .../css/css-images/image-light-dark-ref.html | 17 ------- .../css/css-images/image-light-dark.html | 18 ------- 11 files changed, 71 insertions(+), 158 deletions(-) delete mode 100644 testing/web-platform/mozilla/meta/css/css-images/__dir__.ini delete mode 100644 testing/web-platform/mozilla/tests/css/css-images/image-light-dark-ref.html delete mode 100644 testing/web-platform/mozilla/tests/css/css-images/image-light-dark.html diff --git a/layout/painting/nsImageRenderer.cpp b/layout/painting/nsImageRenderer.cpp index 67165464d77d..fd6829da5f98 100644 --- a/layout/painting/nsImageRenderer.cpp +++ b/layout/painting/nsImageRenderer.cpp @@ -259,9 +259,7 @@ CSSSizeOrRatio nsImageRenderer::ComputeIntrinsicSize() { break; } case StyleImage::Tag::ImageSet: - MOZ_FALLTHROUGH_ASSERT("image-set() should be resolved already"); - case StyleImage::Tag::LightDark: - MOZ_FALLTHROUGH_ASSERT("light-dark() should be resolved already"); + MOZ_FALLTHROUGH_ASSERT("image-set should be resolved already"); // Bug 546052 cross-fade not yet implemented. case StyleImage::Tag::CrossFade: // Per , gradients have no @@ -519,9 +517,7 @@ ImgDrawResult nsImageRenderer::Draw(nsPresContext* aPresContext, break; } case StyleImage::Tag::ImageSet: - MOZ_FALLTHROUGH_ASSERT("image-set() should be resolved already"); - case StyleImage::Tag::LightDark: - MOZ_FALLTHROUGH_ASSERT("light-dark() should be resolved already"); + MOZ_FALLTHROUGH_ASSERT("image-set should be resolved already"); // See bug 546052 - cross-fade implementation still being worked // on. case StyleImage::Tag::CrossFade: diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index e0fc40d1dce0..c5ea8eba2380 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -9751,10 +9751,10 @@ mirror: always rust: true -# Is support for light-dark() on images in content enabled? -- name: layout.css.light-dark.images.enabled +# Is support for light-dark() on content enabled? +- name: layout.css.light-dark.enabled type: RelaxedAtomicBool - value: false + value: true mirror: always rust: true diff --git a/servo/components/style/gecko_bindings/mod.rs b/servo/components/style/gecko_bindings/mod.rs index 24f444cae5f3..f0b0adc7ecb8 100644 --- a/servo/components/style/gecko_bindings/mod.rs +++ b/servo/components/style/gecko_bindings/mod.rs @@ -14,9 +14,7 @@ non_camel_case_types, non_snake_case, non_upper_case_globals, - missing_docs, - unknown_lints, - unnecessary_transmutes, + missing_docs )] // TODO: Remove this when updating bindgen, see // https://github.com/rust-lang/rust-bindgen/issues/1651 diff --git a/servo/components/style/values/computed/image.rs b/servo/components/style/values/computed/image.rs index 7d8328ee0d9b..b99d44f11e62 100644 --- a/servo/components/style/values/computed/image.rs +++ b/servo/components/style/values/computed/image.rs @@ -206,37 +206,3 @@ impl ToComputedValue for specified::LineDirection { } } } - -impl ToComputedValue for specified::Image { - type ComputedValue = Image; - - fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { - match self { - Self::None => Image::None, - Self::Url(u) => Image::Url(u.to_computed_value(context)), - Self::Gradient(g) => Image::Gradient(g.to_computed_value(context)), - #[cfg(feature = "gecko")] - Self::Element(e) => Image::Element(e.to_computed_value(context)), - #[cfg(feature = "servo")] - Self::PaintWorklet(w) => Image::PaintWorklet(w.to_computed_value(context)), - Self::CrossFade(f) => Image::CrossFade(f.to_computed_value(context)), - Self::ImageSet(s) => Image::ImageSet(s.to_computed_value(context)), - Self::LightDark(ld) => ld.compute(context), - } - } - - fn from_computed_value(computed: &Self::ComputedValue) -> Self { - match computed { - Image::None => Self::None, - Image::Url(u) => Self::Url(ToComputedValue::from_computed_value(u)), - Image::Gradient(g) => Self::Gradient(ToComputedValue::from_computed_value(g)), - #[cfg(feature = "gecko")] - Image::Element(e) => Self::Element(ToComputedValue::from_computed_value(e)), - #[cfg(feature = "servo")] - Image::PaintWorklet(w) => Self::PaintWorklet(ToComputedValue::from_computed_value(w)), - Image::CrossFade(f) => Self::CrossFade(ToComputedValue::from_computed_value(f)), - Image::ImageSet(s) => Self::ImageSet(ToComputedValue::from_computed_value(s)), - Image::LightDark(_) => unreachable!("Shouldn't have computed image-set values"), - } - } -} diff --git a/servo/components/style/values/generics/color.rs b/servo/components/style/values/generics/color.rs index 26f60446ea20..eaf29f8f2b37 100644 --- a/servo/components/style/values/generics/color.rs +++ b/servo/components/style/values/generics/color.rs @@ -5,7 +5,7 @@ //! Generic types for color properties. use crate::color::{mix::ColorInterpolationMethod, AbsoluteColor, ColorFunction}; -use crate::values::{specified::percentage::ToPercentage, computed::ToComputedValue, Parser, ParseError}; +use crate::values::specified::percentage::ToPercentage; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; @@ -208,50 +208,3 @@ impl GenericCaretColor { } pub use self::GenericCaretColor as CaretColor; - -/// A light-dark(, ) function. -#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem, ToCss, ToResolvedValue)] -#[css(function, comma)] -#[repr(C)] -pub struct GenericLightDark { - /// The value returned when using a light theme. - pub light: T, - /// The value returned when using a dark theme. - pub dark: T, -} - -impl GenericLightDark { - /// Parse the arguments of the light-dark() function. - pub fn parse_args_with<'i>( - input: &mut Parser<'i, '_>, - mut parse_one: impl FnMut(&mut Parser<'i, '_>) -> Result>, - ) -> Result> { - let light = parse_one(input)?; - input.expect_comma()?; - let dark = parse_one(input)?; - Ok(Self { light, dark }) - } - - /// Parse the light-dark() function. - pub fn parse_with<'i>( - input: &mut Parser<'i, '_>, - parse_one: impl FnMut(&mut Parser<'i, '_>) -> Result>, - ) -> Result> { - input.expect_function_matching("light-dark")?; - input.parse_nested_block(|input| Self::parse_args_with(input, parse_one)) - } -} - -impl GenericLightDark { - /// Choose the light or dark version of this value for computation purposes, and compute it. - pub fn compute(&self, cx: &crate::values::computed::Context) -> T::ComputedValue { - let dark = cx.device().is_dark_color_scheme(cx.builder.color_scheme); - if cx.for_non_inherited_property { - cx.rule_cache_conditions - .borrow_mut() - .set_color_scheme_dependency(cx.builder.color_scheme); - } - let chosen = if dark { &self.dark } else { &self.light }; - chosen.to_computed_value(cx) - } -} diff --git a/servo/components/style/values/generics/image.rs b/servo/components/style/values/generics/image.rs index 1fc3e96c2a55..ca1c716052b6 100644 --- a/servo/components/style/values/generics/image.rs +++ b/servo/components/style/values/generics/image.rs @@ -8,18 +8,20 @@ use crate::color::mix::ColorInterpolationMethod; use crate::custom_properties; -use crate::values::generics::{position::PositionComponent, color::GenericLightDark, Optional}; +use crate::values::generics::position::PositionComponent; +use crate::values::generics::Optional; use crate::values::serialize_atom_identifier; use crate::Atom; use crate::Zero; use servo_arc::Arc; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; + /// An ` | none` value. /// /// https://drafts.csswg.org/css-images/#image-values #[derive( - Clone, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToResolvedValue, ToShmem, + Clone, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem, )] #[repr(C, u8)] pub enum GenericImage { @@ -49,10 +51,7 @@ pub enum GenericImage { CrossFade(Box>), /// An `image-set()` function. - ImageSet(Box>), - - /// A `light-dark()` function. - LightDark(Box>), + ImageSet(#[compute(field_bound)] Box>), } pub use self::GenericImage as Image; @@ -427,7 +426,6 @@ where }, Image::ImageSet(ref is) => is.to_css(dest), Image::CrossFade(ref cf) => cf.to_css(dest), - Image::LightDark(ref ld) => ld.to_css(dest), } } } diff --git a/servo/components/style/values/specified/color.rs b/servo/components/style/values/specified/color.rs index 18ddeec2378e..bd5e0f9e80c3 100644 --- a/servo/components/style/values/specified/color.rs +++ b/servo/components/style/values/specified/color.rs @@ -11,7 +11,7 @@ use crate::media_queries::Device; use crate::parser::{Parse, ParserContext}; use crate::values::computed::{Color as ComputedColor, Context, ToComputedValue}; use crate::values::generics::color::{ - ColorMixFlags, GenericCaretColor, GenericColorMix, GenericColorOrAuto, GenericLightDark + ColorMixFlags, GenericCaretColor, GenericColorMix, GenericColorOrAuto, }; use crate::values::specified::Percentage; use crate::values::{normalize, CustomIdent}; @@ -124,12 +124,54 @@ pub enum Color { /// A color mix. ColorMix(Box), /// A light-dark() color. - LightDark(Box>), + LightDark(Box), /// Quirksmode-only rule for inheriting color from the body #[cfg(feature = "gecko")] InheritFromBodyQuirk, } +/// A light-dark(, ) function. +#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem, ToCss)] +#[css(function, comma)] +pub struct LightDark { + /// The that is returned when using a light theme. + pub light: Color, + /// The that is returned when using a dark theme. + pub dark: Color, +} + +impl LightDark { + fn compute(&self, cx: &Context) -> ComputedColor { + let dark = cx.device().is_dark_color_scheme(cx.builder.color_scheme); + if cx.for_non_inherited_property { + cx.rule_cache_conditions + .borrow_mut() + .set_color_scheme_dependency(cx.builder.color_scheme); + } + let used = if dark { &self.dark } else { &self.light }; + used.to_computed_value(cx) + } + + fn parse<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + preserve_authored: PreserveAuthored, + ) -> Result> { + let enabled = + context.chrome_rules_enabled() || static_prefs::pref!("layout.css.light-dark.enabled"); + if !enabled { + return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); + } + input.expect_function_matching("light-dark")?; + input.parse_nested_block(|input| { + let light = Color::parse_internal(context, input, preserve_authored)?; + input.expect_comma()?; + let dark = Color::parse_internal(context, input, preserve_authored)?; + Ok(LightDark { light, dark }) + }) + } +} + impl From for Color { #[inline] fn from(value: AbsoluteColor) -> Self { @@ -441,7 +483,7 @@ impl Color { return Ok(Color::ColorMix(Box::new(mix))); } - if let Ok(ld) = input.try_parse(|i| GenericLightDark::parse_with(i, |i| Self::parse_internal(context, i, preserve_authored))) + if let Ok(ld) = input.try_parse(|i| LightDark::parse(context, i, preserve_authored)) { return Ok(Color::LightDark(Box::new(ld))); } diff --git a/servo/components/style/values/specified/image.rs b/servo/components/style/values/specified/image.rs index 6c0c4c5f6457..19830cae52c3 100644 --- a/servo/components/style/values/specified/image.rs +++ b/servo/components/style/values/specified/image.rs @@ -10,7 +10,7 @@ use crate::color::mix::ColorInterpolationMethod; use crate::parser::{Parse, ParserContext}; use crate::stylesheets::CorsMode; -use crate::values::generics::color::{ColorMixFlags, GenericLightDark}; +use crate::values::generics::color::ColorMixFlags; use crate::values::generics::image::{ self as generic, Circle, Ellipse, GradientCompatMode, ShapeExtent, }; @@ -113,10 +113,6 @@ fn default_color_interpolation_method( } } -fn image_light_dark_enabled(context: &ParserContext) -> bool { - context.chrome_rules_enabled() || static_prefs::pref!("layout.css.light-dark.images.enabled") -} - #[cfg(feature = "gecko")] fn cross_fade_enabled() -> bool { static_prefs::pref!("layout.css.cross-fade.enabled") @@ -127,6 +123,7 @@ fn cross_fade_enabled() -> bool { false } + impl SpecifiedValueInfo for Gradient { const SUPPORTED_TYPES: u8 = CssType::GRADIENT; @@ -221,8 +218,8 @@ impl Image { return Ok(generic::Image::None); } - if let Ok(url) = - input.try_parse(|input| SpecifiedUrl::parse_with_cors_mode(context, input, cors_mode)) + if let Ok(url) = input + .try_parse(|input| SpecifiedUrl::parse_with_cors_mode(context, input, cors_mode)) { return Ok(generic::Image::Url(url)); } @@ -244,17 +241,16 @@ impl Image { } let function = input.expect_function()?.clone(); - input.parse_nested_block(|input| Ok(match_ignore_ascii_case! { &function, - #[cfg(feature = "servo")] - "paint" => Self::PaintWorklet(PaintWorklet::parse_args(context, input)?), - "cross-fade" if cross_fade_enabled() => Self::CrossFade(Box::new(CrossFade::parse_args(context, input, cors_mode, flags)?)), - "light-dark" if image_light_dark_enabled(context) => Self::LightDark(Box::new(GenericLightDark::parse_args_with(input, |input| { - Self::parse_with_cors_mode(context, input, cors_mode, flags) - })?)), - #[cfg(feature = "gecko")] - "-moz-element" => Self::Element(Self::parse_element(input)?), - _ => return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function))), - })) + input.parse_nested_block(|input| { + Ok(match_ignore_ascii_case! { &function, + #[cfg(feature = "servo")] + "paint" => Self::PaintWorklet(PaintWorklet::parse_args(context, input)?), + "cross-fade" if cross_fade_enabled() => Self::CrossFade(Box::new(CrossFade::parse_args(context, input, cors_mode, flags)?)), + #[cfg(feature = "gecko")] + "-moz-element" => Self::Element(Self::parse_element(input)?), + _ => return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function))), + }) + }) } } diff --git a/testing/web-platform/mozilla/meta/css/css-images/__dir__.ini b/testing/web-platform/mozilla/meta/css/css-images/__dir__.ini deleted file mode 100644 index dbffa06d4f1b..000000000000 --- a/testing/web-platform/mozilla/meta/css/css-images/__dir__.ini +++ /dev/null @@ -1 +0,0 @@ -prefs: [layout.css.light-dark.images.enabled:true] diff --git a/testing/web-platform/mozilla/tests/css/css-images/image-light-dark-ref.html b/testing/web-platform/mozilla/tests/css/css-images/image-light-dark-ref.html deleted file mode 100644 index 5757999b7989..000000000000 --- a/testing/web-platform/mozilla/tests/css/css-images/image-light-dark-ref.html +++ /dev/null @@ -1,17 +0,0 @@ - - -
-
-
-
diff --git a/testing/web-platform/mozilla/tests/css/css-images/image-light-dark.html b/testing/web-platform/mozilla/tests/css/css-images/image-light-dark.html deleted file mode 100644 index 7ffa0390e9cf..000000000000 --- a/testing/web-platform/mozilla/tests/css/css-images/image-light-dark.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - -
-
-
-