Fix stale superview bounds when positioning WebContentsViewMac

Commit: ef2fe534 | 2026-01-22 22:20:56+00:00

← Back to List

Fix stale superview bounds when positioning WebContentsViewMac

Moderate
Commit Hash: ef2fe534f68541754f74820212624d55a79c5a78
Commit Time: 2026-01-22 22:20:56+00:00
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This commit fixes coordinate calculation errors caused by stale superview.bounds data during WebContentsViewMac resizing. The root cause is that BridgedContentView::setFrameSize triggers UpdateWindowGeometry before the NSView's frame is updated, causing WebContentsNSViewBridge::SetBounds() to read stale superview.bounds data. The previous Y-flip calculation used [superview bounds].size.height, producing incorrect frame values during window resize.

The fix adds a superview_height parameter throughout the SetBounds call chain, passing the authoritative container height from views::Widget for Y-flip calculation instead of relying on potentially stale superview.bounds. The changes include:
- Modified remote_cocoa::mojom::WebContentsNSView Mojo interface to add int32 superview_height parameter to SetBounds method
- Modified ui::ViewsHostableView interface to add int superview_height parameter to ViewsHostableSetBounds method
- Updated implementation classes including WebContentsNSViewBridge, WebContentsViewMac, and NativeViewHostMac to pass and use the new parameter
- In NativeViewHostMac::ShowWidget, obtain accurate superview height from host_->GetWidget()->GetClientAreaBoundsInScreen().height()

🎯 Impact Analysis

This change has **moderate to major impact** on WebView2Mac, manifested in the following aspects:

**1. Mojo Interface Change (High Risk)**
- remote_cocoa::mojom::WebContentsNSView::SetBounds interface signature changed, adding int32 superview_height parameter
- If WebView2Mac downstream code has HostingWebContentsNSViewBridge inheriting from remote_cocoa::WebContentsNSViewBridge and overrides the SetBounds method, the method signature must be updated to match the new interface
- All code calling SetBounds needs to pass the additional superview_height parameter

**2. ViewsHostableView Interface Change (High Risk)**
- ui::ViewsHostableView::ViewsHostableSetBounds interface signature changed, adding int superview_height parameter
- WebContentsViewMac implements this interface; if WebView2Mac has custom ViewsHostableView implementations or inherits from WebContentsViewMac, corresponding method signatures need to be updated

**3. Coordinate Calculation Logic Improvement (Positive Impact)**
- Fixes coordinate calculation errors during window resizing, which is a beneficial improvement for WebView2Mac
- Uses authoritative container height for Y-axis flipping, improving accuracy and reliability of NSView positioning
- Especially in dynamic window resizing scenarios, WebView2Mac's content view will receive more accurate position and size

**4. Downstream Integration Recommendations**
- Check and update all classes that inherit or implement WebContentsNSViewBridge (such as HostingWebContentsNSViewBridge)
- Ensure all code calling SetBounds or ViewsHostableSetBounds passes the correct superview_height value
- This value can typically be obtained from Widget::GetClientAreaBoundsInScreen().height()
- Re-test window resizing scenarios to verify accuracy of WebView content positioning

Impacted Classes:

remote_cocoa::mojom::WebContentsNSView remote_cocoa::WebContentsNSViewBridge ui::ViewsHostableView content::WebContentsViewMac views::NativeViewHostMac