[webkit-changes] [WebKit/WebKit] a9d2d3: [SwiftUI] Changing the `webViewContentBackground` ...

Richard Robinson noreply at github.com
Sun Feb 23 23:27:26 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a9d2d3b8f58696db838bdff95cdc85fe1a4f3a4e
      https://github.com/WebKit/WebKit/commit/a9d2d3b8f58696db838bdff95cdc85fe1a4f3a4e
  Author: Richard Robinson <richard_robinson2 at apple.com>
  Date:   2025-02-23 (Sun, 23 Feb 2025)

  Changed paths:
    M Source/WebCore/rendering/RenderLayerCompositor.cpp
    M Source/WebKit/_WebKit_SwiftUI/WebViewRepresentable.swift
    M Tools/SwiftBrowser/Source/ViewModel/AppStorageKeys.swift
    M Tools/SwiftBrowser/Source/Views/ContentView.swift
    M Tools/SwiftBrowser/Source/Views/SettingsView.swift
    M Tools/TestWebKitAPI/Tests/mac/BackgroundColor.mm

  Log Message:
  -----------
  [SwiftUI] Changing the `webViewContentBackground` value doesn't always apply the new value on macOS
https://bugs.webkit.org/show_bug.cgi?id=287963
rdar://145142533

Reviewed by Aditya Keerthi.

Toggling the `webViewContentBackground` view modifier to `.hidden` sometimes has no effect. This is
because of an underlying issue in the existing `_drawsBackground` SPI; specifically, toggling this
value after web content is loaded is not guaranteed to actually hide the background.

This is because after some content is loaded or changed, the `RenderLayerCompositor::updateOverflowControlsLayers` method gets called.
This method checks if an "overhang area" layer is required, and if so, it adds an opaque overhang area layer,
effectively giving the web view an opaque background color. This logic is sound, since the check to determine
if such a layer is required is done via `RenderLayerCompositor::requiresOverhangAreasLayer` which checks to
see if the frame view has an opaque background. If it does not, it returns `false` as expected.

However, the problem is that after the overhang area layer is added, if the web view background is then changed
to a non-opaque color (as is done when `_drawsBackground` is `false`), the `RenderLayerCompositor::updateOverflowControlsLayers`
method isn't guaranteed to be called again and therefore doesn't have a chance to update the presence of the
overhang area layer.

To fix, ensure that `updateOverflowControlsLayers` is called whenever the frame view's background color changes
so that it can properly update the overhang area.

* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::LocalFrameView::updateBackgroundRecursively):

Call `frameViewDidChangeBackground` when the background needs updating.

* Source/WebCore/rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::frameViewDidChangeBackground):
* Source/WebCore/rendering/RenderLayerCompositor.h:

Add a method similar to `frameViewDidChangeSize`, to ensure `updateOverflowControlsLayers` gets called.

* Source/WebKit/_WebKit_SwiftUI/WebViewRepresentable.swift:
(WebViewRepresentable.updatePlatformView(_:context:)):

Optimization to only call the setters if the value actually changes.

* Tools/SwiftBrowser/Source/ViewModel/AppStorageKeys.swift:
* Tools/SwiftBrowser/Source/Views/ContentView.swift:
(ContentView.backgroundHidden):
(ContentView.body):
* Tools/SwiftBrowser/Source/Views/SettingsView.swift:
(BinaryValuePicker.value):
(BinaryValuePicker.body):
(GeneralSettingsView.body):
(ScrollBounceBehaviorPicker.basedOnSize): Deleted.
(ScrollBounceBehaviorPicker.body): Deleted.

Use this view modifier in SwiftBrowser.

* Tools/TestWebKitAPI/Tests/mac/BackgroundColor.mm:
(TestWebKitAPI::testDrawsBackgroundAfterLoadingWebContent):
(TestWebKitAPI::TEST(WebKit, DrawsBackgroundAfterLoadingWebContentNoToYes)):
(TestWebKitAPI::TEST(WebKit, DrawsBackgroundAfterLoadingWebContentYesToNo)):

Add tests for this.

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