servo: Merge #16233 - Set each control points when converting specified keyworded timing fu… (from hiikezoe:timing-function-fix); r=emilio
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sun, 02 Apr 2017 20:12:09 -0500
changeset 350883 56c056de6bb3a04f12bb0bd1d1ff7a402fa00946
parent 350882 941e0f9ff9a789bf98ff910bc24b48ea90ce5c75
child 350884 8cd3a3e5f3dd0c6d90b7df59f23d34ec9a4a0869
push id39969
push userservo-vcs-sync@mozilla.com
push dateMon, 03 Apr 2017 01:54:31 +0000
treeherderautoland@56c056de6bb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #16233 - Set each control points when converting specified keyworded timing fu… (from hiikezoe:timing-function-fix); r=emilio …nction to nsTimingFunction. Gecko's timing function (nsTimingFunction) needs to be specified each control points if timing function can be represented as cubic-bezier function. To avoid scattering control points values (e.g. 0.25, 0.1, ...) we convert specified value to computed value and then use control points values of the computed value. <!-- Please describe your changes on the following line: --> This is a PR of https://bugzilla.mozilla.org/show_bug.cgi?id=1352891 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because it's for stylo. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: a31271b07ff1372e48d8b363a1f4a16b8ff6f98d
servo/components/style/gecko_bindings/sugar/ns_timing_function.rs
servo/components/style/properties/longhand/box.mako.rs
--- a/servo/components/style/gecko_bindings/sugar/ns_timing_function.rs
+++ b/servo/components/style/gecko_bindings/sugar/ns_timing_function.rs
@@ -16,18 +16,21 @@ impl nsTimingFunction {
                       function_type == nsTimingFunction_Type::StepEnd,
                       "function_type should be step-start or step-end");
         self.mType = function_type;
         unsafe {
             self.__bindgen_anon_1.__bindgen_anon_1.as_mut().mStepsOrFrames = steps;
         }
     }
 
