mirror of
https://github.com/servo/servo.git
synced 2025-06-28 02:53:48 +01:00
style: Replace u32 with computed::Integer for computed::TimingFunction.
We make sure the step number is always positive, so using computed::Integer is safe and can derive ToComputedValue. Depends on D9311 Differential Revision: https://phabricator.services.mozilla.com/D9845
This commit is contained in:
parent
a20b6a5166
commit
2bbcb5c633
4 changed files with 9 additions and 54 deletions
|
@ -11,7 +11,7 @@ use values::generics::easing::TimingFunction as GenericTimingFunction;
|
|||
use values::specified::easing::TimingFunction;
|
||||
|
||||
impl nsTimingFunction {
|
||||
fn set_as_step(&mut self, function_type: nsTimingFunction_Type, steps: u32) {
|
||||
fn set_as_step(&mut self, function_type: nsTimingFunction_Type, steps: i32) {
|
||||
debug_assert!(
|
||||
function_type == nsTimingFunction_Type::StepStart ||
|
||||
function_type == nsTimingFunction_Type::StepEnd,
|
||||
|
@ -22,7 +22,7 @@ impl nsTimingFunction {
|
|||
self.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_mut()
|
||||
.mSteps = steps;
|
||||
.mSteps = steps as u32;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,11 @@ impl From<TimingFunction> for nsTimingFunction {
|
|||
match function {
|
||||
GenericTimingFunction::Steps(steps, StepPosition::Start) => {
|
||||
debug_assert!(steps.value() >= 0);
|
||||
tf.set_as_step(nsTimingFunction_Type::StepStart, steps.value() as u32);
|
||||
tf.set_as_step(nsTimingFunction_Type::StepStart, steps.value());
|
||||
},
|
||||
GenericTimingFunction::Steps(steps, StepPosition::End) => {
|
||||
debug_assert!(steps.value() >= 0);
|
||||
tf.set_as_step(nsTimingFunction_Type::StepEnd, steps.value() as u32);
|
||||
tf.set_as_step(nsTimingFunction_Type::StepEnd, steps.value());
|
||||
},
|
||||
GenericTimingFunction::CubicBezier { x1, y1, x2, y2 } => {
|
||||
tf.set_as_bezier(
|
||||
|
@ -91,7 +91,7 @@ impl From<nsTimingFunction> for ComputedTimingFunction {
|
|||
.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_ref()
|
||||
.mSteps
|
||||
.mSteps as i32
|
||||
},
|
||||
StepPosition::Start,
|
||||
),
|
||||
|
@ -101,7 +101,7 @@ impl From<nsTimingFunction> for ComputedTimingFunction {
|
|||
.__bindgen_anon_1
|
||||
.__bindgen_anon_1
|
||||
.as_ref()
|
||||
.mSteps
|
||||
.mSteps as i32
|
||||
},
|
||||
StepPosition::End,
|
||||
),
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
//! Computed types for CSS Easing functions.
|
||||
|
||||
use values::computed::Number;
|
||||
use values::computed::{Integer, Number};
|
||||
use values::generics::easing::TimingFunction as GenericTimingFunction;
|
||||
|
||||
/// A computed timing function.
|
||||
pub type TimingFunction = GenericTimingFunction<u32, Number>;
|
||||
pub type TimingFunction = GenericTimingFunction<Integer, Number>;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
use values::CSSFloat;
|
||||
|
||||
/// A generic easing function.
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)]
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
|
||||
#[value_info(ty = "TIMING_FUNCTION")]
|
||||
pub enum TimingFunction<Integer, Number> {
|
||||
/// `linear | ease | ease-in | ease-out | ease-in-out`
|
||||
|
|
|
@ -8,7 +8,6 @@ use cssparser::Parser;
|
|||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use values::computed::{Context, TimingFunction as ComputedTimingFunction, ToComputedValue};
|
||||
use values::generics::easing::{StepPosition, TimingKeyword};
|
||||
use values::generics::easing::TimingFunction as GenericTimingFunction;
|
||||
use values::specified::{Integer, Number};
|
||||
|
@ -72,47 +71,3 @@ impl Parse for TimingFunction {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for TimingFunction {
|
||||
type ComputedValue = ComputedTimingFunction;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(keyword),
|
||||
GenericTimingFunction::CubicBezier { x1, y1, x2, y2 } => {
|
||||
GenericTimingFunction::CubicBezier {
|
||||
x1: x1.to_computed_value(context),
|
||||
y1: y1.to_computed_value(context),
|
||||
x2: x2.to_computed_value(context),
|
||||
y2: y2.to_computed_value(context),
|
||||
}
|
||||
},
|
||||
GenericTimingFunction::Steps(steps, position) => {
|
||||
GenericTimingFunction::Steps(steps.to_computed_value(context) as u32, position)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
match *computed {
|
||||
GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(keyword),
|
||||
GenericTimingFunction::CubicBezier {
|
||||
ref x1,
|
||||
ref y1,
|
||||
ref x2,
|
||||
ref y2,
|
||||
} => GenericTimingFunction::CubicBezier {
|
||||
x1: Number::from_computed_value(x1),
|
||||
y1: Number::from_computed_value(y1),
|
||||
x2: Number::from_computed_value(x2),
|
||||
y2: Number::from_computed_value(y2),
|
||||
},
|
||||
GenericTimingFunction::Steps(steps, position) => GenericTimingFunction::Steps(
|
||||
Integer::from_computed_value(&(steps as i32)),
|
||||
position,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue