Changeset 234064 in webkit


Ignore:
Timestamp:
Jul 20, 2018 2:10:40 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Picking a color from the color panel for typing attributes needs to inverse transform through color-filter
https://bugs.webkit.org/show_bug.cgi?id=187846

Patch by Ryosuke Niwa <rniwa@apple.com> on 2018-07-20
Reviewed by Simon Fraser.

Source/WebCore:

This patch refines the color inversion for editing introduced in r234005 so that font panels and WebKit embedders
can get and set inverted colors using attributed strings for a selected text in an editable region.

More specifically, when font panels or WebKit embedders set a font color or a background color via WebView's
_applyStyleToSelection and _applyEditingStyleToSelection, WebKit would automatically invert the color before inserting
into DOM so that the color visible to the user matches that's given to WebKit. Conversely,
[WebView attributedSubstringFromRange:nsRange] now return the color visible to the user, i.e. the color after
the color filter had been applied, so that some WebKit embedders can present the visually identical color to the user.

Because DOM never sees the color filter's effect in the computed style, etc... this patch reverts the change made to
StyleChange in r234005 to avoid inverting the color passed to execCommand. This makes editing apps which is unaware
of the dark mode or -apple-color-filter continue to function (because the color picker implemented in DOM will be
applied of the same color filter before being presented to the user).

Finally, this patch introduces a testing hook in applyCommandToFrame so that executing foreColor or backColor with
the soruce of CommandFromMenuOrKeyBinding would trigger the same code path as the one taken by Objective-C

Tests: editing/execCommand/set-backColor-with-color-filter-from-scripts.html

editing/execCommand/set-foreColor-with-color-filter-from-scripts.html
editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html
editing/style/set-backColor-with-color-filter.html
editing/style/set-foreColor-with-color-filter.html

  • editing/EditingStyle.cpp:

(WebCore::EditingStyle::inverseTransformColorIfNeeded): Added.
(WebCore::StyleChange::StyleChange): Revert the change made in r234005 since this code is also used by execCommand
which is not desirable, and won't work for background color.
(WebCore::StyleChange::extractTextStyles): Ditto.

  • editing/EditingStyle.h:
  • editing/Editor.cpp:

(WebCore::Editor::applyStyle):
(WebCore::Editor::applyStyleToSelection): Call EditingStyle::inverseTransformColorIfNeeded when ColorFilterMode is
set to InvertColor.

  • editing/Editor.h:
  • editing/EditorCommand.cpp:

(WebCore::applyCommandToFrame): Added the aforementioned testing hook.

  • editing/cocoa/HTMLConverter.mm:

(WebCore::editingAttributedStringFromRange): Take the color filtr into account. Some WebKit embedders use this
function to compute the font color in the selected text. Note that this function is mostly used for input methods
so the color doesn't really matter, and its implementation is distinct from that of HTMLConverter.

Source/WebKitLegacy/mac:

Invert the filtered font and background colors when using font panels, font pasteboard, and other Objective-C APIs.

  • WebView/WebHTMLView.mm:

(-[WebHTMLView _applyStyleToSelection:withUndoAction:]): Share code with _applyEditingStyleToSelection.
(-[WebHTMLView _applyEditingStyleToSelection:withUndoAction:]):

Tools:

Fixed the bug that testRunner.execCommand was using the second argument as the value.

The second argument, aShowDefaultUI, should always be ignored in testRunner.execCommand,
and the third argument should be used as the value. DumpRenderTree's implementation does this already.

  • WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::execCommand):

  • WebKitTestRunner/InjectedBundle/TestRunner.h:

LayoutTests:

Added tests to make sure foreground or background colors specified in execCommand don't get inverted.

Fixed the test which was asserting that textInputController.attributedSubstringFromRange doesn't invert the color
since that's exactly what WebKit embedders uses to compute the style for color pickers.

Added new tests for copy & paste case using textInputController.legacyAttributedString.

  • editing/execCommand/set-backColor-with-color-filter-from-scripts-expected.txt: Added.
  • editing/execCommand/set-backColor-with-color-filter-from-scripts.html: Added.
  • editing/execCommand/set-foreColor-with-color-filter-from-scripts-expected.txt: Added.
  • editing/execCommand/set-foreColor-with-color-filter-from-scripts.html: Added.
  • editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt:
  • editing/mac/attributed-string/attrib-string-range-with-color-filter.html: This test uses attributedSubstringFromRange,

