Setting foreground color when editing should take color-filter into account, and...
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2018 21:18:27 +0000 (21:18 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jul 2018 21:18:27 +0000 (21:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187778

Reviewed by Ryosuke Niwa.
Source/WebCore:

Fix two aspects of editing with color-filter:

1. When setting foreground color, inverse-transform the color through -apple-color-filter so that the user gets the color
   they chose when in Dark Mode. Tested by editing/style/exec-command-foreColor-with-color-filter.html.

2. When retrieving the style of the collapsed selection, take color filter into account so that color picker
   reflects the color the users sees, instead of the content color. Tested by editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html

Add two additional tests that ensure that -apple-color-filter does not impact the NSAttributedString code
path, since -apple-color-filter should not affect the behavior of Copy.

Tests: editing/mac/attributed-string/attrib-string-colors-with-color-filter.html
       editing/mac/attributed-string/attrib-string-range-with-color-filter.html
       editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html
       editing/style/exec-command-foreColor-with-color-filter.html

* editing/EditingStyle.cpp:
(WebCore::StyleChange::StyleChange):
(WebCore::StyleChange::extractTextStyles):
* editing/EditingStyle.h:
* editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::fontAttributesForSelectionStart const):
* platform/graphics/filters/FilterOperation.cpp:
(WebCore::InvertLightnessFilterOperation::inverseTransformColor const):
* platform/graphics/filters/FilterOperation.h:
(WebCore::FilterOperation::inverseTransformColor const):
* platform/graphics/filters/FilterOperations.cpp:
(WebCore::FilterOperations::transformColor const):
(WebCore::FilterOperations::inverseTransformColor const):
* platform/graphics/filters/FilterOperations.h:

LayoutTests:

* editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt: Added.
* editing/mac/attributed-string/attrib-string-colors-with-color-filter.html: Added.
* editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt: Added.
* editing/mac/attributed-string/attrib-string-range-with-color-filter.html: Added.
* editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt: Added.
* editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html: Added.
* editing/style/exec-command-foreColor-with-color-filter-expected.txt: Added.
* editing/style/exec-command-foreColor-with-color-filter.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234005 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter.html [new file with mode: 0644]
LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html [new file with mode: 0644]
LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html [new file with mode: 0644]
LayoutTests/editing/style/exec-command-foreColor-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/exec-command-foreColor-with-color-filter.html [new file with mode: 0644]
LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/editing/EditingStyle.cpp
Source/WebCore/editing/EditingStyle.h
Source/WebCore/editing/cocoa/EditorCocoa.mm
Source/WebCore/platform/graphics/filters/FilterOperation.cpp
Source/WebCore/platform/graphics/filters/FilterOperation.h
Source/WebCore/platform/graphics/filters/FilterOperations.cpp
Source/WebCore/platform/graphics/filters/FilterOperations.h

index 94b794e..9205439 100644 (file)
@@ -1,3 +1,19 @@
+2018-07-18  Simon Fraser  <simon.fraser@apple.com>
+
+        Setting foreground color when editing should take color-filter into account, and report the correct foreground color for collapsed selections
+        https://bugs.webkit.org/show_bug.cgi?id=187778
+
+        Reviewed by Ryosuke Niwa.
+
+        * editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt: Added.
+        * editing/mac/attributed-string/attrib-string-colors-with-color-filter.html: Added.
+        * editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt: Added.
+        * editing/mac/attributed-string/attrib-string-range-with-color-filter.html: Added.
+        * editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt: Added.
+        * editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html: Added.
+        * editing/style/exec-command-foreColor-with-color-filter-expected.txt: Added.
+        * editing/style/exec-command-foreColor-with-color-filter.html: Added.
+
 2018-07-19  Truitt Savell  <tsavell@apple.com>
 
         [ win-ews ] http/tests/preload/onload_event.html is flakey crash on win-ews
diff --git a/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt b/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt
new file mode 100644 (file)
index 0000000..1c0e6a8
--- /dev/null
@@ -0,0 +1,53 @@
+Input:
+<div style="-apple-color-filter: apple-invert-lightness()">
+    <span style="color: blue; background-color: #EEE">This text is blue</span>
+    <span style="color: yellow; background-color: maroon">This text is yellow</span>
+</div>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+    LineSpacing: 0
+    ParagraphSpacing: 0
+    ParagraphSpacingBefore: 0
+    HeadIndent: 0
+    TailIndent: 0
+    FirstLineHeadIndent: 0
+    LineHeight: 0/0
+    LineHeightMultiple: 0
+    LineBreakMode: 0
+    Tabs: ()
+    DefaultTabInterval: 36
+    Blocks: (
+)
+    Lists: (
+)
+    BaseWritingDirection: 0
+    HyphenationFactor: 0
+    TighteningForTruncation: YES
+    HeaderLevel: 0
+[This text is blue]
+    NSBackgroundColor: #eeeeee (sRGB)
+    NSColor: #0000ff (sRGB)
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #0000ff (sRGB)
+    NSStrokeWidth: 0
+[ ]
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #000000 (sRGB)
+    NSStrokeWidth: 0
+[This text is yellow]
+    NSBackgroundColor: #800000 (sRGB)
+    NSColor: #ffff00 (sRGB)
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #ffff00 (sRGB)
+    NSStrokeWidth: 0
+[\n]
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #000000 (sRGB)
+    NSStrokeWidth: 0
+
diff --git a/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter.html b/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter.html
new file mode 100644 (file)
index 0000000..58e7513
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
+<html>
+<head>
+    <title>-apple-color-filter should not affect attributed string colors</title>
+    <script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<div style="-apple-color-filter: apple-invert-lightness()">
+    <span style="color: blue; background-color: #EEE">This text is blue</span>
+    <span style="color: yellow; background-color: maroon">This text is yellow</span>
+</div>
+</body>
+</html>
diff --git a/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt b/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt
new file mode 100644 (file)
index 0000000..f151a69
--- /dev/null
@@ -0,0 +1,7 @@
+Test that an NSAttributedString from a range doesn't convert colors through -apple-color-filter.
+
+[is t]
+    NSColor: #cccccc (sRGB)
+    NSFont: Times-Roman 16.00 pt.
+
+
diff --git a/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html b/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html
new file mode 100644 (file)
index 0000000..81c8fcf
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
+<div id="target" style="color: #CCC; -apple-color-filter: apple-invert-lightness();"contenteditable>This text is light gray</div>
+<p>
+    Test that an NSAttributedString from a range doesn't convert colors through -apple-color-filter.
+</p>
+<script src="resources/dump-attributed-string.js"></script>
+<script>
+    var shouldAutoDump = false;
+</script>
+<pre id="console"></pre>
+<script>
+    function log(message)
+    {
+        document.getElementById("console").append(message + "\n");
+    }
+
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+
+        var target = document.getElementById("target");
+        target.focus();
+
+        var attributedString = textInputController.attributedSubstringFromRange(2, 4);
+        var serializedString = serializeAttributedString(attributedString);
+        log(serializedString);
+
+        target.parentNode.removeChild(target);
+    } else
+        log("This test can only run in DumpRenderTree.");
+</script>
diff --git a/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt b/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt
new file mode 100644 (file)
index 0000000..1a5e437
--- /dev/null
@@ -0,0 +1,9 @@
+Some text here
+Input:
+<div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4);" contenteditable="">Some text here</div>
+
+Output:
+[ ]
+    NSColor: rgba(239, 239, 239, 0.4) (sRGB)
+    NSFont: Times-Roman 16.00 pt.
+
diff --git a/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html b/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html
new file mode 100644 (file)
index 0000000..b328bf1
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+<script>
+    shouldAutoDump = false;
+</script>
+</head>
+<body>
+
+<div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4);" contenteditable>Some text here</div>
+<pre id="result">This test requires DumpRenderTree</pre>
+<script type="text/javascript">
+    
+document.getElementById("editor").focus();
+getSelection().setPosition(editor, 0);
+
+if (window.testRunner) {
+    var attribString = textInputController.attributedStringForTyping()
+    var serialized = serializeAttributedString(attribString);
+    result.textContent = 'Input:\n' + editor.outerHTML.trim() + '\n\nOutput:\n' + serialized;
+
+    document.body.appendChild(pre);
+}
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/exec-command-foreColor-with-color-filter-expected.txt b/LayoutTests/editing/style/exec-command-foreColor-with-color-filter-expected.txt
new file mode 100644 (file)
index 0000000..cfe4f67
--- /dev/null
@@ -0,0 +1,5 @@
+
+"world" should be #ecfffd:
+| <font>
+|   color="#ecfffd"
+|   "<#selection-anchor>hello world<#selection-focus>"
diff --git a/LayoutTests/editing/style/exec-command-foreColor-with-color-filter.html b/LayoutTests/editing/style/exec-command-foreColor-with-color-filter.html
new file mode 100644 (file)
index 0000000..8d44bb5
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
+<html>
+<head>
+<title>Setting the foreground color should invert the color through -apple-color-filter</title>
+<script src="../../resources/dump-as-markup.js"></script>
+</head>
+<body>
+<div id="test" style="-apple-color-filter: apple-invert-lightness()" contenteditable>hello world</div>
+<script>
+window.getSelection().setPosition(test, 0);
+window.getSelection().modify('extend', 'forward', 'word');
+window.getSelection().modify('extend', 'forward', 'word');
+document.execCommand('foreColor', false, '#224433');
+Markup.dump('test', '"world" should be #ecfffd');
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt b/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt
new file mode 100644 (file)
index 0000000..09981bf
--- /dev/null
@@ -0,0 +1,53 @@
+Input:
+<div style="-apple-color-filter: apple-invert-lightness()">
+    <span style="color: blue; background-color: #EEE">This text is blue</span>
+    <span style="color: yellow; background-color: maroon">This text is yellow</span>
+</div>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+    LineSpacing: 0
+    ParagraphSpacing: 0
+    ParagraphSpacingBefore: 0
+    HeadIndent: 0
+    TailIndent: 0
+    FirstLineHeadIndent: 0
+    LineHeight: 0/0
+    LineHeightMultiple: 0
+    LineBreakMode: 0
+    Tabs: ()
+    DefaultTabInterval: 36
+    Blocks: (
+)
+    Lists: (
+)
+    BaseWritingDirection: 0
+    HyphenationFactor: 0
+    TighteningForTruncation: YES
+    HeaderLevel: 0
+[This text is blue]
+    NSBackgroundColor: #eeeeee (NSCustomColorSpace)
+    NSColor: #0000ff (NSCustomColorSpace)
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #0000ff (NSCustomColorSpace)
+    NSStrokeWidth: 0
+[ ]
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #000000 (NSCustomColorSpace)
+    NSStrokeWidth: 0
+[This text is yellow]
+    NSBackgroundColor: #800000 (NSCustomColorSpace)
+    NSColor: #ffff00 (NSCustomColorSpace)
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #ffff00 (NSCustomColorSpace)
+    NSStrokeWidth: 0
+[\n]
+    NSFont: Times-Roman 16.00 pt.
+    NSKern: 0pt
+    NSStrokeColor: #000000 (NSCustomColorSpace)
+    NSStrokeWidth: 0
+
diff --git a/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt b/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt
new file mode 100644 (file)
index 0000000..fab076c
--- /dev/null
@@ -0,0 +1,7 @@
+Test that an NSAttributedString from a range doesn't convert colors through -apple-color-filter.
+
+[is t]
+    NSColor: #cccccc (NSCustomColorSpace)
+    NSFont: Times-Roman 16.00 pt.
+
+
index 8db5d1b..2a01fdf 100644 (file)
@@ -98,6 +98,7 @@ webkit.org/b/173281 http/tests/security/mixedContent/insecure-image-redirects-to
 webkit.org/b/173281 http/tests/security/mixedContent/secure-redirect-to-insecure-redirect-to-basic-auth-secure-image-allowCrossOriginSubresourcesToAskForCredentials.https.html [ Skip ]
 webkit.org/b/173281 http/tests/security/mixedContent/secure-redirect-to-secure-redirect-to-basic-auth-insecure-image-allowCrossOriginSubresourcesToAskForCredentials.https.html [ Skip ]
 webkit.org/b/173281 http/tests/security/mixedContent/secure-redirect-to-secure-redirect-to-basic-auth-secure-image-allowCrossOriginSubresourcesToAskForCredentials.https.html [ Skip ]
