From f36199201c498db8e4e7a23e1f24a9c421b3bb83 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Mon, 3 Apr 2017 09:52:05 +0900 Subject: [PATCH] Set each control points when converting specified keyworded timing function 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. --- .../sugar/ns_timing_function.rs | 51 +++++++++++++------ .../style/properties/longhand/box.mako.rs | 27 ++++++---- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/components/style/gecko_bindings/sugar/ns_timing_function.rs b/components/style/gecko_bindings/sugar/ns_timing_function.rs index 840879b4d08..53c0d468523 100644 --- a/components/style/gecko_bindings/sugar/ns_timing_function.rs +++ b/components/style/gecko_bindings/sugar/ns_timing_function.rs @@ -21,8 +21,11 @@ impl nsTimingFunction { } } - fn set_as_cubic_bezier(&mut self, p1: Point2D, p2: Point2D) { - self.mType = nsTimingFunction_Type::CubicBezier; + fn set_as_bezier(&mut self, + function_type: nsTimingFunction_Type, + p1: Point2D, + p2: Point2D) { + 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 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 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), - 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); }, } }, diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 363964be74c..d05a5ed4a1e 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -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);