Auto merge of #17494 - servo:derive-all-the-things, r=emilio

Marginally improve shadows

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17494)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-06-23 17:45:58 -07:00 committed by GitHub
commit c586a241bb
6 changed files with 74 additions and 132 deletions

View file

@ -8,7 +8,7 @@ use app_units::Au;
use gecko::values::{convert_rgba_to_nscolor, convert_nscolor_to_rgba}; use gecko::values::{convert_rgba_to_nscolor, convert_nscolor_to_rgba};
use gecko_bindings::structs::nsCSSShadowItem; use gecko_bindings::structs::nsCSSShadowItem;
use values::computed::{Color, Shadow}; use values::computed::{Color, Shadow};
use values::computed::effects::DropShadow; use values::computed::effects::SimpleShadow;
impl nsCSSShadowItem { impl nsCSSShadowItem {
/// Set this item to the given shadow value. /// 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] #[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.mXOffset = shadow.horizontal.0;
self.mYOffset = shadow.vertical.0; self.mYOffset = shadow.vertical.0;
self.mRadius = shadow.blur.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] #[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.mSpread, 0);
debug_assert_eq!(self.mInset, false); debug_assert_eq!(self.mInset, false);
DropShadow { SimpleShadow {
color: Color::rgba(convert_nscolor_to_rgba(self.mColor)), color: Color::rgba(convert_nscolor_to_rgba(self.mColor)),
horizontal: Au(self.mXOffset), horizontal: Au(self.mXOffset),
vertical: Au(self.mYOffset), vertical: Au(self.mYOffset),

View file

@ -3508,7 +3508,7 @@ fn static_assert() {
} }
let mut gecko_shadow = init_shadow(gecko_filter); 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) => { Url(ref url) => {
unsafe { unsafe {
@ -3561,7 +3561,9 @@ fn static_assert() {
}, },
NS_STYLE_FILTER_DROP_SHADOW => { NS_STYLE_FILTER_DROP_SHADOW => {
filters.push(unsafe { 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 => { NS_STYLE_FILTER_URL => {

View file

@ -4,13 +4,15 @@
//! Animated types for CSS values related to effects. //! Animated types for CSS values related to effects.
use properties::animated_properties::Animatable; use properties::animated_properties::{Animatable, IntermediateColor};
#[cfg(feature = "gecko")] #[cfg(not(feature = "gecko"))]
use properties::animated_properties::IntermediateColor; use values::Impossible;
use values::computed::{Angle, Number}; use values::computed::{Angle, Number};
use values::computed::effects::DropShadow as ComputedDropShadow; #[cfg(feature = "gecko")]
use values::computed::effects::Filter as ComputedFilter; use values::computed::effects::Filter as ComputedFilter;
#[cfg(feature = "gecko")]
use values::computed::effects::FilterList as ComputedFilterList; use values::computed::effects::FilterList as ComputedFilterList;
use values::computed::effects::SimpleShadow as ComputedSimpleShadow;
use values::computed::length::Length; use values::computed::length::Length;
use values::generics::effects::Filter as GenericFilter; use values::generics::effects::Filter as GenericFilter;
use values::generics::effects::FilterList as GenericFilterList; use values::generics::effects::FilterList as GenericFilterList;
@ -19,29 +21,20 @@ use values::generics::effects::FilterList as GenericFilterList;
pub type FilterList = GenericFilterList<Filter>; pub type FilterList = GenericFilterList<Filter>;
/// An animated value for a single `filter`. /// An animated value for a single `filter`.
pub type Filter = GenericFilter< #[cfg(feature = "gecko")]
Angle, pub type Filter = GenericFilter<Angle, Number, Length, SimpleShadow>;
// FIXME: Should be `NumberOrPercentage`.
Number,
Length,
DropShadow
>;
/// An animated value for the `drop-shadow()` filter. /// An animated value for a single `filter`.
///
/// Currently unsupported outside of Gecko.
#[cfg(not(feature = "gecko"))] #[cfg(not(feature = "gecko"))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub type Filter = GenericFilter<Angle, Number, Length, Impossible>;
#[derive(Clone, Debug, PartialEq)]
pub enum DropShadow {}
/// An animated value for the `drop-shadow()` filter. /// An animated value for the `drop-shadow()` filter.
/// ///
/// Contrary to the canonical order from the spec, the color is serialised /// Contrary to the canonical order from the spec, the color is serialised
/// first, like in Gecko and Webkit. /// first, like in Gecko and Webkit.
#[cfg(feature = "gecko")] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct DropShadow { pub struct SimpleShadow {
/// Color. /// Color.
pub color: IntermediateColor, pub color: IntermediateColor,
/// Horizontal radius. /// Horizontal radius.
@ -52,6 +45,7 @@ pub struct DropShadow {
pub blur: Length, pub blur: Length,
} }
#[cfg(feature = "gecko")]
impl From<ComputedFilterList> for FilterList { impl From<ComputedFilterList> for FilterList {
#[inline] #[inline]
fn from(filters: ComputedFilterList) -> Self { fn from(filters: ComputedFilterList) -> Self {
@ -59,6 +53,7 @@ impl From<ComputedFilterList> for FilterList {
} }
} }
#[cfg(feature = "gecko")]
impl From<FilterList> for ComputedFilterList { impl From<FilterList> for ComputedFilterList {
#[inline] #[inline]
fn from(filters: FilterList) -> Self { fn from(filters: FilterList) -> Self {
@ -66,6 +61,7 @@ impl From<FilterList> for ComputedFilterList {
} }
} }
#[cfg(feature = "gecko")]
impl From<ComputedFilter> for Filter { impl From<ComputedFilter> for Filter {
#[inline] #[inline]
fn from(filter: ComputedFilter) -> Self { fn from(filter: ComputedFilter) -> Self {
@ -88,6 +84,7 @@ impl From<ComputedFilter> for Filter {
} }
} }
#[cfg(feature = "gecko")]
impl From<Filter> for ComputedFilter { impl From<Filter> for ComputedFilter {
#[inline] #[inline]
fn from(filter: Filter) -> Self { fn from(filter: Filter) -> Self {
@ -110,17 +107,10 @@ impl From<Filter> for ComputedFilter {
} }
} }
impl From<ComputedDropShadow> for DropShadow { impl From<ComputedSimpleShadow> for SimpleShadow {
#[cfg(not(feature = "gecko"))]
#[inline] #[inline]
fn from(shadow: ComputedDropShadow) -> Self { fn from(shadow: ComputedSimpleShadow) -> Self {
match shadow {} SimpleShadow {
}
#[cfg(feature = "gecko")]
#[inline]
fn from(shadow: ComputedDropShadow) -> Self {
DropShadow {
color: shadow.color.into(), color: shadow.color.into(),
horizontal: shadow.horizontal, horizontal: shadow.horizontal,
vertical: shadow.vertical, vertical: shadow.vertical,
@ -129,17 +119,10 @@ impl From<ComputedDropShadow> for DropShadow {
} }
} }
impl From<DropShadow> for ComputedDropShadow { impl From<SimpleShadow> for ComputedSimpleShadow {
#[cfg(not(feature = "gecko"))]
#[inline] #[inline]
fn from(shadow: DropShadow) -> Self { fn from(shadow: SimpleShadow) -> Self {
match shadow {} ComputedSimpleShadow {
}
#[cfg(feature = "gecko")]
#[inline]
fn from(shadow: DropShadow) -> Self {
ComputedDropShadow {
color: shadow.color.into(), color: shadow.color.into(),
horizontal: shadow.horizontal, horizontal: shadow.horizontal,
vertical: shadow.vertical, vertical: shadow.vertical,
@ -148,14 +131,7 @@ impl From<DropShadow> 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<Self, ()> {
match *self {}
}
#[cfg(feature = "gecko")]
#[inline] #[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
let color = self.color.add_weighted(&other.color, self_portion, other_portion)?; let color = self.color.add_weighted(&other.color, self_portion, other_portion)?;
@ -163,7 +139,7 @@ impl Animatable for DropShadow {
let vertical = self.vertical.add_weighted(&other.vertical, self_portion, other_portion)?; let vertical = self.vertical.add_weighted(&other.vertical, self_portion, other_portion)?;
let blur = self.blur.add_weighted(&other.blur, self_portion, other_portion)?; let blur = self.blur.add_weighted(&other.blur, self_portion, other_portion)?;
Ok(DropShadow { Ok(SimpleShadow {
color: color, color: color,
horizontal: horizontal, horizontal: horizontal,
vertical: vertical, vertical: vertical,
@ -171,25 +147,11 @@ impl Animatable for DropShadow {
}) })
} }
#[cfg(not(feature = "gecko"))]
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
match *self {}
}
#[cfg(feature = "gecko")]
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.compute_squared_distance(other).map(|sd| sd.sqrt()) self.compute_squared_distance(other).map(|sd| sd.sqrt())
} }
#[cfg(not(feature = "gecko"))]
#[inline]
fn compute_squared_distance(&self, _other: &Self) -> Result<f64, ()> {
match *self {}
}
#[cfg(feature = "gecko")]
#[inline] #[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
Ok( Ok(

View file

@ -4,8 +4,9 @@
//! Computed types for CSS values related to effects. //! Computed types for CSS values related to effects.
#[cfg(not(feature = "gecko"))]
use values::Impossible;
use values::computed::{Angle, Number}; use values::computed::{Angle, Number};
#[cfg(feature = "gecko")]
use values::computed::color::Color; use values::computed::color::Color;
use values::computed::length::Length; use values::computed::length::Length;
use values::generics::effects::Filter as GenericFilter; use values::generics::effects::Filter as GenericFilter;
@ -15,29 +16,20 @@ use values::generics::effects::FilterList as GenericFilterList;
pub type FilterList = GenericFilterList<Filter>; pub type FilterList = GenericFilterList<Filter>;
/// A computed value for a single `filter`. /// A computed value for a single `filter`.
pub type Filter = GenericFilter< #[cfg(feature = "gecko")]
Angle, pub type Filter = GenericFilter<Angle, Number, Length, SimpleShadow>;
// FIXME: Should be `NumberOrPercentage`.
Number,
Length,
DropShadow,
>;
/// A computed value for the `drop-shadow()` filter. /// A computed value for a single `filter`.
///
/// Currently unsupported outside of Gecko.
#[cfg(not(feature = "gecko"))] #[cfg(not(feature = "gecko"))]
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] pub type Filter = GenericFilter<Angle, Number, Length, Impossible>;
#[derive(Clone, Debug, PartialEq, ToCss)]
pub enum DropShadow {}
/// A computed value for the `drop-shadow()` filter. /// A computed value for the `drop-shadow()` filter.
/// ///
/// Contrary to the canonical order from the spec, the color is serialised /// Contrary to the canonical order from the spec, the color is serialised
/// first, like in Gecko and Webkit. /// first, like in Gecko and Webkit.
#[cfg(feature = "gecko")] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)] #[derive(Clone, Debug, PartialEq, ToCss)]
pub struct DropShadow { pub struct SimpleShadow {
/// Color. /// Color.
pub color: Color, pub color: Color,
/// Horizontal radius. /// Horizontal radius.

View file

@ -36,6 +36,20 @@ define_keyword_type!(None_, "none");
define_keyword_type!(Auto, "auto"); define_keyword_type!(Auto, "auto");
define_keyword_type!(Normal, "normal"); 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<Self, ParseError<'i>> {
Err(StyleParseError::UnspecifiedError.into())
}
}
/// A struct representing one of two kinds of values. /// A struct representing one of two kinds of values.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToCss)] #[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToCss)]

View file

@ -8,13 +8,12 @@ use cssparser::{BasicParseError, Parser, Token};
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext};
use style_traits::ParseError; use style_traits::ParseError;
#[cfg(not(feature = "gecko"))] #[cfg(not(feature = "gecko"))]
use style_traits::StyleParseError; use values::Impossible;
use values::computed::{Context, Number as ComputedNumber, ToComputedValue}; 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::Filter as GenericFilter;
use values::generics::effects::FilterList as GenericFilterList; use values::generics::effects::FilterList as GenericFilterList;
use values::specified::{Angle, Percentage}; use values::specified::{Angle, Percentage};
#[cfg(feature = "gecko")]
use values::specified::color::Color; use values::specified::color::Color;
use values::specified::length::Length; use values::specified::length::Length;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
@ -24,12 +23,17 @@ use values::specified::url::SpecifiedUrl;
pub type FilterList = GenericFilterList<Filter>; pub type FilterList = GenericFilterList<Filter>;
/// A specified value for a single `filter`. /// A specified value for a single `filter`.
pub type Filter = GenericFilter<Angle, Factor, Length, DropShadow>; #[cfg(feature = "gecko")]
pub type Filter = GenericFilter<Angle, Factor, Length, SimpleShadow>;
/// A specified value for a single `filter`.
#[cfg(not(feature = "gecko"))]
pub type Filter = GenericFilter<Angle, Factor, Length, Impossible>;
/// A value for the `<factor>` parts in `Filter`. /// A value for the `<factor>` parts in `Filter`.
/// ///
/// FIXME: Should be `NumberOrPercentage`, but Gecko doesn't support that yet. /// 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)] #[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
pub enum Factor { pub enum Factor {
/// Literal number. /// Literal number.
@ -38,21 +42,13 @@ pub enum Factor {
Percentage(Percentage), 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 DropShadow {}
/// A specified value for the `drop-shadow()` filter. /// A specified value for the `drop-shadow()` filter.
/// ///
/// Contrary to the canonical order from the spec, the color is serialised /// 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. /// 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)] #[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)]
pub struct DropShadow { pub struct SimpleShadow {
/// Color. /// Color.
pub color: Option<Color>, pub color: Option<Color>,
/// Horizontal radius. /// Horizontal radius.
@ -104,7 +100,7 @@ impl Parse for Filter {
"opacity" => Ok(GenericFilter::Opacity(Factor::parse(context, i)?)), "opacity" => Ok(GenericFilter::Opacity(Factor::parse(context, i)?)),
"saturate" => Ok(GenericFilter::Saturate(Factor::parse(context, i)?)), "saturate" => Ok(GenericFilter::Saturate(Factor::parse(context, i)?)),
"sepia" => Ok(GenericFilter::Sepia(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(Parse::parse(context, i)?)),
} }
}) })
} }
@ -147,17 +143,7 @@ impl ToComputedValue for Factor {
} }
} }
impl Parse for DropShadow { impl Parse for SimpleShadow {
#[cfg(not(feature = "gecko"))]
#[inline]
fn parse<'i, 't>(
_context: &ParserContext,
_input: &mut Parser<'i, 't>
) -> Result<Self, ParseError<'i>> {
Err(StyleParseError::UnspecifiedError.into())
}
#[cfg(feature = "gecko")]
#[inline] #[inline]
fn parse<'i, 't>( fn parse<'i, 't>(
context: &ParserContext, context: &ParserContext,
@ -168,7 +154,7 @@ impl Parse for DropShadow {
let vertical = Length::parse(context, input)?; let vertical = Length::parse(context, input)?;
let blur = input.try(|i| Length::parse_non_negative(context, i)).ok(); 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()); let color = color.or_else(|| input.try(|i| Color::parse(context, i)).ok());
Ok(DropShadow { Ok(SimpleShadow {
color: color, color: color,
horizontal: horizontal, horizontal: horizontal,
vertical: vertical, vertical: vertical,
@ -177,19 +163,12 @@ impl Parse for DropShadow {
} }
} }
impl ToComputedValue for DropShadow { impl ToComputedValue for SimpleShadow {
type ComputedValue = ComputedDropShadow; type ComputedValue = ComputedSimpleShadow;
#[cfg(not(feature = "gecko"))]
#[inline]
fn to_computed_value(&self, _context: &Context) -> Self::ComputedValue {
match *self {}
}
#[cfg(feature = "gecko")]
#[inline] #[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
ComputedDropShadow { ComputedSimpleShadow {
color: color:
self.color.as_ref().unwrap_or(&Color::CurrentColor).to_computed_value(context), self.color.as_ref().unwrap_or(&Color::CurrentColor).to_computed_value(context),
horizontal: self.horizontal.to_computed_value(context), horizontal: self.horizontal.to_computed_value(context),
@ -199,16 +178,9 @@ impl ToComputedValue for DropShadow {
} }
} }
#[cfg(not(feature = "gecko"))]
#[inline] #[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self { fn from_computed_value(computed: &Self::ComputedValue) -> Self {
match *computed {} SimpleShadow {
}
#[cfg(feature = "gecko")]
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
DropShadow {
color: Some(ToComputedValue::from_computed_value(&computed.color)), color: Some(ToComputedValue::from_computed_value(&computed.color)),
horizontal: ToComputedValue::from_computed_value(&computed.horizontal), horizontal: ToComputedValue::from_computed_value(&computed.horizontal),
vertical: ToComputedValue::from_computed_value(&computed.vertical), vertical: ToComputedValue::from_computed_value(&computed.vertical),