Bug 1355380 - Part 1: Have nsStyleImageOrientation::CreateAsAngleAndFlip handle negative angles correctly. r?Manishearth draft
authorJonathan Chan <jyc@eqv.io>
Fri, 07 Jul 2017 16:03:37 -0700
changeset 607355 82959c519600a9b567d4f8a791052d3630e93d13
parent 606958 6fec4855b5345eb63fef57089e61829b88f5f4eb
child 607356 b69695e580fe4b2d090b870089ff3a4dc9e5dd3c
push id67982
push userbmo:jyc@eqv.io
push dateWed, 12 Jul 2017 08:20:12 +0000
reviewersManishearth
bugs1355380
milestone56.0a1
Bug 1355380 - Part 1: Have nsStyleImageOrientation::CreateAsAngleAndFlip handle negative angles correctly. r?Manishearth Previously we just took the input angle mod 2π, which will leave negative input angles as negative. By checking if the input mod 2π is negative and if so adding 2π and then taking that mod 2π again we can ensure that we end up with a an angle in the range [0, 2π]. We only do this if the result of the initial mod is negative because this adds rounding error that is enough to mess up whether 135 is determined to be closer to 90 or 180, for example. We add a test for this as well. Also fix property_database.js to account for this (we assert that -90deg should compute to the same value as the initial value, but it should actually compute to 270deg). MozReview-Commit-ID: Faf0f7wIEg3
layout/reftests/image/reftest.list
layout/style/nsStyleStruct.h
layout/style/test/property_database.js
--- a/layout/reftests/image/reftest.list
+++ b/layout/reftests/image/reftest.list
@@ -28,26 +28,28 @@ fuzzy(1,1) == image-orientation-from-ima
 fuzzy(1,1) == image-orientation-from-image.html?180      image-orientation-ref.html?180
 fuzzy(1,1) == image-orientation-from-image.html?270      image-orientation-ref.html?270
 fuzzy(1,1) == image-orientation-from-image.html?0&flip   image-orientation-ref.html?0&flip
 fuzzy(1,1) == image-orientation-from-image.html?90&flip  image-orientation-ref.html?90&flip
 fuzzy(1,1) == image-orientation-from-image.html?180&flip image-orientation-ref.html?180&flip
 fuzzy(1,1) == image-orientation-from-image.html?270&flip image-orientation-ref.html?270&flip
 
 # Tests for image-orientation used with an explicit orientation:
+fuzzy(1,1) == image-orientation-explicit.html?-900     image-orientation-ref.html?180
 fuzzy(1,1) == image-orientation-explicit.html?0        image-orientation-ref.html?0
 fuzzy(1,1) == image-orientation-explicit.html?90       image-orientation-ref.html?90
 fuzzy(1,1) == image-orientation-explicit.html?180      image-orientation-ref.html?180
 fuzzy(1,1) == image-orientation-explicit.html?270      image-orientation-ref.html?270
 fuzzy(1,1) == image-orientation-explicit.html?0&flip   image-orientation-ref.html?0&flip
 fuzzy(1,1) == image-orientation-explicit.html?90&flip  image-orientation-ref.html?90&flip
 fuzzy(1,1) == image-orientation-explicit.html?180&flip image-orientation-ref.html?180&flip
 fuzzy(1,1) == image-orientation-explicit.html?270&flip image-orientation-ref.html?270&flip
 
 # Tests for image-orientation used with non-axis-aligned angles:
+fuzzy(1,1) == image-orientation-explicit.html?-46      image-orientation-ref.html?270
 fuzzy(1,1) fails-if(styloVsGecko||stylo) == image-orientation-explicit.html?-45      image-orientation-ref.html?0
 fuzzy(1,1) == image-orientation-explicit.html?-15      image-orientation-ref.html?0
 fuzzy(1,1) == image-orientation-explicit.html?15       image-orientation-ref.html?0
 fuzzy(1,1) == image-orientation-explicit.html?45       image-orientation-ref.html?90
 fuzzy(1,1) == image-orientation-explicit.html?75       image-orientation-ref.html?90
 fuzzy(1,1) == image-orientation-explicit.html?105      image-orientation-ref.html?90
 fuzzy(1,1) == image-orientation-explicit.html?135      image-orientation-ref.html?180
 fuzzy(1,1) == image-orientation-explicit.html?165      image-orientation-ref.html?180
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -2025,16 +2025,19 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
 struct nsStyleImageOrientation
 {
   static nsStyleImageOrientation CreateAsAngleAndFlip(double aRadians,
                                                       bool aFlip) {
     uint8_t orientation(0);
 
     // Compute the final angle value, rounding to the closest quarter turn.
     double roundedAngle = fmod(aRadians, 2 * M_PI);
+    if (roundedAngle < 0) {
+      roundedAngle = roundedAngle + 2 * M_PI;
+    }
     if      (roundedAngle < 0.25 * M_PI) { orientation = ANGLE_0;  }
     else if (roundedAngle < 0.75 * M_PI) { orientation = ANGLE_90; }
     else if (roundedAngle < 1.25 * M_PI) { orientation = ANGLE_180;}
     else if (roundedAngle < 1.75 * M_PI) { orientation = ANGLE_270;}
     else                                 { orientation = ANGLE_0;  }
 
     // Add a bit for 'flip' if needed.
     if (aFlip) {
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -6770,21 +6770,21 @@ if (IsCSSPropertyPrefEnabled("layout.css
     type: CSS_TYPE_LONGHAND,
     initial_values: [
       "0deg",
       "0grad",
       "0rad",
       "0turn",
 
       // Rounded initial values.
-      "-90deg",
       "15deg",
       "360deg",
     ],
     other_values: [
+      "-90deg",
       "0deg flip",
       "90deg",
       "90deg flip",
       "180deg",
       "180deg flip",
       "270deg",
       "270deg flip",
       "flip",