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