[webkit-changes] [WebKit/WebKit] e11b02: [Writing Tools] Text color becomes black-on-black ...
Aditya Keerthi
noreply at github.com
Thu Aug 8 19:09:00 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: e11b028d2a5fa759cc49a843cc3d67603acaa048
https://github.com/WebKit/WebKit/commit/e11b028d2a5fa759cc49a843cc3d67603acaa048
Author: Aditya Keerthi <akeerthi at apple.com>
Date: 2024-08-08 (Thu, 08 Aug 2024)
Changed paths:
M Source/WebCore/editing/ReplaceSelectionCommand.cpp
M Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm
Log Message:
-----------
[Writing Tools] Text color becomes black-on-black when transforming into list while in dark mode in Mail
https://bugs.webkit.org/show_bug.cgi?id=277801
rdar://129024871
Reviewed by Wenson Hsieh.
In dark mode, Mail uses `-apple-color-filter: apple-invert-lightness()` to
invert colors for emails designed for light mode. In the past, this has
caused issues with pasted content, as colors could be doubly inverted,
resulting in illegible text (see 215122 at main for more details).
To avoid double inversion, `fragmentNeedsColorTransformed` reports whether the
fragment inserted by `ReplaceSelectionCommand` contains content that would be
illegible after color inversion is performed. It works by traversing the
inserted node tree, checking for inline styles and the lightness of colors.
However, the current implementation is flawed, as it early returns `false`, the
moment an inline style with sufficient lightness is encountered. This is
incorrect as an inline style encountered on a parent element, may later be
overridden by a child element. Which means that the used color for the text
may never be considered in the algorithm.
This issue manifests itself in Writing Tools, when a fragment like the following
is inserted:
```
<ul style="color: black">
<li style="color: white">Item 1</li>
<li style="color: white">Item 2</li>
</ul>
```
The algorithm first observes "black", detects that inverted black (white) would
be legible, and bails early from the color transform. However, the actual color
of text is white, which is black when inverted, and illegible in dark mode.
Fix by reworking the algorithm to perform a depth first search, keeping track
of the used inline color, so that the algorithm considers the right colors when
determining whether to perform transformation.
* Source/WebCore/editing/ReplaceSelectionCommand.cpp:
(WebCore::nodeTreeHasInlineStyleWithLegibleColorForInvertLightness):
(WebCore::fragmentNeedsColorTransformed):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
(TEST(PasteHTML, TransformColorsDependsOnUsedInlineStyle)):
The test expects the list item to have 'color: rgb(0, 0, 0)', as that will
appear white to the user following the color filter.
Canonical link: https://commits.webkit.org/282027@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list