Replace Color::getHSL() with sRGBToHSL to ensure it at least gives somewhat sensible...
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 May 2020 22:54:11 +0000 (22:54 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 May 2020 22:54:11 +0000 (22:54 +0000)
commit72bdf2fb2e339f1b97286268bae62cebedf680a7
treeb11638b446e5654eb2002b7d1143e4d8090a90d6
parent1a9a458a7db7dd92d35f26268d371e6d76951a98
Replace Color::getHSL() with sRGBToHSL to ensure it at least gives somewhat sensible results for ExtendedColors and reduce code duplication
https://bugs.webkit.org/show_bug.cgi?id=212143

Reviewed by Simon Fraser.

Source/WebCore:

- Updated API tests to test sRGBToHSL() rather than Color::getHSL() and extended the tests
  to include lightness tests and round tripping tests.
- Update editing/pasteboard/paste-dark-mode-color-filtered.html with extended color test cases.

Replaces Color::getHSL() with sRGBToHSL(color.toSRGBAComponentsLossy()) and adds
an optimized variant, lightness(...) that just extracts the lightness component for
callers that only needed that.

It is now required to explicitly use color.toSRGBAComponentsLossy() to indicate that
for non-SRGB colors, this will be a lossy transformation and give us an easy way to
find all these sites in the future, if we want to make a better conversion for other
color spaces.

* editing/ReplaceSelectionCommand.cpp:
(WebCore::fragmentNeedsColorTransformed):
Switch to using lightness(). This was previously broken for extended colors but now works (though
in a lossy way through sRGB). Update editing/pasteboard/paste-dark-mode-color-filtered.html with extended colors.

* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::detectContentInRange):
Switch to using sRGBToHSL(color.toSRGBAComponentsLossy()).

* page/FrameView.cpp:
(WebCore::FrameView::recalculateScrollbarOverlayStyle):
Switch to using lightness().

* platform/graphics/Color.cpp:
(WebCore::Color::getHSL const): Deleted.
* platform/graphics/Color.h:
Remove Color::getHSL().

* platform/graphics/ColorUtilities.cpp:
(WebCore::lightness):
Added optimized subset of sRGBToHSL which just computes the lightness component for callers
that only need that.

(WebCore::sRGBToHSL):
Simplify/cleanup code a little using initialize-list based std::max/std::min and structured bindings.

* platform/graphics/ColorUtilities.h:
Export functions to allow testing them directly.

Source/WebKit:

* UIProcess/API/ios/WKWebViewIOS.mm:
(-[WKWebView _updateScrollViewBackground]):
Switch to using Color::lightness().

Tools:

* TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
(TestWebKitAPI::TEST):
Update tests to use sRGBToHSL instead of Color::getHSL() and add testing of WebCore::lightness() and
round tripping. Update results for hue to be 0->1 rather than 0->6 which allows the round tripping to succeed.

LayoutTests:

* editing/pasteboard/paste-dark-mode-color-filtered-expected.txt:
* editing/pasteboard/paste-dark-mode-color-filtered.html:
Update test to include a test case that uses extended colors.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261967 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/paste-dark-mode-color-filtered-expected.txt
LayoutTests/editing/pasteboard/paste-dark-mode-color-filtered.html
Source/WebCore/ChangeLog
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/cocoa/DataDetection.mm
Source/WebCore/page/FrameView.cpp
Source/WebCore/platform/graphics/Color.cpp
Source/WebCore/platform/graphics/Color.h
Source/WebCore/platform/graphics/ColorUtilities.cpp
Source/WebCore/platform/graphics/ColorUtilities.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/ColorTests.cpp