Skip to content

Commit

Permalink
style: Fix the default behavior of scale:<number>{1}.
Browse files Browse the repository at this point in the history
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 8, 2018
1 parent 264a679 commit 23f2e99
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
46 changes: 31 additions & 15 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -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.),
}
}
}
Expand All @@ -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)?,
))
}
}

Expand Down
7 changes: 4 additions & 3 deletions components/style/values/computed/transform.rs
Expand Up @@ -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))
},
Expand All @@ -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"),
}
Expand Down
33 changes: 29 additions & 4 deletions components/style/values/generics/transform.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/specified/transform.rs
Expand Up @@ -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.