+webkit.org/b/173281 editing/style/exec-command-foreColor-with-color-filter.html [ Skip ]
 
 # TODO HW filters not yet supported on Windows
 webkit.org/b/74716 css3/filters/effect-blur-hw.html [ Skip ]
index 180caab..25b5e67 100644 (file)
@@ -1,3 +1,41 @@
+2018-07-18  Simon Fraser  <simon.fraser@apple.com>
+
+        Setting foreground color when editing should take color-filter into account, and report the correct foreground color for collapsed selections
+        https://bugs.webkit.org/show_bug.cgi?id=187778
+
+        Reviewed by Ryosuke Niwa.
+        
+        Fix two aspects of editing with color-filter:
+
+        1. When setting foreground color, inverse-transform the color through -apple-color-filter so that the user gets the color
+           they chose when in Dark Mode. Tested by editing/style/exec-command-foreColor-with-color-filter.html.
+
+        2. When retrieving the style of the collapsed selection, take color filter into account so that color picker
+           reflects the color the users sees, instead of the content color. Tested by editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html
+
+        Add two additional tests that ensure that -apple-color-filter does not impact the NSAttributedString code
+        path, since -apple-color-filter should not affect the behavior of Copy.
+
+        Tests: editing/mac/attributed-string/attrib-string-colors-with-color-filter.html
+               editing/mac/attributed-string/attrib-string-range-with-color-filter.html
+               editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html
+               editing/style/exec-command-foreColor-with-color-filter.html
+
+        * editing/EditingStyle.cpp:
+        (WebCore::StyleChange::StyleChange):
+        (WebCore::StyleChange::extractTextStyles):
+        * editing/EditingStyle.h:
+        * editing/cocoa/EditorCocoa.mm:
+        (WebCore::Editor::fontAttributesForSelectionStart const):
+        * platform/graphics/filters/FilterOperation.cpp:
+        (WebCore::InvertLightnessFilterOperation::inverseTransformColor const):
+        * platform/graphics/filters/FilterOperation.h:
+        (WebCore::FilterOperation::inverseTransformColor const):
+        * platform/graphics/filters/FilterOperations.cpp:
+        (WebCore::FilterOperations::transformColor const):
+        (WebCore::FilterOperations::inverseTransformColor const):
+        * platform/graphics/filters/FilterOperations.h:
+
 2018-07-19  David Fenton  <david_fenton@apple.com>
 
         Unreviewed, rolling out r233994.
