Backed out changeset 3977404931e5 for failing mochitest layout/style/test/test_value_computation.html. r=backout
authorSebastian Hengst <archaeopteryx@coole-files.de>
Wed, 12 Jul 2017 00:11:58 +0200
changeset 607425 66d21dbbe9160da0df4a0329f6370a25d2eb78dc
parent 607424 be9cdda2269c36778d4113ac9a639c243ab2ba7a
child 607426 7030f3156472125837acb67927bafc4548adcc86
push id67985
push userbmo:emilio+bugs@crisal.io
push dateWed, 12 Jul 2017 08:36:44 +0000
reviewersbackout
milestone56.0a1
backs out3977404931e5da73fe1afe0a3bd57b89d8368d5f
Backed out changeset 3977404931e5 for failing mochitest layout/style/test/test_value_computation.html. r=backout
servo/components/style/gecko/generated/bindings.rs
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/inherited_box.mako.rs
servo/components/style/values/computed/mod.rs
--- a/servo/components/style/gecko/generated/bindings.rs
+++ b/servo/components/style/gecko/generated/bindings.rs
@@ -892,17 +892,17 @@ extern "C" {
                                        atom: *mut nsIAtom);
 }
 extern "C" {
     pub fn Gecko_CopyAlternateValuesFrom(dest: *mut nsFont,
                                          src: *const nsFont);
 }
 extern "C" {
     pub fn Gecko_SetImageOrientation(aVisibility: *mut nsStyleVisibility,
-                                     aOrientation: u8, aFlip: bool);
+                                     aRadians: f64, aFlip: bool);
 }
 extern "C" {
     pub fn Gecko_SetImageOrientationAsFromImage(aVisibility:
                                                     *mut nsStyleVisibility);
 }
 extern "C" {
     pub fn Gecko_CopyImageOrientationFrom(aDst: *mut nsStyleVisibility,
                                           aSrc: *const nsStyleVisibility);
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -3841,19 +3841,19 @@ fn static_assert() {
     pub fn set_image_orientation(&mut self, v: longhands::image_orientation::computed_value::T) {
         use properties::longhands::image_orientation::computed_value::T;
         match v {
             T::FromImage => {
                 unsafe {
                     bindings::Gecko_SetImageOrientationAsFromImage(&mut self.gecko);
                 }
             },
-            T::AngleWithFlipped(ref orientation, flipped) => {
+            T::AngleWithFlipped(ref angle, flipped) => {
                 unsafe {
-                    bindings::Gecko_SetImageOrientation(&mut self.gecko, *orientation as u8, flipped);
+                    bindings::Gecko_SetImageOrientation(&mut self.gecko, angle.radians() as f64, flipped);
                 }
             }
         }
     }
 
     pub fn copy_image_orientation_from(&mut self, other: &Self) {
         unsafe {
             bindings::Gecko_CopyImageOrientationFrom(&mut self.gecko, &other.gecko);
--- a/servo/components/style/properties/longhand/inherited_box.mako.rs
+++ b/servo/components/style/properties/longhand/inherited_box.mako.rs
@@ -63,18 +63,19 @@
     spec="https://drafts.csswg.org/css-images/#propdef-image-orientation, \
       /// additional values in https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation">
     use std::fmt;
     use style_traits::ToCss;
     use values::specified::Angle;
 
     no_viewport_percentage!(SpecifiedValue);
 
-    use std::f64::consts::PI;
-    const TWO_PI: f64 = 2.0 * PI;
+    use std::f32::consts::PI;
+    use values::CSSFloat;
+    const TWO_PI: CSSFloat = 2.0 * PI;
 
     #[derive(Clone, PartialEq, Copy, Debug)]
     #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
     pub struct SpecifiedValue {
         pub angle: Option<Angle>,
         pub flipped: bool
     }
 
@@ -93,114 +94,68 @@
                 } else {
                     dest.write_str("from-image")
                 }
             }
         }
     }
 
     pub mod computed_value {
-        use std::fmt;
-        use style_traits::ToCss;
-        use values::specified::Angle;
-
-        #[derive(Copy, Clone, Debug, Eq, PartialEq)]
-        #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
-        pub enum Orientation {
-            Angle0 = 0,
-            Angle90,
-            Angle180,
-            Angle270,
-        }
-
-        impl Orientation {
-            pub fn angle(&self) -> Angle {
-                match *self {
-                    Orientation::Angle0 => Angle::from_degrees(0.0, false),
-                    Orientation::Angle90 => Angle::from_degrees(90.0, false),
-                    Orientation::Angle180 => Angle::from_degrees(180.0, false),
-                    Orientation::Angle270 => Angle::from_degrees(270.0, false),
-                }
-            }
-        }
-
-        impl ToCss for Orientation {
-            fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
-                // Should agree with Angle::to_css.
-                match *self {
-                    Orientation::Angle0 => dest.write_str("0deg"),
-                    Orientation::Angle90 => dest.write_str("90deg"),
-                    Orientation::Angle180 => dest.write_str("180deg"),
-                    Orientation::Angle270 => dest.write_str("270deg"),
-                }
-            }
-        }
+        use values::computed::Angle;
 
         #[derive(Clone, PartialEq, Copy, Debug)]
         #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
         pub enum T {
             FromImage,
-            AngleWithFlipped(Orientation, bool),
+            AngleWithFlipped(Angle, bool),
         }
     }
 
-    use self::computed_value::Orientation;
-
     #[inline]
     pub fn get_initial_value() -> computed_value::T {
-        computed_value::T::AngleWithFlipped(Orientation::Angle0, false)
+        computed_value::T::AngleWithFlipped(computed::Angle::zero(), false)
     }
 
     // According to CSS Content Module Level 3:
     // The computed value of the property is calculated by rounding the specified angle
     // to the nearest quarter-turn, rounding away from 0, then moduloing the value by 1 turn.
