Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 914fb1fe0ddac13d3d0fec2e25beaecd109fae06
      
https://github.com/WebKit/WebKit/commit/914fb1fe0ddac13d3d0fec2e25beaecd109fae06
  Author: Wenson Hsieh <[email protected]>
  Date:   2026-02-10 (Tue, 10 Feb 2026)

  Changed paths:
    M Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm
    M Source/WebKit/UIProcess/mac/WebViewImpl.h
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Source/WebKit/WebProcess/WebPage/WebPage.h
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm

  Log Message:
  -----------
  [macOS] NSTextInputClient protocol methods should return rects in the 
screen's coordinate space
https://bugs.webkit.org/show_bug.cgi?id=307392
rdar://169985581

Reviewed by Richard Robinson and Abrar Rahman Protyasha.

The two `NSTextInputClient` methods `documentVisibleRect` and 
`unionRectInVisibleSelectedRange`
expect rects in screen coordinates rather than view coordinates (which is the 
current coordinate
space for these resulting rects). This patch addresses this disparity in 
coordinate spaces.

See below for more details.

Test: EditorStateTests.UnionRectInVisibleSelectedRangeAndDocumentVisibleRect

* Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView unionRectInVisibleSelectedRange]):
(-[WKWebView documentVisibleRect]):
* Source/WebKit/UIProcess/mac/WebViewImpl.h:
* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::convertFromViewToScreen const):

Add a helper method to convert the given rect from web view to screen 
coordinates.

(WebKit::WebViewImpl::selectionDidChange):

Drive-by fix: in the case where `-textInputClientDidUpdateSelection` is called, 
the call to
`-scheduleShowAffordanceForSelectionRect:ofView:forDelegate:` becomes redundant 
in the case where
`textInputClientSelectionUpdatesEnabled` is on. Adjust this to avoid doing 
both, in that scenario.

(WebKit::WebViewImpl::unionRectInVisibleSelectedRangeInScreen const):
(WebKit::WebViewImpl::documentVisibleRectInScreen const):

Rename these internal view impl methods to clarify that their returned values 
are in screen
coordinates already, and use the `convertFromViewToScreen` helper above.

(WebKit::WebViewImpl::firstRectForCharacterRange):
(WebKit::WebViewImpl::unionRectInVisibleSelectedRange const): Deleted.
(WebKit::WebViewImpl::documentVisibleRect const): Deleted.
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
(TestWebKitAPI::TEST(EditorStateTests, 
UnionRectInVisibleSelectedRangeAndDocumentVisibleRect)):

Adjust this API test to also sanity check the resulting rects against the 
bounds of the view. In
doing so, we assume that the rects are in screen coordinates, and first map 
them back to the view's
coordinate space before comparing them with the view's bounds.

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



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

Reply via email to