Title: [234031] branches/safari-606-branch
Revision
234031
Author
[email protected]
Date
2018-07-20 01:05:45 -0700 (Fri, 20 Jul 2018)

Log Message

Cherry-pick r234005. rdar://problem/42417113

    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.
    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

Modified Paths

Added Paths

Diff

Modified: branches/safari-606-branch/LayoutTests/ChangeLog (234030 => 234031)


--- branches/safari-606-branch/LayoutTests/ChangeLog	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/LayoutTests/ChangeLog	2018-07-20 08:05:45 UTC (rev 234031)
@@ -1,3 +1,73 @@
+2018-07-20  Babak Shafiei  <[email protected]>
+
+        Cherry-pick r234005. rdar://problem/42417113
+
+    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.
+    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
+
+    2018-07-18  Simon Fraser  <[email protected]>
+
+            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  Ryan Haddad  <[email protected]>
 
         Cherry-pick r233938. rdar://problem/42387347

Added: branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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
+

Added: branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter.html (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter.html	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-colors-with-color-filter.html	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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=""
+</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>

Added: branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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.
+
+

Added: branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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=""
+<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>

Added: branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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.
+

Added: branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html	2018-07-20 08:05:45 UTC (rev 234031)
@@ -0,0 +1,29 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
+<html>
+<head>
+<script src=""
+<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>

Added: branches/safari-606-branch/LayoutTests/editing/style/exec-command-foreColor-with-color-filter-expected.txt (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/style/exec-command-foreColor-with-color-filter-expected.txt	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/style/exec-command-foreColor-with-color-filter-expected.txt	2018-07-20 08:05:45 UTC (rev 234031)
@@ -0,0 +1,5 @@
+
+"world" should be #ecfffd:
+| <font>
+|   color="#ecfffd"
+|   "<#selection-anchor>hello world<#selection-focus>"

Added: branches/safari-606-branch/LayoutTests/editing/style/exec-command-foreColor-with-color-filter.html (0 => 234031)


--- branches/safari-606-branch/LayoutTests/editing/style/exec-command-foreColor-with-color-filter.html	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/editing/style/exec-command-foreColor-with-color-filter.html	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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=""
+</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>

Added: branches/safari-606-branch/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt (0 => 234031)


--- branches/safari-606-branch/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-colors-with-color-filter-expected.txt	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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
+

Added: branches/safari-606-branch/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt (0 => 234031)


--- branches/safari-606-branch/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt	                        (rev 0)
+++ branches/safari-606-branch/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt	2018-07-20 08:05:45 UTC (rev 234031)
@@ -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.
+
+

Modified: branches/safari-606-branch/LayoutTests/platform/win/TestExpectations (234030 => 234031)


--- branches/safari-606-branch/LayoutTests/platform/win/TestExpectations	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/LayoutTests/platform/win/TestExpectations	2018-07-20 08:05:45 UTC (rev 234031)
@@ -98,6 +98,7 @@
 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 ]

Modified: branches/safari-606-branch/Source/WebCore/ChangeLog (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/ChangeLog	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/ChangeLog	2018-07-20 08:05:45 UTC (rev 234031)
@@ -1,5 +1,97 @@
 2018-07-20  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r234005. rdar://problem/42417113
+
+    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.
+    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
+
+    2018-07-18  Simon Fraser  <[email protected]>
+
+            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-20  Babak Shafiei  <[email protected]>
+
         Cherry-pick r233992. rdar://problem/42417109
 
     Update iOS fullscreen alert text again

Modified: branches/safari-606-branch/Source/WebCore/editing/EditingStyle.cpp (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/editing/EditingStyle.cpp	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/editing/EditingStyle.cpp	2018-07-20 08:05:45 UTC (rev 234031)
@@ -1580,7 +1580,7 @@
     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 @@
     }
 }
 
-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 @@
     }
 
     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);
     }
 

Modified: branches/safari-606-branch/Source/WebCore/editing/EditingStyle.h (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/editing/EditingStyle.h	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/editing/EditingStyle.h	2018-07-20 08:05:45 UTC (rev 234031)
@@ -222,7 +222,7 @@
         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;

Modified: branches/safari-606-branch/Source/WebCore/editing/cocoa/EditorCocoa.mm (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/editing/cocoa/EditorCocoa.mm	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/editing/cocoa/EditorCocoa.mm	2018-07-20 08:05:45 UTC (rev 234031)
@@ -93,11 +93,14 @@
 
     // 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];
 

Modified: branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperation.cpp (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperation.cpp	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperation.cpp	2018-07-20 08:05:45 UTC (rev 234031)
@@ -253,6 +253,29 @@
     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))

Modified: branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperation.h (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperation.h	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperation.h	2018-07-20 08:05:45 UTC (rev 234031)
@@ -80,6 +80,7 @@
     }
     
     virtual bool transformColor(FloatComponents&) const { return false; }
+    virtual bool inverseTransformColor(FloatComponents&) const { return false; }
 
     OperationType type() const { return m_type; }
 
@@ -278,7 +279,7 @@
         return adoptRef(*new InvertLightnessFilterOperation());
     }
 
-    Ref<FilterOperation> clone() const override
+    Ref<FilterOperation> clone() const final
     {
         return adoptRef(*new InvertLightnessFilterOperation());
     }
@@ -286,7 +287,7 @@
     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)
@@ -293,7 +294,8 @@
     {
     }
 
-    bool transformColor(FloatComponents&) const override;
+    bool transformColor(FloatComponents&) const final;
+    bool inverseTransformColor(FloatComponents&) const final;
 };
 
 class WEBCORE_EXPORT BlurFilterOperation : public FilterOperation {

Modified: branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperations.cpp (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperations.cpp	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperations.cpp	2018-07-20 08:05:45 UTC (rev 234031)
@@ -140,6 +140,26 @@
     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) {

Modified: branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperations.h (234030 => 234031)


--- branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperations.h	2018-07-20 08:05:38 UTC (rev 234030)
+++ branches/safari-606-branch/Source/WebCore/platform/graphics/filters/FilterOperations.h	2018-07-20 08:05:45 UTC (rev 234031)
@@ -61,6 +61,7 @@
     bool hasReferenceFilter() const;
 
     bool transformColor(Color&) const;
+    bool inverseTransformColor(Color&) const;
 
 private:
     Vector<RefPtr<FilterOperation>> m_operations;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to