-    // This mirrors the Gecko implementation in
-    // nsStyleImageOrientation::CreateAsAngleAndFlip.
     #[inline]
-    fn orientation_of_angle(angle: &computed::Angle) -> Orientation {
-        // Note that `angle` can be negative.
-        let mut rounded_angle = angle.radians64() % TWO_PI;
-        if rounded_angle < 0.0 {
-            // This computation introduces rounding error. Gecko previously
-            // didn't handle the negative case correctly; by branching we can
-            // match Gecko's behavior when it was correct.
-            rounded_angle = rounded_angle + TWO_PI;
-        }
-        if      rounded_angle < 0.25 * PI { Orientation::Angle0   }
-        else if rounded_angle < 0.75 * PI { Orientation::Angle90  }
-        else if rounded_angle < 1.25 * PI { Orientation::Angle180 }
-        else if rounded_angle < 1.75 * PI { Orientation::Angle270 }
-        else                              { Orientation::Angle0   }
+    fn normalize_angle(angle: &computed::Angle) -> computed::Angle {
+        let radians = angle.radians();
+        let rounded_quarter_turns = (4.0 * radians / TWO_PI).round();
+        let normalized_quarter_turns = (rounded_quarter_turns % 4.0 + 4.0) % 4.0;
+        let normalized_radians = normalized_quarter_turns/4.0 * TWO_PI;
+        computed::Angle::from_radians(normalized_radians)
     }
 
     impl ToComputedValue for SpecifiedValue {
         type ComputedValue = computed_value::T;
 
         #[inline]
         fn to_computed_value(&self, context: &Context) -> computed_value::T {
             if let Some(ref angle) = self.angle {
                 let angle = angle.to_computed_value(context);
-                let orientation = orientation_of_angle(&angle);
-                computed_value::T::AngleWithFlipped(orientation, self.flipped)
+                let normalized_angle = normalize_angle(&angle);
+                computed_value::T::AngleWithFlipped(normalized_angle, self.flipped)
             } else {
                 if self.flipped {
-                    computed_value::T::AngleWithFlipped(Orientation::Angle0, true)
+                    computed_value::T::AngleWithFlipped(computed::Angle::zero(), true)
                 } else {
                     computed_value::T::FromImage
                 }
             }
         }
 
         #[inline]
         fn from_computed_value(computed: &computed_value::T) -> Self {
             match *computed {
                 computed_value::T::FromImage => SpecifiedValue { angle: None, flipped: false },
-                computed_value::T::AngleWithFlipped(ref orientation, flipped) => {
+                computed_value::T::AngleWithFlipped(ref angle, flipped) => {
                     SpecifiedValue {
-                        angle: Some(orientation.angle()),
+                        angle: Some(Angle::from_computed_value(angle)),
                         flipped: flipped,
                     }
                 }
             }
         }
     }
 
     impl ToCss for computed_value::T {
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -8,18 +8,17 @@ use Atom;
 use context::QuirksMode;
 use euclid::Size2D;
 use font_metrics::FontMetricsProvider;
 use media_queries::Device;
 #[cfg(feature = "gecko")]
 use properties;
 use properties::{ComputedValues, StyleBuilder};
 use std::f32;
-use std::f64;
-use std::f64::consts::PI;
+use std::f32::consts::PI;
 use std::fmt;
 use style_traits::ToCss;
 use super::{CSSFloat, CSSInteger, RGBA};
 use super::generics::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
 use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
 use super::generics::grid::TrackList as GenericTrackList;
 use super::specified;
 
@@ -309,37 +308,27 @@ impl Angle {
     /// Construct a computed `Angle` value from a radian amount.
     pub fn from_radians(radians: CSSFloat) -> Self {
         Angle::Radian(radians)
     }
 
     /// Return the amount of radians this angle represents.
     #[inline]
     pub fn radians(&self) -> CSSFloat {
-        self.radians64().min(f32::MAX as f64).max(f32::MIN as f64) as f32
-    }
-
-    /// Return the amount of radians this angle represents as a 64-bit float.
-    /// Gecko stores angles as singles, but does this computation using doubles.
-    /// See nsCSSValue::GetAngleValueInRadians.
-    /// This is significant enough to mess up rounding to the nearest
-    /// quarter-turn for 225 degrees, for example.
-    #[inline]
-    pub fn radians64(&self) -> f64 {
-        const RAD_PER_DEG: f64 = PI / 180.0;
-        const RAD_PER_GRAD: f64 = PI / 200.0;
-        const RAD_PER_TURN: f64 = PI * 2.0;
+        const RAD_PER_DEG: CSSFloat = PI / 180.0;
+        const RAD_PER_GRAD: CSSFloat = PI / 200.0;
+        const RAD_PER_TURN: CSSFloat = PI * 2.0;
 
         let radians = match *self {
-            Angle::Degree(val) => val as f64 * RAD_PER_DEG,
-            Angle::Gradian(val) => val as f64 * RAD_PER_GRAD,
-            Angle::Turn(val) => val as f64 * RAD_PER_TURN,
-            Angle::Radian(val) => val as f64,
+            Angle::Degree(val) => val * RAD_PER_DEG,
+            Angle::Gradian(val) => val * RAD_PER_GRAD,
+            Angle::Turn(val) => val * RAD_PER_TURN,
+            Angle::Radian(val) => val,
         };
-        radians.min(f64::MAX).max(f64::MIN)
+        radians.min(f32::MAX).max(f32::MIN)
     }
 
     /// Returns an angle that represents a rotation of zero radians.
     pub fn zero() -> Self {
         Angle::Radian(0.0)
     }
 }