[webkit-changes] [WebKit/WebKit] d4b099: [macOS 13] Opening the share sheet shouldn't clear...

Wenson Hsieh noreply at github.com
Sat Sep 3 15:27:46 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d4b09926ba372f6cb13c4b3d6ca8464675738ed8
      https://github.com/WebKit/WebKit/commit/d4b09926ba372f6cb13c4b3d6ca8464675738ed8
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2022-09-03 (Sat, 03 Sep 2022)

  Changed paths:
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Tools/TestWebKitAPI/Tests/mac/ContextMenuTests.mm
    M Tools/TestWebKitAPI/cocoa/TestWKWebView.h
    M Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

  Log Message:
  -----------
  [macOS 13] Opening the share sheet shouldn't clear the text selection
https://bugs.webkit.org/show_bug.cgi?id=244742
rdar://98690831

Reviewed by Aditya Keerthi.

In macOS 13, the new share sheet presents as an NSPopover that makes itself first responder upon
appearance. This currently causes the current text selection to get cleared if the web view was the
first responder beforehand, since we'll end up getting a call to `-[WKWebView resignFirstResponder]`
and subsequently tell the web page to remove its selection via `WebPage::clearSelection()`.

To fix this, we don't allow responders within popovers (more generally, `NSPanel`s) to clear the
text selection in a web view upon becoming first responder. This more closely mirrors the behaviors
of `NSTextView` (where we don't clear the selection when resigning first responder at all).

In the future, we should consider making it so that we maintain the active selection when resigning
first responder by default.

Test: ContextMenuTests.SharePopoverDoesNotClearSelection

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView endEditingAndUpdateFocusAppearanceWithReason:]):

Apply similar treatment on Mac Catalyst as well, where we avoid hiding selection views when we're
losing first responder while a popover is being presented.

* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::resignFirstResponder):
* Tools/TestWebKitAPI/Tests/mac/ContextMenuTests.mm:

Add a test to exercise the fix. This test works by selecting text in a web view, making it the first
responder, using the context menu to show a share sheet, waiting for the share sheet to finish
presenting, and finally checking that the text selection is still intact.

(-[PopoverNotificationListener initWithCallback:]):
(-[PopoverNotificationListener dealloc]):
(-[PopoverNotificationListener handleNotification:]):
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/cocoa/TestWKWebView.h:
* Tools/TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestWKWebViewHostWindow canBecomeKeyWindow]):
(-[TestWKWebView forceWindowToBecomeKey]):
(-[TestWKWebView setForceWindowToBecomeKey:]):

Add a flag to force `-canBecomeKeyWindow` to return `YES` on the hosting `NSWindow`; this was
necessary in order to make share sheet presentation resign first responder on the web view, thereby
triggering the bug in lieu of this fix.

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




More information about the webkit-changes mailing list