From 94686df11babb96c4dbfb9afc7d6801a6d8f92bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 2 Mar 2019 02:09:19 +0100 Subject: [PATCH] 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 --- components/style/properties/gecko.mako.rs | 20 +++++-------------- .../longhands/inherited_svg.mako.rs | 3 ++- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 1c8fb3121b3..9ee8ab3c656 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -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}) } @@ -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)] diff --git a/components/style/properties/longhands/inherited_svg.mako.rs b/components/style/properties/longhands/inherited_svg.mako.rs index fcd16833b5f..35d0a02aab2 100644 --- a/components/style/properties/longhands/inherited_svg.mako.rs +++ b/components/style/properties/longhands/inherited_svg.mako.rs @@ -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",