Skip to content

Commit

Permalink
style: Replace u32 with computed::Integer for computed::TimingFunction.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BorisChiou authored and emilio committed Oct 28, 2018
1 parent a20b6a5 commit 2bbcb5c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 54 deletions.
12 changes: 6 additions & 6 deletions components/style/gecko_bindings/sugar/ns_timing_function.rs
Expand Up @@ -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,
Expand All @@ -22,7 +22,7 @@ impl nsTimingFunction {
self.__bindgen_anon_1
.__bindgen_anon_1
.as_mut()
.mSteps = steps;
.mSteps = steps as u32;
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -91,7 +91,7 @@ impl From<nsTimingFunction> for ComputedTimingFunction {
.__bindgen_anon_1
.__bindgen_anon_1
.as_ref()
.mSteps
.mSteps as i32
},
StepPosition::Start,
),
Expand All @@ -101,7 +101,7 @@ impl From<nsTimingFunction> for ComputedTimingFunction {
.__bindgen_anon_1
.__bindgen_anon_1
.as_ref()
.mSteps
.mSteps as i32
},
StepPosition::End,
),
Expand Down
4 changes: 2 additions & 2 deletions components/style/values/computed/easing.rs
Expand Up @@ -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>;
2 changes: 1 addition & 1 deletion components/style/values/generics/easing.rs
Expand Up @@ -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`
Expand Down
45 changes: 0 additions & 45 deletions components/style/values/specified/easing.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
),
}
}
}

0 comments on commit 2bbcb5c

Please sign in to comment.