Bug 189382 - [macOS] [WK2] Support changing foreground colors via color panel
Summary: [macOS] [WK2] Support changing foreground colors via color panel
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-09-06 16:29 PDT by Wenson Hsieh
Modified: 2018-09-11 23:08 PDT (History)
9 users (show)

See Also:


Attachments
Patch (16.40 KB, patch)
2018-09-10 21:28 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-sierra-wk2 (3.33 MB, application/zip)
2018-09-10 22:25 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews102 for mac-sierra (2.32 MB, application/zip)
2018-09-10 22:33 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews202 for win-future (12.90 MB, application/zip)
2018-09-10 23:05 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews115 for mac-sierra (3.02 MB, application/zip)
2018-09-10 23:07 PDT, EWS Watchlist
no flags Details
Archive of layout-test-results from ews121 for ios-simulator-wk2 (2.30 MB, application/zip)
2018-09-10 23:22 PDT, EWS Watchlist
no flags Details
Patch for EWS (21.45 KB, patch)
2018-09-11 08:41 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Another patch for EWS (21.07 KB, patch)
2018-09-11 09:41 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch (1.99 KB, patch)
2018-09-11 16:46 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.