Commit 849dc59d authored by Hiroyuki Ikezoe's avatar Hiroyuki Ikezoe
Browse files

servo: Merge #16233 - Set each control points when converting specified...

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

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 14edec23a870490ec149b634b7887c32c1b7d3bd
parent cb61bf3b
Loading
Loading
Loading
Loading
+36 −15
Original line number Diff line number Diff line
@@ -21,8 +21,11 @@ impl nsTimingFunction {
        }
    }

    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() };
@@ -46,7 +49,7 @@ impl From<ComputedTimingFunction> for nsTimingFunction {
                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
@@ -67,21 +70,39 @@ impl From<SpecifiedTimingFunction> for nsTimingFunction {
                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),
                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.to_computed_value() {
                    ComputedTimingFunction::CubicBezier(p1, p2) => {
                        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);
                    },
                    FunctionKeyword::StepEnd => {
                        tf.set_as_step(nsTimingFunction_Type::StepEnd, 1);
                            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"),
                        }
                    },
                    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);
                    },
                }
            },
+16 −11
Original line number Diff line number Diff line
@@ -671,17 +671,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
                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]
@@ -702,6 +692,21 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
        }
    }

    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);