From ce9f1ed1438dd07422fe93962bdc0bdecd387c9a Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Fri, 8 Sep 2017 18:08:20 +0800 Subject: [PATCH] Fix extremely small pixel value for transform on Servo. Sometimes, we want to use extremely small pixel value in transform, e.g. translate(calc(0.001px)), which should be rendered correctly together with scale(100000). This patch only fixes this case for Servo because Stylo still uses Au on the Gecko side, even if we pass pixel value into FFI directly in the previous patch. --- components/style/values/computed/length.rs | 25 +++++++++++++------ components/style/values/computed/transform.rs | 4 +-- .../html/transform-rounding-001.htm.ini | 3 --- 3 files changed, 20 insertions(+), 12 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-transforms-1_dev/html/transform-rounding-001.htm.ini diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 211c341d721..a83e86bd1e6 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -128,21 +128,27 @@ impl CalcLengthOrPercentage { self.length } + /// Return the percentage value as CSSFloat. #[inline] - #[allow(missing_docs)] pub fn percentage(&self) -> CSSFloat { self.percentage.map_or(0., |p| p.0) } + /// Convert the computed value into used value. + #[inline] + pub fn to_used_value(&self, container_len: Option) -> Option { + self.to_pixel_length(container_len).map(Au::from) + } + /// If there are special rules for computing percentages in a value (e.g. the height property), /// they apply whenever a calc() expression contains percentages. - pub fn to_used_value(&self, container_len: Option) -> Option { + pub fn to_pixel_length(&self, container_len: Option) -> Option { match (container_len, self.percentage) { (Some(len), Some(percent)) => { let pixel = self.length.px() + len.scale_by(percent.0).to_f32_px(); - Some(Au::from_f32_px(self.clamping_mode.clamp(pixel))) + Some(Length::new(self.clamping_mode.clamp(pixel))) }, - (_, None) => Some(Au::from(self.length())), + (_, None) => Some(self.length()), _ => None, } } @@ -377,11 +383,16 @@ impl LengthOrPercentage { /// Returns the used value. pub fn to_used_value(&self, containing_length: Au) -> Au { + Au::from(self.to_pixel_length(containing_length)) + } + + /// Returns the used value as CSSPixelLength. + pub fn to_pixel_length(&self, containing_length: Au) -> Length { match *self { - LengthOrPercentage::Length(length) => Au::from(length), - LengthOrPercentage::Percentage(p) => containing_length.scale_by(p.0), + LengthOrPercentage::Length(length) => length, + LengthOrPercentage::Percentage(p) => containing_length.scale_by(p.0).into(), LengthOrPercentage::Calc(ref calc) => { - calc.to_used_value(Some(containing_length)).unwrap() + calc.to_pixel_length(Some(containing_length)).unwrap() }, } } diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index 1923902b958..21c98c50d99 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -95,8 +95,8 @@ impl TransformList { ComputedOperation::Translate(tx, ty, tz) => { let (tx, ty) = match reference_box { Some(relative_border_box) => { - (tx.to_used_value(relative_border_box.size.width).to_f32_px(), - ty.to_used_value(relative_border_box.size.height).to_f32_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, diff --git a/tests/wpt/metadata-css/css-transforms-1_dev/html/transform-rounding-001.htm.ini b/tests/wpt/metadata-css/css-transforms-1_dev/html/transform-rounding-001.htm.ini deleted file mode 100644 index c8859a8ce3f..00000000000 --- a/tests/wpt/metadata-css/css-transforms-1_dev/html/transform-rounding-001.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[transform-rounding-001.htm] - type: reftest - expected: FAIL