mirror of
https://github.com/servo/servo.git
synced 2025-10-17 00:39:15 +01:00
Auto merge of #17530 - servo:derive-all-the-things, r=emilio
Improve sequence values in style <!-- 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/17530) <!-- Reviewable:end -->
This commit is contained in:
commit
de0ee6cebf
21 changed files with 211 additions and 241 deletions
|
@ -5,21 +5,21 @@
|
|||
//! Animated types for CSS values related to effects.
|
||||
|
||||
use properties::animated_properties::{Animatable, IntermediateColor};
|
||||
use properties::longhands::filter::computed_value::T as ComputedFilterList;
|
||||
#[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;
|
||||
use values::generics::effects::Filter as GenericFilter;
|
||||
use values::generics::effects::FilterList as GenericFilterList;
|
||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||
|
||||
/// An animated value for the `filter` property.
|
||||
pub type FilterList = GenericFilterList<Filter>;
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct FilterList(pub Vec<Filter>);
|
||||
|
||||
/// An animated value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -32,19 +32,31 @@ pub type Filter = GenericFilter<Angle, Number, Length, Impossible>;
|
|||
/// An animated value for the `drop-shadow()` filter.
|
||||
pub type SimpleShadow = GenericSimpleShadow<IntermediateColor, Length, Length>;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl From<ComputedFilterList> for FilterList {
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[inline]
|
||||
fn from(filters: ComputedFilterList) -> Self {
|
||||
filters.0.into_vec().into_iter().map(|f| f.into()).collect::<Vec<_>>().into()
|
||||
FilterList(filters.0)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
fn from(filters: ComputedFilterList) -> Self {
|
||||
FilterList(filters.0.into_iter().map(|f| f.into()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl From<FilterList> for ComputedFilterList {
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[inline]
|
||||
fn from(filters: FilterList) -> Self {
|
||||
filters.0.into_vec().into_iter().map(|f| f.into()).collect::<Vec<_>>().into()
|
||||
ComputedFilterList(filters.0)
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
fn from(filters: FilterList) -> Self {
|
||||
ComputedFilterList(filters.0.into_iter().map(|f| f.into()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,8 @@ use values::computed::{Angle, Number};
|
|||
use values::computed::color::Color;
|
||||
use values::computed::length::Length;
|
||||
use values::generics::effects::Filter as GenericFilter;
|
||||
use values::generics::effects::FilterList as GenericFilterList;
|
||||
use values::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||
|
||||
/// A computed value for the `filter` property.
|
||||
pub type FilterList = GenericFilterList<Filter>;
|
||||
|
||||
/// A computed value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type Filter = GenericFilter<Angle, Number, Length, SimpleShadow>;
|
||||
|
@ -26,16 +22,3 @@ pub type Filter = GenericFilter<Angle, Number, Length, Impossible>;
|
|||
|
||||
/// A computed value for the `drop-shadow()` filter.
|
||||
pub type SimpleShadow = GenericSimpleShadow<Color, Length, Length>;
|
||||
|
||||
impl FilterList {
|
||||
/// Returns the resulting opacity of this filter pipeline.
|
||||
pub fn opacity(&self) -> Number {
|
||||
let mut opacity = 0.;
|
||||
for filter in &*self.0 {
|
||||
if let GenericFilter::Opacity(factor) = *filter {
|
||||
opacity *= factor
|
||||
}
|
||||
}
|
||||
opacity
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ pub use self::background::BackgroundSize;
|
|||
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
|
||||
pub use self::border::{BorderRadius, BorderCornerRadius};
|
||||
pub use self::color::{Color, RGBAColor};
|
||||
pub use self::effects::FilterList;
|
||||
pub use self::effects::Filter;
|
||||
pub use self::flex::FlexBasis;
|
||||
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect};
|
||||
#[cfg(feature = "gecko")]
|
||||
|
|
|
@ -4,18 +4,9 @@
|
|||
|
||||
//! Generic types for CSS values related to effects.
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A generic value for the `filter` property.
|
||||
///
|
||||
/// Keyword `none` is represented by an empty slice.
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub struct FilterList<Filter>(pub Box<[Filter]>);
|
||||
|
||||
/// A generic value for a single `filter`.
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
|
||||
|
@ -71,39 +62,3 @@ pub struct SimpleShadow<Color, SizeLength, ShapeLength> {
|
|||
/// Blur radius.
|
||||
pub blur: ShapeLength,
|
||||
}
|
||||
|
||||
impl<F> FilterList<F> {
|
||||
/// Returns `none`.
|
||||
#[inline]
|
||||
pub fn none() -> Self {
|
||||
FilterList(vec![].into_boxed_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> From<Vec<F>> for FilterList<F> {
|
||||
#[inline]
|
||||
fn from(vec: Vec<F>) -> Self {
|
||||
FilterList(vec.into_boxed_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> ToCss for FilterList<F>
|
||||
where
|
||||
F: ToCss,
|
||||
{
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where
|
||||
W: fmt::Write
|
||||
{
|
||||
if let Some((first, rest)) = self.0.split_first() {
|
||||
first.to_css(dest)?;
|
||||
for filter in rest {
|
||||
dest.write_str(" ")?;
|
||||
filter.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
dest.write_str("none")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use counter_style::{Symbols, parse_counter_style_name};
|
|||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt;
|
||||
use style_traits::{OneOrMoreSeparated, CommaSeparator, ToCss, ParseError, StyleParseError};
|
||||
use style_traits::{Comma, OneOrMoreSeparated, ParseError, StyleParseError, ToCss};
|
||||
use super::CustomIdent;
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
|
@ -125,7 +125,7 @@ pub struct FontSettingTag<T> {
|
|||
}
|
||||
|
||||
impl<T> OneOrMoreSeparated for FontSettingTag<T> {
|
||||
type S = CommaSeparator;
|
||||
type S = Comma;
|
||||
}
|
||||
|
||||
impl<T: ToCss> ToCss for FontSettingTag<T> {
|
||||
|
|
|
@ -52,7 +52,7 @@ impl Parse for Impossible {
|
|||
|
||||
/// A struct representing one of two kinds of values.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToCss)]
|
||||
#[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum Either<A, B> {
|
||||
/// The first value.
|
||||
First(A),
|
||||
|
@ -80,27 +80,6 @@ impl<A: Parse, B: Parse> Parse for Either<A, B> {
|
|||
}
|
||||
}
|
||||
|
||||
use self::computed::{Context, ToComputedValue};
|
||||
|
||||
impl<A: ToComputedValue, B: ToComputedValue> ToComputedValue for Either<A, B> {
|
||||
type ComputedValue = Either<A::ComputedValue, B::ComputedValue>;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
Either::First(ref a) => Either::First(a.to_computed_value(context)),
|
||||
Either::Second(ref a) => Either::Second(a.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
Either::First(ref a) => Either::First(ToComputedValue::from_computed_value(a)),
|
||||
Either::Second(ref a) => Either::Second(ToComputedValue::from_computed_value(a)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-values-4/#custom-idents
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
|
|
@ -12,7 +12,6 @@ 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::generics::effects::SimpleShadow as GenericSimpleShadow;
|
||||
use values::specified::{Angle, Percentage};
|
||||
use values::specified::color::Color;
|
||||
|
@ -20,9 +19,6 @@ use values::specified::length::Length;
|
|||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// A specified value for the `filter` property.
|
||||
pub type FilterList = GenericFilterList<Filter>;
|
||||
|
||||
/// A specified value for a single `filter`.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type Filter = GenericFilter<Angle, Factor, Length, SimpleShadow>;
|
||||
|
@ -46,23 +42,6 @@ pub enum Factor {
|
|||
/// A specified value for the `drop-shadow()` filter.
|
||||
pub type SimpleShadow = GenericSimpleShadow<Option<Color>, Length, Option<Length>>;
|
||||
|
||||
impl Parse for FilterList {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut filters = vec![];
|
||||
while let Ok(filter) = input.try(|i| Filter::parse(context, i)) {
|
||||
filters.push(filter);
|
||||
}
|
||||
if filters.is_empty() {
|
||||
input.expect_ident_matching("none")?;
|
||||
}
|
||||
Ok(GenericFilterList(filters.into_boxed_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Filter {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
|
@ -113,7 +92,7 @@ impl Parse for Factor {
|
|||
|
||||
impl ToComputedValue for Factor {
|
||||
/// This should actually be `ComputedNumberOrPercentage`, but layout uses
|
||||
/// `computed::effects::FilterList` directly in `StackingContext`.
|
||||
/// `computed::effects::Filter` directly in `StackingContext`.
|
||||
type ComputedValue = ComputedNumber;
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -33,7 +33,7 @@ pub use self::background::BackgroundSize;
|
|||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||
pub use self::border::{BorderImageSideWidth, BorderRadius, BorderSideWidth};
|
||||
pub use self::color::{Color, RGBAColor};
|
||||
pub use self::effects::FilterList;
|
||||
pub use self::effects::Filter;
|
||||
pub use self::flex::FlexBasis;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::gecko::ScrollSnapPoint;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue