Bug 1496619 - Part 4: Replace u32 with computed::Integer for computed::TimingFunction r=emilio
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 26 Oct 2018 18:03:31 +0000
changeset 443233 d6e5970c62be7bd99d250d0a43e012ee159829b8
parent 443232 dca7e62232c1c74f4425fb360c4f1ec1645f66d5
child 443234 5b744b960fe0280854c3129aa26b7894083ef632
push id34944
push userncsoregi@mozilla.com
push dateSat, 27 Oct 2018 09:49:55 +0000
treeherdermozilla-central@49d47a692ca4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1496619
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496619 - Part 4: Replace u32 with computed::Integer for computed::TimingFunction r=emilio 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
servo/components/style/gecko_bindings/sugar/ns_timing_function.rs
servo/components/style/values/computed/easing.rs
servo/components/style/values/generics/easing.rs
servo/components/style/values/specified/easing.rs
--- a/servo/components/style/gecko_bindings/sugar/ns_timing_function.rs
+++ b/servo/components/style/gecko_bindings/sugar/ns_timing_function.rs
@@ -6,28 +6,28 @@ use gecko_bindings::structs::{nsTimingFu
 use std::mem;
 use values::computed::ToComputedValue;
 use values::computed::easing::TimingFunction as ComputedTimingFunction;
 use values::generics::easing::{StepPosition, TimingKeyword};
 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,
             "function_type should be step-start or step-end"
         );
         self.mType = function_type;
         unsafe {
             self.__bindgen_anon_1
                 .__bindgen_anon_1
                 .as_mut()
-                .mSteps = steps;
+                .mSteps = steps as u32;
         }
     }
 
     fn set_as_bezier(
         &mut self,
         function_type: nsTimingFunction_Type,
         x1: f32,
         y1: f32,
@@ -53,21 +53,21 @@ impl From<ComputedTimingFunction> for ns
 
 impl From<TimingFunction> for nsTimingFunction {
     fn from(function: TimingFunction) -> nsTimingFunction {
         let mut tf: nsTimingFunction = unsafe { mem::zeroed() };
 
         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(
                     nsTimingFunction_Type::CubicBezier,
                     x1.get(),
                     y1.get(),
                     x2.get(),
                     y2.get(),
@@ -86,27 +86,27 @@ impl From<nsTimingFunction> for Computed
     fn from(function: nsTimingFunction) -> ComputedTimingFunction {
         match function.mType {
             nsTimingFunction_Type::StepStart => GenericTimingFunction::Steps(
                 unsafe {
                     function
                         .__bindgen_anon_1
                         .__bindgen_anon_1
                         .as_ref()
-                        .mSteps
+                        .mSteps as i32
                 },
                 StepPosition::Start,
             ),
             nsTimingFunction_Type::StepEnd => GenericTimingFunction::Steps(
                 unsafe {
                     function
                         .__bindgen_anon_1
                         .__bindgen_anon_1
                         .as_ref()
-                        .mSteps
+                        .mSteps as i32
                 },
                 StepPosition::End,
             ),
             nsTimingFunction_Type::Ease => GenericTimingFunction::Keyword(TimingKeyword::Ease),
             nsTimingFunction_Type::Linear => GenericTimingFunction::Keyword(TimingKeyword::Linear),
             nsTimingFunction_Type::EaseIn => GenericTimingFunction::Keyword(TimingKeyword::EaseIn),
             nsTimingFunction_Type::EaseOut => {
                 GenericTimingFunction::Keyword(TimingKeyword::EaseOut)
--- a/servo/components/style/values/computed/easing.rs
+++ b/servo/components/style/values/computed/easing.rs
@@ -1,11 +1,11 @@
 /* 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/. */
 
 //! 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>;
--- a/servo/components/style/values/generics/easing.rs
+++ b/servo/components/style/values/generics/easing.rs
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Generic types for CSS Easing Functions.
 //! https://drafts.csswg.org/css-easing/#timing-functions
 
 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`
     Keyword(TimingKeyword),
     /// `cubic-bezier(<number>, <number>, <number>, <number>)`
     #[allow(missing_docs)]
     #[css(comma, function)]
     CubicBezier {
--- a/servo/components/style/values/specified/easing.rs
+++ b/servo/components/style/values/specified/easing.rs
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Specified types for CSS Easing functions.
 
 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};
 
 /// A specified timing function.
 pub type TimingFunction = GenericTimingFunction<Integer, Number>;
 
 impl Parse for TimingFunction {
@@ -67,52 +66,8 @@ impl Parse for TimingFunction {
             }).map_err(|()| {
                 location.new_custom_error(
                     StyleParseErrorKind::UnexpectedFunction(function.clone())
                 )
             })
         })
     }
 }
-
-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,
-            ),
-        }
-    }
-}