[webkit-changes] [WebKit/WebKit] bc0fb0: REGRESSION (iPadOS 18): Right-to-left text pasted ...
Wenson Hsieh
noreply at github.com
Thu Jan 23 17:30:33 PST 2025
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: bc0fb06c1c57d1718e0e663baa4f99130afb07a6
https://github.com/WebKit/WebKit/commit/bc0fb06c1c57d1718e0e663baa4f99130afb07a6
Author: Wenson Hsieh <wenson_hsieh at apple.com>
Date: 2025-01-23 (Thu, 23 Jan 2025)
Changed paths:
M LayoutTests/editing/pasteboard/data-transfer-get-data-on-drop-rich-text-expected.txt
M LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt
M LayoutTests/fast/events/ondrop-text-html-expected.txt
M LayoutTests/platform/ios/editing/pasteboard/onpaste-text-html-expected.txt
M LayoutTests/platform/mac/editing/pasteboard/onpaste-text-html-expected.txt
M LayoutTests/platform/mac/fast/events/ondrop-text-html-expected.txt
M Source/WebCore/editing/markup.cpp
M Source/WebCore/editing/markup.h
M Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp
M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
A Tools/TestWebKitAPI/Tests/WebKit/rtl-bidi-text.html
M Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyHTML.mm
Log Message:
-----------
REGRESSION (iPadOS 18): Right-to-left text pasted from Safari into Pages is left aligned
https://bugs.webkit.org/show_bug.cgi?id=286404
rdar://139029945
Reviewed by Abrar Rahman Protyasha.
In iOS 17.4 and iPadOS 18, copying text within a single RTL paragraph in Safari and pasting into
Pages results in LTR text being inserted. This is because BrowserEngineKit adoption
(`async_text_input_i(phone|pad)`) is enabled since these updates, which causes WebKit to stop
directly converting selected text content into attributed string data upon copying; instead, we now
just write web archive and HTML data to the system pasteboard, which is lazily converted into
`NSAttributedString` by the destination app, if needed. This conversion relies on UIFoundation,
which (through `nsattributedstringagent`) loads a web view using the web archive data, and then uses
WebKit APIs to obtain an `NSAttributedString` from the web view.
Previously, WebKit would've written an attributed string directly to the pasteboard, where the
attributes of the text contain an `NSParagraphStyle` that has RTL base writing direction; Pages
would then honor this by inserting an RTL paragraph. However, after enabling lazy attributed string
conversion, the resulting attributed string (derived from web archive data) no longer has a base
writing direction set. That's because the web archive markup contains only a single inline `span`
element which doesn't have any `direction` set, since the selection doesn't (fully) encompass any
block-level elements, which means any information about paragraph writing direction is lost upon
copying:
=> Copied markup: `<head><meta charset='utf-8'></head><span>كتروني هو</span>`
While we could fix this by wrapping the web archive markup with a block-level `div` or `p` element
that carries over the `direction`, this could cause us to paste an extra paragraph, when the copied
content should really be treated as inline content (added to an existing paragraph):
=> `<head><meta charset='utf-8'></head><div dir='rtl'>كتروني هو</div>`
Instead, this patch addresses the issue by wrapping the web archive data in a `body` element. During
sanitization, instead of implicitly generating a `body` element, we'll parse the `body` element from
markup, along with the `dir='rtl'` attribute. The contents of the body then properly contain RTL
text, which allows attributed string conversion to produce paragraph styles with an RTL base writing
direction set.
=> `<head><meta charset='utf-8'></head><body dir='rtl'><span>كتروني هو</span></body>`
* LayoutTests/editing/pasteboard/data-transfer-get-data-on-drop-rich-text-expected.txt:
* LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt:
* LayoutTests/fast/events/ondrop-text-html-expected.txt:
* LayoutTests/platform/ios/editing/pasteboard/onpaste-text-html-expected.txt:
* LayoutTests/platform/mac/editing/pasteboard/onpaste-text-html-expected.txt:
* LayoutTests/platform/mac/fast/events/ondrop-text-html-expected.txt:
* Source/WebCore/editing/markup.cpp:
Rebaseline several layout tests.
* LayoutTests/platform/mac/fast/events/ondrop-text-html-expected.txt:
* Source/WebCore/editing/markup.cpp:
(WebCore::serializePreservingVisualAppearanceInternal):
See description above.
(WebCore::serializePreservingVisualAppearance):
(WebCore::sanitizedMarkupForFragmentInDocument):
* Source/WebCore/editing/markup.h:
* Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp:
(WebCore::LegacyWebArchive::createFromSelection):
Pass in `PreserveDirectionForInlineText::Yes`.
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKit/rtl-bidi-text.html: Added.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyHTML.mm:
(copyAndLoadAttributedStringUsingWebArchive):
(TEST(CopyHTML, SanitizationPreservesRelativeURLInAttributedString)):
(TEST(CopyHTML, CopyingRightToLeftTextPreservesDirection)):
Add an API test to exercise the fix, by:
- Copying selected RTL text.
- Using the copied web archive to generate an attributed string.
- Verifying that the attributed string has a RTL base writing direction.
Canonical link: https://commits.webkit.org/289323@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