Replace Au with CSSPixelLength in CalcLengthOrPercentage.

We replace Au with CSSPixelLength for the length part of
computed::CalcLengthOrPercentage. Therefore, it would be easier to use
CSSPixelLength for all other LengthOrPercentage{*} types.
This commit is contained in:
Boris Chiou 2017-09-08 17:43:41 +08:00
parent a949e2a057
commit 535c1e3c6f
13 changed files with 99 additions and 117 deletions

View file

@ -1520,7 +1520,7 @@ impl Fragment {
LengthOrPercentageOrAuto::Calc(calc) => {
// TODO(nox): This is probably wrong, because it accounts neither for
// clamping (not sure if necessary here) nor percentage.
calc.unclamped_length()
Au::from(calc.unclamped_length())
},
};

View file

@ -29,7 +29,7 @@ impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue {
let has_percentage = other.percentage.is_some();
nsStyleCoord_CalcValue {
mLength: other.unclamped_length().0,
mLength: other.unclamped_length().to_i32_au(),
mPercent: other.percentage.map_or(0., |p| p.0),
mHasPercent: has_percentage,
}
@ -43,7 +43,7 @@ impl From<nsStyleCoord_CalcValue> for CalcLengthOrPercentage {
} else {
None
};
Self::new(Au(other.mLength), percentage)
Self::new(Au(other.mLength).into(), percentage)
}
}

View file

@ -2316,7 +2316,7 @@ impl ComputeSquaredDistance for TransformOperation {
match *lop {
LengthOrPercentage::Length(au) => au.to_f64_px(),
LengthOrPercentage::Percentage(_) => 0.,
LengthOrPercentage::Calc(calc) => calc.length().to_f64_px(),
LengthOrPercentage::Calc(calc) => calc.length().px() as f64,
}
};

View file

