[webkit-changes] [WebKit/WebKit] 6c3e6c: [Cocoa] Expose SPI (for prototyping only) to get s...

Wenson Hsieh noreply at github.com
Sat Feb 15 12:54:09 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6c3e6c50a1785fda5ca163c1e89c6b9aee8e5b9d
      https://github.com/WebKit/WebKit/commit/6c3e6c50a1785fda5ca163c1e89c6b9aee8e5b9d
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2025-02-15 (Sat, 15 Feb 2025)

  Changed paths:
    M LayoutTests/TestExpectations
    A LayoutTests/fast/page-color-sampling/basic-fixed-container-edge-sampling-expected.txt
    A LayoutTests/fast/page-color-sampling/basic-fixed-container-edge-sampling.html
    M LayoutTests/platform/ios/TestExpectations
    M LayoutTests/platform/mac-wk2/TestExpectations
    M LayoutTests/resources/ui-helper.js
    M Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
    M Source/WebCore/page/PageColorSampler.cpp
    M Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm
    M Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTree.serialization.in
    M Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/Shared/WebPreferencesDefaultValues.h
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
    M Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h
    M Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm
    M Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
    M Source/WebKit/UIProcess/PageClient.h
    M Source/WebKit/UIProcess/ios/PageClientImplIOS.h
    M Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/UIProcess/mac/PageClientImplMac.h
    M Source/WebKit/UIProcess/mac/PageClientImplMac.mm
    M Source/WebKit/UIProcess/mac/WKRevealItemPresenter.mm
    M Source/WebKit/UIProcess/mac/WebViewImpl.h
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp
    M Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
    M Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
    M Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h
    M Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm

  Log Message:
  -----------
  [Cocoa] Expose SPI (for prototyping only) to get sampled colors at the edges of fixed-position containers
https://bugs.webkit.org/show_bug.cgi?id=287734
rdar://144839983

Reviewed by Abrar Rahman Protyasha.

Add support for new SPI to get an `(NS|UI)Color` for each rect edge of the layout viewport, or null
if there is no fixed-position container near that edge. This color represents the predominant color
for that edge (in the case where there is a predominant color), and otherwise falls back to the
extended page background color.

This mechanism is fully gated behind a new runtime setting, `FixedContainerEdgeSamplingEnabled`,
which is currently off by default (but enabled in the new tests). See below for more details.

* LayoutTests/TestExpectations:
* LayoutTests/fast/page-color-sampling/basic-fixed-container-edge-sampling-expected.txt: Added.
* LayoutTests/fast/page-color-sampling/basic-fixed-container-edge-sampling.html: Added.

Add a new layout test to exercise this SPI.

* LayoutTests/platform/ios/TestExpectations:
* LayoutTests/platform/mac-wk2/TestExpectations:
* LayoutTests/resources/ui-helper.js:
(window.UIHelper.fixedContainerEdgeColors):
(window.UIHelper.async waitForFixedContainerEdgeColors):
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/page/PageColorSampler.cpp:
(WebCore::PageColorSampler::predominantColor):

Make a couple of minor adjustments to the color sampling heuristic:

-   Fix a bug where all colors are considered similar to each other, since
    `toResolvedColorComponentsInColorSpace` returns values clamped between (0, 1), but the color
    distance math assumes the results are in the interval (0, 255).

-   Fall back to the page extended background color instead of an invalid color, in the case where
    there is no predominant color.

* Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:
(defaultFixedContainerEdgeSamplingEnabled):
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTree.serialization.in:
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h:

Plumb the new `FixedContainerEdges` data through remote layer tree transactions over to the UI
process, only if the new runtime setting is enabled.

(WebKit::RemoteLayerTreeTransaction::fixedContainerEdges const):
(WebKit::RemoteLayerTreeTransaction::setFixedContainerEdges):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/Shared/WebPreferencesDefaultValues.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
(-[WKWebView _sampledBottomFixedPositionContentColor:]):
(-[WKWebView _sampledLeftFixedPositionContentColor:]):
(-[WKWebView _sampledTopFixedPositionContentColor:]):
(-[WKWebView _sampledRightFixedPositionContentColor:]):
(-[WKWebView _sampledBottomFixedPositionContentColor]):
(-[WKWebView _sampledLeftFixedPositionContentColor]):
(-[WKWebView _sampledTopFixedPositionContentColor]):
(-[WKWebView _sampledRightFixedPositionContentColor]):

Implement the new properties.

(-[WKWebView _updateFixedContainerEdges:]):

Add a helper method to update current `_fixedContainerEdges`, dispatching KVO notifications in the
process if needed.

* Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.h:
* Source/WebKit/UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::didCommitLayerTree):

Refactor some of this code so that there's a common Cocoa implementation of `didCommitLayerTree` in
the page client that now updates fixed container edge data, and an iOS-specific override point that
additionally propagates the layer tree commit to `WKContentView`.

* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::didCommitLayerTree):
* Source/WebKit/UIProcess/PageClient.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::didCommitLayerTree):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView cleanUpInteraction]):

iOS: reset edge colors when the process terminates or swaps.

* Source/WebKit/UIProcess/mac/PageClientImplMac.h:
* Source/WebKit/UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::didCommitLayerTree): Deleted.
* Source/WebKit/UIProcess/mac/WKRevealItemPresenter.mm:
* Source/WebKit/UIProcess/mac/WebViewImpl.h:
* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::WebViewImpl):

Change `m_view` into a `WKWebView` instead of an `NSView<WebViewImplDelegate>`, so that we can just
call directly into the `WKWebView` in `handleProcessSwapOrExit`. This view used to be either a
`WKWebView` or a `WKView`, but this abstraction hasn't been necessary for several years, since
`WKView` no longer has any clients.

Note that we also remove the `outerWebView` argument in the constructor here, since the only place
where we create a new `WebViewImpl` is from `WKWebView`, which just uses `self` as the
`outerWebView`.

(WebKit::m_flagsChangedEventMonitorTrackingArea):
(WebKit::WebViewImpl::handleProcessSwapOrExit):

macOS: reset edge colors when the process terminates or swaps.

* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::willCommitLayerTree):

Set the fixed container edge data on the remote layer tree transaction (only if the new setting is
enabled).

* Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* Tools/TestRunnerShared/UIScriptContext/UIScriptController.h:
(WTR::UIScriptController::fixedContainerEdgeColors const):
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.h:
* Tools/WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm:
(WTR::UIScriptControllerCocoa::fixedContainerEdgeColors const):

Add a new testing helper to retrieve the fixed container edge colors on all sides, and return it as
a JS object where each of the values is a string: `"rgb(…)"`.

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