[webkit-changes] [WebKit/WebKit] d83355: [iOS] Add support for bidi content-aware paste and...

Wenson Hsieh noreply at github.com
Tue Jan 21 11:57:33 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d833553549aa3a434c2b7402e48d73615e77fc8b
      https://github.com/WebKit/WebKit/commit/d833553549aa3a434c2b7402e48d73615e77fc8b
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2025-01-21 (Tue, 21 Jan 2025)

  Changed paths:
    A LayoutTests/editing/pasteboard/paste-rtl-text-in-empty-ltr-paragraph-expected.txt
    A LayoutTests/editing/pasteboard/paste-rtl-text-in-empty-ltr-paragraph.html
    M Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/editing/ApplyStyleCommand.cpp
    M Source/WebCore/editing/ApplyStyleCommand.h
    M Source/WebCore/editing/CompositeEditCommand.cpp
    M Source/WebCore/editing/CompositeEditCommand.h
    M Source/WebCore/editing/Editor.cpp
    M Source/WebCore/editing/ReplaceSelectionCommand.cpp
    M Source/WebCore/editing/ReplaceSelectionCommand.h
    M Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp
    A Source/WebCore/platform/text/UnicodeHelpers.cpp
    A Source/WebCore/platform/text/UnicodeHelpers.h
    M Source/WebKit/Shared/WebPreferencesDefaultValues.h
    M Source/WebKit/Shared/ios/WebPreferencesDefaultValuesIOS.mm

  Log Message:
  -----------
  [iOS] Add support for bidi content-aware paste and drop
https://bugs.webkit.org/show_bug.cgi?id=286240
rdar://142486815

Reviewed by Megan Gardner and Abrar Rahman Protyasha.

Add support for new editing behaviors when pasting and dropping text, behind a new internal runtime
flag `BidiContentAwarePasteEnabled`. Currently, pasted content always takes on the text direction at
the start of the selection. When this feature is enabled and only when the user is pasting or
dropping text at the start of a new (empty) paragraph, the text direction of the inserted content
will automatically take the natural text direction of the pasted text, by setting a direction for
the enclosing containing block at the start of the inserted content range.

* LayoutTests/editing/pasteboard/paste-rtl-text-in-empty-ltr-paragraph-expected.txt: Added.
* LayoutTests/editing/pasteboard/paste-rtl-text-in-empty-ltr-paragraph.html: Added.

Add a new layout test to exercise the change.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::ApplyStyleCommand):
(WebCore::ApplyStyleCommand::doApply):
* Source/WebCore/editing/ApplyStyleCommand.h:

Move the `PropertyLevel` enum out of this class, and into `CompositeEditCommand.h` as a separate
enum — `ApplyStylePropertyLevel`. This is so that `CompositeEditCommand::applyStyle` can take an
optional property level argument, which is passed back into `ApplyStyleCommand` when creating and
applying the command.

(WebCore::ApplyStyleCommand::create):
* Source/WebCore/editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::applyStyle):
* Source/WebCore/editing/CompositeEditCommand.h:
* Source/WebCore/editing/Editor.cpp:
(WebCore::Editor::applyParagraphStyle):
* Source/WebCore/editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::doApply):
(WebCore::ReplaceSelectionCommand::updateDirectionForStartOfInsertedContentIfNeeded):

See description above for more details.

* Source/WebCore/editing/ReplaceSelectionCommand.h:
* Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:

Make this use the new `baseTextDirection` helper (see below).

(WebCore::Layout::TextUtil::directionForTextContent):
* Source/WebCore/platform/text/UnicodeHelpers.cpp: Added.
(WebCore::baseTextDirection):
* Source/WebCore/platform/text/UnicodeHelpers.h: Added.

Add a new helper function to determine the text direction for a given string. This is just a thin
wrapper around `ubidi_getBaseDirection`, which (respectively) returns `TextDirection::(LTR|RTL)` for
`UBIDI_(LTR|RTL)`, and `nullopt` for `UBIDI_NEUTRAL`.

* Source/WebKit/Shared/WebPreferencesDefaultValues.h:
* Source/WebKit/Shared/ios/WebPreferencesDefaultValuesIOS.mm:
(WebKit::defaultBidiContentAwarePasteEnabled):

Canonical link: https://commits.webkit.org/289195@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