Rustfmt the new files

This commit is contained in:
Manish Goregaokar 2017-11-01 15:37:24 -07:00
parent 6415294fd5
commit 1c12e0ebc6
No known key found for this signature in database
GPG key ID: 3BBF4D3E2EF79F98
3 changed files with 246 additions and 206 deletions

View file

@ -17,8 +17,15 @@ use values::generics::transform::TimingFunction as GenericTimingFunction;
use values::generics::transform::TransformOrigin as GenericTransformOrigin;
/// A single operation in a computed CSS `transform`
pub type TransformOperation = GenericTransformOperation<Angle, Number, Length, Integer,
LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrNumber>;
pub type TransformOperation = GenericTransformOperation<
Angle,
Number,
Length,
Integer,
LengthOrNumber,
LengthOrPercentage,
LengthOrPercentageOrNumber,
>;
/// A computed CSS `transform`
pub type Transform = GenericTransform<TransformOperation>;
@ -52,6 +59,7 @@ pub type Matrix = GenericMatrix<Number>;
/// computed value of matrix() in -moz-transform
pub type PrefixedMatrix = GenericMatrix<Number, LengthOrPercentageOrNumber>;
#[cfg_attr(rustfmt, rustfmt_skip)]
impl Matrix3D {
#[inline]
/// Get an identity matrix
@ -81,6 +89,7 @@ impl Matrix3D {
}
}
#[cfg_attr(rustfmt, rustfmt_skip)]
impl PrefixedMatrix3D {
#[inline]
/// Get an identity matrix
@ -95,6 +104,7 @@ impl PrefixedMatrix3D {
}
}
#[cfg_attr(rustfmt, rustfmt_skip)]
impl Matrix {
#[inline]
/// Get an identity matrix
@ -108,6 +118,7 @@ impl Matrix {
}
}
#[cfg_attr(rustfmt, rustfmt_skip)]
impl From<Matrix> for Matrix3D {
fn from(m: Matrix) -> Self {
Self {
@ -119,6 +130,7 @@ impl From<Matrix> for Matrix3D {
}
}
#[cfg_attr(rustfmt, rustfmt_skip)]
impl PrefixedMatrix {
#[inline]
/// Get an identity matrix
@ -132,6 +144,7 @@ impl PrefixedMatrix {
}
}
#[cfg_attr(rustfmt, rustfmt_skip)]
impl From<Matrix3D> for Transform3D<CSSFloat> {
#[inline]
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 {
#[inline]
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> {
#[inline]
fn from(m: Matrix) -> Self {
@ -174,16 +189,23 @@ impl TransformOperation {
match *self {
GenericTransformOperation::Translate3D(..) => self.clone(),
GenericTransformOperation::TranslateX(ref x) |
GenericTransformOperation::Translate(ref x, None) =>
GenericTransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero()),
GenericTransformOperation::Translate(ref x, Some(ref y)) =>
GenericTransformOperation::Translate3D(x.clone(), y.clone(), Length::zero()),
GenericTransformOperation::TranslateY(ref y) =>
GenericTransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero()),
GenericTransformOperation::TranslateZ(ref z) =>
GenericTransformOperation::Translate3D(LengthOrPercentage::zero(),
LengthOrPercentage::zero(), z.clone()),
_ => unreachable!()
GenericTransformOperation::Translate(ref x, None) => {
GenericTransformOperation::Translate3D(x.clone(), LengthOrPercentage::zero(), Length::zero())
},
GenericTransformOperation::Translate(ref x, Some(ref y)) => {
GenericTransformOperation::Translate3D(x.clone(), y.clone(), Length::zero())
},
GenericTransformOperation::TranslateY(ref y) => {
GenericTransformOperation::Translate3D(LengthOrPercentage::zero(), y.clone(), Length::zero())
},
GenericTransformOperation::TranslateZ(ref z) => {
GenericTransformOperation::Translate3D(
LengthOrPercentage::zero(),
LengthOrPercentage::zero(),
z.clone(),
)
},
_ => unreachable!(),
}
}
/// Convert to a Scale3D.
@ -197,7 +219,7 @@ impl TransformOperation {
GenericTransformOperation::ScaleX(x) => GenericTransformOperation::Scale3D(x, 1., 1.),
GenericTransformOperation::ScaleY(y) => GenericTransformOperation::Scale3D(1., y, 1.),
GenericTransformOperation::ScaleZ(z) => GenericTransformOperation::Scale3D(1., 1., z),
_ => unreachable!()
_ => unreachable!(),
}
}
}
@ -208,17 +230,17 @@ impl TransformOperation {
impl ToAnimatedZero for TransformOperation {
fn to_animated_zero(&self) -> Result<Self, ()> {
match *self {
GenericTransformOperation::Matrix3D(..) => {
Ok(GenericTransformOperation::Matrix3D(Matrix3D::identity()))
},
GenericTransformOperation::Matrix3D(..) => Ok(GenericTransformOperation::Matrix3D(Matrix3D::identity())),
GenericTransformOperation::PrefixedMatrix3D(..) => {
Ok(GenericTransformOperation::PrefixedMatrix3D(PrefixedMatrix3D::identity()))
},
GenericTransformOperation::Matrix(..) => {
Ok(GenericTransformOperation::Matrix(Matrix::identity()))
Ok(GenericTransformOperation::PrefixedMatrix3D(
PrefixedMatrix3D::identity(),
))
},
GenericTransformOperation::Matrix(..) => Ok(GenericTransformOperation::Matrix(Matrix::identity())),
GenericTransformOperation::PrefixedMatrix(..) => {
Ok(GenericTransformOperation::PrefixedMatrix(PrefixedMatrix::identity()))
Ok(GenericTransformOperation::PrefixedMatrix(
PrefixedMatrix::identity(),
))
},
GenericTransformOperation::Skew(sx, sy) => {
Ok(GenericTransformOperation::Skew(
@ -226,16 +248,8 @@ impl ToAnimatedZero for TransformOperation {
sy.to_animated_zero()?,
))
},
GenericTransformOperation::SkewX(s) => {
Ok(GenericTransformOperation::SkewX(
s.to_animated_zero()?,
))
},
GenericTransformOperation::SkewY(s) => {
Ok(GenericTransformOperation::SkewY(
s.to_animated_zero()?,
))
},
GenericTransformOperation::SkewX(s) => Ok(GenericTransformOperation::SkewX(s.to_animated_zero()?)),
GenericTransformOperation::SkewY(s) => Ok(GenericTransformOperation::SkewY(s.to_animated_zero()?)),
GenericTransformOperation::Translate3D(ref tx, ref ty, ref tz) => {
Ok(GenericTransformOperation::Translate3D(
tx.to_animated_zero()?,
@ -250,54 +264,34 @@ impl ToAnimatedZero for TransformOperation {
))
},
GenericTransformOperation::TranslateX(ref t) => {
Ok(GenericTransformOperation::TranslateX(
t.to_animated_zero()?,
))
Ok(GenericTransformOperation::TranslateX(t.to_animated_zero()?))
},
GenericTransformOperation::TranslateY(ref t) => {
Ok(GenericTransformOperation::TranslateY(
t.to_animated_zero()?,
))
Ok(GenericTransformOperation::TranslateY(t.to_animated_zero()?))
},
GenericTransformOperation::TranslateZ(ref t) => {
Ok(GenericTransformOperation::TranslateZ(
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))
Ok(GenericTransformOperation::TranslateZ(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::Rotate3D(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()))
},
GenericTransformOperation::RotateX(_) => {
Ok(GenericTransformOperation::RotateX(Angle::zero()))
},
GenericTransformOperation::RotateY(_) => {
Ok(GenericTransformOperation::RotateY(Angle::zero()))
},
GenericTransformOperation::RotateZ(_) => {
Ok(GenericTransformOperation::RotateZ(Angle::zero()))
},
GenericTransformOperation::Rotate(_) => {
Ok(GenericTransformOperation::Rotate(Angle::zero()))
},
GenericTransformOperation::RotateX(_) => Ok(GenericTransformOperation::RotateX(Angle::zero())),
GenericTransformOperation::RotateY(_) => Ok(GenericTransformOperation::RotateY(Angle::zero())),
GenericTransformOperation::RotateZ(_) => Ok(GenericTransformOperation::RotateZ(Angle::zero())),
GenericTransformOperation::Rotate(_) => Ok(GenericTransformOperation::Rotate(Angle::zero())),
GenericTransformOperation::Perspective(..) |
GenericTransformOperation::AccumulateMatrix { .. } |
GenericTransformOperation::InterpolateMatrix { .. } => {
GenericTransformOperation::AccumulateMatrix {
..
} |
GenericTransformOperation::InterpolateMatrix {
..
} => {
// Perspective: We convert a perspective function into an equivalent
// ComputedMatrix, and then decompose/interpolate/recompose these matrices.
// AccumulateMatrix/InterpolateMatrix: We do interpolation on
@ -316,9 +310,10 @@ impl ToAnimatedZero for TransformOperation {
impl ToAnimatedZero for Transform {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
Ok(GenericTransform(
self.0.iter().map(|op| op.to_animated_zero()).collect::<Result<Vec<_>, _>>()?
))
Ok(GenericTransform(self.0
.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.
/// If |reference_box| is None, we will drop the percent part from translate because
/// we can resolve it without the layout info.
pub fn to_transform_3d_matrix(&self, reference_box: Option<&Rect<Au>>)
-> Option<Transform3D<CSSFloat>> {
pub fn to_transform_3d_matrix(&self, reference_box: Option<&Rect<Au>>) -> Option<Transform3D<CSSFloat>> {
let mut transform = Transform3D::identity();
let list = &self.0;
if list.len() == 0 {
return None;
}
let extract_pixel_length = |lop: &LengthOrPercentage| {
match *lop {
LengthOrPercentage::Length(px) => px.px(),
LengthOrPercentage::Percentage(_) => 0.,
LengthOrPercentage::Calc(calc) => calc.length().px(),
}
let extract_pixel_length = |lop: &LengthOrPercentage| match *lop {
LengthOrPercentage::Length(px) => px.px(),
LengthOrPercentage::Percentage(_) => 0.,
LengthOrPercentage::Calc(calc) => calc.length().px(),
};
for operation in list {
let matrix = match *operation {
GenericTransformOperation::Rotate3D(ax, ay, az, theta) => {
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
let (ax, ay, az, theta) =
Self::get_normalized_vector_and_angle(ax, ay, az, theta);
let (ax, ay, az, theta) = Self::get_normalized_vector_and_angle(ax, ay, az, theta);
Transform3D::create_rotation(ax, ay, az, theta.into())
}
},
GenericTransformOperation::RotateX(theta) => {
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
Transform3D::create_rotation(1., 0., 0., theta.into())
}
},
GenericTransformOperation::RotateY(theta) => {
let theta = Angle::from_radians(2.0f32 * f32::consts::PI - theta.radians());
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());
Transform3D::create_rotation(0., 0., 1., theta.into())
}
GenericTransformOperation::Perspective(d) => {
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::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::Perspective(d) => 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::ScaleX(s) => Transform3D::create_scale(s, 1., 1.),
GenericTransformOperation::ScaleY(s) => Transform3D::create_scale(1., s, 1.),
GenericTransformOperation::ScaleZ(s) => Transform3D::create_scale(1., 1., s),
GenericTransformOperation::Translate3D(tx, ty, tz) => {
let (tx, ty) = match reference_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 => {
// 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
// distance without any layout info.
(extract_pixel_length(&tx), extract_pixel_length(&ty))
}
},
};
let tz = tz.px();
Transform3D::create_translation(tx, ty, tz)
}
},
GenericTransformOperation::Translate(tx, Some(ty)) => {
let (tx, ty) = match reference_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 => {
// 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
// distance without any layout info.
(extract_pixel_length(&tx), extract_pixel_length(&ty))
}
},
};
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 {
Some(relative_border_box) => {
t.to_pixel_length(relative_border_box.size.width).px()
},
Some(relative_border_box) => t.to_pixel_length(relative_border_box.size.width).px(),
None => {
// 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
// distance without any layout info.
extract_pixel_length(&t)
}
},
};
Transform3D::create_translation(t, 0., 0.)
}
},
GenericTransformOperation::TranslateY(t) => {
let t = match reference_box {
Some(relative_border_box) => {
t.to_pixel_length(relative_border_box.size.height).px()
},
Some(relative_border_box) => t.to_pixel_length(relative_border_box.size.height).px(),
None => {
// 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
// distance without any layout info.
extract_pixel_length(&t)
}
},
};
Transform3D::create_translation(0., t, 0.)
}
GenericTransformOperation::TranslateZ(z) => {
Transform3D::create_translation(0., 0., z.px())
}
},
GenericTransformOperation::TranslateZ(z) => Transform3D::create_translation(0., 0., z.px()),
GenericTransformOperation::Skew(theta_x, theta_y) => {
Transform3D::create_skew(theta_x.into(), theta_y.unwrap_or(Angle::zero()).into())
}
GenericTransformOperation::SkewX(theta) => {
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::Matrix(m) => {
m.into()
}
GenericTransformOperation::PrefixedMatrix3D(_) | GenericTransformOperation::PrefixedMatrix(_) => {
},
GenericTransformOperation::SkewX(theta) => 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::Matrix(m) => m.into(),
GenericTransformOperation::PrefixedMatrix3D(_) |
GenericTransformOperation::PrefixedMatrix(_) => {
// `-moz-transform` is not implemented in Servo yet.
unreachable!()
}
GenericTransformOperation::InterpolateMatrix { .. } |
GenericTransformOperation::AccumulateMatrix { .. } => {
},
GenericTransformOperation::InterpolateMatrix {
..
} |
GenericTransformOperation::AccumulateMatrix {
..
} => {
// TODO: Convert InterpolateMatrix/AccmulateMatrix into a valid Transform3D by
// the reference box and do interpolation on these two Transform3D matrices.
// Both Gecko and Servo don't support this for computing distance, and Servo
// doesn't support animations on InterpolateMatrix/AccumulateMatrix, so
// return None.
return None;
}
},
};
transform = transform.pre_mul(&matrix);
@ -496,8 +472,7 @@ impl Transform {
}
/// 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)
-> (f32, f32, f32, Angle) {
pub fn get_normalized_vector_and_angle(x: f32, y: f32, z: f32, angle: Angle) -> (f32, f32, f32, Angle) {
use euclid::approxeq::ApproxEq;
use euclid::num::Zero;
let vector = DirectionVector::new(x, y, z);