Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1355380 - Part 1: Have nsStyleImageOrientation::CreateAsAngleAndF…
Browse files Browse the repository at this point in the history
…lip 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
  • Loading branch information
jyc committed Jul 7, 2017
1 parent cd2583e commit 5dd8470
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions layout/reftests/image/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fuzzy(1,1) == image-orientation-from-image.html?180&flip image-orientation-ref.h
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
Expand All @@ -43,6 +44,7 @@ fuzzy(1,1) == image-orientation-explicit.html?180&flip image-orientation-ref.htm
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
Expand Down
3 changes: 3 additions & 0 deletions layout/style/nsStyleStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,9 @@ struct nsStyleImageOrientation

// 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;}
Expand Down
2 changes: 1 addition & 1 deletion layout/style/test/property_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -6811,11 +6811,11 @@ if (IsCSSPropertyPrefEnabled("layout.css.image-orientation.enabled")) {
"0turn",

// Rounded initial values.
"-90deg",
"15deg",
"360deg",
],
other_values: [
"-90deg",
"0deg flip",
"90deg",
"90deg flip",
Expand Down

0 comments on commit 5dd8470

Please sign in to comment.