index 5a1dbef..7afde63 100644 (file)
@@ -1580,7 +1580,7 @@ StyleChange::StyleChange(EditingStyle* style, const Position& position)
     reconcileTextDecorationProperties(mutableStyle.get());
     bool shouldStyleWithCSS = document->frame()->editor().shouldStyleWithCSS();
     if (!shouldStyleWithCSS)
-        extractTextStyles(document, *mutableStyle, computedStyle.useFixedFontDefaultSize());
+        extractTextStyles(document, *node, *mutableStyle, computedStyle.useFixedFontDefaultSize());
 
     bool shouldAddUnderline = style->underlineChange() == TextDecorationChange::Add;
     bool shouldAddStrikeThrough = style->strikeThroughChange() == TextDecorationChange::Add;
@@ -1653,7 +1653,7 @@ static void setTextDecorationProperty(MutableStyleProperties& style, const CSSVa
     }
 }
 
-void StyleChange::extractTextStyles(Document* document, MutableStyleProperties& style, bool shouldUseFixedFontDefaultSize)
+void StyleChange::extractTextStyles(Document* document, Node& startNode, MutableStyleProperties& style, bool shouldUseFixedFontDefaultSize)
 {
     if (identifierForStyleProperty(style, CSSPropertyFontWeight) == CSSValueBold) {
         style.removeProperty(CSSPropertyFontWeight);
@@ -1697,7 +1697,12 @@ void StyleChange::extractTextStyles(Document* document, MutableStyleProperties&
     }
 
     if (style.getPropertyCSSValue(CSSPropertyColor)) {
-        m_applyFontColor = Color(textColorFromStyle(style)).serialized();
+        Color newColor = textColorFromStyle(style);
+
+        if (startNode.renderer() && startNode.renderer()->style().hasAppleColorFilter())
+            startNode.renderer()->style().appleColorFilter().inverseTransformColor(newColor);
+
+        m_applyFontColor = newColor.serialized();
         style.removeProperty(CSSPropertyColor);
     }
 
index 4773e07..8a8326a 100644 (file)
@@ -222,7 +222,7 @@ public:
         return !(*this == other);
     }
 private:
-    void extractTextStyles(Document*, MutableStyleProperties&, bool shouldUseFixedFontDefaultSize);
+    void extractTextStyles(Document*, Node& startNode, MutableStyleProperties&, bool shouldUseFixedFontDefaultSize);
 
     RefPtr<MutableStyleProperties> m_cssStyle;
     bool m_applyBold = false;
index 432dc19..bc63453 100644 (file)
@@ -93,11 +93,14 @@ RetainPtr<NSDictionary> Editor::fontAttributesForSelectionStart() const
 
     // FIXME: Why would we not want to retrieve these attributes on iOS?
 #if PLATFORM(MAC)
-    Color backgroundColor = style->visitedDependentColor(CSSPropertyBackgroundColor);
+    // FIXME: for now, always report the colors after applying -apple-color-filter. In future not all clients
+    // may want this, so we may have to add a setting to control it. See also editingAttributedStringFromRange().
+    Color backgroundColor = style->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
     if (backgroundColor.isVisible())
         [attributes setObject:nsColor(backgroundColor) forKey:NSBackgroundColorAttributeName];
 
-    Color foregroundColor = style->visitedDependentColor(CSSPropertyColor);
+    Color foregroundColor = style->visitedDependentColorWithColorFilter(CSSPropertyColor);
+    // FIXME: isBlackColor not suitable for dark mode.
     if (foregroundColor.isValid() && !Color::isBlackColor(foregroundColor))
         [attributes setObject:nsColor(foregroundColor) forKey:NSForegroundColorAttributeName];
 
index d5368b2..22b7373 100644 (file)
@@ -253,6 +253,29 @@ bool InvertLightnessFilterOperation::transformColor(FloatComponents& sRGBColorCo
     return true;
 }
 
+bool InvertLightnessFilterOperation::inverseTransformColor(FloatComponents& sRGBColorComponents) const
+{
+    FloatComponents rgbComponents = sRGBColorComponents;
+    // Apply the matrix.
+    float matrixValues[20] = {
+        -1.124858, -0.244747, 0.119605, 0, 1.25,
+        -0.124506, -1.244758, 0.119264, 0, 1.25,
+        -0.12445, -0.244568, -0.880982, 0, 1.25,
+        0, 0, 0, 1, 0
+
+    };
+    ColorMatrix toLightModeMatrix(matrixValues);
+    toLightModeMatrix.transformColorComponents(rgbComponents);
+
+    // Convert to HSL.
+    FloatComponents hslComponents = sRGBToHSL(rgbComponents);
+    // Hue rotate by 180deg.
+    hslComponents.components[0] = fmod(hslComponents.components[0] + 0.5f, 1.0f);
+    // And return RGB.
+    sRGBColorComponents = HSLToSRGB(hslComponents);
+    return true;
+}
+
 bool BlurFilterOperation::operator==(const FilterOperation& operation) const
 {
     if (!isSameType(operation))
index 7b62e0e..997482f 100644 (file)
@@ -80,6 +80,7 @@ public:
     }
     
     virtual bool transformColor(FloatComponents&) const { return false; }
+    virtual bool inverseTransformColor(FloatComponents&) const { return false; }
 
     OperationType type() const { return m_type; }
 
@@ -278,7 +279,7 @@ public:
         return adoptRef(*new InvertLightnessFilterOperation());
     }
 
