mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Derive ComputeSquaredDistance
This commit is contained in:
parent
51b740033b
commit
277351da35
22 changed files with 162 additions and 391 deletions
|
@ -8,7 +8,6 @@ use properties::animated_properties::{Animatable, RepeatableListAnimatable};
|
|||
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
|
||||
use values::animated::{ToAnimatedValue, ToAnimatedZero};
|
||||
use values::computed::length::LengthOrPercentageOrAuto;
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||
|
||||
/// A computed value for the `background-size` property.
|
||||
|
@ -33,24 +32,6 @@ impl Animatable for BackgroundSize {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for BackgroundSize {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
match (self, other) {
|
||||
(
|
||||
&GenericBackgroundSize::Explicit { width: self_width, height: self_height },
|
||||
&GenericBackgroundSize::Explicit { width: other_width, height: other_height },
|
||||
) => {
|
||||
Ok(
|
||||
self_width.compute_squared_distance(&other_width)? +
|
||||
self_height.compute_squared_distance(&other_height)?
|
||||
)
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for BackgroundSize {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
|
|
|
@ -543,9 +543,9 @@ pub type LengthOrPercentageOrNumber = Either<Number, LengthOrPercentage>;
|
|||
/// NonNegativeLengthOrPercentage | NonNegativeNumber
|
||||
pub type NonNegativeLengthOrPercentageOrNumber = Either<NonNegativeNumber, NonNegativeLengthOrPercentage>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Copy, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Eq, PartialEq)]
|
||||
/// A computed cliprect for clip and image-region
|
||||
pub struct ClipRect {
|
||||
pub top: Option<Au>,
|
||||
|
@ -554,18 +554,6 @@ pub struct ClipRect {
|
|||
pub left: Option<Au>,
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for ClipRect {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
Ok(
|
||||
self.top.compute_squared_distance(&other.top)? +
|
||||
self.right.compute_squared_distance(&other.right)? +
|
||||
self.bottom.compute_squared_distance(&other.bottom)? +
|
||||
self.left.compute_squared_distance(&other.left)?,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for ClipRect {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
dest.write_str("rect(")?;
|
||||
|
@ -671,17 +659,10 @@ impl From<Au> for NonNegativeAu {
|
|||
}
|
||||
|
||||
/// A computed `<percentage>` value.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, HasViewportPercentage)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, Default, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
|
||||
pub struct Percentage(pub CSSFloat);
|
||||
|
||||
impl ComputeSquaredDistance for Percentage {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
self.0.compute_squared_distance(&other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Percentage {
|
||||
/// 0%
|
||||
#[inline]
|
||||
|
|
|
@ -9,7 +9,6 @@ use values::{CSSInteger, CSSFloat};
|
|||
use values::animated::ToAnimatedZero;
|
||||
use values::computed::{NonNegativeAu, NonNegativeNumber};
|
||||
use values::computed::length::{Length, LengthOrPercentage};
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use values::generics::text::InitialLetter as GenericInitialLetter;
|
||||
use values::generics::text::LineHeight as GenericLineHeight;
|
||||
use values::generics::text::Spacing;
|
||||
|
@ -48,28 +47,6 @@ impl Animatable for LineHeight {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for LineHeight {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
match (self, other) {
|
||||
(&GenericLineHeight::Length(ref this), &GenericLineHeight::Length(ref other)) => {
|
||||
this.compute_squared_distance(other)
|
||||
},
|
||||
(&GenericLineHeight::Number(ref this), &GenericLineHeight::Number(ref other)) => {
|
||||
this.compute_squared_distance(other)
|
||||
},
|
||||
(&GenericLineHeight::Normal, &GenericLineHeight::Normal) => {
|
||||
Ok(SquaredDistance::Value(0.))
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
(&GenericLineHeight::MozBlockHeight, &GenericLineHeight::MozBlockHeight) => {
|
||||
Ok(SquaredDistance::Value(0.))
|
||||
},
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for LineHeight {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
use properties::animated_properties::Animatable;
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::computed::{Length, LengthOrPercentage, Number, Percentage};
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use values::generics::transform::TimingFunction as GenericTimingFunction;
|
||||
use values::generics::transform::TransformOrigin as GenericTransformOrigin;
|
||||
|
||||
|
@ -40,17 +39,6 @@ impl Animatable for TransformOrigin {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for TransformOrigin {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
Ok(
|
||||
self.horizontal.compute_squared_distance(&other.horizontal)? +
|
||||
self.vertical.compute_squared_distance(&other.vertical)? +
|
||||
self.depth.compute_squared_distance(&other.depth)?
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedZero for TransformOrigin {
|
||||
#[inline]
|
||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue