Revert "Bug 1966890 - Fix build bustage. try #2" for causing build bustages

This reverts commit 61ae6ce046.

Revert "Bug 1966890 - Fix build bustage"

This reverts commit 35542218b3.

Revert "Bug 1966890 - Expand light-dark() to support images. r=dshin"

This reverts commit 6a6842df06.

Revert "Bug 1966890 - Factor out the light-dark() function. r=dshin"

This reverts commit f9b667bdc0.

Revert "Bug 1966890 - Allow unnecessary transmutes in rust bindings. r=dshin"

This reverts commit 88ed80b1ee.
This commit is contained in:
Alexandru Marc
2025-05-17 20:03:37 +03:00
committed by amarc@mozilla.com
parent 61ae6ce046
commit 70f9124b43
11 changed files with 71 additions and 158 deletions

View File

@@ -259,9 +259,7 @@ CSSSizeOrRatio nsImageRenderer::ComputeIntrinsicSize() {
break; break;
} }
case StyleImage::Tag::ImageSet: case StyleImage::Tag::ImageSet:
MOZ_FALLTHROUGH_ASSERT("image-set() should be resolved already"); MOZ_FALLTHROUGH_ASSERT("image-set should be resolved already");
case StyleImage::Tag::LightDark:
MOZ_FALLTHROUGH_ASSERT("light-dark() should be resolved already");
// Bug 546052 cross-fade not yet implemented. // Bug 546052 cross-fade not yet implemented.
case StyleImage::Tag::CrossFade: case StyleImage::Tag::CrossFade:
// Per <http://dev.w3.org/csswg/css3-images/#gradients>, gradients have no // Per <http://dev.w3.org/csswg/css3-images/#gradients>, gradients have no
@@ -519,9 +517,7 @@ ImgDrawResult nsImageRenderer::Draw(nsPresContext* aPresContext,
break; break;
} }
case StyleImage::Tag::ImageSet: case StyleImage::Tag::ImageSet:
MOZ_FALLTHROUGH_ASSERT("image-set() should be resolved already"); MOZ_FALLTHROUGH_ASSERT("image-set should be resolved already");
case StyleImage::Tag::LightDark:
MOZ_FALLTHROUGH_ASSERT("light-dark() should be resolved already");
// See bug 546052 - cross-fade implementation still being worked // See bug 546052 - cross-fade implementation still being worked
// on. // on.
case StyleImage::Tag::CrossFade: case StyleImage::Tag::CrossFade:

View File

@@ -9751,10 +9751,10 @@
mirror: always mirror: always
rust: true rust: true
# Is support for light-dark() on images in content enabled? # Is support for light-dark() on content enabled?
- name: layout.css.light-dark.images.enabled - name: layout.css.light-dark.enabled
type: RelaxedAtomicBool type: RelaxedAtomicBool
value: false value: true
mirror: always mirror: always
rust: true rust: true

View File

@@ -14,9 +14,7 @@
non_camel_case_types, non_camel_case_types,
non_snake_case, non_snake_case,
non_upper_case_globals, non_upper_case_globals,
missing_docs, missing_docs
unknown_lints,
unnecessary_transmutes,
)] )]
// TODO: Remove this when updating bindgen, see // TODO: Remove this when updating bindgen, see
// https://github.com/rust-lang/rust-bindgen/issues/1651 // https://github.com/rust-lang/rust-bindgen/issues/1651

View File

@@ -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"),
}
}
}

View File

@@ -5,7 +5,7 @@
//! Generic types for color properties. //! Generic types for color properties.
use crate::color::{mix::ColorInterpolationMethod, AbsoluteColor, ColorFunction}; 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 std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss}; use style_traits::{CssWriter, ToCss};
@@ -208,50 +208,3 @@ impl<C> GenericCaretColor<C> {
} }
pub use self::GenericCaretColor as CaretColor; pub use self::GenericCaretColor as CaretColor;
/// A light-dark(<light>, <dark>) function.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem, ToCss, ToResolvedValue)]
#[css(function, comma)]
#[repr(C)]
pub struct GenericLightDark<T> {
/// The value returned when using a light theme.
pub light: T,
/// The value returned when using a dark theme.
pub dark: T,
}
impl<T> GenericLightDark<T> {
/// 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<T, ParseError<'i>>,
) -> Result<Self, ParseError<'i>> {
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<T, ParseError<'i>>,
) -> Result<Self, ParseError<'i>> {
input.expect_function_matching("light-dark")?;
input.parse_nested_block(|input| Self::parse_args_with(input, parse_one))
}
}
impl<T: ToComputedValue> GenericLightDark<T> {
/// 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)
}
}

View File

@@ -8,18 +8,20 @@
use crate::color::mix::ColorInterpolationMethod; use crate::color::mix::ColorInterpolationMethod;
use crate::custom_properties; 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::values::serialize_atom_identifier;
use crate::Atom; use crate::Atom;
use crate::Zero; use crate::Zero;
use servo_arc::Arc; use servo_arc::Arc;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss}; use style_traits::{CssWriter, ToCss};
/// An `<image> | none` value. /// An `<image> | none` value.
/// ///
/// https://drafts.csswg.org/css-images/#image-values /// https://drafts.csswg.org/css-images/#image-values
#[derive( #[derive(
Clone, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToResolvedValue, ToShmem, Clone, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem,
)] )]
#[repr(C, u8)] #[repr(C, u8)]
pub enum GenericImage<G, ImageUrl, Color, Percentage, Resolution> { pub enum GenericImage<G, ImageUrl, Color, Percentage, Resolution> {
@@ -49,10 +51,7 @@ pub enum GenericImage<G, ImageUrl, Color, Percentage, Resolution> {
CrossFade(Box<GenericCrossFade<Self, Color, Percentage>>), CrossFade(Box<GenericCrossFade<Self, Color, Percentage>>),
/// An `image-set()` function. /// An `image-set()` function.
ImageSet(Box<GenericImageSet<Self, Resolution>>), ImageSet(#[compute(field_bound)] Box<GenericImageSet<Self, Resolution>>),
/// A `light-dark()` function.
LightDark(Box<GenericLightDark<Self>>),
} }
pub use self::GenericImage as Image; pub use self::GenericImage as Image;
@@ -427,7 +426,6 @@ where
}, },
Image::ImageSet(ref is) => is.to_css(dest), Image::ImageSet(ref is) => is.to_css(dest),
Image::CrossFade(ref cf) => cf.to_css(dest), Image::CrossFade(ref cf) => cf.to_css(dest),
Image::LightDark(ref ld) => ld.to_css(dest),
} }
} }
} }

View File

