style: Use rust lengths for the SVG lengths.

As it turns out we need this to avoid losing precision both during painting and
during serialization.

This patch also changes to serialize `context-value` if it's the computed value.

I could keep the previous behavior, but it makes no sense to serialize the
initial value. We're the only ones to support this value anyway, and I couldn't
find a definition or spec for this.

Also update tests and expectations for:

 * New unexpected passes.
 * Always serializing the unit in getComputedStyle.
 * Calc and interpolation support.

Chrome also always serializes the unit in getComputedStyle, so I'm pretty sure
this is compatible with them. Chrome is inconsistent and keeps numbers in
specified style, but that's inconsistent with itself and with other quirky
lengths, so I updated the tests instead.

Differential Revision: https://phabricator.services.mozilla.com/D21819
This commit is contained in:
Emilio Cobos Álvarez 2019-03-02 02:09:19 +01:00
parent f1b5d5c06a
commit 94686df11b
2 changed files with 7 additions and 16 deletions

View file

@ -478,12 +478,12 @@ def set_gecko_property(ffi_name, expr):
}
}
};
self.gecko.${gecko_ffi_name}.set(length)
self.gecko.${gecko_ffi_name} = length;
}
pub fn copy_${ident}_from(&mut self, other: &Self) {
use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE;
self.gecko.${gecko_ffi_name}.copy_from(&other.gecko.${gecko_ffi_name});
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
self.gecko.mContextFlags =
(self.gecko.mContextFlags & !CONTEXT_VALUE) |
(other.gecko.mContextFlags & CONTEXT_VALUE);
@ -495,15 +495,11 @@ def set_gecko_property(ffi_name, expr):
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use crate::values::generics::svg::SVGLength;
use crate::values::computed::LengthPercentage;
use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE;
if (self.gecko.mContextFlags & CONTEXT_VALUE) != 0 {
return SVGLength::ContextValue;
}
// TODO(emilio): Use the Rust representation instead.
let length =
LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}).unwrap();
SVGLength::LengthPercentage(length.into())
SVGLength::LengthPercentage(self.gecko.${gecko_ffi_name})
}
</%def>
@ -4707,7 +4703,7 @@ clip-path
bindings::Gecko_nsStyleSVG_SetDashArrayLength(&mut self.gecko, v.len() as u32);
}
for (gecko, servo) in self.gecko.mStrokeDasharray.iter_mut().zip(v) {
gecko.set(servo)
*gecko = servo;
}
}
SVGStrokeDashArray::ContextValue => {
@ -4735,19 +4731,13 @@ clip-path
pub fn clone_stroke_dasharray(&self) -> longhands::stroke_dasharray::computed_value::T {
use crate::gecko_bindings::structs::nsStyleSVG_STROKE_DASHARRAY_CONTEXT as CONTEXT_VALUE;
use crate::values::computed::NonNegativeLengthPercentage;
use crate::values::generics::svg::SVGStrokeDashArray;
if self.gecko.mContextFlags & CONTEXT_VALUE != 0 {
debug_assert_eq!(self.gecko.mStrokeDasharray.len(), 0);
return SVGStrokeDashArray::ContextValue;
}
// TODO(emilio): Use the rust representation instead.
let mut vec = vec![];
for gecko in self.gecko.mStrokeDasharray.iter() {
vec.push(NonNegativeLengthPercentage::from_gecko_style_coord(gecko).unwrap());
}
SVGStrokeDashArray::Values(vec)
SVGStrokeDashArray::Values(self.gecko.mStrokeDasharray.iter().cloned().collect())
}
#[allow(non_snake_case)]

View file

@ -84,7 +84,8 @@ ${helpers.predefined_type(
)}
${helpers.predefined_type(
"stroke-width", "SVGWidth",
"stroke-width",
"SVGWidth",
"computed::SVGWidth::one()",
products="gecko",
animation_value_type="crate::values::computed::SVGWidth",