diff --git a/components/style/gecko/url.rs b/components/style/gecko/url.rs index 8435895b895..4f1efdf052c 100644 --- a/components/style/gecko/url.rs +++ b/components/style/gecko/url.rs @@ -256,7 +256,6 @@ impl ToComputedValue for SpecifiedUrl { /// A specified image `url()` value. #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] -#[repr(C)] pub struct SpecifiedImageUrl(pub SpecifiedUrl); impl SpecifiedImageUrl { @@ -340,6 +339,7 @@ impl ToCss for ComputedUrl { /// The computed value of a CSS image `url()`. #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)] +#[repr(transparent)] pub struct ComputedImageUrl(pub ComputedUrl); impl ComputedImageUrl { diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 45e3124c858..e5595673cb7 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -33,13 +33,11 @@ use crate::gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom; use crate::gecko_bindings::bindings::Gecko_SetListStyleImageNone; use crate::gecko_bindings::bindings::Gecko_SetListStyleImageImageValue; use crate::gecko_bindings::bindings::Gecko_SetNullImageValue; -use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}; use crate::gecko_bindings::structs; use crate::gecko_bindings::structs::nsCSSPropertyID; use crate::gecko_bindings::structs::mozilla::PseudoStyleType; -use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut}; +use crate::gecko_bindings::sugar::ns_style_coord::CoordDataMut; use crate::gecko_bindings::sugar::refptr::RefPtr; -use crate::gecko::values::GeckoStyleCoordConvertible; use crate::gecko::values::round_border_to_device_pixels; use crate::logical_geometry::WritingMode; use crate::media_queries::Device; @@ -52,11 +50,10 @@ use std::marker::PhantomData; use std::mem::{forget, uninitialized, zeroed, ManuallyDrop}; use std::{cmp, ops, ptr}; use crate::values::{self, CustomIdent, Either, KeyframesName, None_}; -use crate::values::computed::{NonNegativeLength, Percentage, TransitionProperty}; +use crate::values::computed::{Percentage, TransitionProperty}; use crate::values::computed::url::ComputedImageUrl; use crate::values::computed::BorderStyle; use crate::values::computed::font::FontSize; -use crate::values::computed::effects::Filter; use crate::values::generics::column::ColumnCount; use crate::values::generics::transform::TransformStyle; use crate::values::generics::url::UrlOrNone; @@ -2162,6 +2159,7 @@ fn static_assert() { gecko_inexhaustive=True, ) %> ${impl_keyword('clear', 'mBreakType', clear_keyword)} + ${impl_transition_time_value('delay', 'Delay')} ${impl_transition_time_value('duration', 'Duration')} ${impl_transition_timing_function()} @@ -2926,8 +2924,7 @@ fn static_assert() { ${impl_simple_copy('_x_span', 'mSpan')} -<%self:impl_trait style_struct_name="Effects" - skip_longhands="clip filter"> +<%self:impl_trait style_struct_name="Effects" skip_longhands="clip"> pub fn set_clip(&mut self, v: longhands::clip::computed_value::T) { use crate::gecko_bindings::structs::NS_STYLE_CLIP_AUTO; use crate::gecko_bindings::structs::NS_STYLE_CLIP_RECT; @@ -3035,136 +3032,6 @@ fn static_assert() { Either::First(ClipRect { top, right, bottom, left }) } - - <% - # This array is several filter function which has percentage or - # number value for function of clone / set. - # The setting / cloning process of other function(e.g. Blur / HueRotate) is - # different from these function. So this array don't include such function. - FILTER_FUNCTIONS = [ 'Brightness', 'Contrast', 'Grayscale', 'Invert', - 'Opacity', 'Saturate', 'Sepia' ] - %> - - pub fn set_filter(&mut self, v: I) - where - I: IntoIterator, - I::IntoIter: ExactSizeIterator, - { - use crate::values::generics::effects::Filter::*; - use crate::gecko_bindings::structs::nsStyleFilter; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_BLUR; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_BRIGHTNESS; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_CONTRAST; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_GRAYSCALE; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_INVERT; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_OPACITY; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_SATURATE; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_SEPIA; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_HUE_ROTATE; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_DROP_SHADOW; - - fn fill_filter(m_type: u32, value: CoordDataValue, gecko_filter: &mut nsStyleFilter){ - gecko_filter.mType = m_type; - gecko_filter.mFilterParameter.set_value(value); - } - - let v = v.into_iter(); - unsafe { - Gecko_ResetFilters(&mut *self.gecko, v.len()); - } - debug_assert_eq!(v.len(), self.gecko.mFilters.len()); - - for (servo, gecko_filter) in v.zip(self.gecko.mFilters.iter_mut()) { - match servo { - % for func in FILTER_FUNCTIONS: - ${func}(factor) => fill_filter(NS_STYLE_FILTER_${func.upper()}, - CoordDataValue::Factor(factor.0), - gecko_filter), - % endfor - Blur(length) => fill_filter(NS_STYLE_FILTER_BLUR, - CoordDataValue::Coord(length.0.to_i32_au()), - gecko_filter), - - HueRotate(angle) => fill_filter(NS_STYLE_FILTER_HUE_ROTATE, - CoordDataValue::from(angle), - gecko_filter), - - DropShadow(shadow) => { - gecko_filter.mType = NS_STYLE_FILTER_DROP_SHADOW; - unsafe { - let ref mut union = gecko_filter.__bindgen_anon_1; - ptr::write(union.mDropShadow.as_mut(), shadow); - } - }, - Url(ref url) => { - unsafe { - bindings::Gecko_nsStyleFilter_SetURLValue(gecko_filter, url); - } - }, - } - } - } - - pub fn copy_filter_from(&mut self, other: &Self) { - unsafe { - Gecko_CopyFiltersFrom(&other.gecko as *const _ as *mut _, &mut *self.gecko); - } - } - - pub fn reset_filter(&mut self, other: &Self) { - self.copy_filter_from(other) - } - - pub fn clone_filter(&self) -> longhands::filter::computed_value::T { - use crate::values::generics::effects::Filter; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_BLUR; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_BRIGHTNESS; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_CONTRAST; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_GRAYSCALE; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_INVERT; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_OPACITY; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_SATURATE; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_SEPIA; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_HUE_ROTATE; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_DROP_SHADOW; - use crate::gecko_bindings::structs::NS_STYLE_FILTER_URL; - - longhands::filter::computed_value::List(self.gecko.mFilters.iter().map(|filter| { - match filter.mType { - % for func in FILTER_FUNCTIONS: - NS_STYLE_FILTER_${func.upper()} => { - Filter::${func}( - GeckoStyleCoordConvertible::from_gecko_style_coord( - &filter.mFilterParameter - ).unwrap() - ) - }, - % endfor - NS_STYLE_FILTER_BLUR => { - Filter::Blur(NonNegativeLength::from_gecko_style_coord( - &filter.mFilterParameter - ).unwrap()) - }, - NS_STYLE_FILTER_HUE_ROTATE => { - Filter::HueRotate(GeckoStyleCoordConvertible::from_gecko_style_coord( - &filter.mFilterParameter, - ).unwrap()) - }, - NS_STYLE_FILTER_DROP_SHADOW => { - Filter::DropShadow(unsafe { - (*filter.__bindgen_anon_1.mDropShadow.as_ref()).clone() - }) - }, - NS_STYLE_FILTER_URL => { - Filter::Url(unsafe { - filter.__bindgen_anon_1.mURL.as_ref().clone() - }) - } - _ => unreachable!("Unknown filter function?"), - } - }).collect()) - } - <%self:impl_trait style_struct_name="InheritedBox"> diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index d3b3ecd11e4..48f499c7ec3 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -22,7 +22,7 @@ use std::mem::{self, ManuallyDrop}; use crate::hash::FxHashMap; use super::ComputedValues; use crate::values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; -use crate::values::animated::effects::Filter as AnimatedFilter; +use crate::values::animated::effects::AnimatedFilter; #[cfg(feature = "gecko")] use crate::values::computed::TransitionProperty; use crate::values::computed::{ClipRect, Context}; use crate::values::computed::ToComputedValue; diff --git a/components/style/properties/longhands/effects.mako.rs b/components/style/properties/longhands/effects.mako.rs index 9bb8adda32e..c50a0d18ca6 100644 --- a/components/style/properties/longhands/effects.mako.rs +++ b/components/style/properties/longhands/effects.mako.rs @@ -47,6 +47,8 @@ ${helpers.predefined_type( "Filter", None, vector=True, + simple_vector_bindings=True, + gecko_ffi_name="mFilters", separator="Space", animation_value_type="AnimatedFilterList", vector_animation_type="with_zero", diff --git a/components/style/values/animated/effects.rs b/components/style/values/animated/effects.rs index 4c559cd4c30..49e751fec55 100644 --- a/components/style/values/animated/effects.rs +++ b/components/style/values/animated/effects.rs @@ -19,8 +19,8 @@ pub type AnimatedSimpleShadow = GenericSimpleShadow; /// An animated value for a single `filter`. #[cfg(feature = "gecko")] -pub type Filter = GenericFilter; +pub type AnimatedFilter = GenericFilter; /// An animated value for a single `filter`. #[cfg(not(feature = "gecko"))] -pub type Filter = GenericFilter; +pub type AnimatedFilter = GenericFilter; diff --git a/components/style/values/computed/effects.rs b/components/style/values/computed/effects.rs index d103f407a75..24ec689e49c 100644 --- a/components/style/values/computed/effects.rs +++ b/components/style/values/computed/effects.rs @@ -24,7 +24,7 @@ pub type Filter = GenericFilter; /// A computed value for a single `filter`. -#[cfg(not(feature = "gecko"))] +#[cfg(feature = "servo")] pub type Filter = GenericFilter; diff --git a/components/style/values/generics/effects.rs b/components/style/values/generics/effects.rs index a27adc49e52..beca716e997 100644 --- a/components/style/values/generics/effects.rs +++ b/components/style/values/generics/effects.rs @@ -34,8 +34,10 @@ pub struct GenericBoxShadow { pub use self::GenericBoxShadow as BoxShadow; /// A generic value for a single `filter`. +/// +/// cbindgen:derive-tagged-enum-copy-constructor=true #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] -#[animation(no_bound(Url))] +#[animation(no_bound(U))] #[derive( Clone, ComputeSquaredDistance, @@ -49,7 +51,8 @@ pub use self::GenericBoxShadow as BoxShadow; ToResolvedValue, ToShmem, )] -pub enum Filter { +#[repr(C, u8)] +pub enum GenericFilter { /// `blur()` #[css(function)] Blur(Length), @@ -79,12 +82,14 @@ pub enum Filter { Sepia(Factor), /// `drop-shadow(...)` #[css(function)] - DropShadow(DropShadow), + DropShadow(Shadow), /// `` #[animation(error)] - Url(Url), + Url(U), } +pub use self::GenericFilter as Filter; + /// A generic value for the `drop-shadow()` filter and the `text-shadow` property. /// /// Contrary to the canonical order from the spec, the color is serialised diff --git a/components/style/values/specified/effects.rs b/components/style/values/specified/effects.rs index 3ffad2fa89c..24af52d1556 100644 --- a/components/style/values/specified/effects.rs +++ b/components/style/values/specified/effects.rs @@ -18,7 +18,7 @@ use crate::values::specified::length::{Length, NonNegativeLength}; #[cfg(feature = "gecko")] use crate::values::specified::url::SpecifiedUrl; use crate::values::specified::{Angle, Number, NumberOrPercentage}; -#[cfg(not(feature = "gecko"))] +#[cfg(feature = "servo")] use crate::values::Impossible; use crate::Zero; use cssparser::{self, BasicParseErrorKind, Parser, Token}; @@ -30,11 +30,13 @@ pub type BoxShadow = /// A specified value for a single `filter`. #[cfg(feature = "gecko")] -pub type Filter = GenericFilter; +pub type SpecifiedFilter = GenericFilter; /// A specified value for a single `filter`. -#[cfg(not(feature = "gecko"))] -pub type Filter = GenericFilter; +#[cfg(feature = "servo")] +pub type SpecifiedFilter = GenericFilter; + +pub use self::SpecifiedFilter as Filter; /// A value for the `` parts in `Filter`. #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]