@ -7,9 +7,9 @@
use app_units::{Au, AU_PER_PX};
use ordered_float::NotNaN;
use std::fmt;
use std::ops::Add;
use std::ops::{Add, Neg};
use style_traits::ToCss;
use style_traits::values::specified::AllowedLengthType;
use style_traits::values::specified::AllowedNumericType;
use super::{Number, ToComputedValue, Context, Percentage};
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified};
use values::animated::{Animate, Procedure, ToAnimatedZero};
@ -55,7 +55,7 @@ impl ToComputedValue for specified::Length {
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
specified::Length::NoCalc(l) => l.to_computed_value(context),
specified::Length::Calc(ref calc) => calc.to_computed_value(context).length().into(),
specified::Length::Calc(ref calc) => calc.to_computed_value(context).length(),
}
}
@ -70,8 +70,8 @@ impl ToComputedValue for specified::Length {
#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedZero)]
pub struct CalcLengthOrPercentage {
#[animation(constant)]
pub clamping_mode: AllowedLengthType,
length: Au,
pub clamping_mode: AllowedNumericType,
length: Length,
pub percentage: Option<Percentage>,
}
@ -81,8 +81,7 @@ impl ComputeSquaredDistance for CalcLengthOrPercentage {
// FIXME(nox): This looks incorrect to me, to add a distance between lengths
// with a distance between percentages.
Ok(
self.unclamped_length().to_f64_px().compute_squared_distance(
&other.unclamped_length().to_f64_px())? +
self.unclamped_length().compute_squared_distance(&other.unclamped_length())? +
self.percentage().compute_squared_distance(&other.percentage())?,
)
}
@ -91,15 +90,15 @@ impl ComputeSquaredDistance for CalcLengthOrPercentage {
impl CalcLengthOrPercentage {
/// Returns a new `CalcLengthOrPercentage`.
#[inline]
pub fn new(length: Au, percentage: Option<Percentage>) -> Self {
Self::with_clamping_mode(length, percentage, AllowedLengthType::All)
pub fn new(length: Length, percentage: Option<Percentage>) -> Self {
Self::with_clamping_mode(length, percentage, AllowedNumericType::All)
}
/// Returns a new `CalcLengthOrPercentage` with a specific clamping mode.
#[inline]
pub fn with_clamping_mode(length: Au,
pub fn with_clamping_mode(length: Length,
percentage: Option<Percentage>,
clamping_mode: AllowedLengthType)
clamping_mode: AllowedNumericType)
-> Self {
Self {
clamping_mode: clamping_mode,
@ -112,20 +111,20 @@ impl CalcLengthOrPercentage {
///
/// Panics in debug mode if a percentage is present in the expression.
#[inline]
pub fn length(&self) -> Au {
pub fn length(&self) -> CSSPixelLength {
debug_assert!(self.percentage.is_none());
self.length_component()
}
/// Returns the length component of this `calc()`
#[inline]
pub fn length_component(&self) -> Au {
self.clamping_mode.clamp(self.length)
pub fn length_component(&self) -> CSSPixelLength {
CSSPixelLength::new(self.clamping_mode.clamp(self.length.px()))
}
/// Returns the `<length>` component of this `calc()`, unclamped.
#[inline]
pub fn unclamped_length(&self) -> Au {
pub fn unclamped_length(&self) -> CSSPixelLength {
self.length
}
@ -140,9 +139,10 @@ impl CalcLengthOrPercentage {
pub fn to_used_value(&self, container_len: Option<Au>) -> Option<Au> {
match (container_len, self.percentage) {
(Some(len), Some(percent)) => {
Some(self.clamping_mode.clamp(self.length + len.scale_by(percent.0)))
let pixel = self.length.px() + len.scale_by(percent.0).to_f32_px();
Some(Au::from_f32_px(self.clamping_mode.clamp(pixel)))
},
(_, None) => Some(self.length()),
(_, None) => Some(Au::from(self.length())),
_ => None,
}
}
@ -152,10 +152,10 @@ impl From<LengthOrPercentage> for CalcLengthOrPercentage {
fn from(len: LengthOrPercentage) -> CalcLengthOrPercentage {
match len {
LengthOrPercentage::Percentage(this) => {
CalcLengthOrPercentage::new(Au(0), Some(this))
CalcLengthOrPercentage::new(Length::new(0.), Some(this))
}
LengthOrPercentage::Length(this) => {
CalcLengthOrPercentage::new(this, None)
CalcLengthOrPercentage::new(this.into(), None)
}
LengthOrPercentage::Calc(this) => {
this
@ -168,10 +168,10 @@ impl From<LengthOrPercentageOrAuto> for Option<CalcLengthOrPercentage> {
fn from(len: LengthOrPercentageOrAuto) -> Option<CalcLengthOrPercentage> {
match len {
LengthOrPercentageOrAuto::Percentage(this) => {
Some(CalcLengthOrPercentage::new(Au(0), Some(this)))
Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this)))
}
LengthOrPercentageOrAuto::Length(this) => {
Some(CalcLengthOrPercentage::new(this, None))
Some(CalcLengthOrPercentage::new(this.into(), None))
}
LengthOrPercentageOrAuto::Calc(this) => {
Some(this)
@ -187,10 +187,10 @@ impl From<LengthOrPercentageOrNone> for Option<CalcLengthOrPercentage> {
fn from(len: LengthOrPercentageOrNone) -> Option<CalcLengthOrPercentage> {
match len {
LengthOrPercentageOrNone::Percentage(this) => {
Some(CalcLengthOrPercentage::new(Au(0), Some(this)))
Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this)))
}
LengthOrPercentageOrNone::Length(this) => {
Some(CalcLengthOrPercentage::new(this, None))
Some(CalcLengthOrPercentage::new(this.into(), None))
}
LengthOrPercentageOrNone::Calc(this) => {
Some(this)
@ -208,14 +208,14 @@ impl ToCss for CalcLengthOrPercentage {
let (length, percentage) = match (self.length, self.percentage) {
(l, None) => return l.to_css(dest),
(l, Some(p)) if l == Au(0) => return p.to_css(dest),
(l, Some(p)) if l.px() == 0. => return p.to_css(dest),
(l, Some(p)) => (l, p),
};
dest.write_str("calc(")?;
percentage.to_css(dest)?;
dest.write_str(if length < Zero::zero() { " - " } else { " + " })?;
dest.write_str(if length.px() < Zero::zero() { " - " } else { " + " })?;
length.abs().to_css(dest)?;
dest.write_str(")")
@ -226,11 +226,12 @@ impl specified::CalcLengthOrPercentage {
/// Compute the value, zooming any absolute units by the zoom function.
fn to_computed_value_with_zoom<F>(&self, context: &Context, zoom_fn: F,
base_size: FontBaseSize) -> CalcLengthOrPercentage
where F: Fn(Au) -> Au {
let mut length = Au(0);
where F: Fn(Length) -> Length {
use std::f32;
let mut length = 0.;
if let Some(absolute) = self.absolute {
length += zoom_fn(Au::from(absolute.to_computed_value(context)));
length += zoom_fn(absolute.to_computed_value(context)).px();
}
for val in &[self.vw.map(ViewportPercentageLength::Vw),
@ -239,7 +240,7 @@ impl specified::CalcLengthOrPercentage {
self.vmax.map(ViewportPercentageLength::Vmax)] {
if let Some(val) = *val {
let viewport_size = context.viewport_size_for_viewport_unit_resolution();
length += Au::from(val.to_computed_value(viewport_size));
length += val.to_computed_value(viewport_size).px();
}
}
@ -248,20 +249,20 @@ impl specified::CalcLengthOrPercentage {
self.ex.map(FontRelativeLength::Ex),
self.rem.map(FontRelativeLength::Rem)] {
if let Some(val) = *val {
length += Au::from(val.to_computed_value(context, base_size));
length += val.to_computed_value(context, base_size).px();
}
}
CalcLengthOrPercentage {
clamping_mode: self.clamping_mode,
length: length,
length: Length::new(length.min(f32::MAX).max(f32::MIN)),
percentage: self.percentage,
}
}
/// Compute font-size or line-height taking into account text-zoom if necessary.
pub fn to_computed_value_zoomed(&self, context: &Context, base_size: FontBaseSize) -> CalcLengthOrPercentage {
self.to_computed_value_with_zoom(context, |abs| Au::from(context.maybe_zoom_text(abs.into())), base_size)
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs), base_size)
}
}
@ -277,7 +278,7 @@ impl ToComputedValue for specified::CalcLengthOrPercentage {
fn from_computed_value(computed: &CalcLengthOrPercentage) -> Self {
specified::CalcLengthOrPercentage {
clamping_mode: computed.clamping_mode,
absolute: Some(AbsoluteLength::from_computed_value(&computed.length.into())),
absolute: Some(AbsoluteLength::from_computed_value(&computed.length)),
percentage: computed.percentage,
..Default::default()
}
@ -368,7 +369,7 @@ impl LengthOrPercentage {
match *self {
Length(l) => (l, NotNaN::new(0.0).unwrap()),
Percentage(p) => (Au(0), NotNaN::new(p.0).unwrap()),
Calc(c) => (c.unclamped_length(), NotNaN::new(c.percentage()).unwrap()),
Calc(c) => (Au::from(c.unclamped_length()), NotNaN::new(c.percentage()).unwrap()),
}
}
@ -690,6 +691,11 @@ impl CSSPixelLength {
pub fn to_i32_au(&self) -> i32 {
Au::from(*self).0
}
/// Return the absolute value of this length.
pub fn abs(self) -> Self {
CSSPixelLength::new(self.0.abs())
}
}
impl ToCss for CSSPixelLength {
@ -700,6 +706,15 @@ impl ToCss for CSSPixelLength {
}
}
impl Neg for CSSPixelLength {
type Output = Self;
#[inline]
fn neg(self) -> Self {
CSSPixelLength::new(-self.0)
}
}
impl From<CSSPixelLength> for Au {
#[inline]
fn from(len: CSSPixelLength) -> Self {

View file

@ -74,7 +74,7 @@ impl TransformList {
match *lop {
LengthOrPercentage::Length(au) => au.to_f32_px(),
LengthOrPercentage::Percentage(_) => 0.,
LengthOrPercentage::Calc(calc) => calc.length().to_f32_px(),
LengthOrPercentage::Calc(calc) => calc.length().px(),
}
};

View file

@ -11,7 +11,7 @@ use parser::ParserContext;
use std::ascii::AsciiExt;
use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::values::specified::AllowedLengthType;
use style_traits::values::specified::AllowedNumericType;
use values::{CSSInteger, CSSFloat};
use values::computed;
use values::specified::{Angle, Time};
@ -67,7 +67,7 @@ pub enum CalcUnit {
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
pub struct CalcLengthOrPercentage {
pub clamping_mode: AllowedLengthType,
pub clamping_mode: AllowedNumericType,
pub absolute: Option<AbsoluteLength>,
pub vw: Option<CSSFloat>,
pub vh: Option<CSSFloat>,
@ -291,7 +291,7 @@ impl CalcNode {
/// Tries to simplify this expression into a `<length>` or `<percentage`>
/// value.
fn to_length_or_percentage(&self, clamping_mode: AllowedLengthType)
fn to_length_or_percentage(&self, clamping_mode: AllowedNumericType)
-> Result<CalcLengthOrPercentage, ()> {
let mut ret = CalcLengthOrPercentage {
clamping_mode: clamping_mode,
@ -565,7 +565,7 @@ impl CalcNode {
pub fn parse_length_or_percentage<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedLengthType
clamping_mode: AllowedNumericType
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
Self::parse(context, input, CalcUnit::LengthOrPercentage)?
.to_length_or_percentage(clamping_mode)
@ -586,7 +586,7 @@ impl CalcNode {
pub fn parse_length<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedLengthType
clamping_mode: AllowedNumericType
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
Self::parse(context, input, CalcUnit::Length)?
.to_length_or_percentage(clamping_mode)

View file

@ -15,7 +15,7 @@ use std::{cmp, fmt, mem};
use std::ascii::AsciiExt;
use std::ops::{Add, Mul};
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::values::specified::AllowedLengthType;
use style_traits::values::specified::AllowedNumericType;
use stylesheets::CssRuleType;
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, None_, Normal};
@ -642,7 +642,7 @@ impl Length {
#[inline]
fn parse_internal<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>,
num_context: AllowedLengthType,
num_context: AllowedNumericType,
allow_quirks: AllowQuirks)
-> Result<Length, ParseError<'i>> {
// FIXME: remove early returns when lifetimes are non-lexical
@ -683,7 +683,7 @@ impl Length {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks)
-> Result<Length, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
}
/// Get an absolute length from a px value.
@ -713,7 +713,7 @@ impl Length {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks)
-> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
}
}
@ -725,7 +725,7 @@ impl<T: Parse> Either<Length, T> {
if let Ok(v) = input.try(|input| T::parse(context, input)) {
return Ok(Either::Second(v));
}
Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No).map(Either::First)
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No).map(Either::First)
}
}
@ -752,7 +752,7 @@ impl<T: Parse> Parse for Either<NonNegativeLength, T> {
if let Ok(v) = input.try(|input| T::parse(context, input)) {
return Ok(Either::Second(v));
}
Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No)
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No)
.map(NonNegative::<Length>).map(Either::First)
}
}
@ -836,7 +836,7 @@ impl LengthOrPercentage {
fn parse_internal<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>,
num_context: AllowedLengthType,
num_context: AllowedNumericType,
allow_quirks: AllowQuirks)
-> Result<LengthOrPercentage, ParseError<'i>>
{
@ -885,7 +885,7 @@ impl LengthOrPercentage {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks)
-> Result<LengthOrPercentage, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
}
/// Parse a length, treating dimensionless numbers as pixels
@ -946,7 +946,7 @@ impl LengthOrPercentage {
pub fn parse_quirky<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks) -> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
}
}
@ -978,7 +978,7 @@ impl From<computed::Percentage> for LengthOrPercentageOrAuto {
impl LengthOrPercentageOrAuto {
fn parse_internal<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>,
num_context: AllowedLengthType,
num_context: AllowedNumericType,
allow_quirks: AllowQuirks)
-> Result<Self, ParseError<'i>> {
// FIXME: remove early returns when lifetimes are non-lexical
@ -1030,7 +1030,7 @@ impl LengthOrPercentageOrAuto {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks)
-> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
}
/// Returns the `auto` value.
@ -1063,7 +1063,7 @@ impl LengthOrPercentageOrAuto {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks)
-> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks)
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
}
}
@ -1081,7 +1081,7 @@ pub enum LengthOrPercentageOrNone {
impl LengthOrPercentageOrNone {
fn parse_internal<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>,
num_context: AllowedLengthType,
num_context: AllowedNumericType,
allow_quirks: AllowQuirks)
-> Result<LengthOrPercentageOrNone, ParseError<'i>>
{
@ -1133,14 +1133,14 @@ impl LengthOrPercentageOrNone {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks)
-> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks)
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
}
}
impl Parse for LengthOrPercentageOrNone {
#[inline]
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedLengthType::All, AllowQuirks::No)
Self::parse_internal(context, input, AllowedNumericType::All, AllowQuirks::No)
}
}

View file

@ -203,14 +203,15 @@ impl<S: Side> ToComputedValue for PositionComponent<S> {
match length.to_computed_value(context) {
ComputedLengthOrPercentage::Length(length) => {
ComputedLengthOrPercentage::Calc(
CalcLengthOrPercentage::new(-length, Some(Percentage::hundred())))
CalcLengthOrPercentage::new((-length).into(), Some(Percentage::hundred())))
},
ComputedLengthOrPercentage::Percentage(p) => {
ComputedLengthOrPercentage::Percentage(Percentage(1.0 - p.0))
},
ComputedLengthOrPercentage::Calc(calc) => {
let p = Percentage(1. - calc.percentage.map_or(0., |p| p.0));
ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(-calc.unclamped_length(), Some(p)))
let l = -calc.unclamped_length();
ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(l, Some(p)))
},
}
},

View file

@ -84,7 +84,7 @@ impl ToComputedValue for LineHeight {
#[inline]
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
use app_units::Au;
use values::computed::NonNegativeLength;
use values::specified::length::FontBaseSize;
match *self {
GenericLineHeight::Normal => {
@ -119,13 +119,13 @@ impl ToComputedValue for LineHeight {
.to_computed_value(
context,
FontBaseSize::CurrentStyle,
);
).px();
let absolute_length = computed_calc.unclamped_length();
computed_calc
let absolute_length = computed_calc.unclamped_length().px();
let pixel = computed_calc
.clamping_mode
.clamp(absolute_length + Au::from(font_relative_length))
.into()
.clamp(absolute_length + font_relative_length);
NonNegativeLength::new(pixel)
}
};
GenericLineHeight::Length(result)

View file

@ -469,49 +469,6 @@ macro_rules! __define_css_keyword_enum__actual {
/// Helper types for the handling of specified values.
pub mod specified {
use ParsingMode;
use app_units::Au;
use std::cmp;
/// Whether to allow negative lengths or not.
#[repr(u8)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AllowedLengthType {
/// Allow all kind of lengths.
All,
/// Allow only non-negative lengths.
NonNegative
}
impl Default for AllowedLengthType {
#[inline]
fn default() -> Self {
AllowedLengthType::All
}
}
impl AllowedLengthType {
/// Whether value is valid for this allowed length type.
#[inline]
pub fn is_ok(&self, parsing_mode: ParsingMode, value: f32) -> bool {
if parsing_mode.allows_all_numeric_values() {
return true;
}
match *self {
AllowedLengthType::All => true,
AllowedLengthType::NonNegative => value >= 0.,
}
}
/// Clamp the value following the rules of this numeric type.
#[inline]
pub fn clamp(&self, val: Au) -> Au {
match *self {
AllowedLengthType::All => val,
AllowedLengthType::NonNegative => cmp::max(Au(0), val),
}
}
}
/// Whether to allow negative lengths or not.
#[repr(u8)]
@ -526,6 +483,13 @@ pub mod specified {
AtLeastOne,
}
impl Default for AllowedNumericType {
#[inline]
fn default() -> Self {
AllowedNumericType::All
}
}
impl AllowedNumericType {
/// Whether the value fits the rules of this numeric type.
#[inline]

View file

@ -107,7 +107,7 @@ impl Zoom {
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Zoom, ParseError<'i>> {
use PARSING_MODE_DEFAULT;
use cssparser::Token;
use values::specified::AllowedLengthType::NonNegative;
use values::specified::AllowedNumericType::NonNegative;
match *input.next()? {
// TODO: This parse() method should take ParserContext as an

View file

@ -90,16 +90,18 @@ fn test_transform_interpolation_on_translate() {
Length::new(25.),
)]));
let to = TransformList(Some(vec![
TransformOperation::Translate(LengthOrPercentage::Length(Au(100)),
LengthOrPercentage::Length(Au(50)),
TransformOperation::Translate(LengthOrPercentage::Length(Au::from_px(100)),
LengthOrPercentage::Length(Au::from_px(50)),
Length::new(75.))]));
assert_eq!(
from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(),
TransformList(Some(vec![TransformOperation::Translate(
// calc(50px + 25%)
LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Au(50), Some(Percentage(0.25)))),
LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Length::new(50.),
Some(Percentage(0.25)))),
// calc(25px + 50%)
LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Au(25), Some(Percentage(0.5)))),
LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Length::new(25.),
Some(Percentage(0.5)))),
Length::new(50.),
)]))
);

View file

@ -8,12 +8,12 @@ use style::values::computed::{CalcLengthOrPercentage, Percentage};
#[test]
fn test_length_calc() {
let calc = CalcLengthOrPercentage::new(Au(10), Some(Percentage(0.2)));
let calc = CalcLengthOrPercentage::new(Au(10).into(), Some(Percentage(0.2)));
assert_eq!(calc.to_used_value(Some(Au(10))), Some(Au(12)));
assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_used_value(None), None);
let calc = CalcLengthOrPercentage::new(Au(10), None);
let calc = CalcLengthOrPercentage::new(Au(10).into(), None);
assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10)));
assert_eq!(calc.to_used_value(None), Some(Au(10)));
}