Bug 1354437 - stylo: Make border-spacing animatable. draft
authorJeremy Chen <jeremychen@mozilla.com>
Wed, 26 Apr 2017 20:46:34 +0800
changeset 568663 a6232f0377c8878e56efec141b6ac809b497b5cf
parent 568509 0f5ba06c4c5959030a05cb852656d854065e2226
child 568664 d3a9393c8a588ed82e856f0cefa8bed8608401d6
push id55946
push userjichen@mozilla.com
push dateWed, 26 Apr 2017 12:47:10 +0000
bugs1354437
milestone55.0a1
Bug 1354437 - stylo: Make border-spacing animatable. Two things are included in this patch: 1. Implement ComputeDistance for border-spacing, so we could get the right distance while doing animations. 2. Implement clone function for gecko glue code of border-spacing, so we could make animations of border-spacing work properly in stylo build. MozReview-Commit-ID: CPfpDNrOSyt
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/inherited_table.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -3211,16 +3211,23 @@ fn static_assert() {
         self.gecko.mBorderSpacingCol = v.horizontal.0;
         self.gecko.mBorderSpacingRow = v.vertical.0;
     }
 
     pub fn copy_border_spacing_from(&mut self, other: &Self) {
         self.gecko.mBorderSpacingCol = other.gecko.mBorderSpacingCol;
         self.gecko.mBorderSpacingRow = other.gecko.mBorderSpacingRow;
     }
+
+    pub fn clone_border_spacing(&self) -> longhands::border_spacing::computed_value::T {
+        longhands::border_spacing::computed_value::T {
+            horizontal: Au(self.gecko.mBorderSpacingCol),
+            vertical: Au(self.gecko.mBorderSpacingRow)
+        }
+    }
 </%self:impl_trait>
 
 
 <%self:impl_trait style_struct_name="InheritedText"
                   skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing
                                   -webkit-text-stroke-width text-emphasis-position -moz-tab-size -moz-text-size-adjust">
 
     <% text_align_keyword = Keyword("text-align", "start end left right center justify -moz-center -moz-left " +
--- a/servo/components/style/properties/longhand/inherited_table.mako.rs
+++ b/servo/components/style/properties/longhand/inherited_table.mako.rs
@@ -15,26 +15,26 @@
                          animation_value_type="none",
                          spec="https://drafts.csswg.org/css-tables/#propdef-empty-cells")}
 ${helpers.single_keyword("caption-side", "top bottom",
                          extra_gecko_values="right left top-outside bottom-outside",
                          needs_conversion="True",
                          animation_value_type="none",
                          spec="https://drafts.csswg.org/css-tables/#propdef-caption-side")}
 
-<%helpers:longhand name="border-spacing" animation_value_type="none" boxed="True"
+<%helpers:longhand name="border-spacing" animation_value_type="ComputedValue" boxed="True"
                    spec="https://drafts.csswg.org/css-tables/#propdef-border-spacing">
     use app_units::Au;
     use std::fmt;
     use style_traits::ToCss;
     use values::HasViewportPercentage;
 
     pub mod computed_value {
         use app_units::Au;
-        use properties::animated_properties::Interpolate;
+        use properties::animated_properties::{ComputeDistance, Interpolate};
 
         #[derive(Clone, Copy, Debug, PartialEq)]
         #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
         pub struct T {
             pub horizontal: Au,
             pub vertical: Au,
         }
 
@@ -43,16 +43,29 @@
             #[inline]
             fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
                 Ok(T {
                     horizontal: try!(self.horizontal.interpolate(&other.horizontal, time)),
                     vertical: try!(self.vertical.interpolate(&other.vertical, time)),
                 })
             }
         }
+
+        impl ComputeDistance for T {
+            #[inline]
+            fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
+                self.compute_squared_distance(other).map(|sd| sd.sqrt())
+            }
+
+            #[inline]
+            fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
+                Ok(try!(self.horizontal.compute_squared_distance(&other.horizontal)) +
+                   try!(self.vertical.compute_squared_distance(&other.vertical)))
+            }
+        }
     }
 
     impl HasViewportPercentage for SpecifiedValue {
         fn has_viewport_percentage(&self) -> bool {
             self.horizontal.has_viewport_percentage() ||
             self.vertical.as_ref().map_or(false, |v| v.has_viewport_percentage())
         }
     }