mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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:
commit
112bb55b92
8 changed files with 72 additions and 95 deletions
|
@ -14,7 +14,7 @@ use style_traits::{CssWriter, ToCss};
|
|||
use style_traits::values::specified::AllowedNumericType;
|
||||
use super::{Number, ToComputedValue, Context, Percentage};
|
||||
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::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use values::generics::NonNegative;
|
||||
|
@ -664,6 +664,20 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone {
|
|||
/// A wrapper of LengthOrPercentage, whose value must be >= 0.
|
||||
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 {
|
||||
#[inline]
|
||||
fn from(length: NonNegativeLength) -> Self {
|
||||
|
|
|
@ -18,6 +18,7 @@ use rule_cache::RuleCacheConditions;
|
|||
#[cfg(feature = "servo")]
|
||||
use servo_url::ServoUrl;
|
||||
use std::cell::RefCell;
|
||||
use std::cmp;
|
||||
use std::f32;
|
||||
use std::fmt::{self, Write};
|
||||
#[cfg(feature = "servo")]
|
||||
|
@ -25,6 +26,7 @@ use std::sync::Arc;
|
|||
use style_traits::{CssWriter, ToCss};
|
||||
use style_traits::cursor::CursorKind;
|
||||
use super::{CSSFloat, CSSInteger};
|
||||
use super::animated::ToAnimatedValue;
|
||||
use super::generics::{GreaterThanOrEqualToOne, NonNegative};
|
||||
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
|
||||
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.
|
||||
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 {
|
||||
#[inline]
|
||||
fn from(number: CSSFloat) -> NonNegativeNumber {
|
||||
|
@ -444,6 +460,20 @@ impl From<NonNegativeNumber> for CSSFloat {
|
|||
/// A wrapper of Number, but the value >= 1.
|
||||
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 {
|
||||
#[inline]
|
||||
fn from(number: CSSFloat) -> GreaterThanOrEqualToOneNumber {
|
||||
|
@ -511,6 +541,20 @@ impl IntegerOrAuto {
|
|||
/// A wrapper of Integer, but only accept a value >= 1.
|
||||
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 {
|
||||
#[inline]
|
||||
fn from(int: CSSInteger) -> PositiveInteger {
|
||||
|
|
|
@ -9,7 +9,6 @@ use properties::StyleBuilder;
|
|||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::{CSSInteger, CSSFloat};
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::computed::{NonNegativeLength, NonNegativeNumber};
|
||||
use values::computed::length::{Length, LengthOrPercentage};
|
||||
use values::generics::text::InitialLetter as GenericInitialLetter;
|
||||
|
@ -31,11 +30,6 @@ pub type WordSpacing = Spacing<LengthOrPercentage>;
|
|||
/// A computed value for the `line-height` property.
|
||||
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLength>;
|
||||
|
||||
impl ToAnimatedZero for LineHeight {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
/// text-overflow.
|
||||
/// When the specified value only has one side, that's the "second"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue