Don't allow NSWindow to steal focus from modal window on scrim click

提交: 03549f10 | 2026-04-08 19:30:25

← 返回列表

Don't allow NSWindow to steal focus from modal window on scrim click

Moderate
提交哈希: 03549f10a1c37ca13adbaf1c8d1195ad302cb88a
提交时间: 2026-04-08 19:30:25
影响等级: Moderate
生成工具: chromium-watcher
上游审核链接: 查看上游审核 🔗

📋 摘要

Clicking the web content scrim behind a tab-modal dialog caused the parent
browser window to become the key window, breaking keyboard navigation (Enter,
Esc, Tab) in the dialog. The fix intercepts NSEventTypeLeftMouseDown events in
NativeWidgetMacNSWindow::sendEvent: when the hit-test result is kSubView and a
visible child modal window exists: the event is swallowed and the child modal
is explicitly made the key window. A new helper method
-topmostVisibleChildModalWindow is added to NativeWidgetMacNSWindow, and a
public accessor modal_type() is added to NativeWidgetNSWindowBridge so Obj-C
code can query the modal type of each bridge-owned child window.

🎯 影响分析

The changes touch core Remote Cocoa files used directly by WebView2Mac, so the
impact is concrete:

1. NativeWidgetMacNSWindow(-sendEvent:) — The downstream Edge build does not yet
contain this fix. If a WebView2Mac host window has a visible child modal
dialog (e.g. window.alert/confirm/prompt, or any kChild-modal views::Widget),
clicking the web content area can still steal focus from that dialog and break
keyboard navigation. When merging, care is needed: the downstream sendEvent:
contains an Edge-specific double-click drag-region handler guarded by
MICROSOFT_EDGE_BRANDING. The new NSEventTypeLeftMouseDown modal-intercept
branch must be inserted after that custom block and before the
hasViewsMenuActive branch to avoid conflicts.

2. NativeWidgetNSWindowBridge(modal_type()) — The downstream bridge header already
has the modal_type_ field (line 453) but lacks the public accessor. This
method must be added; without it the new -topmostVisibleChildModalWindow
helper will not compile in the downstream tree.

3. The new -topmostVisibleChildModalWindow helper depends on child_windows() and
modal_type(), both of which already exist downstream, so the merge complexity
is low.

Overall this is a beneficial fix for modal dialog keyboard accessibility in
WebView2Mac, requiring careful integration with the downstream Edge-specific
sendEvent: extensions.

受影响的类:

NativeWidgetMacNSWindow NativeWidgetNSWindowBridge