Skip to content

Commit

Permalink
Add impl From<nsTimingFunction> for TransitionTimingFunction and impl…
Browse files Browse the repository at this point in the history
… From<TransitionTimingFunction> for nsTimingFunction. r=heycam
  • Loading branch information
Hiroyuki Ikezoe authored and Hiroyuki Ikezoe committed Jan 10, 2017
1 parent 98ed440 commit ff0819b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/style/gecko_bindings/sugar/mod.rs
Expand Up @@ -9,6 +9,7 @@ mod ns_css_shadow_array;
mod ns_style_auto_array;
pub mod ns_style_coord;
mod ns_t_array;
mod ns_timing_function;
pub mod ownership;
pub mod refptr;
mod style_complex_color;
70 changes: 70 additions & 0 deletions components/style/gecko_bindings/sugar/ns_timing_function.rs
@@ -0,0 +1,70 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use euclid::point::TypedPoint2D;
use gecko_bindings::structs::{nsTimingFunction, nsTimingFunction_Type};
use properties::longhands::transition_timing_function::single_value::computed_value::StartEnd;
use properties::longhands::transition_timing_function::single_value::computed_value::T as TransitionTimingFunction;
use std::mem;

impl From<TransitionTimingFunction> for nsTimingFunction {
fn from(function: TransitionTimingFunction) -> nsTimingFunction {
let mut tf: nsTimingFunction = unsafe { mem::zeroed() };

match function {
TransitionTimingFunction::Steps(steps, StartEnd::Start) => {
tf.mType = nsTimingFunction_Type::StepStart;
unsafe {
tf.__bindgen_anon_1.__bindgen_anon_1.as_mut().mSteps = steps;
}
},
TransitionTimingFunction::Steps(steps, StartEnd::End) => {
tf.mType = nsTimingFunction_Type::StepEnd;
unsafe {
tf.__bindgen_anon_1.__bindgen_anon_1.as_mut().mSteps = steps;
}
},
TransitionTimingFunction::CubicBezier(p1, p2) => {
tf.mType = nsTimingFunction_Type::CubicBezier;
let ref mut gecko_cubic_bezier =
unsafe { tf.__bindgen_anon_1.mFunc.as_mut() };
gecko_cubic_bezier.mX1 = p1.x;
gecko_cubic_bezier.mY1 = p1.y;
gecko_cubic_bezier.mX2 = p2.x;
gecko_cubic_bezier.mY2 = p2.y;
},
// FIXME: we need to add more types once TransitionTimingFunction
// has more types.
}
tf
}
}

impl From<nsTimingFunction> for TransitionTimingFunction {
fn from(function: nsTimingFunction) -> TransitionTimingFunction {
match function.mType {
nsTimingFunction_Type::StepStart => {
TransitionTimingFunction::Steps(unsafe { function.__bindgen_anon_1.__bindgen_anon_1.as_ref().mSteps },
StartEnd::Start)
},
nsTimingFunction_Type::StepEnd => {
TransitionTimingFunction::Steps(unsafe { function.__bindgen_anon_1.__bindgen_anon_1.as_ref().mSteps },
StartEnd::End)
},
// FIXME: As above, we need to fix here.
nsTimingFunction_Type::Ease |
nsTimingFunction_Type::Linear |
nsTimingFunction_Type::EaseIn |
nsTimingFunction_Type::EaseOut |
nsTimingFunction_Type::EaseInOut |
nsTimingFunction_Type::CubicBezier => {
TransitionTimingFunction::CubicBezier(
TypedPoint2D::new(unsafe { function.__bindgen_anon_1.mFunc.as_ref().mX1 },
unsafe { function.__bindgen_anon_1.mFunc.as_ref().mY1 }),
TypedPoint2D::new(unsafe { function.__bindgen_anon_1.mFunc.as_ref().mX2 },
unsafe { function.__bindgen_anon_1.mFunc.as_ref().mY2 }))
},
}
}
}

0 comments on commit ff0819b

Please sign in to comment.