@@ -11,7 +11,7 @@ use crate::media_queries::Device;
use crate::parser::{Parse, ParserContext}; use crate::parser::{Parse, ParserContext};
use crate::values::computed::{Color as ComputedColor, Context, ToComputedValue}; use crate::values::computed::{Color as ComputedColor, Context, ToComputedValue};
use crate::values::generics::color::{ use crate::values::generics::color::{
ColorMixFlags, GenericCaretColor, GenericColorMix, GenericColorOrAuto, GenericLightDark ColorMixFlags, GenericCaretColor, GenericColorMix, GenericColorOrAuto,
}; };
use crate::values::specified::Percentage; use crate::values::specified::Percentage;
use crate::values::{normalize, CustomIdent}; use crate::values::{normalize, CustomIdent};
@@ -124,12 +124,54 @@ pub enum Color {
/// A color mix. /// A color mix.
ColorMix(Box<ColorMix>), ColorMix(Box<ColorMix>),
/// A light-dark() color. /// A light-dark() color.
LightDark(Box<GenericLightDark<Self>>), LightDark(Box<LightDark>),
/// Quirksmode-only rule for inheriting color from the body /// Quirksmode-only rule for inheriting color from the body
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
InheritFromBodyQuirk, InheritFromBodyQuirk,
} }
/// A light-dark(<light-color>, <dark-color>) function.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem, ToCss)]
#[css(function, comma)]
pub struct LightDark {
/// The <color> that is returned when using a light theme.
pub light: Color,
/// The <color> 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<Self, ParseError<'i>> {
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<AbsoluteColor> for Color { impl From<AbsoluteColor> for Color {
#[inline] #[inline]
fn from(value: AbsoluteColor) -> Self { fn from(value: AbsoluteColor) -> Self {
@@ -441,7 +483,7 @@ impl Color {
return Ok(Color::ColorMix(Box::new(mix))); 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))); return Ok(Color::LightDark(Box::new(ld)));
} }

View File

@@ -10,7 +10,7 @@
use crate::color::mix::ColorInterpolationMethod; use crate::color::mix::ColorInterpolationMethod;
use crate::parser::{Parse, ParserContext}; use crate::parser::{Parse, ParserContext};
use crate::stylesheets::CorsMode; use crate::stylesheets::CorsMode;
use crate::values::generics::color::{ColorMixFlags, GenericLightDark}; use crate::values::generics::color::ColorMixFlags;
use crate::values::generics::image::{ use crate::values::generics::image::{
self as generic, Circle, Ellipse, GradientCompatMode, ShapeExtent, self as generic, Circle, Ellipse, GradientCompatMode, ShapeExtent,
}; };
@@ -113,10 +113,6 @@ fn default_color_interpolation_method<T>(
} }
} }
fn image_light_dark_enabled(context: &ParserContext) -> bool {
context.chrome_rules_enabled() || static_prefs::pref!("layout.css.light-dark.images.enabled")
}
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn cross_fade_enabled() -> bool { fn cross_fade_enabled() -> bool {
static_prefs::pref!("layout.css.cross-fade.enabled") static_prefs::pref!("layout.css.cross-fade.enabled")
@@ -127,6 +123,7 @@ fn cross_fade_enabled() -> bool {
false false
} }
impl SpecifiedValueInfo for Gradient { impl SpecifiedValueInfo for Gradient {
const SUPPORTED_TYPES: u8 = CssType::GRADIENT; const SUPPORTED_TYPES: u8 = CssType::GRADIENT;
@@ -221,8 +218,8 @@ impl Image {
return Ok(generic::Image::None); return Ok(generic::Image::None);
} }
if let Ok(url) = if let Ok(url) = input
input.try_parse(|input| SpecifiedUrl::parse_with_cors_mode(context, input, cors_mode)) .try_parse(|input| SpecifiedUrl::parse_with_cors_mode(context, input, cors_mode))
{ {
return Ok(generic::Image::Url(url)); return Ok(generic::Image::Url(url));
} }
@@ -244,17 +241,16 @@ impl Image {
} }
let function = input.expect_function()?.clone(); let function = input.expect_function()?.clone();
input.parse_nested_block(|input| Ok(match_ignore_ascii_case! { &function, input.parse_nested_block(|input| {
#[cfg(feature = "servo")] Ok(match_ignore_ascii_case! { &function,
"paint" => Self::PaintWorklet(PaintWorklet::parse_args(context, input)?), #[cfg(feature = "servo")]
"cross-fade" if cross_fade_enabled() => Self::CrossFade(Box::new(CrossFade::parse_args(context, input, cors_mode, flags)?)), "paint" => Self::PaintWorklet(PaintWorklet::parse_args(context, input)?),
"light-dark" if image_light_dark_enabled(context) => Self::LightDark(Box::new(GenericLightDark::parse_args_with(input, |input| { "cross-fade" if cross_fade_enabled() => Self::CrossFade(Box::new(CrossFade::parse_args(context, input, cors_mode, flags)?)),
Self::parse_with_cors_mode(context, input, cors_mode, flags) #[cfg(feature = "gecko")]
})?)), "-moz-element" => Self::Element(Self::parse_element(input)?),
#[cfg(feature = "gecko")] _ => return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function))),
"-moz-element" => Self::Element(Self::parse_element(input)?), })
_ => return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function))), })
}))
} }
} }

View File

@@ -1 +0,0 @@
prefs: [layout.css.light-dark.images.enabled:true]

View File

@@ -1,17 +0,0 @@
<!doctype html>
<style>
div {
width: 100px;
height: 100px;
&.light {
background-image: url("/images/green.png");
}
&.dark {
background-image: url("/images/red.png");
}
}
</style>
<div class="dark"></div>
<div class="light"></div>
<div class="dark"></div>
<div class="light"></div>

View File

@@ -1,18 +0,0 @@
<!doctype html>
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/10577">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1966890">
<link rel="match" href="image-light-dark-ref.html">
<style>
div:empty {
width: 100px;
height: 100px;
background-image: light-dark(
url("/images/green.png"),
url("/images/red.png")
);
}
</style>
<div style="color-scheme: dark"></div>
<div style="color-scheme: light"></div>
<div style="color-scheme: dark"><div></div></div>
<div style="color-scheme: light"><div></div></div>