Add color filter for transforming colors in Dark Mode
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2018 02:03:33 +0000 (02:03 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jul 2018 02:03:33 +0000 (02:03 +0000)
commita75d565c7c879b8f1eaadb46918379d5103b9efd
treee335c1a8552757678e886564126b7ad30e163e82
parent016e9bda6c99b1fc7ca475679e6804e9e8c59292
Add color filter for transforming colors in Dark Mode
https://bugs.webkit.org/show_bug.cgi?id=187717
Source/WebCore:

rdar://problem/41146650

Reviewed by Dean Jackson.

Add a new filter function for use in -apple-color-filter for transforming colors
when in Dark Mode. The filter is called apple-invert-lightness(), and takes no parameters.
It's based on a lightness invert in HSL space, with some adjustments to improve the contrast
of some colors on dark backgrounds, so does a much better job that using invert() with hue-rotate().

Test: css3/color-filters/color-filter-apple-invert-lightness.html

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::valueForFilter):
* css/CSSValueKeywords.in:
* css/StyleResolver.cpp:
(WebCore::filterOperationForType):
(WebCore::StyleResolver::createFilterOperations):
* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::parseSingleValue):
* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeFilterImage):
(WebCore::CSSPropertyParserHelpers::isPixelFilterFunction):
(WebCore::CSSPropertyParserHelpers::isColorFilterFunction):
(WebCore::CSSPropertyParserHelpers::consumeFilterFunction):
(WebCore::CSSPropertyParserHelpers::consumeFilter):
(WebCore::CSSPropertyParserHelpers::isValidPrimitiveFilterFunction): Deleted.
* css/parser/CSSPropertyParserHelpers.h:
* page/FrameView.cpp:
(WebCore::FrameView::paintContents):
* platform/graphics/Color.cpp:
* platform/graphics/ColorUtilities.cpp:
(WebCore::sRGBToLinearComponents):
(WebCore::linearToSRGBComponents):
(WebCore::sRGBToLinearColorComponentForLuminance):
(WebCore::luminance):
(WebCore::sRGBToHSL):
(WebCore::calcHue):
(WebCore::HSLToSRGB):
(WebCore::ColorMatrix::ColorMatrix):
* platform/graphics/ColorUtilities.h:
* platform/graphics/ca/cocoa/PlatformCAFiltersCocoa.mm:
(PlatformCAFilters::filterValueForOperation):
(PlatformCAFilters::colorMatrixValueForFilter):
* platform/graphics/filters/FEColorMatrix.cpp:
* platform/graphics/filters/FilterOperation.cpp:
(WebCore::InvertLightnessFilterOperation::operator== const):
(WebCore::InvertLightnessFilterOperation::blend):
(WebCore::InvertLightnessFilterOperation::transformColor const):
(WebCore::operator<<):
* platform/graphics/filters/FilterOperation.h:
* rendering/FilterEffectRenderer.cpp:
(WebCore::FilterEffectRenderer::build):

Source/WebKit:

Reviewed by Dean Jackson.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<FilterOperation>::encode):
(IPC::decodeFilterOperation):

LayoutTests:

rdar://problem/41146650

Reviewed by Dean Jackson.

* css3/color-filters/color-filter-apple-invert-lightness-expected.html: Added.
* css3/color-filters/color-filter-apple-invert-lightness.html: Added.
* css3/color-filters/color-filter-parsing-expected.txt:
* css3/color-filters/color-filter-parsing.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233877 268f45cc-cd09-0410-ab3c-d52691b4dbfc
22 files changed:
LayoutTests/ChangeLog
LayoutTests/css3/color-filters/color-filter-apple-invert-lightness-expected.html [new file with mode: 0644]
LayoutTests/css3/color-filters/color-filter-apple-invert-lightness.html [new file with mode: 0644]
LayoutTests/css3/color-filters/color-filter-parsing-expected.txt
LayoutTests/css3/color-filters/color-filter-parsing.html
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Source/WebCore/css/parser/CSSPropertyParserHelpers.h
Source/WebCore/platform/graphics/Color.cpp
Source/WebCore/platform/graphics/ColorUtilities.cpp
Source/WebCore/platform/graphics/ColorUtilities.h
Source/WebCore/platform/graphics/ca/cocoa/PlatformCAFiltersCocoa.mm
Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp
Source/WebCore/platform/graphics/filters/FilterOperation.cpp
Source/WebCore/platform/graphics/filters/FilterOperation.h
Source/WebCore/rendering/FilterEffectRenderer.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp