Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 0c720ad19cf2d37dbd38cb71bfcbebf10f53e78c
      
https://github.com/WebKit/WebKit/commit/0c720ad19cf2d37dbd38cb71bfcbebf10f53e78c
  Author: Wenson Hsieh <[email protected]>
  Date:   2025-07-04 (Fri, 04 Jul 2025)

  Changed paths:
    M Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
    M Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/ObscuredContentInsets.mm
    M Tools/TestWebKitAPI/cocoa/TestUIDelegate.h
    M Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm

  Log Message:
  -----------
  [macOS] [Liquid Glass] Add a UI delegate method to let clients override top 
inset color based on a proposed default color
https://bugs.webkit.org/show_bug.cgi?id=295447
rdar://154998521

Reviewed by Abrar Rahman Protyasha.

Add support for `-[WKUIDelegate 
_webView:adjustedColorForTopContentInsetColor:]`. This new UI
delegate method has some important nuances that make it well-suited for a 
client (like Safari) to
only *sometimes* extend colors into the top inset area, and otherwise fall back 
to a hard scroll
pocket tinted with the system background:

1.  It's called for both the top scroll pocket capture color, as well as the 
top fixed color
    extension (i.e. the "top inset color" here refers to both pieces of UI).

2.  It's safe to change a couple of properties of the scroll pocket underneath 
this delegate method
    without triggering reentrancy (or worse, infinite recursion):
    a. `-[WKWebView _setShouldSuppressTopColorExtensionView:]`
    b. `-[WKWebView _setOverrideTopScrollEdgeEffectColor:]`

3.  It's automatically called when the system appearance changes, as the web 
view internally updates
    the scroll pocket capture color.

See below for more details.

* Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _updateFixedColorExtensionViews]):

Call out to the delegate through 
`-_adjustedColorForTopContentInsetColorFromUIDelegate:` when we're
about to reveal the top fixed color extension view. We intentionally check the 
state of
`_shouldSuppressTopColorExtensionView` after calling into the delegate, such 
that changes to the
property during the delegate call take effect immediately.

(-[WKWebView _doAfterAdjustingColorForTopContentInsetFromUIDelegate:]):

Add a helper to invoke the given callback on the next runloop if we're in the 
middle of a call to
`-_adjustedColorForTopContentInsetColorFromUIDelegate:`, if needed.

(-[WKWebView _adjustedColorForTopContentInsetColorFromUIDelegate:]):

Add a helper method to invoke the new UI delegate method (or simply return the 
default proposed
color, if the method is not implemented).

(-[WKWebView _setShouldSuppressTopColorExtensionView:]):

Defer calls to update the scroll pocket until the next runloop; see below for 
more details.

* Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h:
* Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView _setOverrideTopScrollEdgeEffectColor:]):

Defer calls to update the scroll pocket until the next runloop to avoid 
recursing infinitely if the
client implements the new delegate method. Note that this doesn't completely 
*prevent* an
incorrectly-implemented WebKit client from triggering fixed color updates 
indefinitely. See (2)
above for more details.

* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::updateTopScrollPocketCaptureColor):

Call out to the delegate through 
`-_adjustedColorForTopContentInsetColorFromUIDelegate:` when
computing and setting the top capture color.

(WebKit::WebViewImpl::effectiveAppearanceDidChange):

Update the scroll pocket capture color here, which depends on 
`+controlBackgroundColor` as well as
the UI delegate.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/ObscuredContentInsets.mm:
(TestWebKitAPI::TEST(ObscuredContentInsets, 
AdjustedColorForTopContentInsetColor)):

Add an API test that adopts this new UI delegate method in a way that's similar 
to how Safari would
use it, by (only sometimes) overriding the proposed color. This also forces an 
appearance change
on the web view, and checks that as a result, the delegate has the opportunity 
to override the
capture color.

* Tools/TestWebKitAPI/cocoa/TestUIDelegate.h:
* Tools/TestWebKitAPI/cocoa/TestUIDelegate.mm:
(-[TestUIDelegate _webView:adjustedColorForTopContentInsetColor:]):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to