-    fn set_as_cubic_bezier(&mut self, p1: Point2D<f32>, p2: Point2D<f32>) {
-        self.mType = nsTimingFunction_Type::CubicBezier;
+    fn set_as_bezier(&mut self,
+                     function_type: nsTimingFunction_Type,
+                     p1: Point2D<f32>,
+                     p2: Point2D<f32>) {
+        self.mType = function_type;
         unsafe {
             let ref mut gecko_cubic_bezier =
                 unsafe { self.__bindgen_anon_1.mFunc.as_mut() };
             gecko_cubic_bezier.mX1 = p1.x;
             gecko_cubic_bezier.mY1 = p1.y;
             gecko_cubic_bezier.mX2 = p2.x;
             gecko_cubic_bezier.mY2 = p2.y;
         }
@@ -41,17 +44,17 @@ impl From<ComputedTimingFunction> for ns
         match function {
             ComputedTimingFunction::Steps(steps, StartEnd::Start) => {
                 tf.set_as_step(nsTimingFunction_Type::StepStart, steps);
             },
             ComputedTimingFunction::Steps(steps, StartEnd::End) => {
                 tf.set_as_step(nsTimingFunction_Type::StepEnd, steps);
             },
             ComputedTimingFunction::CubicBezier(p1, p2) => {
-                tf.set_as_cubic_bezier(p1, p2);
+                tf.set_as_bezier(nsTimingFunction_Type::CubicBezier, p1, p2);
             },
         }
         tf
     }
 }
 
 impl From<SpecifiedTimingFunction> for nsTimingFunction {
     fn from(function: SpecifiedTimingFunction) -> nsTimingFunction {
@@ -62,31 +65,49 @@ impl From<SpecifiedTimingFunction> for n
                 debug_assert!(steps.value() >= 0);
                 tf.set_as_step(nsTimingFunction_Type::StepStart, steps.value() as u32);
             },
             SpecifiedTimingFunction::Steps(steps, StartEnd::End) => {
                 debug_assert!(steps.value() >= 0);
                 tf.set_as_step(nsTimingFunction_Type::StepEnd, steps.value() as u32);
             },
             SpecifiedTimingFunction::CubicBezier(p1, p2) => {
-                tf.set_as_cubic_bezier(Point2D::new(p1.x.value, p1.y.value),
-                                       Point2D::new(p2.x.value, p2.y.value));
+                tf.set_as_bezier(nsTimingFunction_Type::CubicBezier,
+                                 Point2D::new(p1.x.value, p1.y.value),
+                                 Point2D::new(p2.x.value, p2.y.value));
             },
             SpecifiedTimingFunction::Keyword(keyword) => {
-                match keyword {
-                    FunctionKeyword::Ease => tf.mType = nsTimingFunction_Type::Ease,
-                    FunctionKeyword::Linear => tf.mType = nsTimingFunction_Type::Linear,
-                    FunctionKeyword::EaseIn => tf.mType = nsTimingFunction_Type::EaseIn,
-                    FunctionKeyword::EaseOut => tf.mType = nsTimingFunction_Type::EaseOut,
-                    FunctionKeyword::EaseInOut => tf.mType = nsTimingFunction_Type::EaseInOut,
-                    FunctionKeyword::StepStart => {
-                        tf.set_as_step(nsTimingFunction_Type::StepStart, 1);
+                match keyword.to_computed_value() {
+                    ComputedTimingFunction::CubicBezier(p1, p2) => {
+                        match keyword {
+                            FunctionKeyword::Ease => {
+                                tf.set_as_bezier(nsTimingFunction_Type::Ease, p1, p2);
+                            },
+                            FunctionKeyword::Linear => {
+                                tf.set_as_bezier(nsTimingFunction_Type::Linear, p1, p2);
+                            },
+                            FunctionKeyword::EaseIn => {
+                                tf.set_as_bezier(nsTimingFunction_Type::EaseIn, p1, p2);
+                            },
+                            FunctionKeyword::EaseOut => {
+                                tf.set_as_bezier(nsTimingFunction_Type::EaseOut, p1, p2);
+                            },
+                            FunctionKeyword::EaseInOut => {
+                                tf.set_as_bezier(nsTimingFunction_Type::EaseInOut, p1, p2);
+                            },
+                            _ => unreachable!("Unexpected bezier function type"),
+                        }
                     },
-                    FunctionKeyword::StepEnd => {
-                        tf.set_as_step(nsTimingFunction_Type::StepEnd, 1);
+                    ComputedTimingFunction::Steps(steps, StartEnd::Start) => {
+                        debug_assert!(keyword == FunctionKeyword::StepStart && steps == 1);
+                        tf.set_as_step(nsTimingFunction_Type::StepStart, steps);
+                    },
+                    ComputedTimingFunction::Steps(steps, StartEnd::End) => {
+                        debug_assert!(keyword == FunctionKeyword::StepEnd && steps == 1);
+                        tf.set_as_step(nsTimingFunction_Type::StepEnd, steps);
                     },
                 }
             },
         }
         tf
     }
 }
 
--- a/servo/components/style/properties/longhand/box.mako.rs
+++ b/servo/components/style/properties/longhand/box.mako.rs
@@ -666,27 +666,17 @@
                 SpecifiedValue::CubicBezier(p1, p2) => {
                     computed_value::T::CubicBezier(
                         Point2D::new(p1.x.to_computed_value(context), p1.y.to_computed_value(context)),
                         Point2D::new(p2.x.to_computed_value(context), p2.y.to_computed_value(context)))
                 },
                 SpecifiedValue::Steps(count, start_end) => {
                     computed_value::T::Steps(count.to_computed_value(context) as u32, start_end)
                 },
-                SpecifiedValue::Keyword(keyword) => {
-                    match keyword {
-                        FunctionKeyword::Ease => ease(),
-                        FunctionKeyword::Linear => linear(),
-                        FunctionKeyword::EaseIn => ease_in(),
-                        FunctionKeyword::EaseOut => ease_out(),
-                        FunctionKeyword::EaseInOut => ease_in_out(),
-                        FunctionKeyword::StepStart => STEP_START,
-                        FunctionKeyword::StepEnd => STEP_END,
-                    }
-                },
+                SpecifiedValue::Keyword(keyword) => keyword.to_computed_value(),
             }
         }
         #[inline]
         fn from_computed_value(computed: &computed_value::T) -> Self {
             match *computed {
                 computed_value::T::CubicBezier(p1, p2) => {
                     SpecifiedValue::CubicBezier(
                         Point2D::new(Number::from_computed_value(&p1.x),
@@ -697,16 +687,31 @@
                 computed_value::T::Steps(count, start_end) => {
                     let int_count = count as i32;
                     SpecifiedValue::Steps(specified::Integer::from_computed_value(&int_count), start_end)
                 },
             }
         }
     }
 
+    impl FunctionKeyword {
+        #[inline]
+        pub fn to_computed_value(&self) -> computed_value::T {
+            match *self {
+                FunctionKeyword::Ease => ease(),
+                FunctionKeyword::Linear => linear(),
+                FunctionKeyword::EaseIn => ease_in(),
+                FunctionKeyword::EaseOut => ease_out(),
+                FunctionKeyword::EaseInOut => ease_in_out(),
+                FunctionKeyword::StepStart => STEP_START,
+                FunctionKeyword::StepEnd => STEP_END,
+            }
+        }
+    }
+
     use values::HasViewportPercentage;
     no_viewport_percentage!(SpecifiedValue);
 
     #[inline]
     pub fn get_initial_value() -> computed_value::T {
         ease()
     }