From ae1c890c9eb69ac994c0a409e30b0efad537d9c4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 23 Jun 2017 15:00:34 +0200 Subject: [PATCH 1/2] Rename DropShadow to SimpleShadow --- .../sugar/ns_css_shadow_item.rs | 12 ++++---- components/style/properties/gecko.mako.rs | 6 ++-- components/style/values/animated/effects.rs | 28 +++++++++---------- components/style/values/computed/effects.rs | 6 ++-- components/style/values/specified/effects.rs | 22 +++++++-------- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/components/style/gecko_bindings/sugar/ns_css_shadow_item.rs b/components/style/gecko_bindings/sugar/ns_css_shadow_item.rs index 45072ba2eb2..c186945a47c 100644 --- a/components/style/gecko_bindings/sugar/ns_css_shadow_item.rs +++ b/components/style/gecko_bindings/sugar/ns_css_shadow_item.rs @@ -8,7 +8,7 @@ use app_units::Au; use gecko::values::{convert_rgba_to_nscolor, convert_nscolor_to_rgba}; use gecko_bindings::structs::nsCSSShadowItem; use values::computed::{Color, Shadow}; -use values::computed::effects::DropShadow; +use values::computed::effects::SimpleShadow; impl nsCSSShadowItem { /// Set this item to the given shadow value. @@ -41,9 +41,9 @@ impl nsCSSShadowItem { } } - /// Sets this item from the given drop shadow. + /// Sets this item from the given simple shadow. #[inline] - pub fn set_from_drop_shadow(&mut self, shadow: DropShadow) { + pub fn set_from_simple_shadow(&mut self, shadow: SimpleShadow) { self.mXOffset = shadow.horizontal.0; self.mYOffset = shadow.vertical.0; self.mRadius = shadow.blur.0; @@ -60,12 +60,12 @@ impl nsCSSShadowItem { } } - /// Returns this item as a drop shadow. + /// Returns this item as a simple shadow. #[inline] - pub fn to_drop_shadow(&self) -> DropShadow { + pub fn to_simple_shadow(&self) -> SimpleShadow { debug_assert_eq!(self.mSpread, 0); debug_assert_eq!(self.mInset, false); - DropShadow { + SimpleShadow { color: Color::rgba(convert_nscolor_to_rgba(self.mColor)), horizontal: Au(self.mXOffset), vertical: Au(self.mYOffset), diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 4ff4ca4d06a..83c41e407dd 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -3508,7 +3508,7 @@ fn static_assert() { } let mut gecko_shadow = init_shadow(gecko_filter); - gecko_shadow.mArray[0].set_from_drop_shadow(shadow); + gecko_shadow.mArray[0].set_from_simple_shadow(shadow); }, Url(ref url) => { unsafe { @@ -3561,7 +3561,9 @@ fn static_assert() { }, NS_STYLE_FILTER_DROP_SHADOW => { filters.push(unsafe { - Filter::DropShadow((**filter.__bindgen_anon_1.mDropShadow.as_ref()).mArray[0].to_drop_shadow()) + Filter::DropShadow( + (**filter.__bindgen_anon_1.mDropShadow.as_ref()).mArray[0].to_simple_shadow(), + ) }); }, NS_STYLE_FILTER_URL => { diff --git a/components/style/values/animated/effects.rs b/components/style/values/animated/effects.rs index f6de998ec3e..3874f3fe358 100644 --- a/components/style/values/animated/effects.rs +++ b/components/style/values/animated/effects.rs @@ -8,9 +8,9 @@ use properties::animated_properties::Animatable; #[cfg(feature = "gecko")] use properties::animated_properties::IntermediateColor; use values::computed::{Angle, Number}; -use values::computed::effects::DropShadow as ComputedDropShadow; use values::computed::effects::Filter as ComputedFilter; use values::computed::effects::FilterList as ComputedFilterList; +use values::computed::effects::SimpleShadow as ComputedSimpleShadow; use values::computed::length::Length; use values::generics::effects::Filter as GenericFilter; use values::generics::effects::FilterList as GenericFilterList; @@ -24,7 +24,7 @@ pub type Filter = GenericFilter< // FIXME: Should be `NumberOrPercentage`. Number, Length, - DropShadow + SimpleShadow, >; /// An animated value for the `drop-shadow()` filter. @@ -33,7 +33,7 @@ pub type Filter = GenericFilter< #[cfg(not(feature = "gecko"))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Debug, PartialEq)] -pub enum DropShadow {} +pub enum SimpleShadow {} /// An animated value for the `drop-shadow()` filter. /// @@ -41,7 +41,7 @@ pub enum DropShadow {} /// first, like in Gecko and Webkit. #[cfg(feature = "gecko")] #[derive(Clone, Debug, PartialEq)] -pub struct DropShadow { +pub struct SimpleShadow { /// Color. pub color: IntermediateColor, /// Horizontal radius. @@ -110,17 +110,17 @@ impl From for ComputedFilter { } } -impl From for DropShadow { +impl From for SimpleShadow { #[cfg(not(feature = "gecko"))] #[inline] - fn from(shadow: ComputedDropShadow) -> Self { + fn from(shadow: ComputedSimpleShadow) -> Self { match shadow {} } #[cfg(feature = "gecko")] #[inline] - fn from(shadow: ComputedDropShadow) -> Self { - DropShadow { + fn from(shadow: ComputedSimpleShadow) -> Self { + SimpleShadow { color: shadow.color.into(), horizontal: shadow.horizontal, vertical: shadow.vertical, @@ -129,17 +129,17 @@ impl From for DropShadow { } } -impl From for ComputedDropShadow { +impl From for ComputedSimpleShadow { #[cfg(not(feature = "gecko"))] #[inline] - fn from(shadow: DropShadow) -> Self { + fn from(shadow: SimpleShadow) -> Self { match shadow {} } #[cfg(feature = "gecko")] #[inline] - fn from(shadow: DropShadow) -> Self { - ComputedDropShadow { + fn from(shadow: SimpleShadow) -> Self { + ComputedSimpleShadow { color: shadow.color.into(), horizontal: shadow.horizontal, vertical: shadow.vertical, @@ -148,7 +148,7 @@ impl From for ComputedDropShadow { } } -impl Animatable for DropShadow { +impl Animatable for SimpleShadow { #[cfg(not(feature = "gecko"))] #[inline] fn add_weighted(&self, _other: &Self, _self_portion: f64, _other_portion: f64) -> Result { @@ -163,7 +163,7 @@ impl Animatable for DropShadow { let vertical = self.vertical.add_weighted(&other.vertical, self_portion, other_portion)?; let blur = self.blur.add_weighted(&other.blur, self_portion, other_portion)?; - Ok(DropShadow { + Ok(SimpleShadow { color: color, horizontal: horizontal, vertical: vertical, diff --git a/components/style/values/computed/effects.rs b/components/style/values/computed/effects.rs index 4fae8656bb1..e5e0fbb8de5 100644 --- a/components/style/values/computed/effects.rs +++ b/components/style/values/computed/effects.rs @@ -20,7 +20,7 @@ pub type Filter = GenericFilter< // FIXME: Should be `NumberOrPercentage`. Number, Length, - DropShadow, + SimpleShadow, >; /// A computed value for the `drop-shadow()` filter. @@ -29,7 +29,7 @@ pub type Filter = GenericFilter< #[cfg(not(feature = "gecko"))] #[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] #[derive(Clone, Debug, PartialEq, ToCss)] -pub enum DropShadow {} +pub enum SimpleShadow {} /// A computed value for the `drop-shadow()` filter. /// @@ -37,7 +37,7 @@ pub enum DropShadow {} /// first, like in Gecko and Webkit. #[cfg(feature = "gecko")] #[derive(Clone, Debug, PartialEq, ToCss)] -pub struct DropShadow { +pub struct SimpleShadow { /// Color. pub color: Color, /// Horizontal radius. diff --git a/components/style/values/specified/effects.rs b/components/style/values/specified/effects.rs index 7987ddc8169..c4d2adeebc5 100644 --- a/components/style/values/specified/effects.rs +++ b/components/style/values/specified/effects.rs @@ -10,7 +10,7 @@ use style_traits::ParseError; #[cfg(not(feature = "gecko"))] use style_traits::StyleParseError; use values::computed::{Context, Number as ComputedNumber, ToComputedValue}; -use values::computed::effects::DropShadow as ComputedDropShadow; +use values::computed::effects::SimpleShadow as ComputedSimpleShadow; use values::generics::effects::Filter as GenericFilter; use values::generics::effects::FilterList as GenericFilterList; use values::specified::{Angle, Percentage}; @@ -24,7 +24,7 @@ use values::specified::url::SpecifiedUrl; pub type FilterList = GenericFilterList; /// A specified value for a single `filter`. -pub type Filter = GenericFilter; +pub type Filter = GenericFilter; /// A value for the `` parts in `Filter`. /// @@ -44,7 +44,7 @@ pub enum Factor { #[cfg(not(feature = "gecko"))] #[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] #[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)] -pub enum DropShadow {} +pub enum SimpleShadow {} /// A specified value for the `drop-shadow()` filter. /// @@ -52,7 +52,7 @@ pub enum DropShadow {} /// first, like in Gecko's computed values and in all Webkit's values. #[cfg(feature = "gecko")] #[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)] -pub struct DropShadow { +pub struct SimpleShadow { /// Color. pub color: Option, /// Horizontal radius. @@ -104,7 +104,7 @@ impl Parse for Filter { "opacity" => Ok(GenericFilter::Opacity(Factor::parse(context, i)?)), "saturate" => Ok(GenericFilter::Saturate(Factor::parse(context, i)?)), "sepia" => Ok(GenericFilter::Sepia(Factor::parse(context, i)?)), - "drop-shadow" => Ok(GenericFilter::DropShadow(DropShadow::parse(context, i)?)), + "drop-shadow" => Ok(GenericFilter::DropShadow(SimpleShadow::parse(context, i)?)), } }) } @@ -147,7 +147,7 @@ impl ToComputedValue for Factor { } } -impl Parse for DropShadow { +impl Parse for SimpleShadow { #[cfg(not(feature = "gecko"))] #[inline] fn parse<'i, 't>( @@ -168,7 +168,7 @@ impl Parse for DropShadow { let vertical = Length::parse(context, input)?; let blur = input.try(|i| Length::parse_non_negative(context, i)).ok(); let color = color.or_else(|| input.try(|i| Color::parse(context, i)).ok()); - Ok(DropShadow { + Ok(SimpleShadow { color: color, horizontal: horizontal, vertical: vertical, @@ -177,8 +177,8 @@ impl Parse for DropShadow { } } -impl ToComputedValue for DropShadow { - type ComputedValue = ComputedDropShadow; +impl ToComputedValue for SimpleShadow { + type ComputedValue = ComputedSimpleShadow; #[cfg(not(feature = "gecko"))] #[inline] @@ -189,7 +189,7 @@ impl ToComputedValue for DropShadow { #[cfg(feature = "gecko")] #[inline] fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { - ComputedDropShadow { + ComputedSimpleShadow { color: self.color.as_ref().unwrap_or(&Color::CurrentColor).to_computed_value(context), horizontal: self.horizontal.to_computed_value(context), @@ -208,7 +208,7 @@ impl ToComputedValue for DropShadow { #[cfg(feature = "gecko")] #[inline] fn from_computed_value(computed: &Self::ComputedValue) -> Self { - DropShadow { + SimpleShadow { color: Some(ToComputedValue::from_computed_value(&computed.color)), horizontal: ToComputedValue::from_computed_value(&computed.horizontal), vertical: ToComputedValue::from_computed_value(&computed.vertical), From c9b123266deb987dcb116a0eeb063b253f6b7040 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 23 Jun 2017 15:49:08 +0200 Subject: [PATCH 2/2] Unconditionally compile SimpleShadow even in Servo --- components/style/values/animated/effects.rs | 66 +++++--------------- components/style/values/computed/effects.rs | 22 +++---- components/style/values/mod.rs | 14 +++++ components/style/values/specified/effects.rs | 46 +++----------- 4 files changed, 44 insertions(+), 104 deletions(-) diff --git a/components/style/values/animated/effects.rs b/components/style/values/animated/effects.rs index 3874f3fe358..d53afdfc90b 100644 --- a/components/style/values/animated/effects.rs +++ b/components/style/values/animated/effects.rs @@ -4,11 +4,13 @@ //! Animated types for CSS values related to effects. -use properties::animated_properties::Animatable; -#[cfg(feature = "gecko")] -use properties::animated_properties::IntermediateColor; +use properties::animated_properties::{Animatable, IntermediateColor}; +#[cfg(not(feature = "gecko"))] +use values::Impossible; use values::computed::{Angle, Number}; +#[cfg(feature = "gecko")] use values::computed::effects::Filter as ComputedFilter; +#[cfg(feature = "gecko")] use values::computed::effects::FilterList as ComputedFilterList; use values::computed::effects::SimpleShadow as ComputedSimpleShadow; use values::computed::length::Length; @@ -19,27 +21,18 @@ use values::generics::effects::FilterList as GenericFilterList; pub type FilterList = GenericFilterList; /// An animated value for a single `filter`. -pub type Filter = GenericFilter< - Angle, - // FIXME: Should be `NumberOrPercentage`. - Number, - Length, - SimpleShadow, ->; +#[cfg(feature = "gecko")] +pub type Filter = GenericFilter; -/// An animated value for the `drop-shadow()` filter. -/// -/// Currently unsupported outside of Gecko. +/// An animated value for a single `filter`. #[cfg(not(feature = "gecko"))] -#[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[derive(Clone, Debug, PartialEq)] -pub enum SimpleShadow {} +pub type Filter = GenericFilter; /// An animated value for the `drop-shadow()` filter. /// /// Contrary to the canonical order from the spec, the color is serialised /// first, like in Gecko and Webkit. -#[cfg(feature = "gecko")] +#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Debug, PartialEq)] pub struct SimpleShadow { /// Color. @@ -52,6 +45,7 @@ pub struct SimpleShadow { pub blur: Length, } +#[cfg(feature = "gecko")] impl From for FilterList { #[inline] fn from(filters: ComputedFilterList) -> Self { @@ -59,6 +53,7 @@ impl From for FilterList { } } +#[cfg(feature = "gecko")] impl From for ComputedFilterList { #[inline] fn from(filters: FilterList) -> Self { @@ -66,6 +61,7 @@ impl From for ComputedFilterList { } } +#[cfg(feature = "gecko")] impl From for Filter { #[inline] fn from(filter: ComputedFilter) -> Self { @@ -88,6 +84,7 @@ impl From for Filter { } } +#[cfg(feature = "gecko")] impl From for ComputedFilter { #[inline] fn from(filter: Filter) -> Self { @@ -111,13 +108,6 @@ impl From for ComputedFilter { } impl From for SimpleShadow { - #[cfg(not(feature = "gecko"))] - #[inline] - fn from(shadow: ComputedSimpleShadow) -> Self { - match shadow {} - } - - #[cfg(feature = "gecko")] #[inline] fn from(shadow: ComputedSimpleShadow) -> Self { SimpleShadow { @@ -130,13 +120,6 @@ impl From for SimpleShadow { } impl From for ComputedSimpleShadow { - #[cfg(not(feature = "gecko"))] - #[inline] - fn from(shadow: SimpleShadow) -> Self { - match shadow {} - } - - #[cfg(feature = "gecko")] #[inline] fn from(shadow: SimpleShadow) -> Self { ComputedSimpleShadow { @@ -149,13 +132,6 @@ impl From for ComputedSimpleShadow { } impl Animatable for SimpleShadow { - #[cfg(not(feature = "gecko"))] - #[inline] - fn add_weighted(&self, _other: &Self, _self_portion: f64, _other_portion: f64) -> Result { - match *self {} - } - - #[cfg(feature = "gecko")] #[inline] fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result { let color = self.color.add_weighted(&other.color, self_portion, other_portion)?; @@ -171,25 +147,11 @@ impl Animatable for SimpleShadow { }) } - #[cfg(not(feature = "gecko"))] - #[inline] - fn compute_distance(&self, _other: &Self) -> Result { - match *self {} - } - - #[cfg(feature = "gecko")] #[inline] fn compute_distance(&self, other: &Self) -> Result { self.compute_squared_distance(other).map(|sd| sd.sqrt()) } - #[cfg(not(feature = "gecko"))] - #[inline] - fn compute_squared_distance(&self, _other: &Self) -> Result { - match *self {} - } - - #[cfg(feature = "gecko")] #[inline] fn compute_squared_distance(&self, other: &Self) -> Result { Ok( diff --git a/components/style/values/computed/effects.rs b/components/style/values/computed/effects.rs index e5e0fbb8de5..8db3c3880a3 100644 --- a/components/style/values/computed/effects.rs +++ b/components/style/values/computed/effects.rs @@ -4,8 +4,9 @@ //! Computed types for CSS values related to effects. +#[cfg(not(feature = "gecko"))] +use values::Impossible; use values::computed::{Angle, Number}; -#[cfg(feature = "gecko")] use values::computed::color::Color; use values::computed::length::Length; use values::generics::effects::Filter as GenericFilter; @@ -15,27 +16,18 @@ use values::generics::effects::FilterList as GenericFilterList; pub type FilterList = GenericFilterList; /// A computed value for a single `filter`. -pub type Filter = GenericFilter< - Angle, - // FIXME: Should be `NumberOrPercentage`. - Number, - Length, - SimpleShadow, ->; +#[cfg(feature = "gecko")] +pub type Filter = GenericFilter; -/// A computed value for the `drop-shadow()` filter. -/// -/// Currently unsupported outside of Gecko. +/// A computed value for a single `filter`. #[cfg(not(feature = "gecko"))] -#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] -#[derive(Clone, Debug, PartialEq, ToCss)] -pub enum SimpleShadow {} +pub type Filter = GenericFilter; /// A computed value for the `drop-shadow()` filter. /// /// Contrary to the canonical order from the spec, the color is serialised /// first, like in Gecko and Webkit. -#[cfg(feature = "gecko")] +#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Debug, PartialEq, ToCss)] pub struct SimpleShadow { /// Color. diff --git a/components/style/values/mod.rs b/components/style/values/mod.rs index 65d6baa6362..631295dc435 100644 --- a/components/style/values/mod.rs +++ b/components/style/values/mod.rs @@ -36,6 +36,20 @@ define_keyword_type!(None_, "none"); define_keyword_type!(Auto, "auto"); define_keyword_type!(Normal, "normal"); +/// Convenience void type to disable some properties and values through types. +#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] +#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)] +pub enum Impossible {} + +impl Parse for Impossible { + fn parse<'i, 't>( + _context: &ParserContext, + _input: &mut Parser<'i, 't>) + -> Result> { + Err(StyleParseError::UnspecifiedError.into()) + } +} + /// A struct representing one of two kinds of values. #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToCss)] diff --git a/components/style/values/specified/effects.rs b/components/style/values/specified/effects.rs index c4d2adeebc5..7dd8763da9a 100644 --- a/components/style/values/specified/effects.rs +++ b/components/style/values/specified/effects.rs @@ -8,13 +8,12 @@ use cssparser::{BasicParseError, Parser, Token}; use parser::{Parse, ParserContext}; use style_traits::ParseError; #[cfg(not(feature = "gecko"))] -use style_traits::StyleParseError; +use values::Impossible; use values::computed::{Context, Number as ComputedNumber, ToComputedValue}; use values::computed::effects::SimpleShadow as ComputedSimpleShadow; use values::generics::effects::Filter as GenericFilter; use values::generics::effects::FilterList as GenericFilterList; use values::specified::{Angle, Percentage}; -#[cfg(feature = "gecko")] use values::specified::color::Color; use values::specified::length::Length; #[cfg(feature = "gecko")] @@ -24,12 +23,17 @@ use values::specified::url::SpecifiedUrl; pub type FilterList = GenericFilterList; /// A specified value for a single `filter`. +#[cfg(feature = "gecko")] pub type Filter = GenericFilter; +/// A specified value for a single `filter`. +#[cfg(not(feature = "gecko"))] +pub type Filter = GenericFilter; + /// A value for the `` parts in `Filter`. /// /// FIXME: Should be `NumberOrPercentage`, but Gecko doesn't support that yet. -#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] +#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)] pub enum Factor { /// Literal number. @@ -38,19 +42,11 @@ pub enum Factor { Percentage(Percentage), } -/// A specified value for the `drop-shadow()` filter. -/// -/// Currently unsupported outside of Gecko. -#[cfg(not(feature = "gecko"))] -#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] -#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)] -pub enum SimpleShadow {} - /// A specified value for the `drop-shadow()` filter. /// /// Contrary to the canonical order from the spec, the color is serialised /// first, like in Gecko's computed values and in all Webkit's values. -#[cfg(feature = "gecko")] +#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)] pub struct SimpleShadow { /// Color. @@ -104,7 +100,7 @@ impl Parse for Filter { "opacity" => Ok(GenericFilter::Opacity(Factor::parse(context, i)?)), "saturate" => Ok(GenericFilter::Saturate(Factor::parse(context, i)?)), "sepia" => Ok(GenericFilter::Sepia(Factor::parse(context, i)?)), - "drop-shadow" => Ok(GenericFilter::DropShadow(SimpleShadow::parse(context, i)?)), + "drop-shadow" => Ok(GenericFilter::DropShadow(Parse::parse(context, i)?)), } }) } @@ -148,16 +144,6 @@ impl ToComputedValue for Factor { } impl Parse for SimpleShadow { - #[cfg(not(feature = "gecko"))] - #[inline] - fn parse<'i, 't>( - _context: &ParserContext, - _input: &mut Parser<'i, 't> - ) -> Result> { - Err(StyleParseError::UnspecifiedError.into()) - } - - #[cfg(feature = "gecko")] #[inline] fn parse<'i, 't>( context: &ParserContext, @@ -180,13 +166,6 @@ impl Parse for SimpleShadow { impl ToComputedValue for SimpleShadow { type ComputedValue = ComputedSimpleShadow; - #[cfg(not(feature = "gecko"))] - #[inline] - fn to_computed_value(&self, _context: &Context) -> Self::ComputedValue { - match *self {} - } - - #[cfg(feature = "gecko")] #[inline] fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { ComputedSimpleShadow { @@ -199,13 +178,6 @@ impl ToComputedValue for SimpleShadow { } } - #[cfg(not(feature = "gecko"))] - #[inline] - fn from_computed_value(computed: &Self::ComputedValue) -> Self { - match *computed {} - } - - #[cfg(feature = "gecko")] #[inline] fn from_computed_value(computed: &Self::ComputedValue) -> Self { SimpleShadow {