RESOLVED FIXED 180528
Update HSL/HSLA parsing to match CSS Color 4
https://bugs.webkit.org/show_bug.cgi?id=180528
Summary Update HSL/HSLA parsing to match CSS Color 4
Chris Nardi
Reported 2017-12-07 07:34:41 PST
In CSS Color 4, the HSL and HSLA functions were synonymized, the hue was allowed to be an angle value, the alpha value was allowed to be a percent, and a new syntax was described with whitespace separating the parameters and a backslash separating the optional alpha value. Safari has not implemented any of these changes. This should be tested in the future by https://wpt.fyi/css/css-color (see https://github.com/w3c/web-platform-tests/pull/8598). The spec is at https://drafts.csswg.org/css-color-4/#the-hsl-notation.
Attachments
Patch (15.93 KB, patch)
2017-12-19 16:55 PST, Chris Nardi
no flags
Patch (8.15 KB, patch)
2017-12-19 17:00 PST, Chris Nardi
no flags
Patch (8.17 KB, patch)
2017-12-19 17:13 PST, Chris Nardi
no flags
Patch (10.22 KB, patch)
2017-12-19 17:33 PST, Chris Nardi
no flags
Patch (626.32 KB, patch)
2017-12-19 17:37 PST, Chris Nardi
no flags
Archive of layout-test-results from ews101 for mac-elcapitan (899.51 KB, application/zip)
2017-12-19 18:11 PST, EWS Watchlist
no flags
Archive of layout-test-results from ews104 for mac-elcapitan-wk2 (1.33 MB, application/zip)
2017-12-19 18:18 PST, EWS Watchlist
no flags
Archive of layout-test-results from ews113 for mac-elcapitan (909.17 KB, application/zip)
2017-12-19 18:35 PST, EWS Watchlist
no flags
Patch (834.97 KB, patch)
2017-12-19 18:43 PST, Chris Nardi
no flags
Patch (822.94 KB, patch)
2017-12-19 18:47 PST, Chris Nardi
no flags
Archive of layout-test-results from ews103 for mac-elcapitan (1.10 MB, application/zip)
2017-12-19 19:41 PST, EWS Watchlist
no flags
Archive of layout-test-results from ews114 for mac-elcapitan (1.88 MB, application/zip)
2017-12-19 19:48 PST, EWS Watchlist
no flags
Patch (831.12 KB, patch)
2017-12-19 19:51 PST, Chris Nardi
no flags
Patch (831.34 KB, patch)
2017-12-19 20:36 PST, Chris Nardi
no flags
Patch (831.29 KB, patch)
2017-12-19 21:30 PST, Chris Nardi
no flags
Patch (866.71 KB, patch)
2017-12-19 22:26 PST, Chris Nardi
no flags
Patch (850.06 KB, patch)
2018-01-10 18:03 PST, Chris Nardi
no flags
Patch (850.30 KB, patch)
2018-01-18 17:40 PST, Chris Nardi
no flags
Rebase after r227595 (464.01 KB, patch)
2018-01-25 10:42 PST, Chris Nardi
no flags
Archive of layout-test-results from ews206 for win-future (11.75 MB, application/zip)
2018-01-25 12:43 PST, EWS Watchlist
no flags
Rebase (419.39 KB, patch)
2018-04-20 12:03 PDT, Chris Nardi
no flags
Address comments by Simon (419.38 KB, patch)
2018-04-20 14:41 PDT, Chris Nardi
no flags
Radar WebKit Bug Importer
Comment 1 2017-12-07 19:34:38 PST
Chris Nardi
Comment 2 2017-12-19 16:55:45 PST
Chris Nardi
Comment 3 2017-12-19 17:00:31 PST
Simon Fraser (smfr)
Comment 4 2017-12-19 17:01:18 PST
Comment on attachment 329855 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=329855&action=review > Source/WebCore/ChangeLog:8 > + No new tests (OOPS!). It needs some, obviously. Look in LayoutTests/fast/css/.... for examples. > Source/WebCore/platform/graphics/Color.cpp:108 > + hueVal += 6.0; > + else if (hueVal >= 6.0) > + hueVal -= 6.0; > + if (hueVal < 1.0) > + return temp1 + (temp2 - temp1) * hueVal; > + if (hueVal < 3.0) So is this changing how we compute hue? That's a little surprising. > Tools/Scripts/webkitpy/common/checkout/scm/detection.py:6 > +# Copyright (c) 2009, 2010, 2011 Google Inc. All rights reserved. > +# Copyright (c) 2009 Apple Inc. All rights reserved. > +# > +# Redistribution and use in source and binary forms, with or without > +# modification, are permitted provided that the following conditions are > +# met: I guess you nuked the line endings on this file.
Chris Nardi
Comment 5 2017-12-19 17:04:41 PST
Yeah, I messed up with that. I think the new patch should make more sense -- doing all of this from Windows is hard. As to an overview of this change: this is basically porting my Chromium change at https://chromium-review.googlesource.com/c/chromium/src/+/812125 over to WebKit. I changed the implementation of HSL to RGB because the pseudocode changed in the spec. Functionally, this should fix two bugs as the comparisons were missing equality tests. Overall, it should just be easier to read this implementation as it should be nearly identical with the pseudocode in the spec.
Chris Nardi
Comment 6 2017-12-19 17:05:37 PST
Additionally, this is tested in WPT, and I notice that none of those tests have been imported by WebKit, so I'm not sure what the best course would be there for testing.
Chris Nardi
Comment 7 2017-12-19 17:13:24 PST
Simon Fraser (smfr)
Comment 8 2017-12-19 17:26:12 PST
(In reply to Chris Nardi from comment #6) > Additionally, this is tested in WPT, and I notice that none of those tests > have been imported by WebKit, so I'm not sure what the best course would be > there for testing. If there are behavior changes detected by WPT which webkit has imported, then we'll see that in the EWS output, and your patch should contain some rebaselining of results. If not, then it suggests that the code is not tested and you should add new tests (WPT or otherwise).
Chris Nardi
Comment 9 2017-12-19 17:33:14 PST
Chris Nardi
Comment 10 2017-12-19 17:37:10 PST
EWS Watchlist
Comment 11 2017-12-19 18:11:17 PST
Comment on attachment 329861 [details] Patch Attachment 329861 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/5763541 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 12 2017-12-19 18:11:19 PST
Created attachment 329863 [details] Archive of layout-test-results from ews101 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews101 Port: mac-elcapitan Platform: Mac OS X 10.11.6
EWS Watchlist
Comment 13 2017-12-19 18:18:14 PST
Comment on attachment 329861 [details] Patch Attachment 329861 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/5763566 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 14 2017-12-19 18:18:16 PST
Created attachment 329864 [details] Archive of layout-test-results from ews104 for mac-elcapitan-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews104 Port: mac-elcapitan-wk2 Platform: Mac OS X 10.11.6
EWS Watchlist
Comment 15 2017-12-19 18:35:21 PST
Comment on attachment 329861 [details] Patch Attachment 329861 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/5763649 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 16 2017-12-19 18:35:22 PST
Created attachment 329869 [details] Archive of layout-test-results from ews113 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews113 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Chris Nardi
Comment 17 2017-12-19 18:43:48 PST
Chris Nardi
Comment 18 2017-12-19 18:47:18 PST
EWS Watchlist
Comment 19 2017-12-19 19:01:16 PST
Attachment 329873 [details] did not pass style-queue: ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/TestExpectations:1029: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/TestExpectations:1030: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/TestExpectations:1031: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/platform/gtk/TestExpectations:1765: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/platform/gtk/TestExpectations:1766: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/platform/gtk/TestExpectations:2913: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/platform/gtk/TestExpectations:2914: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/platform/gtk/TestExpectations:3375: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/platform/gtk/TestExpectations:3376: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/platform/gtk/TestExpectations:3377: Path does not exist. [test/expectations] [5] Total errors found: 10 in 261 files If any of these errors are false positives, please file a bug against check-webkit-style.
EWS Watchlist
Comment 20 2017-12-19 19:41:37 PST
Comment on attachment 329873 [details] Patch Attachment 329873 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/5764960 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 21 2017-12-19 19:41:38 PST
Created attachment 329879 [details] Archive of layout-test-results from ews103 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-elcapitan Platform: Mac OS X 10.11.6
EWS Watchlist
Comment 22 2017-12-19 19:48:05 PST
Comment on attachment 329873 [details] Patch Attachment 329873 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/5764888 Number of test failures exceeded the failure limit.
EWS Watchlist
Comment 23 2017-12-19 19:48:07 PST
Created attachment 329881 [details] Archive of layout-test-results from ews114 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews114 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Chris Nardi
Comment 24 2017-12-19 19:51:36 PST
Chris Nardi
Comment 25 2017-12-19 20:36:31 PST
EWS Watchlist
Comment 26 2017-12-19 20:45:42 PST
Attachment 329890 [details] did not pass style-queue: ERROR: LayoutTests/TestExpectations:1070: expecting "[", "#", or end of line instead of "ImageOnlyFailure" [test/expectations] [5] ERROR: LayoutTests/TestExpectations:1070: Path does not exist. [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/TestExpectations:1070: expecting "[", "#", or end of line instead of "ImageOnlyFailure" [test/expectations] [5] ERROR: /Volumes/Data/StyleQueue/WebKit/LayoutTests/TestExpectations:1070: Path does not exist. [test/expectations] [5] Total errors found: 4 in 265 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Nardi
Comment 27 2017-12-19 21:30:45 PST
Chris Nardi
Comment 28 2017-12-19 22:26:03 PST
Chris Nardi
Comment 29 2017-12-21 20:52:29 PST
It looks like this change should be ready for review. Only wincairo didn't pass, but I suspect the cause is something similar to https://bugs.webkit.org/show_bug.cgi?id=179682#c72.
Chris Nardi
Comment 30 2018-01-10 18:03:06 PST
Chris Nardi
Comment 31 2018-01-15 13:02:15 PST
Since this is adding new syntax to the HSL/HSLA functions, do I need to take any additional steps with this patch? I notice that https://webkit.org/status/ shows supported for Color 4.
Dean Jackson
Comment 32 2018-01-18 16:46:14 PST
Comment on attachment 331000 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=331000&action=review > Source/WebCore/ChangeLog:9 > + This change imports web-platform-tests/css/css-color to test the new behavior. It also updates the syntax. > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:534 > - colorArray[0] = (((hslValue->intValue() % 360) + 360) % 360) / 360.0; > + colorArray[0] = fmod(fmod(angleValue, 360.0) + 360.0, 360.0) / 60.0; Please add a comment explaining why this is / 60 now. Or, keep it as [0,1] and adjust in calcHue. (I don't really understand why the specification decided [0,6) was a "simplification")
Chris Nardi
Comment 33 2018-01-18 17:29:34 PST
(In reply to Dean Jackson from comment #32) > Comment on attachment 331000 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=331000&action=review > > > Source/WebCore/ChangeLog:9 > > + This change imports web-platform-tests/css/css-color to test the new behavior. > > It also updates the syntax. > > > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:534 > > - colorArray[0] = (((hslValue->intValue() % 360) + 360) % 360) / 360.0; > > + colorArray[0] = fmod(fmod(angleValue, 360.0) + 360.0, 360.0) / 60.0; > > Please add a comment explaining why this is / 60 now. Or, keep it as [0,1] > and adjust in calcHue. > > (I don't really understand why the specification decided [0,6) was a > "simplification") I added a comment above calcHue(), but I can add this inline in CSSPropertyParserHelpers.cpp too.
Chris Nardi
Comment 34 2018-01-18 17:40:17 PST
Chris Nardi
Comment 35 2018-01-25 10:42:00 PST
Created attachment 332286 [details] Rebase after r227595
EWS Watchlist
Comment 36 2018-01-25 12:43:36 PST
Comment on attachment 332286 [details] Rebase after r227595 Attachment 332286 [details] did not pass win-ews (win): Output: http://webkit-queues.webkit.org/results/6211307 New failing tests: http/tests/preload/onerror_event.html http/tests/misc/bubble-drag-events.html
EWS Watchlist
Comment 37 2018-01-25 12:43:47 PST
Created attachment 332301 [details] Archive of layout-test-results from ews206 for win-future The attached test failures were seen while running run-webkit-tests on the win-ews. Bot: ews206 Port: win-future Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Chris Nardi
Comment 38 2018-03-05 17:23:55 PST
Dean: any thoughts on the latest version of this patch?
Chris Nardi
Comment 39 2018-04-20 12:03:23 PDT
Simon Fraser (smfr)
Comment 40 2018-04-20 14:16:51 PDT
Comment on attachment 338448 [details] Rebase View in context: https://bugs.webkit.org/attachment.cgi?id=338448&action=review > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:536 > + RefPtr<CSSPrimitiveValue> hslValue = consumeAngle(args, cssParserMode, UnitlessQuirk::Forbid); auto > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:537 > + double angleValue; Bonus points if the name indicates if it's degrees or radians. > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:546 > + // The hue needs to be in the range [0.0, 6.0) This needs a comment to say where the 6 comes from. I assume this feeds into the calcHue logic. Should we convert to the 6-based values here, or keep it as an angle at this point? > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:570 > + RefPtr<CSSPrimitiveValue> alphaPercent = consumePercent(args, ValueRangeAll); auto
Chris Nardi
Comment 41 2018-04-20 14:41:39 PDT
Created attachment 338462 [details] Address comments by Simon
Chris Nardi
Comment 42 2018-04-20 14:45:45 PDT
(In reply to Simon Fraser (smfr) from comment #40) > > Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:546 > > + // The hue needs to be in the range [0.0, 6.0) > > This needs a comment to say where the 6 comes from. I assume this feeds into > the calcHue logic. Should we convert to the 6-based values here, or keep it > as an angle at this point? I added "for calcHue()" to hopefully clarify; the other values are already converted to their [0.0, 1.0) values right below so I think it makes sense to convert at this point. For reference, changing it to 6-based instead of 1-based is because the spec's pseudocode changed in Color 4 (https://drafts.csswg.org/css-color/#hsl-to-rgb), and matching our implementation to the pseudocode should help spot any bugs/make updates easier.
EWS Watchlist
Comment 43 2018-04-20 14:59:34 PDT
Comment on attachment 338462 [details] Address comments by Simon Rejecting attachment 338462 [details] from commit-queue. cnardi@chromium.org does not have committer permissions according to https://trac.webkit.org/browser/trunk/Tools/Scripts/webkitpy/common/config/contributors.json. - If you do not have committer rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags. - If you have committer rights please correct the error in Tools/Scripts/webkitpy/common/config/contributors.json by adding yourself to the file (no review needed). The commit-queue restarts itself every 2 hours. After restart the commit-queue will correctly respect your committer rights.
WebKit Commit Bot
Comment 44 2018-04-20 15:28:57 PDT
Comment on attachment 338462 [details] Address comments by Simon Clearing flags on attachment: 338462 Committed r230861: <https://trac.webkit.org/changeset/230861>
WebKit Commit Bot
Comment 45 2018-04-20 15:28:59 PDT
All reviewed patches have been landed. Closing bug.
Simon Fraser (smfr)
Comment 46 2018-06-14 20:51:59 PDT
This patch broke round-tripping HSL values between color.getHSL() and makeRGBAFromHSLA(). makeRGBAFromHSLA () says: // Hue is in the range of 0 to 6.0, the remainder are in the range 0 to 1.0 and getHSL() wants 0-1 hue.
Simon Fraser (smfr)
Comment 47 2018-06-14 20:55:49 PDT
I filed bug 186642.
Note You need to log in before you can comment on or make changes to this bug.