Bug 189382

Summary: [macOS] [WK2] Support changing foreground colors via color panel
Product: WebKit Reporter: Wenson Hsieh <wenson_hsieh>
Component: HTML EditingAssignee: Wenson Hsieh <wenson_hsieh>
Status: RESOLVED FIXED    
Severity: Normal CC: bdakin, commit-queue, ews-watchlist, mitz, rniwa, thorton, tsavell, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Archive of layout-test-results from ews106 for mac-sierra-wk2
none
Archive of layout-test-results from ews102 for mac-sierra
none
Archive of layout-test-results from ews202 for win-future
none
Archive of layout-test-results from ews115 for mac-sierra
none
Archive of layout-test-results from ews121 for ios-simulator-wk2
none
Patch for EWS
none
Another patch for EWS
none
Patch none

Description Wenson Hsieh 2018-09-06 16:29:14 PDT
Currently, attempting to choose a font color using the color picker (accessible through NSFontPanel) does nothing in WKWebView. However, this works in legacy WebKit.
Comment 1 Radar WebKit Bug Importer 2018-09-07 09:54:52 PDT
<rdar://problem/44227311>
Comment 2 Wenson Hsieh 2018-09-10 21:28:05 PDT
Created attachment 349376 [details]
Patch
Comment 3 Ryosuke Niwa 2018-09-10 21:35:12 PDT
Comment on attachment 349376 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349376&action=review

> Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm:276
> +    checkFontColorAtStartAndEndWithInputEvents("rgb(255, 0, 0)");

Let's also add an assertion to make sure we're inserting a font element instead of a span in this case.

> Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm:287
> +    checkFontColorAtStartAndEndWithInputEvents("rgb(204, 179, 51)");

Ditto.
Comment 4 EWS Watchlist 2018-09-10 22:25:43 PDT Comment hidden (obsolete)
Comment 5 EWS Watchlist 2018-09-10 22:25:44 PDT Comment hidden (obsolete)
Comment 6 EWS Watchlist 2018-09-10 22:33:14 PDT Comment hidden (obsolete)
Comment 7 EWS Watchlist 2018-09-10 22:33:15 PDT Comment hidden (obsolete)
Comment 8 EWS Watchlist 2018-09-10 23:05:00 PDT Comment hidden (obsolete)
Comment 9 EWS Watchlist 2018-09-10 23:05:12 PDT Comment hidden (obsolete)
Comment 10 EWS Watchlist 2018-09-10 23:07:42 PDT Comment hidden (obsolete)
Comment 11 EWS Watchlist 2018-09-10 23:07:44 PDT Comment hidden (obsolete)
Comment 12 EWS Watchlist 2018-09-10 23:22:45 PDT Comment hidden (obsolete)
Comment 13 EWS Watchlist 2018-09-10 23:22:46 PDT Comment hidden (obsolete)
Comment 14 Wenson Hsieh 2018-09-11 07:20:50 PDT
Comment on attachment 349376 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349376&action=review

>> Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm:276
>> +    checkFontColorAtStartAndEndWithInputEvents("rgb(255, 0, 0)");
> 
> Let's also add an assertion to make sure we're inserting a font element instead of a span in this case.

