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

Change how some clamped types are animated

<!-- 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/20040)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-02-14 05:48:10 -05:00 committed by GitHub
commit 112bb55b92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 95 deletions

View file

@ -55,7 +55,6 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::font::FontSettings as GenericFontSettings; use values::generics::font::FontSettings as GenericFontSettings;
use values::computed::font::FontVariationSettings; use values::computed::font::FontVariationSettings;
use values::generics::font::VariationValue; use values::generics::font::VariationValue;
use values::generics::NonNegative;
use values::generics::effects::Filter; use values::generics::effects::Filter;
use values::generics::position as generic_position; use values::generics::position as generic_position;
use values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber, SVGPaint}; use values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber, SVGPaint};
@ -789,7 +788,7 @@ impl ToAnimatedZero for AnimationValue {
impl RepeatableListAnimatable for LengthOrPercentage {} impl RepeatableListAnimatable for LengthOrPercentage {}
impl RepeatableListAnimatable for Either<f32, LengthOrPercentage> {} impl RepeatableListAnimatable for Either<f32, LengthOrPercentage> {}
impl RepeatableListAnimatable for Either<NonNegativeNumber, NonNegativeLengthOrPercentage> {} impl RepeatableListAnimatable for Either<NonNegativeNumber, NonNegativeLengthOrPercentage> {}
impl RepeatableListAnimatable for SvgLengthOrPercentageOrNumber<NonNegativeLengthOrPercentage, NonNegativeNumber> {} impl RepeatableListAnimatable for SvgLengthOrPercentageOrNumber<LengthOrPercentage, Number> {}
macro_rules! repeated_vec_impl { macro_rules! repeated_vec_impl {
($($ty:ty),*) => { ($($ty:ty),*) => {
@ -3012,12 +3011,8 @@ impl Animate for AnimatedFilter {
}, },
% endfor % endfor
% for func in ['Brightness', 'Contrast', 'Opacity', 'Saturate']: % for func in ['Brightness', 'Contrast', 'Opacity', 'Saturate']:
(&Filter::${func}(ref this), &Filter::${func}(ref other)) => { (&Filter::${func}(this), &Filter::${func}(other)) => {
Ok(Filter::${func}(NonNegative(animate_multiplicative_factor( Ok(Filter::${func}(animate_multiplicative_factor(this, other, procedure)?))
this.0,
other.0,
procedure,
)?)))
}, },
% endfor % endfor
% if product == "gecko": % if product == "gecko":
@ -3038,7 +3033,7 @@ impl ToAnimatedZero for AnimatedFilter {
Filter::${func}(ref this) => Ok(Filter::${func}(this.to_animated_zero()?)), Filter::${func}(ref this) => Ok(Filter::${func}(this.to_animated_zero()?)),
% endfor % endfor
% for func in ['Brightness', 'Contrast', 'Opacity', 'Saturate']: % for func in ['Brightness', 'Contrast', 'Opacity', 'Saturate']:
Filter::${func}(_) => Ok(Filter::${func}(NonNegative(1.))), Filter::${func}(_) => Ok(Filter::${func}(1.)),
% endfor % endfor
% if product == "gecko": % if product == "gecko":
Filter::DropShadow(ref this) => Ok(Filter::DropShadow(this.to_animated_zero()?)), Filter::DropShadow(ref this) => Ok(Filter::DropShadow(this.to_animated_zero()?)),

View file

@ -12,7 +12,7 @@ use std::cmp;
use values::Impossible; use values::Impossible;
use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use values::animated::color::RGBA; use values::animated::color::RGBA;
use values::computed::{Angle, NonNegativeNumber}; use values::computed::{Angle, Number};
use values::computed::length::{Length, NonNegativeLength}; use values::computed::length::{Length, NonNegativeLength};
use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::effects::BoxShadow as GenericBoxShadow; use values::generics::effects::BoxShadow as GenericBoxShadow;
@ -42,11 +42,11 @@ pub struct FilterList(pub Vec<Filter>);
/// An animated value for a single `filter`. /// An animated value for a single `filter`.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub type Filter = GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, SimpleShadow>; pub type Filter = GenericFilter<Angle, Number, NonNegativeLength, SimpleShadow>;
/// An animated value for a single `filter`. /// An animated value for a single `filter`.
#[cfg(not(feature = "gecko"))] #[cfg(not(feature = "gecko"))]
pub type Filter = GenericFilter<Angle, NonNegativeNumber, NonNegativeLength, Impossible>; pub type Filter = GenericFilter<Angle, Number, NonNegativeLength, Impossible>;
/// An animated value for the `drop-shadow()` filter. /// An animated value for the `drop-shadow()` filter.
pub type SimpleShadow = GenericSimpleShadow<Option<RGBA>, Length, NonNegativeLength>; pub type SimpleShadow = GenericSimpleShadow<Option<RGBA>, Length, NonNegativeLength>;
@ -155,25 +155,11 @@ impl ComputeSquaredDistance for BoxShadow {
impl ToAnimatedValue for ComputedFilterList { impl ToAnimatedValue for ComputedFilterList {
type AnimatedValue = FilterList; type AnimatedValue = FilterList;
#[cfg(not(feature = "gecko"))]
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
FilterList(self.0)
}
#[cfg(feature = "gecko")]
#[inline] #[inline]
fn to_animated_value(self) -> Self::AnimatedValue { fn to_animated_value(self) -> Self::AnimatedValue {
FilterList(self.0.to_animated_value()) FilterList(self.0.to_animated_value())
} }
#[cfg(not(feature = "gecko"))]
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
ComputedFilterList(animated.0)
}
#[cfg(feature = "gecko")]
#[inline] #[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self { fn from_animated_value(animated: Self::AnimatedValue) -> Self {
ComputedFilterList(ToAnimatedValue::from_animated_value(animated.0)) ComputedFilterList(ToAnimatedValue::from_animated_value(animated.0))

View file

@ -11,18 +11,13 @@
use app_units::Au; use app_units::Au;
use euclid::{Point2D, Size2D}; use euclid::{Point2D, Size2D};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::cmp::max;
use values::computed::Angle as ComputedAngle; use values::computed::Angle as ComputedAngle;
use values::computed::BorderCornerRadius as ComputedBorderCornerRadius; use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use values::computed::ComputedUrl; use values::computed::ComputedUrl;
use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber;
use values::computed::MaxLength as ComputedMaxLength; use values::computed::MaxLength as ComputedMaxLength;
use values::computed::MozLength as ComputedMozLength; use values::computed::MozLength as ComputedMozLength;
use values::computed::NonNegativeLength as ComputedNonNegativeLength; use values::computed::NonNegativeLength as ComputedNonNegativeLength;
use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage;
use values::computed::NonNegativeNumber as ComputedNonNegativeNumber;
use values::computed::PositiveInteger as ComputedPositiveInteger;
use values::specified::url::SpecifiedUrl; use values::specified::url::SpecifiedUrl;
pub mod color; pub mod color;
@ -266,34 +261,6 @@ trivial_to_animated_value!(ComputedUrl);
trivial_to_animated_value!(bool); trivial_to_animated_value!(bool);
trivial_to_animated_value!(f32); trivial_to_animated_value!(f32);
impl ToAnimatedValue for ComputedNonNegativeNumber {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
animated.0.max(0.).into()
}
}
impl ToAnimatedValue for ComputedGreaterThanOrEqualToOneNumber {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
animated.0.max(1.).into()
}
}
impl ToAnimatedValue for ComputedNonNegativeLength { impl ToAnimatedValue for ComputedNonNegativeLength {
type AnimatedValue = Self; type AnimatedValue = Self;
@ -308,34 +275,6 @@ impl ToAnimatedValue for ComputedNonNegativeLength {
} }
} }
impl ToAnimatedValue for ComputedPositiveInteger {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
max(animated.0, 1).into()
}
}
impl ToAnimatedValue for ComputedNonNegativeLengthOrPercentage {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
animated.0.clamp_to_non_negative().into()
}
}
impl ToAnimatedValue for ComputedBorderCornerRadius { impl ToAnimatedValue for ComputedBorderCornerRadius {
type AnimatedValue = Self; type AnimatedValue = Self;

View file

@ -14,7 +14,7 @@ use style_traits::{CssWriter, ToCss};
use style_traits::values::specified::AllowedNumericType; use style_traits::values::specified::AllowedNumericType;
use super::{Number, ToComputedValue, Context, Percentage}; use super::{Number, ToComputedValue, Context, Percentage};
use values::{Auto, CSSFloat, Either, None_, Normal, specified}; use values::{Auto, CSSFloat, Either, None_, Normal, specified};
use values::animated::{Animate, Procedure, ToAnimatedZero}; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use values::computed::NonNegativeNumber; use values::computed::NonNegativeNumber;
use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::NonNegative; use values::generics::NonNegative;
@ -664,6 +664,20 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone {
/// A wrapper of LengthOrPercentage, whose value must be >= 0. /// A wrapper of LengthOrPercentage, whose value must be >= 0.
pub type NonNegativeLengthOrPercentage = NonNegative<LengthOrPercentage>; pub type NonNegativeLengthOrPercentage = NonNegative<LengthOrPercentage>;
impl ToAnimatedValue for NonNegativeLengthOrPercentage {
type AnimatedValue = LengthOrPercentage;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
self.into()
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
animated.clamp_to_non_negative().into()
}
}
impl From<NonNegativeLength> for NonNegativeLengthOrPercentage { impl From<NonNegativeLength> for NonNegativeLengthOrPercentage {
#[inline] #[inline]
fn from(length: NonNegativeLength) -> Self { fn from(length: NonNegativeLength) -> Self {

View file

@ -18,6 +18,7 @@ use rule_cache::RuleCacheConditions;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::cell::RefCell; use std::cell::RefCell;
use std::cmp;
use std::f32; use std::f32;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
@ -25,6 +26,7 @@ use std::sync::Arc;
use style_traits::{CssWriter, ToCss}; use style_traits::{CssWriter, ToCss};
use style_traits::cursor::CursorKind; use style_traits::cursor::CursorKind;
use super::{CSSFloat, CSSInteger}; use super::{CSSFloat, CSSInteger};
use super::animated::ToAnimatedValue;
use super::generics::{GreaterThanOrEqualToOne, NonNegative}; use super::generics::{GreaterThanOrEqualToOne, NonNegative};
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth}; use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList}; use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList};
@ -427,6 +429,20 @@ pub type Number = CSSFloat;
/// A wrapper of Number, but the value >= 0. /// A wrapper of Number, but the value >= 0.
pub type NonNegativeNumber = NonNegative<CSSFloat>; pub type NonNegativeNumber = NonNegative<CSSFloat>;
impl ToAnimatedValue for NonNegativeNumber {
type AnimatedValue = CSSFloat;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
self.0
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
animated.max(0.).into()
}
}
impl From<CSSFloat> for NonNegativeNumber { impl From<CSSFloat> for NonNegativeNumber {
#[inline] #[inline]
fn from(number: CSSFloat) -> NonNegativeNumber { fn from(number: CSSFloat) -> NonNegativeNumber {
@ -444,6 +460,20 @@ impl From<NonNegativeNumber> for CSSFloat {
/// A wrapper of Number, but the value >= 1. /// A wrapper of Number, but the value >= 1.
pub type GreaterThanOrEqualToOneNumber = GreaterThanOrEqualToOne<CSSFloat>; pub type GreaterThanOrEqualToOneNumber = GreaterThanOrEqualToOne<CSSFloat>;
impl ToAnimatedValue for GreaterThanOrEqualToOneNumber {
type AnimatedValue = CSSFloat;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
self.0
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
animated.max(1.).into()
}
}
impl From<CSSFloat> for GreaterThanOrEqualToOneNumber { impl From<CSSFloat> for GreaterThanOrEqualToOneNumber {
#[inline] #[inline]
fn from(number: CSSFloat) -> GreaterThanOrEqualToOneNumber { fn from(number: CSSFloat) -> GreaterThanOrEqualToOneNumber {
@ -511,6 +541,20 @@ impl IntegerOrAuto {
/// A wrapper of Integer, but only accept a value >= 1. /// A wrapper of Integer, but only accept a value >= 1.
pub type PositiveInteger = GreaterThanOrEqualToOne<CSSInteger>; pub type PositiveInteger = GreaterThanOrEqualToOne<CSSInteger>;
impl ToAnimatedValue for PositiveInteger {
type AnimatedValue = CSSInteger;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
self.0
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
cmp::max(animated, 1).into()
}
}
impl From<CSSInteger> for PositiveInteger { impl From<CSSInteger> for PositiveInteger {
#[inline] #[inline]
fn from(int: CSSInteger) -> PositiveInteger { fn from(int: CSSInteger) -> PositiveInteger {

View file

@ -9,7 +9,6 @@ use properties::StyleBuilder;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss}; use style_traits::{CssWriter, ToCss};
use values::{CSSInteger, CSSFloat}; use values::{CSSInteger, CSSFloat};
use values::animated::ToAnimatedZero;
use values::computed::{NonNegativeLength, NonNegativeNumber}; use values::computed::{NonNegativeLength, NonNegativeNumber};
use values::computed::length::{Length, LengthOrPercentage}; use values::computed::length::{Length, LengthOrPercentage};
use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::InitialLetter as GenericInitialLetter;
@ -31,11 +30,6 @@ pub type WordSpacing = Spacing<LengthOrPercentage>;
/// A computed value for the `line-height` property. /// A computed value for the `line-height` property.
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLength>; pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLength>;
impl ToAnimatedZero for LineHeight {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
}
#[derive(Clone, Debug, MallocSizeOf, PartialEq)] #[derive(Clone, Debug, MallocSizeOf, PartialEq)]
/// text-overflow. /// text-overflow.
/// When the specified value only has one side, that's the "second" /// When the specified value only has one side, that's the "second"

View file

@ -121,6 +121,11 @@ pub enum LineHeight<Number, LengthOrPercentage> {
Length(LengthOrPercentage), Length(LengthOrPercentage),
} }
impl<N, L> ToAnimatedZero for LineHeight<N, L> {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
}
impl<N, L> LineHeight<N, L> { impl<N, L> LineHeight<N, L> {
/// Returns `normal`. /// Returns `normal`.
#[inline] #[inline]

View file

@ -64,7 +64,7 @@ where
/// Convenience void type to disable some properties and values through types. /// Convenience void type to disable some properties and values through types.
#[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))] #[cfg_attr(feature = "servo", derive(Deserialize, MallocSizeOf, Serialize))]
#[derive(Clone, Copy, Debug, PartialEq, ToComputedValue, ToCss)] #[derive(Clone, Copy, Debug, PartialEq, ToAnimatedValue, ToComputedValue, ToCss)]
pub enum Impossible {} pub enum Impossible {}
// FIXME(nox): This should be derived but the derive code cannot cope // FIXME(nox): This should be derived but the derive code cannot cope