Add impl From<nsTimingFunction> for TransitionTimingFunction and impl From<TransitionTimingFunction> for nsTimingFunction. r?heycam
draft
Add impl From<nsTimingFunction> for TransitionTimingFunction and impl From<TransitionTimingFunction> for nsTimingFunction. r?heycam
MozReview-Commit-ID: 5EZWELn01uw
--- a/servo/components/style/gecko_bindings/sugar/mod.rs
+++ b/servo/components/style/gecko_bindings/sugar/mod.rs
@@ -1,12 +1,13 @@
/* 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/. */
mod ns_com_ptr;
mod ns_css_shadow_array;
mod ns_style_auto_array;
pub mod ns_style_coord;
+mod ns_timing_function;
mod ns_t_array;
pub mod ownership;
pub mod refptr;
mod style_complex_color;
new file mode 100644
--- /dev/null
+++ b/servo/components/style/gecko_bindings/sugar/ns_timing_function.rs
@@ -0,0 +1,69 @@
+/* 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::animation_timing_function::computed_value::{StartEnd, 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 }))
+ },
+ }
+ }
+}