Sounds good!
Comment 15 Wenson Hsieh 2018-09-11 07:31:10 PDT
(In reply to Build Bot from comment #13)
> Created attachment 349384 [details]
> Archive of layout-test-results from ews121 for ios-simulator-wk2
> 
> The attached test failures were seen while running run-webkit-tests on the
> ios-sim-ews.
> Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.4

The test expectation here doesn't seem right to me:

> -PASS foreColor(rgba(0, 50, 100, 0.4)) on all of "<font><u style="color:red;">hello</u></font>" yields "<font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font>"
> +FAIL foreColor(rgba(0, 50, 100, 0.4)) on all of "<font><u style="color:red;">hello</u></font>" yields "<font><u style="color: rgba(0, 50, 100, 0.4);">hello</u></font>", expected "<font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font>"

This test expects <font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font> after changing the foreground color to a color with alpha, but this just results in a bogus text color, since the font element does not support RGBA colors (I'm seeing a fully opaque dark green in Safari 12 when visiting data:text/html,<font%20color="rgba(0,%2050,%20100,%200.4)"><u>hello</u></font>). After this patch, we get <font><u style="color: rgba(0, 50, 100, 0.4);">hello</u></font>, which results in light blue, transparent text (as one would probably expect).

I think this can be safely rebaselined.
Comment 16 Wenson Hsieh 2018-09-11 07:34:47 PDT
(In reply to Wenson Hsieh from comment #15)
> (In reply to Build Bot from comment #13)
> > Created attachment 349384 [details]
> > Archive of layout-test-results from ews121 for ios-simulator-wk2
> > 
> > The attached test failures were seen while running run-webkit-tests on the
> > ios-sim-ews.
> > Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.4
> 
> The test expectation here doesn't seem right to me:
> 
> > -PASS foreColor(rgba(0, 50, 100, 0.4)) on all of "<font><u style="color:red;">hello</u></font>" yields "<font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font>"
> > +FAIL foreColor(rgba(0, 50, 100, 0.4)) on all of "<font><u style="color:red;">hello</u></font>" yields "<font><u style="color: rgba(0, 50, 100, 0.4);">hello</u></font>", expected "<font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font>"
> 
> This test expects <font color="rgba(0, 50, 100, 0.4)"><u>hello</u></font>
> after changing the foreground color to a color with alpha, but this just
> results in a bogus text color, since the font element does not support RGBA
> colors (I'm seeing a fully opaque dark green in Safari 12 when visiting
> data:text/html,<font%20color="rgba(0,%2050,%20100,%200.4)"><u>hello</u></
> font>). After this patch, we get <font><u style="color: rgba(0, 50, 100,
> 0.4);">hello</u></font>, which results in light blue, transparent text (as
> one would probably expect).
> 
> I think this can be safely rebaselined.

Actually, instead of just rebaselining the test, I think I'll change this failing test case to just apply "rgb(0, 50, 100)" without alpha, and then add "rgba(0, 50, 100, 0.4)" as an additional test case.
Comment 17 Wenson Hsieh 2018-09-11 08:41:22 PDT
Created attachment 349397 [details]
Patch for EWS
Comment 18 Wenson Hsieh 2018-09-11 09:41:55 PDT
Created attachment 349401 [details]
Another patch for EWS
Comment 19 Wenson Hsieh 2018-09-11 09:46:18 PDT
> Actually, instead of just rebaselining the test, I think I'll change this
> failing test case to just apply "rgb(0, 50, 100)" without alpha, and then
> add "rgba(0, 50, 100, 0.4)" as an additional test case.

On second thought, maybe it's not a great idea to use inline styles to represent RGBA font colors, when "StyleWithCSS" is set to false...

Another approach is to just drop the alpha component when setting the color attribute of the font element, since we can't represent transparent colors using only attributes on the font element (rather than CSS). Then, for our API test, we can exercise the case where "StyleWithCSS" is true.

I posted a separate patch that implements this approach.
Comment 20 Wenson Hsieh 2018-09-11 14:59:45 PDT
Chatted with Ryosuke about this, and agree that fulfilling user expectation is more important than respecting StyleWithCSS being false, when setting a font color with alpha ≠ 1. We'll go with the original approach.

Committed r235914: <https://trac.webkit.org/changeset/235914>
Comment 22 Wenson Hsieh 2018-09-11 16:27:57 PDT
(In reply to Truitt Savell from comment #21)
> Looks like the new API, FontManagerTests.ChangeFontColorWithColorPanel, test
> is failing on Sierra WK1 from: https://trac.webkit.org/changeset/235914
> 
> 
> Log:
> https://build.webkit.org/builders/Apple%20Sierra%20Release%20WK1%20(Tests)/
> builds/12719/steps/run-api-tests/logs/stdio
> 
> Run Failure:
> https://build.webkit.org/builders/Apple%20Sierra%20Release%20WK1%20(Tests)/
> builds/12719

Thanks — I'll take a look shortly.
Comment 23 Wenson Hsieh 2018-09-11 16:46:00 PDT
Reopening to attach new patch.
Comment 24 Wenson Hsieh 2018-09-11 16:46:01 PDT
Created attachment 349492 [details]
Patch
Comment 25 WebKit Commit Bot 2018-09-11 23:08:36 PDT
Comment on attachment 349492 [details]
Patch

Clearing flags on attachment: 349492

Committed r235931: <https://trac.webkit.org/changeset/235931>
Comment 26 WebKit Commit Bot 2018-09-11 23:08:37 PDT
All reviewed patches have been landed.  Closing bug.