Bug 1367327 - stylo: compute and store SVG unitless length as a factor number. draft
authorJeremy Chen <jeremychen@mozilla.com>
Thu, 25 May 2017 11:36:26 +0800
changeset 584932 01850f3bec9eed32a3c69b7a05f3c6b54ca7782c
parent 584931 371bd6bdf9a9a0b1dca8f9d23440bda7fa08aecb
child 630575 c87d55786a1c3030ad929b19dd9b288b4b0f3ff3
push id60945
push userbmo:jeremychen@mozilla.com
push dateFri, 26 May 2017 08:03:32 +0000
bugs1367327
milestone55.0a1
Bug 1367327 - stylo: compute and store SVG unitless length as a factor number. There are 3 SVG properties that accept SVG unitless length, stroke-width, stroke-dasharray, and stroke-dashoffset. We compute and store SVG unitless length as a factor number for stroke-dasharray, but not for stroke-width and stroke-dashoffset. MozReview-Commit-ID: GxQYzOkjsb
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/inherited_svg.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -4008,17 +4008,17 @@ clip-path
             T::exclude => structs::NS_STYLE_MASK_COMPOSITE_EXCLUDE as u8,
         }
     </%self:simple_image_array_property>
 
     <% impl_shape_source("clip_path", "mClipPath") %>
 </%self:impl_trait>
 
 <%self:impl_trait style_struct_name="InheritedSVG"
-                  skip_longhands="paint-order stroke-dasharray"
+                  skip_longhands="paint-order stroke-dasharray stroke-dashoffset stroke-width"
                   skip_additionals="*">
     pub fn set_paint_order(&mut self, v: longhands::paint_order::computed_value::T) {
         use self::longhands::paint_order;
 
         if v.0 == 0 {
             self.gecko.mPaintOrder = structs::NS_STYLE_PAINT_ORDER_NORMAL as u8;
         } else {
             let mut order = 0;
@@ -4076,16 +4076,56 @@ clip-path
                     vec.push(Either::Second(LengthOrPercentage::Percentage(p))),
                 CoordDataValue::Calc(calc) =>
                     vec.push(Either::Second(LengthOrPercentage::Calc(calc.into()))),
                 _ => unreachable!(),
             }
         }
         longhands::stroke_dasharray::computed_value::T(vec)
     }
+
+    pub fn set_stroke_dashoffset(&mut self, v: longhands::stroke_dashoffset::computed_value::T) {
+        match v {
+            Either::First(number) => self.gecko.mStrokeDashoffset.set_value(CoordDataValue::Factor(number)),
+            Either::Second(lop) => self.gecko.mStrokeDashoffset.set(lop),
+        }
+    }
+
+    ${impl_coord_copy('stroke_dashoffset', 'mStrokeDashoffset')}
+
+    pub fn clone_stroke_dashoffset(&self) -> longhands::stroke_dashoffset::computed_value::T {
+        use values::computed::LengthOrPercentage;
+        match self.gecko.mStrokeDashoffset.as_value() {
+            CoordDataValue::Factor(number) => Either::First(number),
+            CoordDataValue::Coord(coord) => Either::Second(LengthOrPercentage::Length(Au(coord))),
+            CoordDataValue::Percent(p) => Either::Second(LengthOrPercentage::Percentage(p)),
+            CoordDataValue::Calc(calc) => Either::Second(LengthOrPercentage::Calc(calc.into())),
+            _ => unreachable!(),
+        }
+    }
+
+    pub fn set_stroke_width(&mut self, v: longhands::stroke_width::computed_value::T) {
+        match v {
+            Either::First(number) => self.gecko.mStrokeWidth.set_value(CoordDataValue::Factor(number)),
+            Either::Second(lop) => self.gecko.mStrokeWidth.set(lop),
+        }
+    }
+
+    ${impl_coord_copy('stroke_width', 'mStrokeWidth')}
+
+    pub fn clone_stroke_width(&self) -> longhands::stroke_width::computed_value::T {
+        use values::computed::LengthOrPercentage;
+        match self.gecko.mStrokeWidth.as_value() {
+            CoordDataValue::Factor(number) => Either::First(number),
+            CoordDataValue::Coord(coord) => Either::Second(LengthOrPercentage::Length(Au(coord))),
+            CoordDataValue::Percent(p) => Either::Second(LengthOrPercentage::Percentage(p)),
+            CoordDataValue::Calc(calc) => Either::Second(LengthOrPercentage::Calc(calc.into())),
+            _ => unreachable!(),
+        }
+    }
 </%self:impl_trait>
 
 <%self:impl_trait style_struct_name="Color"
                   skip_longhands="*">
     pub fn set_color(&mut self, v: longhands::color::computed_value::T) {
         let result = convert_rgba_to_nscolor(&v);
         ${set_gecko_property("mColor", "result")}
     }
--- a/servo/components/style/properties/longhand/inherited_svg.mako.rs
+++ b/servo/components/style/properties/longhand/inherited_svg.mako.rs
@@ -61,19 +61,19 @@
     "stroke", "SVGPaint",
     "Default::default()",
     products="gecko",
     animation_value_type="none",
     boxed=True,
     spec="https://www.w3.org/TR/SVG2/painting.html#SpecifyingStrokePaint")}
 
 ${helpers.predefined_type(
-    "stroke-width", "LengthOrPercentage",
-    "computed::LengthOrPercentage::one()",
-    "parse_numbers_are_pixels_non_negative",
+    "stroke-width", "LengthOrPercentageOrNumber",
+    "Either::First(1.0)",
+    "parse_non_negative",
     products="gecko",
     animation_value_type="ComputedValue",
     spec="https://www.w3.org/TR/SVG2/painting.html#StrokeWidth")}
 
 ${helpers.single_keyword("stroke-linecap", "butt round square",
                          products="gecko", animation_value_type="discrete",
                          spec="https://www.w3.org/TR/SVG11/painting.html#StrokeLinecapProperty")}
 
@@ -98,19 +98,18 @@
                           delegate_animate="True",
                           allow_empty="True",
                           products="gecko",
                           animation_value_type="ComputedValue",
                           space_separated_allowed="True",
                           spec="https://www.w3.org/TR/SVG2/painting.html#StrokeDashing")}
 
 ${helpers.predefined_type(
-    "stroke-dashoffset", "LengthOrPercentage",
-    "computed::LengthOrPercentage::zero()",
-    "parse_numbers_are_pixels",
+    "stroke-dashoffset", "LengthOrPercentageOrNumber",
+    "Either::First(0.0)",
     products="gecko",
     animation_value_type="ComputedValue",
     spec="https://www.w3.org/TR/SVG2/painting.html#StrokeDashing")}
 
 // Section 14 - Clipping, Masking and Compositing
 ${helpers.single_keyword("clip-rule", "nonzero evenodd",
                          products="gecko",
                          gecko_enum_prefix="StyleFillRule",