Implement WidgetDelegate::OnWindow[Begin/End]UserBoundsChange for Mac
Moderate
Commit Hash:
070e93c445f9184221b9e51b6cbc2c64a526dac8
Commit Time: 2026-03-24 18:17:06
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review:
View Upstream Review 🔗
📋 Summary
This commit implements window move begin/end notifications for macOS, bringing parity with Aura and Desktop Windows platforms. Key changes include:
1. Added windowWillMove: handler in ViewsNSWindowDelegate that responds to window-about-to-move events, sets an _isMoving flag, and uses an NSEvent local monitor to detect mouse release for drag completion. Modified windowDidMove: from being called once at drag end to being called multiple times during drag, checking mouse button state to determine if the move is final. Added windowEndMove helper and cleanup in windowWillClose:.
2. Added OnWindowWillMove() and OnWindowDidEndMove() methods in NativeWidgetNSWindowBridge, forwarding via mojo to the host. Added in_move_ state tracking field.
3. Added OnWindowWillMove() and OnWindowDidEndMove() mojo interface methods in native_widget_ns_window_host.mojom.
4. NativeWidgetMacNSWindowHost implements the new mojo interface methods, forwarding to NativeWidgetMac.
5. NativeWidgetMac adds OnWindowWillMove() and OnWindowDidEndMove() methods calling delegate_'s OnNativeWidgetBeginUserBoundsChange() and OnNativeWidgetEndUserBoundsChange(). Also added BeginUserBoundsChange/EndUserBoundsChange calls in OnWindowWillStartLiveResize/OnWindowDidEndLiveResize.
1. Added windowWillMove: handler in ViewsNSWindowDelegate that responds to window-about-to-move events, sets an _isMoving flag, and uses an NSEvent local monitor to detect mouse release for drag completion. Modified windowDidMove: from being called once at drag end to being called multiple times during drag, checking mouse button state to determine if the move is final. Added windowEndMove helper and cleanup in windowWillClose:.
2. Added OnWindowWillMove() and OnWindowDidEndMove() methods in NativeWidgetNSWindowBridge, forwarding via mojo to the host. Added in_move_ state tracking field.
3. Added OnWindowWillMove() and OnWindowDidEndMove() mojo interface methods in native_widget_ns_window_host.mojom.
4. NativeWidgetMacNSWindowHost implements the new mojo interface methods, forwarding to NativeWidgetMac.
5. NativeWidgetMac adds OnWindowWillMove() and OnWindowDidEndMove() methods calling delegate_'s OnNativeWidgetBeginUserBoundsChange() and OnNativeWidgetEndUserBoundsChange(). Also added BeginUserBoundsChange/EndUserBoundsChange calls in OnWindowWillStartLiveResize/OnWindowDidEndLiveResize.
🎯 Impact Analysis
This change has a moderate impact on WebView2Mac that warrants attention. Key analysis:
1. **New mojo interface methods**: Added OnWindowWillMove() and OnWindowDidEndMove() to native_widget_ns_window_host.mojom. This is the core Remote Cocoa cross-process communication interface between WebView2Mac's app shim and browser processes. Upon integration, the mojom interface definition and all implementing classes (including NativeWidgetMacNSWindowHost and DummyHostImpl) must be updated in the Edge repo.
2. **DummyHostImpl update required**: Edge repo's DummyHostImpl (empty implementation for handling synchronous calls when mojo interface is unbound) needs empty implementations of OnWindowWillMove() and OnWindowDidEndMove(), or compilation will fail.
3. **ViewsNSWindowDelegate behavior change**: windowDidMove: semantics changed from "called once at drag end" to "called multiple times during drag". Edge repo's windowDidMove: only calls OnPositionChanged(); this change preserves that call but adds move-end detection logic. For WebView2Mac's non-embedded child windows (find bar, date picker, etc.), window position change notifications will now fire more frequently.
4. **NativeWidgetMac resize callback enhancement**: OnWindowWillStartLiveResize and OnWindowDidEndLiveResize now also call OnNativeWidgetBeginUserBoundsChange/EndUserBoundsChange. WebView2Mac's child windows will trigger these callbacks during user resize. If WebView2Mac's WidgetDelegate subclasses have custom OnWindowBeginUserBoundsChange/EndUserBoundsChange handlers, behavior will change.
5. **Limited impact on embedded WebView**: WebView2Mac's primary embedded WebView runs within the host app's window without creating an independent NativeWidgetMacNSWindow, so windowWillMove:/windowDidMove: events won't directly trigger WebView2Mac code paths. However, child windows created by WebView2Mac (popups, dialogs) use standard NativeWidgetMacNSWindow and will be affected.
1. **New mojo interface methods**: Added OnWindowWillMove() and OnWindowDidEndMove() to native_widget_ns_window_host.mojom. This is the core Remote Cocoa cross-process communication interface between WebView2Mac's app shim and browser processes. Upon integration, the mojom interface definition and all implementing classes (including NativeWidgetMacNSWindowHost and DummyHostImpl) must be updated in the Edge repo.
2. **DummyHostImpl update required**: Edge repo's DummyHostImpl (empty implementation for handling synchronous calls when mojo interface is unbound) needs empty implementations of OnWindowWillMove() and OnWindowDidEndMove(), or compilation will fail.
3. **ViewsNSWindowDelegate behavior change**: windowDidMove: semantics changed from "called once at drag end" to "called multiple times during drag". Edge repo's windowDidMove: only calls OnPositionChanged(); this change preserves that call but adds move-end detection logic. For WebView2Mac's non-embedded child windows (find bar, date picker, etc.), window position change notifications will now fire more frequently.
4. **NativeWidgetMac resize callback enhancement**: OnWindowWillStartLiveResize and OnWindowDidEndLiveResize now also call OnNativeWidgetBeginUserBoundsChange/EndUserBoundsChange. WebView2Mac's child windows will trigger these callbacks during user resize. If WebView2Mac's WidgetDelegate subclasses have custom OnWindowBeginUserBoundsChange/EndUserBoundsChange handlers, behavior will change.
5. **Limited impact on embedded WebView**: WebView2Mac's primary embedded WebView runs within the host app's window without creating an independent NativeWidgetMacNSWindow, so windowWillMove:/windowDidMove: events won't directly trigger WebView2Mac code paths. However, child windows created by WebView2Mac (popups, dialogs) use standard NativeWidgetMacNSWindow and will be affected.
Impacted Classes:
remote_cocoa::mojom::NativeWidgetNSWindowHost
remote_cocoa::NativeWidgetNSWindowBridge
remote_cocoa::ViewsNSWindowDelegate
views::NativeWidgetMacNSWindowHost
views::NativeWidgetMac