[webkit-changes] [WebKit/WebKit] 7a2c65: [visionOS] Context menu is automatically dismissed...

Wenson Hsieh noreply at github.com
Fri Jan 31 23:00:43 PST 2025


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

  Changed paths:
    A LayoutTests/fast/events/ios/dragstart-hang-does-not-dismiss-context-menu-expected.txt
    A LayoutTests/fast/events/ios/dragstart-hang-does-not-dismiss-context-menu.html
    M Source/WebKit/UIProcess/ios/UIKitUtilities.h
    M Source/WebKit/UIProcess/ios/UIKitUtilities.mm
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/UIProcess/ios/WKTextInteractionWrapper.mm

  Log Message:
  -----------
  [visionOS] Context menu is automatically dismissed when previewing an image or attachment for the first time
https://bugs.webkit.org/show_bug.cgi?id=286825
rdar://143333992

Reviewed by Abrar Rahman Protyasha.

On visionOS, long pressing an image or attachment for the first time on a webpage causes the
resulting context menu to automatically dismiss after a few seconds. This happens because the first
time we initiate a drag in a web process, we end up spending a large amount of time underneath
`+[UIScreen initialize]` within the web process, while trying to render the drag image using the
helpers in `DragImageIOS.mm` (which instantiate `UIGraphicsImageRenderer`). This, in turn, causes
the IPC response message `WebPageProxy::DidHandleDragStartRequest` to be delayed by a few seconds,
such that the IPC message to start a UI-side drag session arrives *after* the context menu
presentation animation is already complete.

Consequently, we attempt to hide the selection highlight and edit menu while a drag session is
active, which goes through the (somewhat-poorly-named) method `-willStartScrollingOverflow`, which
ends up dismissing the context menu from within UIKit code.

I'm using https://webkit.org/b/286819 to track refactoring the iOS `DragImage` helper functions to
avoid instantiating the main `UIScreen`; to fix this bug, I'm making adjustments to prevent drag
initiation from (indirectly) dismissing an open context menu, in the event that starting a drag in
the web process takes longer than the context menu presentation animation.

* LayoutTests/fast/events/ios/dragstart-hang-does-not-dismiss-context-menu-expected.txt: Added.
* LayoutTests/fast/events/ios/dragstart-hang-does-not-dismiss-context-menu.html: Added.

Add a layout test to excercise this change, by intentionally hanging inside of a `dragstart` for
long enough, that it effective triggers the same bug that's originally observed on visionOS.

* Source/WebKit/UIProcess/ios/UIKitUtilities.h:
* Source/WebKit/UIProcess/ios/UIKitUtilities.mm:
(-[UIContextMenuInteraction _wk_isMenuVisible]):

Add a helper method to return whether or not the context menu is currently visible.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(WebKit::WKSelectionDrawingInfo::WKSelectionDrawingInfo):

Make another small adjustment here, to treat the case where the selection is a non-editable caret
in the same way as if the selection were null (`None`), only for the purposes of painting the UIKit
selection. While this is already taken care of by `-[WKContentView selectedTextRange]`, it means
we'll still call into `-selectionChanged` unnecessarily in the case where a selection changes from
being `None` → (non-editable) `Caret` or vice versa.

Importantly, in the context of this bug, this extra call to `-selectionChanged` also causes the
active context menu to dismiss after starting a drag.

* Source/WebKit/UIProcess/ios/WKTextInteractionWrapper.mm:
(-[WKTextInteractionWrapper willBeginDragLift]):

Check if the context menu is visible when beginning a drag lift, and avoid hiding the selection.

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