mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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.
This commit is contained in:
parent
eb1865070a
commit
f36199201c
2 changed files with 52 additions and 26 deletions
|
@ -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),
|
||||
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);
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue