From 2c831119fe8f2488db7a80cc82544be4dcf9a495 Mon Sep 17 00:00:00 2001 From: Jinwoo Song Date: Mon, 1 Jun 2015 11:35:14 +0900 Subject: [PATCH] CSS 'transformation: skew()' should take type as parameters Current implementation is taking type as parameter so skew() does not work properly. Let the skew() to get as specification described. Fixes #6237. --- components/style/properties.mako.rs | 33 +++++++++++------- tests/ref/basic.list | 1 + tests/ref/transform_skew_a.html | 51 ++++++++++++++++++++++++++++ tests/ref/transform_skew_ref.html | 52 +++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 tests/ref/transform_skew_a.html create mode 100644 tests/ref/transform_skew_ref.html diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 69d14fad990b..11f3b63f6714 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -3167,9 +3167,9 @@ pub mod longhands { (*self).clone() } - pub fn skew(&mut self, sx: CSSFloat, sy: CSSFloat) { - *self = ComputedMatrix::new(1.0, sx, - sy, 1.0, + pub fn skew(&mut self, theta_x: CSSFloat, theta_y: CSSFloat) { + *self = ComputedMatrix::new(1.0, -theta_y.tan(), + -theta_x.tan(), 1.0, computed::LengthAndPercentage::zero(), computed::LengthAndPercentage::zero()) * (*self).clone() @@ -3259,13 +3259,22 @@ pub mod longhands { Ok((first, second)) } + fn parse_two_angles(input: &mut Parser) -> Result<(specified::Angle, specified::Angle),()> { + let first = try!(specified::Angle::parse(input)); + let second = input.try(|input| { + try!(input.expect_comma()); + specified::Angle::parse(input) + }).unwrap_or(specified::Angle(0.0)); + Ok((first, second)) + } + #[derive(Clone, Debug, PartialEq)] enum SpecifiedOperation { Matrix(SpecifiedMatrix), Translate(specified::LengthAndPercentage, specified::LengthAndPercentage), Scale(CSSFloat, CSSFloat), Rotate(specified::Angle), - Skew(CSSFloat, CSSFloat), + Skew(specified::Angle, specified::Angle), } impl ToCss for SpecifiedOperation { @@ -3388,22 +3397,22 @@ pub mod longhands { }, "skew" => { try!(input.parse_nested_block(|input| { - let (sx, sy) = try!(parse_two_floats(input)); - result.push(SpecifiedOperation::Skew(sx, sy)); + let (theta_x, theta_y) = try!(parse_two_angles(input)); + result.push(SpecifiedOperation::Skew(theta_x, theta_y)); Ok(()) })) }, "skewx" => { try!(input.parse_nested_block(|input| { - let sx = try!(input.expect_number()); - result.push(SpecifiedOperation::Skew(sx, 1.0)); + let theta_x = try!(specified::Angle::parse(input)); + result.push(SpecifiedOperation::Skew(theta_x, specified::Angle(0.0))); Ok(()) })) }, "skewy" => { try!(input.parse_nested_block(|input| { - let sy = try!(input.expect_number()); - result.push(SpecifiedOperation::Skew(1.0, sy)); + let theta_y = try!(specified::Angle::parse(input)); + result.push(SpecifiedOperation::Skew(specified::Angle(0.0), theta_y)); Ok(()) })) } @@ -3448,8 +3457,8 @@ pub mod longhands { SpecifiedOperation::Rotate(ref theta) => { result.rotate(f32::consts::PI_2 - theta.radians()); } - SpecifiedOperation::Skew(sx, sy) => { - result.skew(sx, sy) + SpecifiedOperation::Skew(ref theta_x, ref theta_y) => { + result.skew(f32::consts::PI_2 - theta_x.radians(), f32::consts::PI_2 - theta_y.radians()) } } } diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 4c3679508da4..78f7b2e5cc8d 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -313,6 +313,7 @@ flaky_cpu == linebreak_simple_a.html linebreak_simple_b.html == text_transform_none_a.html text_transform_none_ref.html == text_transform_uppercase_a.html text_transform_uppercase_ref.html == transform_simple_a.html transform_simple_ref.html +== transform_skew_a.html transform_skew_ref.html == transform_stacking_context_a.html transform_stacking_context_ref.html == upper_id_attr.html upper_id_attr_ref.html flaky_cpu,experimental == vertical-lr-blocks.html vertical-lr-blocks_ref.html diff --git a/tests/ref/transform_skew_a.html b/tests/ref/transform_skew_a.html new file mode 100644 index 000000000000..72ca47908808 --- /dev/null +++ b/tests/ref/transform_skew_a.html @@ -0,0 +1,51 @@ + + + + + + +

+

+
+
+

+ +

+

+
+
+

+ +

+

+
+
+

+ + diff --git a/tests/ref/transform_skew_ref.html b/tests/ref/transform_skew_ref.html new file mode 100644 index 000000000000..e006ae49c717 --- /dev/null +++ b/tests/ref/transform_skew_ref.html @@ -0,0 +1,52 @@ + + + + + + +

+

+
+
+

+ +

+

+
+
+

+ +

+

+
+
+

+ +