Bug 1371196 - Round font-weight when interpolating, don't floor; r=hiro
authorBrian Birtles <birtles@gmail.com>
Fri, 09 Jun 2017 12:19:47 +0900
changeset 413647 52c02dbc1e23924cc7d999a2ec09ca0345ff5e4f
parent 413646 646b691852bd9bf6d50e2ca2b14daa85a7f8ecdb
child 413648 bd00685e1e660debac3597016d58bd13715e7a16
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro
bugs1371196, 528234
milestone55.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 1371196 - Round font-weight when interpolating, don't floor; r=hiro The spec says, font weight: interpolated via discrete steps (multiples of 100). The interpolation happens in real number space and is converted to an integer by rounding to the nearest multiple of 100, with values halfway between multiples of 100 rounded towards positive infinity.[1] However, our implementation pre-dates this spec text (bug 528234 landed Nov 2009 whereas the spec was updated in Mar 2012[2]). This patch rounds the result by simply adding 50 to the result before we floor it (which is good enough in this case because we don't need to worry about negative values). It also slightly simplifies the logic by re-using Clamp from MathAlgorithms.h. [1] https://drafts.csswg.org/css-transitions/#animtype-font-weight [2] https://github.com/w3c/csswg-drafts/commit/00c62861095c9c3b911f3af0747790440a8e6467 MozReview-Commit-ID: BjCg7MG70hW
dom/smil/test/db_smilCSSFromTo.js
layout/style/StyleAnimationValue.cpp
--- a/dom/smil/test/db_smilCSSFromTo.js
+++ b/dom/smil/test/db_smilCSSFromTo.js
@@ -326,17 +326,17 @@ var gFromToBundles = [
     new AnimTestcaseFromTo("small-caps", "normal"),
   ]),
   new TestcaseBundle(gPropList.font_weight, [
     new AnimTestcaseFromTo("100", "900", { midComp: "500" }),
     new AnimTestcaseFromTo("700", "100", { midComp: "400" }),
     new AnimTestcaseFromTo("inherit", "200",
                            { fromComp: "400", midComp: "300" }),
     new AnimTestcaseFromTo("normal", "bold",
-                           { fromComp: "400", midComp: "500", toComp: "700" }),
+                           { fromComp: "400", midComp: "600", toComp: "700" }),
     new AnimTestcaseFromTo("lighter", "bolder", {},
                            "need support for animating between " +
                            "relative 'font-weight' values"),
   ]),
   // NOTE: Mozilla doesn't currently support "glyph-orientation-horizontal" or
   // "glyph-orientation-vertical", but I'm testing them here in case we ever
   // add support for them, because they're explicitly not animatable in the SVG
   // spec.
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -2920,22 +2920,20 @@ StyleAnimationValue::AddWeighted(nsCSSPr
       return true;
     }
     case eUnit_Integer: {
       // https://drafts.csswg.org/css-transitions/#animtype-integer
       double interpolatedValue = aCoeff1 * double(aValue1.GetIntValue()) +
                                  aCoeff2 * double(aValue2.GetIntValue());
       int32_t result = floor(interpolatedValue + 0.5);
       if (aProperty == eCSSProperty_font_weight) {
-        if (result < 100) {
-          result = 100;
-        } else if (result > 900) {
-          result = 900;
-        }
+        // https://drafts.csswg.org/css-transitions/#animtype-font-weight
+        result += 50;
         result -= result % 100;
+        result = Clamp(result, 100, 900);
       } else {
         result = RestrictValue(aProperty, result);
       }
       aResultValue.SetIntValue(result, eUnit_Integer);
       return true;
     }
     case eUnit_Coord: {
       aResultValue.SetCoordValue(RestrictValue(aProperty, NSToCoordRound(