-    Ref<FilterOperation> clone() const override
+    Ref<FilterOperation> clone() const final
     {
         return adoptRef(*new InvertLightnessFilterOperation());
     }
@@ -286,14 +287,15 @@ public:
     RefPtr<FilterOperation> blend(const FilterOperation* from, double progress, bool blendToPassthrough = false) override;
 
 private:
-    bool operator==(const FilterOperation&) const override;
+    bool operator==(const FilterOperation&) const final;
 
     InvertLightnessFilterOperation()
         : FilterOperation(APPLE_INVERT_LIGHTNESS)
     {
     }
 
-    bool transformColor(FloatComponents&) const override;
+    bool transformColor(FloatComponents&) const final;
+    bool inverseTransformColor(FloatComponents&) const final;
 };
 
 class WEBCORE_EXPORT BlurFilterOperation : public FilterOperation {
index 14c473a..36dfcf7 100644 (file)
@@ -140,6 +140,26 @@ bool FilterOperations::transformColor(Color& color) const
     return true;
 }
 
+bool FilterOperations::inverseTransformColor(Color& color) const
+{
+    if (isEmpty() || !color.isValid())
+        return false;
+    // Color filter does not apply to semantic CSS colors (like "Windowframe").
+    if (color.isSemantic())
+        return false;
+
+    FloatComponents components;
+    color.getRGBA(components.components[0], components.components[1], components.components[2], components.components[3]);
+
+    for (auto& operation : m_operations) {
+        if (!operation->inverseTransformColor(components))
+            return false;
+    }
+
+    color = Color(components.components[0], components.components[1], components.components[2], components.components[3]);
+    return true;
+}
+
 bool FilterOperations::hasFilterThatAffectsOpacity() const
 {
     for (auto& operation : m_operations) {
index 9ab304e..930343c 100644 (file)
@@ -61,6 +61,7 @@ public:
     bool hasReferenceFilter() const;
 
     bool transformColor(Color&) const;
+    bool inverseTransformColor(Color&) const;
 
 private:
     Vector<RefPtr<FilterOperation>> m_operations;