which implemented using editingAttributedStringFromRange in WebCore. Since this is exactly what WebKit embedders uses
to compute the current style of the selected text, we need to invert the color here. This API's main clinet is input methods
so this shouldn't affect other editing operations, in particular, copy and paste, which uses HTMLConverter.

  • editing/mac/attributed-string/attribute-string-for-copy-with-color-filter-expected.txt: Added.
  • editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html: Added. Make sure the attributed string

generated for copy & paste does not invert foreground or background colors via textInputController.legacyAttributedString.
This is testing HTMLConverter, not editingAttributedStringFromRange, used by WebKit embedders and input methods.

  • editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt:
  • editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html: Added background color in the test.
  • editing/style/set-backColor-with-color-filter-expected.txt: Added.
  • editing/style/set-backColor-with-color-filter.html: Added.
  • editing/style/set-foreColor-with-color-filter-expected.txt: Renamed from exec-command-foreColor-with-color-filter-expected.txt.
  • editing/style/set-foreColor-with-color-filter.html: Renamed from exec-command-foreColor-with-color-filter.html.

Updated the test to use testRunner.execCommand which uses CommandFromMenuOrKeyBinding in applyCommandToFrame since we're
trying to test the code path taken by WebKit embedders and font panel here.

Location:
trunk
Files:
5 added
21 edited
4 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r234061 r234064  
     12018-07-20  Ryosuke Niwa  <rniwa@apple.com>
     2
     3        Picking a color from the color panel for typing attributes needs to inverse transform through color-filter
     4        https://bugs.webkit.org/show_bug.cgi?id=187846
     5
     6        Reviewed by Simon Fraser.
     7
     8        Added tests to make sure foreground or background colors specified in execCommand don't get inverted.
     9
     10        Fixed the test which was asserting that textInputController.attributedSubstringFromRange doesn't invert the color
     11        since that's exactly what WebKit embedders uses to compute the style for color pickers.
     12
     13        Added new tests for copy & paste case using textInputController.legacyAttributedString.
     14
     15        * editing/execCommand/set-backColor-with-color-filter-from-scripts-expected.txt: Added.
     16        * editing/execCommand/set-backColor-with-color-filter-from-scripts.html: Added.
     17        * editing/execCommand/set-foreColor-with-color-filter-from-scripts-expected.txt: Added.
     18        * editing/execCommand/set-foreColor-with-color-filter-from-scripts.html: Added.
     19        * editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt:
     20        * editing/mac/attributed-string/attrib-string-range-with-color-filter.html: This test uses attributedSubstringFromRange,
     21        which implemented using editingAttributedStringFromRange in WebCore. Since this is exactly what WebKit embedders uses
     22        to compute the current style of the selected text, we need to invert the color here. This API's main clinet is input methods
     23        so this shouldn't affect other editing operations, in particular, copy and paste, which uses HTMLConverter.
     24        * editing/mac/attributed-string/attribute-string-for-copy-with-color-filter-expected.txt: Added.
     25        * editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html: Added. Make sure the attributed string
     26        generated for copy & paste does not invert foreground or background colors via textInputController.legacyAttributedString.
     27        This is testing HTMLConverter, not editingAttributedStringFromRange, used by WebKit embedders and input methods.
     28        * editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt:
     29        * editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html: Added background color in the test.
     30        * editing/style/set-backColor-with-color-filter-expected.txt: Added.
     31        * editing/style/set-backColor-with-color-filter.html: Added.
     32        * editing/style/set-foreColor-with-color-filter-expected.txt: Renamed from exec-command-foreColor-with-color-filter-expected.txt.
     33        * editing/style/set-foreColor-with-color-filter.html: Renamed from exec-command-foreColor-with-color-filter.html.
     34        Updated the test to use testRunner.execCommand which uses CommandFromMenuOrKeyBinding in applyCommandToFrame since we're
     35        trying to test the code path taken by WebKit embedders and font panel here.
     36
    1372018-07-20  Chris Dumez  <cdumez@apple.com>
    238
  • trunk/LayoutTests/editing/execCommand/set-backColor-with-color-filter-from-scripts.html

    r234063 r234064  
    11<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
    22<html>
    3 <head>
    4 <title>Setting the foreground color should invert the color through -apple-color-filter</title>
    5 <script src="../../resources/dump-as-markup.js"></script>
    6 </head>
    73<body>
    84<div id="test" style="-apple-color-filter: apple-invert-lightness()" contenteditable>hello world</div>
     5<script src="../../resources/dump-as-markup.js"></script>
    96<script>
     7Markup.description('Setting the background color should invert the color through -apple-color-filter');
     8
    109window.getSelection().setPosition(test, 0);
    1110window.getSelection().modify('extend', 'forward', 'word');
    1211window.getSelection().modify('extend', 'forward', 'word');
    13 document.execCommand('foreColor', false, '#224433');
    14 Markup.dump('test', '"world" should be #ecfffd');
     12document.execCommand('backColor', false, '#224433');
     13Markup.dump('test', `"world" should be #224433 / rgb(${0x22}, ${0x44}, ${0x33})`);
    1514
    1615</script>
  • trunk/LayoutTests/editing/execCommand/set-foreColor-with-color-filter-from-scripts.html

    r234063 r234064  
    11<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
    22<html>
    3 <head>
    4 <title>Setting the foreground color should invert the color through -apple-color-filter</title>
    5 <script src="../../resources/dump-as-markup.js"></script>
    6 </head>
    73<body>
    84<div id="test" style="-apple-color-filter: apple-invert-lightness()" contenteditable>hello world</div>
     5<script src="../../resources/dump-as-markup.js"></script>
    96<script>
     7Markup.description('Setting the foreground color should not invert the color through -apple-color-filter');
     8
    109window.getSelection().setPosition(test, 0);
    1110window.getSelection().modify('extend', 'forward', 'word');
    1211window.getSelection().modify('extend', 'forward', 'word');
    1312document.execCommand('foreColor', false, '#224433');
    14 Markup.dump('test', '"world" should be #ecfffd');
     13Markup.dump('test', '"world" should be #224433');
    1514
    1615</script>
  • trunk/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt

    r234005 r234064  
    1 Test that an NSAttributedString from a range doesn't convert colors through -apple-color-filter.
     1Test that an NSAttributedString from a range converts colors through -apple-color-filter.
    22
    33[is t]
    4     NSColor: #cccccc (sRGB)
     4    NSColor: #5c5c5c (sRGB)
    55    NSFont: Times-Roman 16.00 pt.
    66
  • trunk/LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html

    r234005 r234064  
    22<div id="target" style="color: #CCC; -apple-color-filter: apple-invert-lightness();"contenteditable>This text is light gray</div>
    33<p>
    4     Test that an NSAttributedString from a range doesn't convert colors through -apple-color-filter.
     4    Test that an NSAttributedString from a range converts colors through -apple-color-filter.
    55</p>
    66<script src="resources/dump-attributed-string.js"></script>
  • trunk/LayoutTests/editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html

    r234063 r234064  
    11<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
    2 <div id="target" style="color: #CCC; -apple-color-filter: apple-invert-lightness();"contenteditable>This text is light gray</div>
     2<div id="target" style="color: #ccc; background: #369; -apple-color-filter: apple-invert-lightness();" contenteditable>This text is light gray</div>
    33<p>
    4     Test that an NSAttributedString from a range doesn't convert colors through -apple-color-filter.
     4    Test that an NSAttributedString for copy doesn't convert colors through -apple-color-filter.
    55</p>
    66<script src="resources/dump-attributed-string.js"></script>
     
    2121        target.focus();
    2222
    23         var attributedString = textInputController.attributedSubstringFromRange(2, 4);
     23        const range = new Range;
     24        range.setStart(target.firstChild, 2);
     25        range.setEnd(target.firstChild, 4);
     26
     27        var attributedString = textInputController.legacyAttributedString(range);
    2428        var serializedString = serializeAttributedString(attributedString);
    2529        log(serializedString);
  • trunk/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt

    r234005 r234064  
    11Some text here
    22Input:
    3 <div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4);" contenteditable="">Some text here</div>
     3<div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4); background: #ccc;" contenteditable="">Some text here</div>
    44
    55Output:
    66[ ]
     7    NSBackgroundColor: #5c5c5c (sRGB)
    78    NSColor: rgba(239, 239, 239, 0.4) (sRGB)
    89    NSFont: Times-Roman 16.00 pt.
  • trunk/LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html

    r234014 r234064  
    99<body>
    1010
    11 <div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4);" contenteditable>Some text here</div>
     11<div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4); background: #ccc;" contenteditable>Some text here</div>
    1212<pre id="result">This test requires DumpRenderTree</pre>
    1313<script type="text/javascript">
  • trunk/LayoutTests/editing/style/set-backColor-with-color-filter.html

    r234063 r234064  
    11<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
    22<html>
    3 <head>
    4 <title>Setting the foreground color should invert the color through -apple-color-filter</title>
    5 <script src="../../resources/dump-as-markup.js"></script>
    6 </head>
    73<body>
    84<div id="test" style="-apple-color-filter: apple-invert-lightness()" contenteditable>hello world</div>
     5<script src="../../resources/dump-as-markup.js"></script>
    96<script>
     7
     8Markup.description('Setting the background color should invert the color through -apple-color-filter');
     9
    1010window.getSelection().setPosition(test, 0);
    1111window.getSelection().modify('extend', 'forward', 'word');
    1212window.getSelection().modify('extend', 'forward', 'word');
    13 document.execCommand('foreColor', false, '#224433');
    14 Markup.dump('test', '"world" should be #ecfffd');
     13if (window.testRunner)
     14    testRunner.execCommand('backColor', false, '#224433');
     15else
     16    document.write('This test requires WebKitTestRunner or DumpRenderTree');
     17
     18Markup.dump('test', `"world" should be #ecfffd / rgb(${0xec}, ${0xff}, ${0xfd})`);
    1519
    1620</script>
  • trunk/LayoutTests/editing/style/set-foreColor-with-color-filter-expected.txt

    r234063 r234064  
     1Setting the foreground color should invert the color through -apple-color-filter
    12
    23"world" should be #ecfffd:
  • trunk/LayoutTests/editing/style/set-foreColor-with-color-filter.html

    r234063 r234064  
    11<!DOCTYPE html><!-- webkit-test-runner [ enableColorFilter=true ] -->
    22<html>
    3 <head>
    4 <title>Setting the foreground color should invert the color through -apple-color-filter</title>
    5 <script src="../../resources/dump-as-markup.js"></script>
    6 </head>
    73<body>
    84<div id="test" style="-apple-color-filter: apple-invert-lightness()" contenteditable>hello world</div>
     5<script src="../../resources/dump-as-markup.js"></script>
    96<script>
     7
     8Markup.description('Setting the foreground color should invert the color through -apple-color-filter');
     9
    1010window.getSelection().setPosition(test, 0);
    1111window.getSelection().modify('extend', 'forward', 'word');
    1212window.getSelection().modify('extend', 'forward', 'word');
    13 document.execCommand('foreColor', false, '#224433');
     13if (window.testRunner)
     14    testRunner.execCommand('foreColor', false, '#224433');
     15else
     16    document.write('This test requires WebKitTestRunner or DumpRenderTree');
     17
    1418Markup.dump('test', '"world" should be #ecfffd');
    1519
  • trunk/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt

    r234005 r234064  
    1 Test that an NSAttributedString from a range doesn't convert colors through -apple-color-filter.
     1Test that an NSAttributedString from a range converts colors through -apple-color-filter.
    22
    33[is t]
    4     NSColor: #cccccc (NSCustomColorSpace)
     4    NSColor: #5c5c5c (NSCustomColorSpace)
    55    NSFont: Times-Roman 16.00 pt.
    66
  • trunk/LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt

    r234041 r234064  
    11Some text here
    22Input:
    3 <div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4);" contenteditable="">Some text here</div>
     3<div id="editor" style="-apple-color-filter: apple-invert-lightness(); color: rgba(20, 20, 20, 0.4); background: #ccc;" contenteditable="">Some text here</div>
    44
    55Output:
    66[ ]
     7    NSBackgroundColor: #5c5c5c (NSCustomColorSpace)
    78    NSColor: rgba(239, 239, 239, 0.4) (NSCustomColorSpace)
    89    NSFont: Times-Roman 16.00 pt.
  • trunk/LayoutTests/platform/win/TestExpectations

    r234005 r234064  
    9999webkit.org/b/173281 http/tests/security/mixedContent/secure-redirect-to-secure-redirect-to-basic-auth-insecure-image-allowCrossOriginSubresourcesToAskForCredentials.https.html [ Skip ]
    100100webkit.org/b/173281 http/tests/security/mixedContent/secure-redirect-to-secure-redirect-to-basic-auth-secure-image-allowCrossOriginSubresourcesToAskForCredentials.https.html [ Skip ]
    101 webkit.org/b/173281 editing/style/exec-command-foreColor-with-color-filter.html [ Skip ]
     101webkit.org/b/173281 editing/style/set-foreColor-with-color-filter.html [ Skip ]
     102webkit.org/b/173281 editing/style/set-backColor-with-color-filter.html [ Skip ]
    102103
    103104# TODO HW filters not yet supported on Windows
  • trunk/Source/WebCore/ChangeLog

    r234055 r234064  
     12018-07-20  Ryosuke Niwa  <rniwa@apple.com>
     2
     3        Picking a color from the color panel for typing attributes needs to inverse transform through color-filter
     4        https://bugs.webkit.org/show_bug.cgi?id=187846
     5
     6        Reviewed by Simon Fraser.
     7
     8        This patch refines the color inversion for editing introduced in r234005 so that font panels and WebKit embedders
     9        can get and set inverted colors using attributed strings for a selected text in an editable region.
     10
     11        More specifically, when font panels or WebKit embedders set a font color or a background color via WebView's
     12        _applyStyleToSelection and _applyEditingStyleToSelection, WebKit would automatically invert the color before inserting
     13        into DOM so that the color visible to the user matches that's given to WebKit. Conversely,
     14        [WebView attributedSubstringFromRange:nsRange] now return the color visible to the user, i.e. the color after
     15        the color filter had been applied, so that some WebKit embedders can present the visually identical color to the user.
     16
     17        Because DOM never sees the color filter's effect in the computed style, etc... this patch reverts the change made to
     18        StyleChange in r234005 to avoid inverting the color passed to execCommand. This makes editing apps which is unaware
     19        of the dark mode or -apple-color-filter continue to function (because the color picker implemented in DOM will be
     20        applied of the same color filter before being presented to the user).
     21
     22        Finally, this patch introduces a testing hook in applyCommandToFrame so that executing foreColor or backColor with
     23        the soruce of CommandFromMenuOrKeyBinding would trigger the same code path as the one taken by Objective-C
     24
     25        Tests: editing/execCommand/set-backColor-with-color-filter-from-scripts.html
     26               editing/execCommand/set-foreColor-with-color-filter-from-scripts.html
     27               editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html
     28               editing/style/set-backColor-with-color-filter.html
     29               editing/style/set-foreColor-with-color-filter.html
     30
     31        * editing/EditingStyle.cpp:
     32        (WebCore::EditingStyle::inverseTransformColorIfNeeded): Added.
     33        (WebCore::StyleChange::StyleChange): Revert the change made in r234005 since this code is also used by execCommand
     34        which is not desirable, and won't work for background color.
     35        (WebCore::StyleChange::extractTextStyles): Ditto.
     36        * editing/EditingStyle.h:
     37        * editing/Editor.cpp:
     38        (WebCore::Editor::applyStyle):
     39        (WebCore::Editor::applyStyleToSelection): Call EditingStyle::inverseTransformColorIfNeeded when ColorFilterMode is
     40        set to InvertColor.
     41        * editing/Editor.h:
     42        * editing/EditorCommand.cpp:
     43        (WebCore::applyCommandToFrame): Added the aforementioned testing hook.
     44        * editing/cocoa/HTMLConverter.mm:
     45        (WebCore::editingAttributedStringFromRange): Take the color filtr into account. Some WebKit embedders use this
     46        function to compute the font color in the selected text. Note that this function is mostly used for input methods
     47        so the color doesn't really matter, and its implementation is distinct from that of HTMLConverter.
     48
    1492018-07-19  Jer Noble  <jer.noble@apple.com>
    250
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r234005 r234064  
    15391539}
    15401540
     1541Ref<EditingStyle> EditingStyle::inverseTransformColorIfNeeded(Element& element)
     1542{
     1543    auto* renderer = element.renderer();
     1544    if (!m_mutableStyle || !renderer || !renderer->style().hasAppleColorFilter())
     1545        return *this;
     1546
     1547    bool hasColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyColor);
     1548    bool hasBackgroundColor = m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor);
     1549    if (!hasColor && !hasBackgroundColor)
     1550        return *this;
     1551
     1552    auto styleWithInvertedColors = copy();
     1553    ASSERT(styleWithInvertedColors->m_mutableStyle);
     1554
     1555    const auto& colorFilter = renderer->style().appleColorFilter();
     1556    auto invertedColor = [&](CSSPropertyID propertyID) {
     1557        Color newColor = cssValueToColor(extractPropertyValue(*m_mutableStyle, propertyID).get());
     1558        colorFilter.inverseTransformColor(newColor);
     1559        styleWithInvertedColors->m_mutableStyle->setProperty(propertyID, newColor.cssText());
     1560    };
     1561
     1562    if (hasColor)
     1563        invertedColor(CSSPropertyColor);
     1564
     1565    if (hasBackgroundColor)
     1566        invertedColor(CSSPropertyBackgroundColor);
     1567
     1568    return styleWithInvertedColors;
     1569}
     1570
    15411571static void reconcileTextDecorationProperties(MutableStyleProperties* style)
    15421572{   
     
    15811611    bool shouldStyleWithCSS = document->frame()->editor().shouldStyleWithCSS();
    15821612    if (!shouldStyleWithCSS)
    1583         extractTextStyles(document, *node, *mutableStyle, computedStyle.useFixedFontDefaultSize());
     1613        extractTextStyles(document, *mutableStyle, computedStyle.useFixedFontDefaultSize());
    15841614
    15851615    bool shouldAddUnderline = style->underlineChange() == TextDecorationChange::Add;
     
    16541684}
    16551685
    1656 void StyleChange::extractTextStyles(Document* document, Node& startNode, MutableStyleProperties& style, bool shouldUseFixedFontDefaultSize)
     1686void StyleChange::extractTextStyles(Document* document, MutableStyleProperties& style, bool shouldUseFixedFontDefaultSize)
    16571687{
    16581688    if (identifierForStyleProperty(style, CSSPropertyFontWeight) == CSSValueBold) {
     
    16981728
    16991729    if (style.getPropertyCSSValue(CSSPropertyColor)) {
    1700         Color newColor = textColorFromStyle(style);
    1701 
    1702         if (startNode.renderer() && startNode.renderer()->style().hasAppleColorFilter())
    1703             startNode.renderer()->style().appleColorFilter().inverseTransformColor(newColor);
    1704 
    1705         m_applyFontColor = newColor.serialized();
     1730        m_applyFontColor = Color(textColorFromStyle(style)).serialized();
    17061731        style.removeProperty(CSSPropertyColor);
    17071732    }
  • trunk/Source/WebCore/editing/EditingStyle.h

    r234005 r234064  
    169169    static WritingDirection textDirectionForSelection(const VisibleSelection&, EditingStyle* typingStyle, bool& hasNestedOrMultipleEmbeddings);
    170170
     171    Ref<EditingStyle> inverseTransformColorIfNeeded(Element&);
     172
    171173private:
    172174    EditingStyle();
     
    223225    }
    224226private:
    225     void extractTextStyles(Document*, Node& startNode, MutableStyleProperties&, bool shouldUseFixedFontDefaultSize);
     227    void extractTextStyles(Document*, MutableStyleProperties&, bool shouldUseFixedFontDefaultSize);
    226228
    227229    RefPtr<MutableStyleProperties> m_cssStyle;
  • trunk/Source/WebCore/editing/Editor.cpp

    r233434 r234064  
    893893{
    894894    if (style)
    895         applyStyle(EditingStyle::create(style), editingAction);
    896 }
    897 
    898 void Editor::applyStyle(RefPtr<EditingStyle>&& style, EditAction editingAction)
     895        applyStyle(EditingStyle::create(style), editingAction, ColorFilterMode::UseOriginalColor);
     896}
     897
     898void Editor::applyStyle(RefPtr<EditingStyle>&& style, EditAction editingAction, ColorFilterMode colorFilterMode)
    899899{
    900900    if (!style)
     
    911911        return;
    912912
     913    Ref<EditingStyle> styleToApply = colorFilterMode == ColorFilterMode::InvertColor ? style->inverseTransformColorIfNeeded(*element) : style.releaseNonNull();
     914
    913915    switch (selectionType) {
    914916    case VisibleSelection::CaretSelection:
    915         computeAndSetTypingStyle(*style, editingAction);
     917        computeAndSetTypingStyle(styleToApply.get(), editingAction);
    916918        break;
    917919    case VisibleSelection::RangeSelection:
    918         ApplyStyleCommand::create(document(), style.get(), editingAction)->apply();
     920        ApplyStyleCommand::create(document(), styleToApply.ptr(), editingAction)->apply();
    919921        break;
    920922    default:
     
    963965}
    964966
    965 void Editor::applyStyleToSelection(Ref<EditingStyle>&& style, EditAction editingAction)
     967void Editor::applyStyleToSelection(Ref<EditingStyle>&& style, EditAction editingAction, ColorFilterMode colorFilterMode)
    966968{
    967969    if (style->isEmpty() || !canEditRichly())
     
    972974        return;
    973975
    974     applyStyle(WTFMove(style), editingAction);
     976    applyStyle(WTFMove(style), editingAction, colorFilterMode);
    975977}
    976978
  • trunk/Source/WebCore/editing/Editor.h

    r233434 r234064  
    217217
    218218    WEBCORE_EXPORT void applyStyle(StyleProperties*, EditAction = EditActionUnspecified);
    219     void applyStyle(RefPtr<EditingStyle>&&, EditAction);
     219    enum class ColorFilterMode { InvertColor, UseOriginalColor };
     220    void applyStyle(RefPtr<EditingStyle>&&, EditAction, ColorFilterMode);
    220221    void applyParagraphStyle(StyleProperties*, EditAction = EditActionUnspecified);
    221222    WEBCORE_EXPORT void applyStyleToSelection(StyleProperties*, EditAction);
    222     WEBCORE_EXPORT void applyStyleToSelection(Ref<EditingStyle>&&, EditAction);
     223    WEBCORE_EXPORT void applyStyleToSelection(Ref<EditingStyle>&&, EditAction, ColorFilterMode);
    223224    void applyParagraphStyleToSelection(StyleProperties*, EditAction);
    224225
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r233122 r234064  
    101101    switch (source) {
    102102    case CommandFromMenuOrKeyBinding:
    103         frame.editor().applyStyleToSelection(WTFMove(style), action);
     103        // Use InvertColor for testing purposes. foreColor and backColor are never triggered with CommandFromMenuOrKeyBinding outside DRT/WTR.
     104        frame.editor().applyStyleToSelection(WTFMove(style), action, Editor::ColorFilterMode::InvertColor);
    104105        return true;
    105106    case CommandFromDOM:
    106107    case CommandFromDOMWithUserInterface:
    107         frame.editor().applyStyle(WTFMove(style), EditActionUnspecified);
     108        frame.editor().applyStyle(WTFMove(style), EditActionUnspecified, Editor::ColorFilterMode::UseOriginalColor);
    108109        return true;
    109110    }
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r233833 r234064  
    25152515            [attrs.get() setObject:[fontManager convertFont:WebDefaultFont() toSize:style.fontCascade().primaryFont().platformData().size()] forKey:NSFontAttributeName];
    25162516
    2517         Color foregroundColor = style.visitedDependentColor(CSSPropertyColor);
     2517        Color foregroundColor = style.visitedDependentColorWithColorFilter(CSSPropertyColor);
    25182518        if (foregroundColor.isVisible())
    25192519            [attrs.get() setObject:nsColor(foregroundColor) forKey:NSForegroundColorAttributeName];
     
    25212521            [attrs.get() removeObjectForKey:NSForegroundColorAttributeName];
    25222522
    2523         Color backgroundColor = style.visitedDependentColor(CSSPropertyBackgroundColor);
     2523        Color backgroundColor = style.visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
    25242524        if (backgroundColor.isVisible())
    25252525            [attrs.get() setObject:nsColor(backgroundColor) forKey:NSBackgroundColorAttributeName];
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r233869 r234064  
     12018-07-20  Ryosuke Niwa  <rniwa@apple.com>
     2
     3        Picking a color from the color panel for typing attributes needs to inverse transform through color-filter
     4        https://bugs.webkit.org/show_bug.cgi?id=187846
     5
     6        Reviewed by Simon Fraser.
     7
     8        Invert the filtered font and background colors when using font panels, font pasteboard, and other Objective-C APIs.
     9
     10        * WebView/WebHTMLView.mm:
     11        (-[WebHTMLView _applyStyleToSelection:withUndoAction:]): Share code with _applyEditingStyleToSelection.
     12        (-[WebHTMLView _applyEditingStyleToSelection:withUndoAction:]):
     13
    1142018-07-11  Dean Jackson  <dino@apple.com>
    215
  • trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm

    r233079 r234064  
    52055205- (void)_applyStyleToSelection:(DOMCSSStyleDeclaration *)style withUndoAction:(EditAction)undoAction
    52065206{
    5207     if (Frame* coreFrame = core([self _frame])) {
    5208         // FIXME: We shouldn't have to make a copy here. We want callers of this function to work directly with StyleProperties eventually.
    5209         Ref<MutableStyleProperties> properties(core(style)->copyProperties());
    5210         coreFrame->editor().applyStyleToSelection(properties.ptr(), undoAction);
    5211     }
     5207    [self _applyEditingStyleToSelection:EditingStyle::create(core(style)) withUndoAction:undoAction];
    52125208}
    52135209
     
    52155211{
    52165212    if (Frame* coreFrame = core([self _frame]))
    5217         coreFrame->editor().applyStyleToSelection(WTFMove(editingStyle), undoAction);
     5213        coreFrame->editor().applyStyleToSelection(WTFMove(editingStyle), undoAction, Editor::ColorFilterMode::InvertColor);
    52185214}
    52195215
  • trunk/Tools/ChangeLog

    r234063 r234064  
     12018-07-20  Ryosuke Niwa  <rniwa@apple.com>
     2
     3        Picking a color from the color panel for typing attributes needs to inverse transform through color-filter
     4        https://bugs.webkit.org/show_bug.cgi?id=187846
     5
     6        Reviewed by Simon Fraser.
     7
     8        Fixed the bug that testRunner.execCommand was using the second argument as the value.
     9
     10        The second argument, aShowDefaultUI, should always be ignored in testRunner.execCommand,
     11        and the third argument should be used as the value. DumpRenderTree's implementation does this already.
     12
     13        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     14        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     15        (WTR::TestRunner::execCommand):
     16        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     17
    1182018-07-20  Dean Jackson  <dino@apple.com>
    219
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r233888 r234064  
    9898    // Special DOM functions.
    9999    void clearBackForwardList();
    100     void execCommand(DOMString name, DOMString argument);
     100    void execCommand(DOMString name, DOMString showUI, DOMString value);
    101101    boolean isCommandEnabled(DOMString name);
    102102    unsigned long windowCount();
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r233888 r234064  
    292292}
    293293
    294 void TestRunner::execCommand(JSStringRef name, JSStringRef argument)
    295 {
    296     WKBundlePageExecuteEditingCommand(InjectedBundle::singleton().page()->page(), toWK(name).get(), toWK(argument).get());
     294void TestRunner::execCommand(JSStringRef name, JSStringRef showUI, JSStringRef value)
     295{
     296    WKBundlePageExecuteEditingCommand(InjectedBundle::singleton().page()->page(), toWK(name).get(), toWK(value).get());
    297297}
    298298
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r233888 r234064  
    136136    // Special DOM functions.
    137137    void clearBackForwardList();
    138     void execCommand(JSStringRef name, JSStringRef argument);
     138    void execCommand(JSStringRef name, JSStringRef showUI, JSStringRef value);
    139139    bool isCommandEnabled(JSStringRef name);
    140140    unsigned windowCount();
Note: See TracChangeset for help on using the changeset viewer.