Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9c77e5d284fb1befc9a3fae0403b05033e662730
      
https://github.com/WebKit/WebKit/commit/9c77e5d284fb1befc9a3fae0403b05033e662730
  Author: Megan Gardner <[email protected]>
  Date:   2026-09-21 (Mon, 21 Sep 2026)

  Changed paths:
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/rendering/TextPaintStyle.cpp
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/PasteHTML.mm

  Log Message:
  -----------
  [Compose] quoted email content is gray on gray background, making all text 
fully illegible
https://bugs.webkit.org/show_bug.cgi?id=324378
rdar://173567695

Reviewed by Wenson Hsieh.

Replying in Mail on iOS in dark mode leaves the quoted original gray on gray, 
at a 1.02:1 contrast
ratio where WCAG asks for 4.5:1.

Quoted markup carries the sender's colors, e.g. `background-color: #fff; color: 
#1d1d1f`. Mail
compose enables `_punchOutWhiteBackgroundsInDarkMode`, so the white background 
is composited away
and the near black text is left on the dark backdrop. Punching out a background 
without accounting
for the foreground it was hiding is the defect.

305399@main fixed this for paste, in `ReplaceSelectionCommand`. Reply quoting 
never gets there:
Mail injects the quoted body by assigning `innerHTML` on a detached element and 
splicing it in with
`appendChild`. macOS Mail takes a different code path to the same effect, but 
does not reproduce the
bug, because its compose user style sheet either inverts lightness or forces a 
white background.

So handle it where the punch out happens. When computing the text fill color, 
find the nearest
ancestor with a visible background; if it is being punched out and the declared 
color is not legible
against the backdrop that replaces it, fall back to the default foreground 
color. This reuses
`textColorIsLegibleAgainstBackgroundColor`, already used here to keep printed 
text legible. Being at
paint time, it covers every path into the compose body, and it leaves the DOM 
alone so the sender's
colors survive into the outgoing message -- at the cost of not being visible to 
`getComputedStyle`.

This does not replace 305399@main, which also strips `caret-color` and 
`background-color`, and whose
test asserts the computed values that this patch deliberately leaves alone.

Since this runs for every text fragment we paint, the ancestor walk is guarded 
by two O(1) checks
first: the punch out setting, and whether the style set a color at all. Content 
inheriting its color
from the editable body cannot be stranded, so in practice nothing in a Mail 
compose body walks the
render tree.

Test: Tools/TestWebKitAPI/Tests/WebKit/WKWebView/PasteHTML.mm

* Source/WebCore/dom/Document.cpp:
(WebCore::Document::backgroundColorIsPunchedOut):
* Source/WebCore/dom/Document.h:
* Source/WebCore/rendering/TextPaintStyle.cpp:
(WebCore::adjustColorForPunchedOutBackground):
(WebCore::computeTextPaintStyle):
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/PasteHTML.mm:
(TestWebKitAPI::TEST(PasteHTML, 
QuotedContentOnPunchedOutBackgroundRemainsLegible)):
Injects quoted content the way Mail does, and asserts the background was 
punched out before
checking contrast so the test cannot pass without reproducing the bug.

Canonical link: https://commits.webkit.org/321514@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to