Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: ad620275e07cc44aee2bcd5cce7855ed78808e39
https://github.com/WebKit/WebKit/commit/ad620275e07cc44aee2bcd5cce7855ed78808e39
Author: Joanne Pan <[email protected]>
Date: 2026-07-13 (Mon, 13 Jul 2026)
Changed paths:
A
LayoutTests/editing/pasteboard/paste-canvas-background-dark-mode-expected.txt
A LayoutTests/editing/pasteboard/paste-canvas-background-dark-mode.html
M Source/WebCore/editing/ReplaceSelectionCommand.cpp
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/PasteHTML.mm
Log Message:
-----------
Pasting Confluence content is rendered incorrectly if in Dark Mode
https://bugs.webkit.org/show_bug.cgi?id=318886
rdar://178843535
Reviewed by Wenson Hsieh and Ryosuke Niwa.
The problem:
This is a regression from bug 308854 (rdar://171391621), which made copy
preserve the source page's background-color on the pasted content (matching
Chrome). Multi-paragraph copy writes it onto each <p>; single-paragraph copy
writes it onto the wrapping <span>. Mail's compose view renders Dark Mode with
the invert-lightness color filter (plus white punch-out), so the preserved
page surface is pasted verbatim and then bands:
- A light page surface such as #f4f5f7 misses white punch-out (only pure white
is punched out) and is painted as a solid band.
- A dark-mode page surface such as #1d2125 (rgb(29, 33, 37)) inverts into a
light band.
- Design-system cells specify their fill as var(--token, #fallback), so the
raw inline value is an unresolved variable reference rather than a color.
WebKit's dark-mode paste fixup left all of these alone, and it happened on both
single-paragraph (background on an inline <span>) and multi-paragraph pastes.
The fix:
In ReplaceSelectionCommand's dark-mode paste fixup (collectStylesToRemove),
when pasting into an editor that punches out white backgrounds in Dark Mode,
drop a pasted element's background-color when it is a canvas-like page surface:
opaque, non-semantic, and either light (lightness > 0.6) or a near-black
neutral (lightness < 0.2 with low saturation). This applies regardless of
whether the element is block-level or inline, so the surface is shed whether
the caused-by placed it on a multi-paragraph <p> or a single-paragraph wrapping
<span>. Saturated status colors (green/red/blue lozenges) survive via the
saturation check; translucent and semantic colors are kept. Pure white is left
to the editor's existing white punch-out (compositeOperatorForBackgroundColor
returns DestinationIn/Out), so it is not dropped here.
Because a cell's fill may be a var() reference that propertyAsColor resolves to
an invalid color, the used color is read from the render style
(visitedDependentBackgroundColor) when the inline value is absent or invalid.
The light threshold reuses the constant already used a few functions up for the
invert-lightness legibility check (isLightEnoughToTreatAsBackground), so #f4f5f7
(lightness 0.96) is dropped while a status highlight like #ffc107 (0.51) is
kept. The copy-serialization behavior from bug 308854 (and Chrome parity) is
untouched. This change is entirely on the paste side and only affects editors
that opt into punchOutWhiteBackgroundsInDarkMode.
Note: comparing against documentBackgroundColor() does not work here because it
applies the color filter, so in an invert-lightness editor the canvas reads
dark while the pasted color is raw. lightness() is used (rather than
luminance())
to stay consistent with the neighboring heuristic; if we later switch from
lightness() to luminance(), both places should change together.
* Source/WebCore/editing/ReplaceSelectionCommand.cpp:
(WebCore::isLightEnoughToTreatAsBackground): Added; shared lightness threshold.
(WebCore::isLightOrDarkNeutralBackgroundColor): Added; light, or near-black
neutral, page surface.
(WebCore::nodeTreeHasInlineStyleWithLegibleColorForInvertLightness): Use the
shared threshold.
(WebCore::collectStylesToRemove): Drop canvas-like backgrounds when pasting
into a punch-out dark editor, resolving var() fills via the render style.
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/PasteHTML.mm:
(TEST(PasteHTML, DropsCanvasLikeBackgroundWhenPastingIntoPunchOutEditor)):
Added.
* LayoutTests/editing/pasteboard/paste-canvas-background-dark-mode.html: Added;
covers light/var()/near-black surfaces on block and inline, pure-white
punch-out, translucency, boundaries, and kept status colors.
*
LayoutTests/editing/pasteboard/paste-canvas-background-dark-mode-expected.txt:
Added.
Canonical link: https://commits.webkit.org/317029@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications