Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 620a1ea677f50d3d9af23ff22bedeee59eccc356
      
https://github.com/WebKit/WebKit/commit/620a1ea677f50d3d9af23ff22bedeee59eccc356
  Author: Richard Robinson <[email protected]>
  Date:   2026-05-01 (Fri, 01 May 2026)

  Changed paths:
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration+Extras.swift
    M Source/WebKit/UIProcess/API/Swift/WebPage+Configuration.swift
    M Source/WebKit/UIProcess/API/Swift/WebPage.swift
    M Source/WebKit/UIProcess/Cocoa/WKUIDelegateAdapter.swift
    M Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
    M Tools/TestWebKitAPI/Helpers/cocoa/Foundation+Extras.swift
    M Tools/TestWebKitAPI/Helpers/cocoa/JavaScriptMessages.swift
    M Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift
    M Tools/TestWebKitAPI/Tests/WebKit/WebPage/JavaScriptExpressionTests.swift

  Log Message:
  -----------
  [AppKit Gestures] Unable to invoke context menus on highlighted text via click
https://bugs.webkit.org/show_bug.cgi?id=313861
rdar://175290015

Reviewed by Abrar Rahman Protyasha.

In `WKTextSelectionController`, the `if !hasSelection || 
!editorState.hasPostLayoutAndVisualData()` predicate
was evaluating to `true` because the editor state had no post-layout data. As a 
result, the system didn't try
to invoke a context menu.

This issue was happening only in Safari, and only in non-contenteditable 
regions, and only when there
is no prior user interaction, because:

1. In non-Safari clients, `m_requiresUserActionForEditingControlsManager` is 
set to `false`, meaning that
`WebPage::shouldAvoidComputingPostLayoutDataForEditorState` always returns 
`false` and therefore the editor
state is always updated. This is not true for Safari.

2. In contenteditable regions, there is a focused element, and so 
`m_userInteractionsSincePageTransition.add(UserInteractionFlag::FocusedElement);`
gets invoked, and `WebPage::shouldAvoidComputingPostLayoutDataForEditorState` 
once again returns false.

Therefore, in order for a non-contenteditable region in Safari to have its 
editor state updated, a user interaction
must happen. This was not happening in most of the cases in 
WKTextSelectionController, since several WebPage
functions like `WebPage::updateSelectionWithExtentPointAndBoundary` did not 
properly attribute user interaction.

Fix by updating the relevant methods to add a missing

```
SetForScope userIsInteractingChange { m_userIsInteracting, true };
```

Tests: Tools/TestWebKitAPI/Helpers/cocoa/Foundation+Extras.swift
       Tools/TestWebKitAPI/Helpers/cocoa/JavaScriptMessages.swift
       Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift
       Tools/TestWebKitAPI/Tests/WebKit/WebPage/JavaScriptExpressionTests.swift

* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(dictionaryRepresentationForEditorState):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration+Extras.swift:
* Source/WebKit/UIProcess/API/Swift/WebPage+Configuration.swift:
(Configuration.requiresUserActionForEditingControlsManager):
* Source/WebKit/UIProcess/API/Swift/WebPage.swift:
(editorStateSnapshotsContinuations):
(KeyValueObservations.contents):
(addEditorStateUpdate(_:)):
(editorStateSnapshots):
(WebPage.terminateWebContentProcess): Deleted.
* Source/WebKit/UIProcess/Cocoa/WKUIDelegateAdapter.swift:
(WKUIDelegateAdapter._webView(_:editorStateDidChange:)):
* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::selectWithGesture):
(WebKit::WebPage::updateSelectionWithExtentPointAndBoundary):
(WebKit::WebPage::selectTextWithGranularityAtPoint):
* Tools/TestWebKitAPI/Helpers/cocoa/Foundation+Extras.swift:
(CGRect.center):
(State.signal):
(State.wait):
* Tools/TestWebKitAPI/Helpers/cocoa/JavaScriptMessages.swift:
(BoundingClientRect.expression):
(BoundingClientRect.encoded):
(SelectionBoundingClientRect.expression): Deleted.
(SelectionBoundingClientRect.encoded): Deleted.
* Tools/TestWebKitAPI/Tests/WebKit/WebPage/AppKitGesturesTests.swift:
(AppKitGesturesTests.updatingTextRangeSelectionByUserInteractionUpdatesEditorState(_:)):
(AppKitGesturesTests.clickingOnSelectedWordOpensContextMenu(_:)):
(AppKitGesturesTests.doubleClickingInWordSelectsWord(_:)):
(AppKitGesturesTests.clickingInWordChangesSelection(_:)):
(AppKitGesturesTests.clickingChangesSelection):
(convertToCoreGraphicsScreenCoordinates(_:window:)):
(AppKitGesturesTests.loadHTML(_:)):
(AppKitGesturesTests.screenBoundsOfText(_:)):
(AppKitGesturesTests.doubleClickingInWordSelectsWord): Deleted.
* Tools/TestWebKitAPI/Tests/WebKit/WebPage/JavaScriptExpressionTests.swift:
(JavaScriptExpressionTests.selectionBoundingClientRectReturnsNonEmptyRectForRangeSelection):
(JavaScriptExpressionTests.selectionBoundingClientRectReturnsZeroWidthRectForCollapsedSelection):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to