Fix stale superview bounds when positioning WebContentsViewMac during resize

提交: ef2fe534 | 2026-01-22 22:20:56

← 返回列表

Fix stale superview bounds when positioning WebContentsViewMac during resize

Major
提交哈希: ef2fe534f68541754f74820212624d55a79c5a78
提交时间: 2026-01-22 22:20:56
影响等级: Major
生成工具: webview2-upstream-sentry

📋 摘要

This commit fixes incorrect frame positioning in WebContentsNSViewBridge::SetBounds() caused by stale superview.bounds during resize, when BridgedContentView::setFrameSize triggers UpdateWindowGeometry before the NSView's frame is updated. Changes span multiple layers: the Mojo interface web_contents_ns_view_bridge.mojom adds a superview_height parameter to SetBounds; NativeViewHostMac obtains the authoritative superview height from Widget::GetClientAreaBoundsInScreen() and passes it in; WebContentsViewMac forwards the height to both in-process and out-of-process (Remote Cocoa) paths; WebContentsNSViewBridge::SetBounds uses the passed superview_height instead of [superview bounds].size.height for Y flipping; the ViewsHostableView interface is updated accordingly.

🎯 影响分析

This change has a direct and significant impact on WebView2Mac. Edge downstream has a HostingWebContentsNSViewBridge class in content/app_shim_remote_cocoa/edge_embedded_browser/ that inherits from WebContentsNSViewBridge and overrides SetBounds. The upstream signature change from (const gfx::Rect&) to (const gfx::Rect&, int32_t superview_height) has already been reflected in the downstream override. However, the downstream SetBounds implementation uses its own coordinate transformation logic (via hostingNSView.bounds.size.height and convertRect:fromView:), still reading hostingNSView.bounds at call time, which may suffer from the same stale-bounds issue during resize that this upstream commit fixes. It is recommended to evaluate whether the downstream HostingWebContentsNSViewBridge::SetBounds should also use the passed superview_height instead of hostingNSView.bounds.size.height for consistent resize correctness.

受影响的类:

remote_cocoa::WebContentsNSViewBridge content::WebContentsViewMac ui::ViewsHostableView views::NativeViewHostMac embedded_browser_webview::HostingWebContentsNSViewBridge