mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Rustfmt the new files
This commit is contained in:
parent
6415294fd5
commit
1c12e0ebc6
3 changed files with 246 additions and 206 deletions
|
@ -17,8 +17,15 @@ use values::generics::transform::TimingFunction as GenericTimingFunction;
|
||||||
use values::generics::transform::TransformOrigin as GenericTransformOrigin;
|
use values::generics::transform::TransformOrigin as GenericTransformOrigin;
|
||||||
|
|
||||||
/// A single operation in a computed CSS `transform`
|
/// A single operation in a computed CSS `transform`
|
||||||
pub type TransformOperation = GenericTransformOperation<Angle, Number, Length, Integer,
|
pub type TransformOperation = GenericTransformOperation<
|
||||||
LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrNumber>;
|
Angle,
|
||||||
|
Number,
|
||||||
|
Length,
|
||||||
|
Integer,
|
||||||
|
LengthOrNumber,
|
||||||
|
LengthOrPercentage,
|
||||||
|
LengthOrPercentageOrNumber,
|
||||||
|
>;
|
||||||
/// A computed CSS `transform`
|
/// A computed CSS `transform`
|
||||||
pub type Transform = GenericTransform<TransformOperation>;
|
pub type Transform = GenericTransform<TransformOperation>;
|
||||||
|
|
||||||
|
@ -52,6 +59,7 @@ pub type Matrix = GenericMatrix<Number>;
|
||||||
/// computed value of matrix() in -moz-transform
|
/// computed value of matrix() in -moz-transform
|
||||||
pub type PrefixedMatrix = GenericMatrix<Number, LengthOrPercentageOrNumber>;
|
pub type PrefixedMatrix = GenericMatrix<Number, LengthOrPercentageOrNumber>;
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl Matrix3D {
|
impl Matrix3D {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Get an identity matrix
|
/// Get an identity matrix
|
||||||
|
@ -81,6 +89,7 @@ impl Matrix3D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl PrefixedMatrix3D {
|
impl PrefixedMatrix3D {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Get an identity matrix
|
/// Get an identity matrix
|
||||||
|
@ -95,6 +104,7 @@ impl PrefixedMatrix3D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl Matrix {
|
impl Matrix {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Get an identity matrix
|
/// Get an identity matrix
|
||||||
|
@ -108,6 +118,7 @@ impl Matrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl From<Matrix> for Matrix3D {
|
impl From<Matrix> for Matrix3D {
|
||||||
fn from(m: Matrix) -> Self {
|
fn from(m: Matrix) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -119,6 +130,7 @@ impl From<Matrix> for Matrix3D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl PrefixedMatrix {
|
impl PrefixedMatrix {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Get an identity matrix
|
/// Get an identity matrix
|
||||||
|
@ -132,6 +144,7 @@ impl PrefixedMatrix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl From<Matrix3D> for Transform3D<CSSFloat> {
|
impl From<Matrix3D> for Transform3D<CSSFloat> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(m: Matrix3D) -> Self {
|
fn from(m: Matrix3D) -> Self {
|
||||||
|
@ -143,6 +156,7 @@ impl From<Matrix3D> for Transform3D<CSSFloat> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl From<Transform3D<CSSFloat>> for Matrix3D {
|
impl From<Transform3D<CSSFloat>> for Matrix3D {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(m: Transform3D<CSSFloat>) -> Self {
|
fn from(m: Transform3D<CSSFloat>) -> Self {
|
||||||
|
@ -155,6 +169,7 @@ impl From<Transform3D<CSSFloat>> for Matrix3D {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl From<Matrix> for Transform3D<CSSFloat> {
|
impl From<Matrix> for Transform3D<CSSFloat> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(m: Matrix) -> Self {
|
fn from(m: Matrix) -> Self {
|
||||||
|
@ -174,16 +189,23 @@ impl TransformOperation {
|
||||||
match *self {
|
match *self {
|
||||||
GenericTransformOperation::Translate3D(..) => self.clone(),
|
GenericTransformOperation::Translate3D(..) => self.clone(),
|
||||||
GenericTransformOperation::TranslateX(ref x) |
|
GenericTransformOperation::TranslateX(ref x) |
|
||||||
GenericTransformOperation::Translate(ref x, None) =>
|
GenericTransformOperation::Translate(ref x, None) => {
|
||||||
GenericTransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero()),
|
GenericTransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero())
|
||||||
GenericTransformOperation::Translate(ref x, Some(ref y)) =>
|
},
|
||||||
GenericTransformOperation::Translate3D(x.clone(), y.clone(), Length::zero()),
|
GenericTransformOperation::Translate(ref x, Some(ref y)) => {
|
||||||
GenericTransformOperation::TranslateY(ref y) =>
|
GenericTransformOperation::Translate3D(x.clone(), y.clone(), Length::zero())
|
||||||
GenericTransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero()),
|
},
|
||||||
GenericTransformOperation::TranslateZ(ref z) =>
|
GenericTransformOperation::TranslateY(ref y) => {
|
||||||
GenericTransformOperation::Translate3D(LengthOrPercentage::zero(),
|
GenericTransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero())
|
||||||
LengthOrPercentage::zero(), z.clone()),
|
},
|
||||||
_ => unreachable!()
|
GenericTransformOperation::TranslateZ(ref z) => {
|
||||||
|
GenericTransformOperation::Translate3D(
|
||||||
|
LengthOrPercentage::zero(),
|
||||||
|
LengthOrPercentage::zero(),
|
||||||
|
z.clone(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Convert to a Scale3D.
|
/// Convert to a Scale3D.
|
||||||
|
@ -197,7 +219,7 @@ impl TransformOperation {
|
||||||
GenericTransformOperation::ScaleX(x) => GenericTransformOperation::Scale3D(x, 1., 1.),
|
GenericTransformOperation::ScaleX(x) => GenericTransformOperation::Scale3D(x, 1., 1.),
|
||||||
GenericTransformOperation::ScaleY(y) => GenericTransformOperation::Scale3D(1., y, 1.),
|
GenericTransformOperation::ScaleY(y) => GenericTransformOperation::Scale3D(1., y, 1.),
|
||||||
GenericTransformOperation::ScaleZ(z) => GenericTransformOperation::Scale3D(1., 1., z),
|
GenericTransformOperation::ScaleZ(z) => GenericTransformOperation::Scale3D(1., 1., z),
|
||||||
_ => unreachable!()
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,17 +230,17 @@ impl TransformOperation {
|
||||||
impl ToAnimatedZero for TransformOperation {
|
impl ToAnimatedZero for TransformOperation {
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||||
match *self {
|
match *self {
|
||||||
GenericTransformOperation::Matrix3D(..) => {
|
GenericTransformOperation::Matrix3D(..) => Ok(GenericTransformOperation::Matrix3D(Matrix3D::identity())),
|
||||||
Ok(GenericTransformOperation::Matrix3D(Matrix3D::identity()))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::PrefixedMatrix3D(..) => {
|
GenericTransformOperation::PrefixedMatrix3D(..) => {
|
||||||
Ok(GenericTransformOperation::PrefixedMatrix3D(PrefixedMatrix3D::identity()))
|
Ok(GenericTransformOperation::PrefixedMatrix3D(
|
||||||
},
|
PrefixedMatrix3D::identity(),
|
||||||
GenericTransformOperation::Matrix(..) => {
|
))
|
||||||
Ok(GenericTransformOperation::Matrix(Matrix::identity()))
|
|
||||||
},
|
},
|
||||||
|
GenericTransformOperation::Matrix(..) => Ok(GenericTransformOperation::Matrix(Matrix::identity())),
|
||||||
GenericTransformOperation::PrefixedMatrix(..) => {
|
GenericTransformOperation::PrefixedMatrix(..) => {
|
||||||
Ok(GenericTransformOperation::PrefixedMatrix(PrefixedMatrix::identity()))
|
Ok(GenericTransformOperation::PrefixedMatrix(
|
||||||
|
PrefixedMatrix::identity(),
|
||||||
|
))
|
||||||
},
|
},
|
||||||
GenericTransformOperation::Skew(sx, sy) => {
|
GenericTransformOperation::Skew(sx, sy) => {
|
||||||
Ok(GenericTransformOperation::Skew(
|
Ok(GenericTransformOperation::Skew(
|
||||||
|
@ -226,16 +248,8 @@ impl ToAnimatedZero for TransformOperation {
|
||||||
sy.to_animated_zero()?,
|
sy.to_animated_zero()?,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
GenericTransformOperation::SkewX(s) => {
|
GenericTransformOperation::SkewX(s) => Ok(GenericTransformOperation::SkewX(s.to_animated_zero()?)),
|
||||||
Ok(GenericTransformOperation::SkewX(
|
GenericTransformOperation::SkewY(s) => Ok(GenericTransformOperation::SkewY(s.to_animated_zero()?)),
|
||||||
s.to_animated_zero()?,
|
|
||||||
))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::SkewY(s) => {
|
|
||||||
Ok(GenericTransformOperation::SkewY(
|
|
||||||
s.to_animated_zero()?,
|
|
||||||
))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::Translate3D(ref tx, ref ty, ref tz) => {
|
GenericTransformOperation::Translate3D(ref tx, ref ty, ref tz) => {
|
||||||
Ok(GenericTransformOperation::Translate3D(
|
Ok(GenericTransformOperation::Translate3D(
|
||||||
tx.to_animated_zero()?,
|
tx.to_animated_zero()?,
|
||||||
|
@ -250,54 +264,34 @@ impl ToAnimatedZero for TransformOperation {
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
GenericTransformOperation::TranslateX(ref t) => {
|
GenericTransformOperation::TranslateX(ref t) => {
|
||||||
Ok(GenericTransformOperation::TranslateX(
|
Ok(GenericTransformOperation::TranslateX(t.to_animated_zero()?))
|
||||||
t.to_animated_zero()?,
|
|
||||||
))
|
|
||||||
},
|
},
|
||||||
GenericTransformOperation::TranslateY(ref t) => {
|
GenericTransformOperation::TranslateY(ref t) => {
|
||||||
Ok(GenericTransformOperation::TranslateY(
|
Ok(GenericTransformOperation::TranslateY(t.to_animated_zero()?))
|
||||||
t.to_animated_zero()?,
|
|
||||||
))
|
|
||||||
},
|
},
|
||||||
GenericTransformOperation::TranslateZ(ref t) => {
|
GenericTransformOperation::TranslateZ(ref t) => {
|
||||||
Ok(GenericTransformOperation::TranslateZ(
|
Ok(GenericTransformOperation::TranslateZ(t.to_animated_zero()?))
|
||||||
t.to_animated_zero()?,
|
|
||||||
))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::Scale3D(..) => {
|
|
||||||
Ok(GenericTransformOperation::Scale3D(1.0, 1.0, 1.0))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::Scale(_, _) => {
|
|
||||||
Ok(GenericTransformOperation::Scale(1.0, Some(1.0)))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::ScaleX(..) => {
|
|
||||||
Ok(GenericTransformOperation::ScaleX(1.0))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::ScaleY(..) => {
|
|
||||||
Ok(GenericTransformOperation::ScaleY(1.0))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::ScaleZ(..) => {
|
|
||||||
Ok(GenericTransformOperation::ScaleZ(1.0))
|
|
||||||
},
|
},
|
||||||
|
GenericTransformOperation::Scale3D(..) => Ok(GenericTransformOperation::Scale3D(1.0, 1.0, 1.0)),
|
||||||
|
GenericTransformOperation::Scale(_, _) => Ok(GenericTransformOperation::Scale(1.0, Some(1.0))),
|
||||||
|
GenericTransformOperation::ScaleX(..) => Ok(GenericTransformOperation::ScaleX(1.0)),
|
||||||
|
GenericTransformOperation::ScaleY(..) => Ok(GenericTransformOperation::ScaleY(1.0)),
|
||||||
|
GenericTransformOperation::ScaleZ(..) => Ok(GenericTransformOperation::ScaleZ(1.0)),
|
||||||
GenericTransformOperation::Rotate3D(x, y, z, a) => {
|
GenericTransformOperation::Rotate3D(x, y, z, a) => {
|
||||||
let (x, y, z, _) = Transform::get_normalized_vector_and_angle(x, y, z, a);
|
let (x, y, z, _) = Transform::get_normalized_vector_and_angle(x, y, z, a);
|
||||||
Ok(GenericTransformOperation::Rotate3D(x, y, z, Angle::zero()))
|
Ok(GenericTransformOperation::Rotate3D(x, y, z, Angle::zero()))
|
||||||
},
|
},
|
||||||
GenericTransformOperation::RotateX(_) => {
|
GenericTransformOperation::RotateX(_) => Ok(GenericTransformOperation::RotateX(Angle::zero())),
|
||||||
Ok(GenericTransformOperation::RotateX(Angle::zero()))
|
GenericTransformOperation::RotateY(_) => Ok(GenericTransformOperation::RotateY(Angle::zero())),
|
||||||
},
|
GenericTransformOperation::RotateZ(_) => Ok(GenericTransformOperation::RotateZ(Angle::zero())),
|
||||||
GenericTransformOperation::RotateY(_) => {
|
GenericTransformOperation::Rotate(_) => Ok(GenericTransformOperation::Rotate(Angle::zero())),
|
||||||
Ok(GenericTransformOperation::RotateY(Angle::zero()))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::RotateZ(_) => {
|
|
||||||
Ok(GenericTransformOperation::RotateZ(Angle::zero()))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::Rotate(_) => {
|
|
||||||
Ok(GenericTransformOperation::Rotate(Angle::zero()))
|
|
||||||
},
|
|
||||||
GenericTransformOperation::Perspective(..) |
|
GenericTransformOperation::Perspective(..) |
|
||||||
GenericTransformOperation::AccumulateMatrix { .. } |
|
GenericTransformOperation::AccumulateMatrix {
|
||||||
GenericTransformOperation::InterpolateMatrix { .. } => {
|
..
|
||||||
|
} |
|
||||||
|
GenericTransformOperation::InterpolateMatrix {
|
||||||
|
..
|
||||||
|
} => {
|
||||||
// Perspective: We convert a perspective function into an equivalent
|
// Perspective: We convert a perspective function into an equivalent
|
||||||
// ComputedMatrix, and then decompose/interpolate/recompose these matrices.
|
// ComputedMatrix, and then decompose/interpolate/recompose these matrices.
|
||||||
// AccumulateMatrix/InterpolateMatrix: We do interpolation on
|
// AccumulateMatrix/InterpolateMatrix: We do interpolation on
|
||||||
|
@ -316,9 +310,10 @@ impl ToAnimatedZero for TransformOperation {
|
||||||
impl ToAnimatedZero for Transform {
|
impl ToAnimatedZero for Transform {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_animated_zero(&self) -> Result<Self, ()> {
|
fn to_animated_zero(&self) -> Result<Self, ()> {
|
||||||
Ok(GenericTransform(
|
Ok(GenericTransform(self.0
|
||||||
self.0.iter().map(|op| op.to_animated_zero()).collect::<Result<Vec<_>, _>>()?
|
.iter()
|
||||||
))
|
.map(|op| op.to_animated_zero())
|
||||||
|
.collect::<Result<Vec<_>, _>>()?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,150 +321,131 @@ impl Transform {
|
||||||
/// Return the equivalent 3d matrix of this transform list.
|
/// Return the equivalent 3d matrix of this transform list.
|
||||||
/// If |reference_box| is None, we will drop the percent part from translate because
|
/// If |reference_box| is None, we will drop the percent part from translate because
|
||||||
/// we can resolve it without the layout info.
|
/// we can resolve it without the layout info.
|
||||||
pub fn to_transform_3d_matrix(&self, reference_box: Option<&Rect<Au>>)
|
pub fn to_transform_3d_matrix(&self, reference_box: Option<&Rect<Au>>) -> Option<Transform3D<CSSFloat>> {
|
||||||
-> Option<Transform3D<CSSFloat>> {
|
|
||||||
let mut transform = Transform3D::identity();
|
let mut transform = Transform3D::identity();
|
||||||
let list = &self.0;
|
let list = &self.0;
|
||||||
if list.len() == 0 {
|
if list.len() == 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let extract_pixel_length = |lop: &LengthOrPercentage| {
|
let extract_pixel_length = |lop: &LengthOrPercentage| match *lop {
|
||||||
match *lop {
|
LengthOrPercentage::Length(px) => px.px(),
|
||||||
LengthOrPercentage::Length(px) => px.px(),
|
LengthOrPercentage::Percentage(_) => 0.,
|
||||||
LengthOrPercentage::Percentage(_) => 0.,
|
LengthOrPercentage::Calc(calc) => calc.length().px(),
|
||||||
LengthOrPercentage::Calc(calc) => calc.length().px(),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for operation in list {
|
for operation in list {
|
||||||
let matrix = match *operation {
|
let matrix = match *operation {
|
||||||
GenericTransformOperation::Rotate3D(ax, ay, az, theta) => {
|
GenericTransformOperation::Rotate3D(ax, ay, az, theta) => {
|
||||||
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
||||||
let (ax, ay, az, theta) =
|
let (ax, ay, az, theta) = Self::get_normalized_vector_and_angle(ax, ay, az, theta);
|
||||||
Self::get_normalized_vector_and_angle(ax, ay, az, theta);
|
|
||||||
Transform3D::create_rotation(ax, ay, az, theta.into())
|
Transform3D::create_rotation(ax, ay, az, theta.into())
|
||||||
}
|
},
|
||||||
GenericTransformOperation::RotateX(theta) => {
|
GenericTransformOperation::RotateX(theta) => {
|
||||||
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
||||||
Transform3D::create_rotation(1., 0., 0., theta.into())
|
Transform3D::create_rotation(1., 0., 0., theta.into())
|
||||||
}
|
},
|
||||||
GenericTransformOperation::RotateY(theta) => {
|
GenericTransformOperation::RotateY(theta) => {
|
||||||
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
||||||
Transform3D::create_rotation(0., 1., 0., theta.into())
|
Transform3D::create_rotation(0., 1., 0., theta.into())
|
||||||
}
|
},
|
||||||
GenericTransformOperation::RotateZ(theta) | GenericTransformOperation::Rotate(theta) => {
|
GenericTransformOperation::RotateZ(theta) |
|
||||||
|
GenericTransformOperation::Rotate(theta) => {
|
||||||
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
|
||||||
Transform3D::create_rotation(0., 0., 1., theta.into())
|
Transform3D::create_rotation(0., 0., 1., theta.into())
|
||||||
}
|
},
|
||||||
GenericTransformOperation::Perspective(d) => {
|
GenericTransformOperation::Perspective(d) => Self::create_perspective_matrix(d.px()),
|
||||||
Self::create_perspective_matrix(d.px())
|
GenericTransformOperation::Scale3D(sx, sy, sz) => Transform3D::create_scale(sx, sy, sz),
|
||||||
}
|
GenericTransformOperation::Scale(sx, sy) => Transform3D::create_scale(sx, sy.unwrap_or(sx), 1.),
|
||||||
GenericTransformOperation::Scale3D(sx, sy, sz) => {
|
GenericTransformOperation::ScaleX(s) => Transform3D::create_scale(s, 1., 1.),
|
||||||
Transform3D::create_scale(sx, sy, sz)
|
GenericTransformOperation::ScaleY(s) => Transform3D::create_scale(1., s, 1.),
|
||||||
}
|
GenericTransformOperation::ScaleZ(s) => Transform3D::create_scale(1., 1., s),
|
||||||
GenericTransformOperation::Scale(sx, sy) => {
|
|
||||||
Transform3D::create_scale(sx, sy.unwrap_or(sx), 1.)
|
|
||||||
}
|
|
||||||
GenericTransformOperation::ScaleX(s) => {
|
|
||||||
Transform3D::create_scale(s, s, 1.)
|
|
||||||
}
|
|
||||||
GenericTransformOperation::ScaleY(s) => {
|
|
||||||
Transform3D::create_scale(1., s, 1.)
|
|
||||||
}
|
|
||||||
GenericTransformOperation::ScaleZ(s) => {
|
|
||||||
Transform3D::create_scale(1., 1., s)
|
|
||||||
}
|
|
||||||
GenericTransformOperation::Translate3D(tx, ty, tz) => {
|
GenericTransformOperation::Translate3D(tx, ty, tz) => {
|
||||||
let (tx, ty) = match reference_box {
|
let (tx, ty) = match reference_box {
|
||||||
Some(relative_border_box) => {
|
Some(relative_border_box) => {
|
||||||
(tx.to_pixel_length(relative_border_box.size.width).px(),
|
(
|
||||||
ty.to_pixel_length(relative_border_box.size.height).px())
|
tx.to_pixel_length(relative_border_box.size.width).px(),
|
||||||
|
ty.to_pixel_length(relative_border_box.size.height).px(),
|
||||||
|
)
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
// If we don't have reference box, we cannot resolve the used value,
|
// If we don't have reference box, we cannot resolve the used value,
|
||||||
// so only retrieve the length part. This will be used for computing
|
// so only retrieve the length part. This will be used for computing
|
||||||
// distance without any layout info.
|
// distance without any layout info.
|
||||||
(extract_pixel_length(&tx), extract_pixel_length(&ty))
|
(extract_pixel_length(&tx), extract_pixel_length(&ty))
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
let tz = tz.px();
|
let tz = tz.px();
|
||||||
Transform3D::create_translation(tx, ty, tz)
|
Transform3D::create_translation(tx, ty, tz)
|
||||||
}
|
},
|
||||||
GenericTransformOperation::Translate(tx, Some(ty)) => {
|
GenericTransformOperation::Translate(tx, Some(ty)) => {
|
||||||
let (tx, ty) = match reference_box {
|
let (tx, ty) = match reference_box {
|
||||||
Some(relative_border_box) => {
|
Some(relative_border_box) => {
|
||||||
(tx.to_pixel_length(relative_border_box.size.width).px(),
|
(
|
||||||
ty.to_pixel_length(relative_border_box.size.height).px())
|
tx.to_pixel_length(relative_border_box.size.width).px(),
|
||||||
|
ty.to_pixel_length(relative_border_box.size.height).px(),
|
||||||
|
)
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
// If we don't have reference box, we cannot resolve the used value,
|
// If we don't have reference box, we cannot resolve the used value,
|
||||||
// so only retrieve the length part. This will be used for computing
|
// so only retrieve the length part. This will be used for computing
|
||||||
// distance without any layout info.
|
// distance without any layout info.
|
||||||
(extract_pixel_length(&tx), extract_pixel_length(&ty))
|
(extract_pixel_length(&tx), extract_pixel_length(&ty))
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
Transform3D::create_translation(tx, ty, 0.)
|
Transform3D::create_translation(tx, ty, 0.)
|
||||||
}
|
},
|
||||||
GenericTransformOperation::TranslateX(t) | GenericTransformOperation::Translate(t, None) => {
|
GenericTransformOperation::TranslateX(t) |
|
||||||
|
GenericTransformOperation::Translate(t, None) => {
|
||||||
let t = match reference_box {
|
let t = match reference_box {
|
||||||
Some(relative_border_box) => {
|
Some(relative_border_box) => t.to_pixel_length(relative_border_box.size.width).px(),
|
||||||
t.to_pixel_length(relative_border_box.size.width).px()
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
// If we don't have reference box, we cannot resolve the used value,
|
// If we don't have reference box, we cannot resolve the used value,
|
||||||
// so only retrieve the length part. This will be used for computing
|
// so only retrieve the length part. This will be used for computing
|
||||||
// distance without any layout info.
|
// distance without any layout info.
|
||||||
extract_pixel_length(&t)
|
extract_pixel_length(&t)
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
Transform3D::create_translation(t, 0., 0.)
|
Transform3D::create_translation(t, 0., 0.)
|
||||||
}
|
},
|
||||||
GenericTransformOperation::TranslateY(t) => {
|
GenericTransformOperation::TranslateY(t) => {
|
||||||
let t = match reference_box {
|
let t = match reference_box {
|
||||||
Some(relative_border_box) => {
|
Some(relative_border_box) => t.to_pixel_length(relative_border_box.size.height).px(),
|
||||||
t.to_pixel_length(relative_border_box.size.height).px()
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
// If we don't have reference box, we cannot resolve the used value,
|
// If we don't have reference box, we cannot resolve the used value,
|
||||||
// so only retrieve the length part. This will be used for computing
|
// so only retrieve the length part. This will be used for computing
|
||||||
// distance without any layout info.
|
// distance without any layout info.
|
||||||
extract_pixel_length(&t)
|
extract_pixel_length(&t)
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
Transform3D::create_translation(0., t, 0.)
|
Transform3D::create_translation(0., t, 0.)
|
||||||
}
|
},
|
||||||
GenericTransformOperation::TranslateZ(z) => {
|
GenericTransformOperation::TranslateZ(z) => Transform3D::create_translation(0., 0., z.px()),
|
||||||
Transform3D::create_translation(0., 0., z.px())
|
|
||||||
}
|
|
||||||
GenericTransformOperation::Skew(theta_x, theta_y) => {
|
GenericTransformOperation::Skew(theta_x, theta_y) => {
|
||||||
Transform3D::create_skew(theta_x.into(), theta_y.unwrap_or(Angle::zero()).into())
|
Transform3D::create_skew(theta_x.into(), theta_y.unwrap_or(Angle::zero()).into())
|
||||||
}
|
},
|
||||||
GenericTransformOperation::SkewX(theta) => {
|
GenericTransformOperation::SkewX(theta) => Transform3D::create_skew(theta.into(), Angle::zero().into()),
|
||||||
Transform3D::create_skew(theta.into(), Angle::zero().into())
|
GenericTransformOperation::SkewY(theta) => Transform3D::create_skew(Angle::zero().into(), theta.into()),
|
||||||
}
|
GenericTransformOperation::Matrix3D(m) => m.into(),
|
||||||
GenericTransformOperation::SkewY(theta) => {
|
GenericTransformOperation::Matrix(m) => m.into(),
|
||||||
Transform3D::create_skew(Angle::zero().into(), theta.into())
|
GenericTransformOperation::PrefixedMatrix3D(_) |
|
||||||
}
|
GenericTransformOperation::PrefixedMatrix(_) => {
|
||||||
GenericTransformOperation::Matrix3D(m) => {
|
|
||||||
m.into()
|
|
||||||
}
|
|
||||||
GenericTransformOperation::Matrix(m) => {
|
|
||||||
m.into()
|
|
||||||
}
|
|
||||||
GenericTransformOperation::PrefixedMatrix3D(_) | GenericTransformOperation::PrefixedMatrix(_) => {
|
|
||||||
// `-moz-transform` is not implemented in Servo yet.
|
// `-moz-transform` is not implemented in Servo yet.
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
},
|
||||||
GenericTransformOperation::InterpolateMatrix { .. } |
|
GenericTransformOperation::InterpolateMatrix {
|
||||||
GenericTransformOperation::AccumulateMatrix { .. } => {
|
..
|
||||||
|
} |
|
||||||
|
GenericTransformOperation::AccumulateMatrix {
|
||||||
|
..
|
||||||
|
} => {
|
||||||
// TODO: Convert InterpolateMatrix/AccmulateMatrix into a valid Transform3D by
|
// TODO: Convert InterpolateMatrix/AccmulateMatrix into a valid Transform3D by
|
||||||
// the reference box and do interpolation on these two Transform3D matrices.
|
// the reference box and do interpolation on these two Transform3D matrices.
|
||||||
// Both Gecko and Servo don't support this for computing distance, and Servo
|
// Both Gecko and Servo don't support this for computing distance, and Servo
|
||||||
// doesn't support animations on InterpolateMatrix/AccumulateMatrix, so
|
// doesn't support animations on InterpolateMatrix/AccumulateMatrix, so
|
||||||
// return None.
|
// return None.
|
||||||
return None;
|
return None;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
transform = transform.pre_mul(&matrix);
|
transform = transform.pre_mul(&matrix);
|
||||||
|
@ -496,8 +472,7 @@ impl Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the normalized direction vector and its angle for Rotate3D.
|
/// Return the normalized direction vector and its angle for Rotate3D.
|
||||||
pub fn get_normalized_vector_and_angle(x: f32, y: f32, z: f32, angle: Angle)
|
pub fn get_normalized_vector_and_angle(x: f32, y: f32, z: f32, angle: Angle) -> (f32, f32, f32, Angle) {
|
||||||
-> (f32, f32, f32, Angle) {
|
|
||||||
use euclid::approxeq::ApproxEq;
|
use euclid::approxeq::ApproxEq;
|
||||||
use euclid::num::Zero;
|
use euclid::num::Zero;
|
||||||
let vector = DirectionVector::new(x, y, z);
|
let vector = DirectionVector::new(x, y, z);
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub struct Matrix<T, U = T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
pub struct Matrix3D<T, U = T, V = T> {
|
pub struct Matrix3D<T, U = T, V = T> {
|
||||||
pub m11: T, pub m12: T, pub m13: T, pub m14: T,
|
pub m11: T, pub m12: T, pub m13: T, pub m14: T,
|
||||||
|
@ -51,7 +52,12 @@ pub enum TimingFunction<Integer, Number> {
|
||||||
Keyword(TimingKeyword),
|
Keyword(TimingKeyword),
|
||||||
/// `cubic-bezier(<number>, <number>, <number>, <number>)`
|
/// `cubic-bezier(<number>, <number>, <number>, <number>)`
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
CubicBezier { x1: Number, y1: Number, x2: Number, y2: Number },
|
CubicBezier {
|
||||||
|
x1: Number,
|
||||||
|
y1: Number,
|
||||||
|
x2: Number,
|
||||||
|
y2: Number,
|
||||||
|
},
|
||||||
/// `step-start | step-end | steps(<integer>, [ start | end ]?)`
|
/// `step-start | step-end | steps(<integer>, [ start | end ]?)`
|
||||||
Steps(Integer, StepPosition),
|
Steps(Integer, StepPosition),
|
||||||
/// `frames(<integer>)`
|
/// `frames(<integer>)`
|
||||||
|
@ -103,7 +109,12 @@ where
|
||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
TimingFunction::Keyword(keyword) => keyword.to_css(dest),
|
TimingFunction::Keyword(keyword) => keyword.to_css(dest),
|
||||||
TimingFunction::CubicBezier { ref x1, ref y1, ref x2, ref y2 } => {
|
TimingFunction::CubicBezier {
|
||||||
|
ref x1,
|
||||||
|
ref y1,
|
||||||
|
ref x2,
|
||||||
|
ref y2,
|
||||||
|
} => {
|
||||||
dest.write_str("cubic-bezier(")?;
|
dest.write_str("cubic-bezier(")?;
|
||||||
x1.to_css(dest)?;
|
x1.to_css(dest)?;
|
||||||
dest.write_str(", ")?;
|
dest.write_str(", ")?;
|
||||||
|
@ -223,23 +234,63 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthOrNumber, Leng
|
||||||
Perspective(Length),
|
Perspective(Length),
|
||||||
/// A intermediate type for interpolation of mismatched transform lists.
|
/// A intermediate type for interpolation of mismatched transform lists.
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
InterpolateMatrix { #[compute(ignore_bound)]
|
InterpolateMatrix {
|
||||||
from_list: Transform<TransformOperation<Angle, Number, Length, Integer,
|
#[compute(ignore_bound)]
|
||||||
LengthOrNumber, LengthOrPercentage, LoPoNumber>>,
|
from_list: Transform<
|
||||||
#[compute(ignore_bound)]
|
TransformOperation<
|
||||||
to_list: Transform<TransformOperation<Angle, Number, Length, Integer,
|
Angle,
|
||||||
LengthOrNumber, LengthOrPercentage, LoPoNumber>>,
|
Number,
|
||||||
#[compute(clone)] progress: computed::Percentage },
|
Length,
|
||||||
|
Integer,
|
||||||
|
LengthOrNumber,
|
||||||
|
LengthOrPercentage,
|
||||||
|
LoPoNumber,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
#[compute(ignore_bound)]
|
||||||
|
to_list: Transform<
|
||||||
|
TransformOperation<
|
||||||
|
Angle,
|
||||||
|
Number,
|
||||||
|
Length,
|
||||||
|
Integer,
|
||||||
|
LengthOrNumber,
|
||||||
|
LengthOrPercentage,
|
||||||
|
LoPoNumber,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
#[compute(clone)]
|
||||||
|
progress: computed::Percentage,
|
||||||
|
},
|
||||||
/// A intermediate type for accumulation of mismatched transform lists.
|
/// A intermediate type for accumulation of mismatched transform lists.
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
AccumulateMatrix {
|
||||||
AccumulateMatrix { #[compute(ignore_bound)]
|
#[compute(ignore_bound)]
|
||||||
from_list: Transform<TransformOperation<Angle, Number, Length, Integer,
|
from_list: Transform<
|
||||||
LengthOrNumber, LengthOrPercentage, LoPoNumber>>,
|
TransformOperation<
|
||||||
#[compute(ignore_bound)]
|
Angle,
|
||||||
to_list: Transform<TransformOperation<Angle, Number, Length, Integer,
|
Number,
|
||||||
LengthOrNumber, LengthOrPercentage, LoPoNumber>>,
|
Length,
|
||||||
count: Integer },
|
Integer,
|
||||||
|
LengthOrNumber,
|
||||||
|
LengthOrPercentage,
|
||||||
|
LoPoNumber,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
#[compute(ignore_bound)]
|
||||||
|
to_list: Transform<
|
||||||
|
TransformOperation<
|
||||||
|
Angle,
|
||||||
|
Number,
|
||||||
|
Length,
|
||||||
|
Integer,
|
||||||
|
LengthOrNumber,
|
||||||
|
LengthOrPercentage,
|
||||||
|
LoPoNumber,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
count: Integer,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Animate, ToComputedValue)]
|
#[derive(Animate, ToComputedValue)]
|
||||||
|
@ -254,7 +305,7 @@ impl<Angle, Number, Length, Integer, LengthOrNumber, LengthOrPercentage, LoPoNum
|
||||||
use self::TransformOperation::*;
|
use self::TransformOperation::*;
|
||||||
match *self {
|
match *self {
|
||||||
Translate(..) | Translate3D(..) | TranslateX(..) | TranslateY(..) | TranslateZ(..) => true,
|
Translate(..) | Translate3D(..) | TranslateX(..) | TranslateY(..) | TranslateZ(..) => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,11 +314,12 @@ impl<Angle, Number, Length, Integer, LengthOrNumber, LengthOrPercentage, LoPoNum
|
||||||
use self::TransformOperation::*;
|
use self::TransformOperation::*;
|
||||||
match *self {
|
match *self {
|
||||||
Scale(..) | Scale3D(..) | ScaleX(..) | ScaleY(..) | ScaleZ(..) => true,
|
Scale(..) | Scale3D(..) | ScaleX(..) | ScaleY(..) | ScaleZ(..) => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
impl<Angle: ToCss + Copy, Number: ToCss + Copy, Length: ToCss,
|
impl<Angle: ToCss + Copy, Number: ToCss + Copy, Length: ToCss,
|
||||||
Integer: ToCss + Copy, LengthOrNumber: ToCss, LengthOrPercentage: ToCss, LoPoNumber: ToCss>
|
Integer: ToCss + Copy, LengthOrNumber: ToCss, LengthOrPercentage: ToCss, LoPoNumber: ToCss>
|
||||||
ToCss for
|
ToCss for
|
||||||
|
@ -379,9 +431,12 @@ impl<Angle: ToCss + Copy, Number: ToCss + Copy, Length: ToCss,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ToCss> ToCss for Transform<T> {
|
impl<T: ToCss> ToCss for Transform<T> {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: fmt::Write,
|
||||||
|
{
|
||||||
if self.0.is_empty() {
|
if self.0.is_empty() {
|
||||||
return dest.write_str("none")
|
return dest.write_str("none");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
|
|
|
@ -20,8 +20,15 @@ use values::specified::{LengthOrNumber, LengthOrPercentage, LengthOrPercentageOr
|
||||||
use values::specified::position::{Side, X, Y};
|
use values::specified::position::{Side, X, Y};
|
||||||
|
|
||||||
/// A single operation in a specified CSS `transform`
|
/// A single operation in a specified CSS `transform`
|
||||||
pub type TransformOperation = GenericTransformOperation<Angle, Number, Length, Integer,
|
pub type TransformOperation = GenericTransformOperation<
|
||||||
LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrNumber>;
|
Angle,
|
||||||
|
Number,
|
||||||
|
Length,
|
||||||
|
Integer,
|
||||||
|
LengthOrNumber,
|
||||||
|
LengthOrPercentage,
|
||||||
|
LengthOrPercentageOrNumber,
|
||||||
|
>;
|
||||||
/// A specified CSS `transform`
|
/// A specified CSS `transform`
|
||||||
pub type Transform = GenericTransform<TransformOperation>;
|
pub type Transform = GenericTransform<TransformOperation>;
|
||||||
|
|
||||||
|
@ -39,15 +46,19 @@ impl Transform {
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
use style_traits::{Separator, Space};
|
use style_traits::{Separator, Space};
|
||||||
|
|
||||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
if input
|
||||||
return Ok(GenericTransform(Vec::new()))
|
.try(|input| input.expect_ident_matching("none"))
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
return Ok(GenericTransform(Vec::new()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(GenericTransform(Space::parse(input, |input| {
|
Ok(GenericTransform(Space::parse(input, |input| {
|
||||||
let function = input.expect_function()?.clone();
|
let function = input.expect_function()?.clone();
|
||||||
input.parse_nested_block(|input| {
|
input.parse_nested_block(|input| {
|
||||||
let location = input.current_source_location();
|
let location = input.current_source_location();
|
||||||
let result = match_ignore_ascii_case! { &function,
|
let result =
|
||||||
|
match_ignore_ascii_case! { &function,
|
||||||
"matrix" => {
|
"matrix" => {
|
||||||
let a = specified::parse_number(context, input)?;
|
let a = specified::parse_number(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
|
@ -260,7 +271,9 @@ pub type TimingFunction = GenericTimingFunction<Integer, Number>;
|
||||||
impl Parse for TransformOrigin {
|
impl Parse for TransformOrigin {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let parse_depth = |input: &mut Parser| {
|
let parse_depth = |input: &mut Parser| {
|
||||||
input.try(|i| Length::parse(context, i)).unwrap_or(Length::from_px(0.))
|
input.try(|i| Length::parse(context, i)).unwrap_or(
|
||||||
|
Length::from_px(0.),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
match input.try(|i| OriginComponent::parse(context, i)) {
|
match input.try(|i| OriginComponent::parse(context, i)) {
|
||||||
Ok(x_origin @ OriginComponent::Center) => {
|
Ok(x_origin @ OriginComponent::Center) => {
|
||||||
|
@ -307,7 +320,8 @@ impl Parse for TransformOrigin {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Parse for OriginComponent<S>
|
impl<S> Parse for OriginComponent<S>
|
||||||
where S: Parse,
|
where
|
||||||
|
S: Parse,
|
||||||
{
|
{
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
if input.try(|i| i.expect_ident_matching("center")).is_ok() {
|
if input.try(|i| i.expect_ident_matching("center")).is_ok() {
|
||||||
|
@ -322,18 +336,15 @@ impl<S> Parse for OriginComponent<S>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> ToComputedValue for OriginComponent<S>
|
impl<S> ToComputedValue for OriginComponent<S>
|
||||||
where S: Side,
|
where
|
||||||
|
S: Side,
|
||||||
{
|
{
|
||||||
type ComputedValue = ComputedLengthOrPercentage;
|
type ComputedValue = ComputedLengthOrPercentage;
|
||||||
|
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||||
match *self {
|
match *self {
|
||||||
OriginComponent::Center => {
|
OriginComponent::Center => ComputedLengthOrPercentage::Percentage(ComputedPercentage(0.5)),
|
||||||
ComputedLengthOrPercentage::Percentage(ComputedPercentage(0.5))
|
OriginComponent::Length(ref length) => length.to_computed_value(context),
|
||||||
},
|
|
||||||
OriginComponent::Length(ref length) => {
|
|
||||||
length.to_computed_value(context)
|
|
||||||
},
|
|
||||||
OriginComponent::Side(ref keyword) => {
|
OriginComponent::Side(ref keyword) => {
|
||||||
let p = ComputedPercentage(if keyword.is_start() { 0. } else { 1. });
|
let p = ComputedPercentage(if keyword.is_start() { 0. } else { 1. });
|
||||||
ComputedLengthOrPercentage::Percentage(p)
|
ComputedLengthOrPercentage::Percentage(p)
|
||||||
|
@ -362,7 +373,9 @@ fn allow_frames_timing() -> bool {
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn allow_frames_timing() -> bool { true }
|
fn allow_frames_timing() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
impl Parse for TimingFunction {
|
impl Parse for TimingFunction {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
|
@ -370,7 +383,8 @@ impl Parse for TimingFunction {
|
||||||
return Ok(GenericTimingFunction::Keyword(keyword));
|
return Ok(GenericTimingFunction::Keyword(keyword));
|
||||||
}
|
}
|
||||||
if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
|
if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
|
||||||
let position = match_ignore_ascii_case! { &ident,
|
let position =
|
||||||
|
match_ignore_ascii_case! { &ident,
|
||||||
"step-start" => StepPosition::Start,
|
"step-start" => StepPosition::Start,
|
||||||
"step-end" => StepPosition::End,
|
"step-end" => StepPosition::End,
|
||||||
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))),
|
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))),
|
||||||
|
@ -424,10 +438,13 @@ impl ToComputedValue for TimingFunction {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||||
match *self {
|
match *self {
|
||||||
GenericTimingFunction::Keyword(keyword) => {
|
GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(keyword),
|
||||||
GenericTimingFunction::Keyword(keyword)
|
GenericTimingFunction::CubicBezier {
|
||||||
},
|
x1,
|
||||||
GenericTimingFunction::CubicBezier { x1, y1, x2, y2 } => {
|
y1,
|
||||||
|
x2,
|
||||||
|
y2,
|
||||||
|
} => {
|
||||||
GenericTimingFunction::CubicBezier {
|
GenericTimingFunction::CubicBezier {
|
||||||
x1: x1.to_computed_value(context),
|
x1: x1.to_computed_value(context),
|
||||||
y1: y1.to_computed_value(context),
|
y1: y1.to_computed_value(context),
|
||||||
|
@ -436,15 +453,10 @@ impl ToComputedValue for TimingFunction {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GenericTimingFunction::Steps(steps, position) => {
|
GenericTimingFunction::Steps(steps, position) => {
|
||||||
GenericTimingFunction::Steps(
|
GenericTimingFunction::Steps(steps.to_computed_value(context) as u32, position)
|
||||||
steps.to_computed_value(context) as u32,
|
|
||||||
position,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
GenericTimingFunction::Frames(frames) => {
|
GenericTimingFunction::Frames(frames) => {
|
||||||
GenericTimingFunction::Frames(
|
GenericTimingFunction::Frames(frames.to_computed_value(context) as u32)
|
||||||
frames.to_computed_value(context) as u32,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -452,10 +464,13 @@ impl ToComputedValue for TimingFunction {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||||
match *computed {
|
match *computed {
|
||||||
GenericTimingFunction::Keyword(keyword) => {
|
GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(keyword),
|
||||||
GenericTimingFunction::Keyword(keyword)
|
GenericTimingFunction::CubicBezier {
|
||||||
},
|
ref x1,
|
||||||
GenericTimingFunction::CubicBezier { ref x1, ref y1, ref x2, ref y2 } => {
|
ref y1,
|
||||||
|
ref x2,
|
||||||
|
ref y2,
|
||||||
|
} => {
|
||||||
GenericTimingFunction::CubicBezier {
|
GenericTimingFunction::CubicBezier {
|
||||||
x1: Number::from_computed_value(x1),
|
x1: Number::from_computed_value(x1),
|
||||||
y1: Number::from_computed_value(y1),
|
y1: Number::from_computed_value(y1),
|
||||||
|
@ -464,15 +479,10 @@ impl ToComputedValue for TimingFunction {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GenericTimingFunction::Steps(steps, position) => {
|
GenericTimingFunction::Steps(steps, position) => {
|
||||||
GenericTimingFunction::Steps(
|
GenericTimingFunction::Steps(Integer::from_computed_value(&(steps as i32)), position)
|
||||||
Integer::from_computed_value(&(steps as i32)),
|
|
||||||
position,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
GenericTimingFunction::Frames(frames) => {
|
GenericTimingFunction::Frames(frames) => {
|
||||||
GenericTimingFunction::Frames(
|
GenericTimingFunction::Frames(Integer::from_computed_value(&(frames as i32)))
|
||||||
Integer::from_computed_value(&(frames as i32)),
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue