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.
This commit is contained in:
Boris Chiou 2017-09-08 18:08:20 +08:00
parent b89286e8e7
commit ce9f1ed143
3 changed files with 20 additions and 12 deletions

View file

@ -128,21 +128,27 @@ impl CalcLengthOrPercentage {
self.length self.length
} }
/// Return the percentage value as CSSFloat.
#[inline] #[inline]
#[allow(missing_docs)]
pub fn percentage(&self) -> CSSFloat { pub fn percentage(&self) -> CSSFloat {
self.percentage.map_or(0., |p| p.0) 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<Au>) -> Option<Au> {
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), /// If there are special rules for computing percentages in a value (e.g. the height property),
/// they apply whenever a calc() expression contains percentages. /// they apply whenever a calc() expression contains percentages.
pub fn to_used_value(&self, container_len: Option<Au>) -> Option<Au> { pub fn to_pixel_length(&self, container_len: Option<Au>) -> Option<Length> {
match (container_len, self.percentage) { match (container_len, self.percentage) {
(Some(len), Some(percent)) => { (Some(len), Some(percent)) => {
let pixel = self.length.px() + len.scale_by(percent.0).to_f32_px(); 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, _ => None,
} }
} }
@ -377,11 +383,16 @@ impl LengthOrPercentage {
/// Returns the used value. /// Returns the used value.
pub fn to_used_value(&self, containing_length: Au) -> Au { 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 { match *self {
LengthOrPercentage::Length(length) => Au::from(length), LengthOrPercentage::Length(length) => length,
LengthOrPercentage::Percentage(p) => containing_length.scale_by(p.0), LengthOrPercentage::Percentage(p) => containing_length.scale_by(p.0).into(),
LengthOrPercentage::Calc(ref calc) => { LengthOrPercentage::Calc(ref calc) => {
calc.to_used_value(Some(containing_length)).unwrap() calc.to_pixel_length(Some(containing_length)).unwrap()
}, },
} }
} }

View file

@ -95,8 +95,8 @@ impl TransformList {
ComputedOperation::Translate(tx, ty, tz) => { ComputedOperation::Translate(tx, ty, tz) => {
let (tx, ty) = match reference_box { let (tx, ty) = match reference_box {
Some(relative_border_box) => { Some(relative_border_box) => {
(tx.to_used_value(relative_border_box.size.width).to_f32_px(), (tx.to_pixel_length(relative_border_box.size.width).px(),
ty.to_used_value(relative_border_box.size.height).to_f32_px()) ty.to_pixel_length(relative_border_box.size.height).px())
}, },
None => { None => {
// If we don't have reference box, we cannot resolve the used value, // If we don't have reference box, we cannot resolve the used value,

View file

@ -1,3 +0,0 @@
[transform-rounding-001.htm]
type: reftest
expected: FAIL