Picking a color from the color panel for typing attributes needs to inverse transform...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jul 2018 21:10:40 +0000 (21:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jul 2018 21:10:40 +0000 (21:10 +0000)
commit145b039dc77194279573a61437849afda9b77c16
tree351b6bb8df9762b5cf019fe8a95dccb1742c723d
parentfc60fb8faf9b397f898a8e92014fc3c6f93778c7
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234064 268f45cc-cd09-0410-ab3c-d52691b4dbfc
32 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/execCommand/set-backColor-with-color-filter-from-scripts-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/set-backColor-with-color-filter-from-scripts.html [new file with mode: 0644]
LayoutTests/editing/execCommand/set-foreColor-with-color-filter-from-scripts-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/set-foreColor-with-color-filter-from-scripts.html [moved from LayoutTests/editing/style/exec-command-foreColor-with-color-filter.html with 75% similarity]
LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt
LayoutTests/editing/mac/attributed-string/attrib-string-range-with-color-filter.html
LayoutTests/editing/mac/attributed-string/attribute-string-for-copy-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html [new file with mode: 0644]
LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt
LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter.html
LayoutTests/editing/style/set-backColor-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/set-backColor-with-color-filter.html [new file with mode: 0644]
LayoutTests/editing/style/set-foreColor-with-color-filter-expected.txt [moved from LayoutTests/editing/style/exec-command-foreColor-with-color-filter-expected.txt with 58% similarity]
LayoutTests/editing/style/set-foreColor-with-color-filter.html [new file with mode: 0644]
LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attrib-string-range-with-color-filter-expected.txt
LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attribute-string-for-copy-with-color-filter-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/editing/EditingStyle.cpp
Source/WebCore/editing/EditingStyle.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/EditorCommand.cpp
Source/WebCore/editing/cocoa/HTMLConverter.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h