Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 6cae1bfde08c0c5e7e3c8e95af3d09480e85a8e6
https://github.com/WebKit/WebKit/commit/6cae1bfde08c0c5e7e3c8e95af3d09480e85a8e6
Author: Aditya Keerthi <[email protected]>
Date: 2025-10-27 (Mon, 27 Oct 2025)
Changed paths:
M LayoutTests/editing/pasteboard/paste-dark-mode-color-filtered-expected.txt
M LayoutTests/editing/pasteboard/paste-dark-mode-color-filtered.html
M Source/WebCore/Modules/async-clipboard/ClipboardItemBindingsDataSource.cpp
M Source/WebCore/dom/DataTransfer.cpp
M Source/WebCore/editing/ReplaceSelectionCommand.cpp
M Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
M Source/WebCore/editing/glib/WebContentReaderGLib.cpp
M Source/WebCore/editing/markup.cpp
M Source/WebCore/editing/markup.h
M Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteWebArchive.mm
Log Message:
-----------
REGRESSION (iOS 26): Pasting content cut from Notes into Mail is illegible in
dark mode
https://bugs.webkit.org/show_bug.cgi?id=301300
rdar://157387343
Reviewed by Richard Robinson, Ryosuke Niwa, Wenson Hsieh, and Abrar Rahman
Protyasha.
When pasting a web archive, markup is sanitized before it is inserted into the
destination document. Sanitization is performed by inserting the markup into a
new document, and then serializing the contents back into a markup string.
During the sanitization step, styles are re-serialized. This step adds inline
styles to the markup in order to preserve visual appearance.
As a result of the serialization step, markup such as `<span>Content</span>` is
transformed into `<span style="color: rgb(0, 0, 0)">Content</span>` (note that
other inline styles are omitted in this example for brevity). The black text
color is due to the fact that the document and page used for sanitization are
both in light mode, and the text color is `canvastext`.
In iOS 26, Mail removed their use of `-apple-color-filter:
-apple-invert-lightness()`
on documents that explicitly declare dark mode support. This change extends to
new, empty, Mail compose windows, which have `color-scheme: light dark`
specified
on `:root`. As a result, the black text color is no longer inverted to white,
and
the pasted text is illegible.
To fix, make the page and document used for markup sanitization dark-mode aware.
This ensures that the sanitized content will specify a dark mode color in inline
style. Ultimately, the inline style will be stripped during the pre-existing
style deduplication step.
* LayoutTests/editing/pasteboard/paste-dark-mode-color-filtered-expected.txt:
* LayoutTests/editing/pasteboard/paste-dark-mode-color-filtered.html:
Rebaseline following the change in `ReplaceSelectionCommand::doApply`. The
change
is okay, since the visual appearance is still the same (text remains legible in
dark mode).
* Source/WebCore/Modules/async-clipboard/ClipboardItemBindingsDataSource.cpp:
(WebCore::ClipboardItemBindingsDataSource::ClipboardItemTypeLoader::sanitizeDataIfNeeded):
* Source/WebCore/dom/DataTransfer.cpp:
(WebCore::DataTransfer::setDataFromItemList):
* Source/WebCore/editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplacementFragment::ReplacementFragment):
(WebCore::ReplaceSelectionCommand::doApply):
In order to keep `PasteHTML.TransformColorsOfDarkContentButNotSemanticColor`
passing, remove redundant styles *before* performing color inversion. Without
this change, an unnecessary `caret-color: rgb(0, 0, 0)` would be added, since
`caret-color: auto/currentcolor` resolves to a computed color. Following the
rest of this patch, that would be `caret-color: rgb(255, 255, 255)` in dark
mode.
However, that value would be inverted (`inverseTransformColorIfNeeded`) upon
insertion, for documents that use `-apple-color-filter:
-apple-invert-lightness()`.
As a result, the final markup would be `caret-color: rgb(0, 0, 0)`. Since that
value differs from the document's default caret-color (white in dark mode), it
would be preserved in inline style.
This change should be safe since color inversion would only be skipped if the
content is already illegible.
Continue to also remove redundant styles after performing color inversion, to
avoid introducing unnecessary markup.
* Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragmentInternal):
(WebCore::sanitizeMarkupWithArchive):
(WebCore::WebContentReader::readHTML):
(WebCore::WebContentMarkupReader::readHTML):
* Source/WebCore/editing/glib/WebContentReaderGLib.cpp:
(WebCore::WebContentMarkupReader::readHTML):
* Source/WebCore/editing/markup.cpp:
(WebCore::createPageForSanitizingWebContent):
Declare the document used for sanitization as supporting both light and dark
mode using the meta tag. Set up the appearance on the page used for sanitization
by forwarding values from the destination page.
The page only uses dark mode if the destination document is using dark mode.
This
is done to avoid conditionalizing the existence of the meta tag.
(WebCore::sanitizeMarkup):
* Source/WebCore/editing/markup.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteWebArchive.mm:
(TEST(PasteWebArchive, DestinationUsesDarkMode)):
Canonical link: https://commits.webkit.org/302202@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications