Permalink
Browse files

style: Fix the default behavior of scale:<number>{1}.

The current spec says: "If only the X value is given, the Y value
defaults to the same value.", so we should update the behavior.

Besides, we also update the serialization, so we serialization both
specified and computed value by servo. We enable the preference
for all the css-transforms, so some of them are passed now.

Differential Revision: https://phabricator.services.mozilla.com/D10638
  • Loading branch information...
BorisChiou authored and emilio committed Nov 6, 2018
1 parent 264a679 commit 23f2e99e9966200d07d187c0cacbe3b9f6f47185
@@ -2212,7 +2212,6 @@ impl ComputedScale {
Scale::None => (1.0, 1.0, 1.0),
Scale::Scale3D(sx, sy, sz) => (sx, sy, sz),
Scale::Scale(sx, sy) => (sx, sy, 1.),
Scale::ScaleX(sx) => (sx, 1., 1.),
}
}
}
@@ -2224,21 +2223,38 @@ impl Animate for ComputedScale {
other: &Self,
procedure: Procedure,
) -> Result<Self, ()> {
let from = ComputedScale::resolve(self);
let to = ComputedScale::resolve(other);
// FIXME(emilio, bug 1464791): why does this do something different than
// Scale3D / TransformOperation::Scale3D?
if procedure == Procedure::Add {
// scale(x1,y1,z1)*scale(x2,y2,z2) = scale(x1*x2, y1*y2, z1*z2)
return Ok(Scale::Scale3D(from.0 * to.0, from.1 * to.1, from.2 * to.2));
match (self, other) {
(&Scale::None, &Scale::None) => Ok(Scale::None),
(&Scale::Scale3D(_, ..), _) | (_, &Scale::Scale3D(_, ..)) => {
let from = ComputedScale::resolve(self);
let to = ComputedScale::resolve(other);
// FIXME(emilio, bug 1464791): why does this do something different than
// Scale3D / TransformOperation::Scale3D?
if procedure == Procedure::Add {
// scale(x1,y1,z1)*scale(x2,y2,z2) = scale(x1*x2, y1*y2, z1*z2)
return Ok(Scale::Scale3D(from.0 * to.0, from.1 * to.1, from.2 * to.2));
}
Ok(Scale::Scale3D(
animate_multiplicative_factor(from.0, to.0, procedure)?,
animate_multiplicative_factor(from.1, to.1, procedure)?,
animate_multiplicative_factor(from.2, to.2, procedure)?,
))
},
(&Scale::Scale(_, ..), _) | (_, &Scale::Scale(_, ..)) => {
let from = ComputedScale::resolve(self);
let to = ComputedScale::resolve(other);
// FIXME(emilio, bug 1464791): why does this do something different than
// Scale / TransformOperation::Scale?
if procedure == Procedure::Add {
// scale(x1,y1)*scale(x2,y2) = scale(x1*x2, y1*y2)
return Ok(Scale::Scale(from.0 * to.0, from.1 * to.1));
}
Ok(Scale::Scale(
animate_multiplicative_factor(from.0, to.0, procedure)?,
animate_multiplicative_factor(from.1, to.1, procedure)?,
))
},
}
Ok(Scale::Scale3D(
animate_multiplicative_factor(from.0, to.0, procedure)?,
animate_multiplicative_factor(from.1, to.1, procedure)?,
animate_multiplicative_factor(from.2, to.2, procedure)?,
))
}
}
@@ -367,8 +367,9 @@ impl Scale {
pub fn to_transform_operation(&self) -> Option<TransformOperation> {
match *self {
generic::Scale::None => None,
generic::Scale::ScaleX(sx) => Some(generic::TransformOperation::ScaleX(sx)),
generic::Scale::Scale(sx, sy) => Some(generic::TransformOperation::Scale(sx, Some(sy))),
generic::Scale::Scale(sx, sy) => {
Some(generic::TransformOperation::Scale(sx, Some(sy)))
},
generic::Scale::Scale3D(sx, sy, sz) => {
Some(generic::TransformOperation::Scale3D(sx, sy, sz))
},
@@ -378,8 +379,8 @@ impl Scale {
/// Convert Scale to TransformOperation.
pub fn from_transform_operation(operation: &TransformOperation) -> Scale {
match *operation {
generic::TransformOperation::ScaleX(sx) => generic::Scale::ScaleX(sx),
generic::TransformOperation::Scale(sx, Some(sy)) => generic::Scale::Scale(sx, sy),
generic::TransformOperation::Scale(sx, None) => generic::Scale::Scale(sx, sx),
generic::TransformOperation::Scale3D(sx, sy, sz) => generic::Scale::Scale3D(sx, sy, sz),
_ => unreachable!("Found unexpected value for scale"),
}
@@ -7,6 +7,8 @@
use app_units::Au;
use euclid::{self, Rect, Transform3D};
use num_traits::Zero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
use values::computed::length::Length as ComputedLength;
use values::computed::length::LengthOrPercentage as ComputedLengthOrPercentage;
use values::specified::angle::Angle as SpecifiedAngle;
@@ -560,22 +562,45 @@ pub enum Rotate<Number, Angle> {
SpecifiedValueInfo,
ToAnimatedZero,
ToComputedValue,
ToCss,
)]
/// A value of the `Scale` property
///
/// <https://drafts.csswg.org/css-transforms-2/#individual-transforms>
pub enum Scale<Number> {
/// 'none'
None,
/// '<number>'
ScaleX(Number),
/// '<number>{2}'
/// '<number>{1,2}'
Scale(Number, Number),
/// '<number>{3}'
Scale3D(Number, Number, Number),
}
impl<Number: ToCss + PartialEq> ToCss for Scale<Number> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
match self {
&Scale::None => dest.write_str("none"),
&Scale::Scale(ref x, ref y) => {
x.to_css(dest)?;
if x != y {
dest.write_char(' ')?;
y.to_css(dest)?;
}
Ok(())
},
&Scale::Scale3D(ref x, ref y, ref z) => {
x.to_css(dest)?;
dest.write_char(' ')?;
y.to_css(dest)?;
dest.write_char(' ')?;
z.to_css(dest)
},
}
}
}
#[derive(
Clone,
ComputeSquaredDistance,
@@ -423,6 +423,6 @@ impl Parse for Scale {
}
// 'scale: <number>'
Ok(generic::Scale::ScaleX(sx))
Ok(generic::Scale::Scale(sx, sx))
}
}

0 comments on commit 23f2e99

Please sign in to comment.