Handle double-click-to-zoom on custom draggable regions on macOS
Major
提交哈希:
2be0ae48ad7c700ec9dca07e83e73407947cbad4
提交时间: 2026-04-21 02:54:20
影响等级: Major
生成工具: chromium-watcher
上游审核链接:
查看上游审核 🔗
📋 摘要
This commit adds double-click handling for custom draggable regions (HTCAPTION) in NativeWidgetMacNSWindow's sendEvent: method. macOS AppKit natively handles double-click-to-zoom only for the native titlebar region (via _NSTitlebarContainerView), but not for custom caption areas like the empty space in a vertical tab strip.
The fix intercepts left-button double-click mouseUp events in sendEvent:. When the click lands within contentLayoutRect and hitTest: returns nil (indicating a custom draggable background area), it reads the AppleActionOnDoubleClick system preference and performs the corresponding action (Fill/Maximize/Minimize). It also declares the private NSWindow API _zoomFill: and adds a browser test verifying double-click zoom on the vertical tab strip's empty area.
The fix intercepts left-button double-click mouseUp events in sendEvent:. When the click lands within contentLayoutRect and hitTest: returns nil (indicating a custom draggable background area), it reads the AppleActionOnDoubleClick system preference and performs the corresponding action (Fill/Maximize/Minimize). It also declares the private NSWindow API _zoomFill: and adds a browser test verifying double-click zoom on the vertical tab strip's empty area.
🎯 影响分析
This commit has a major impact on WebView2Mac for the following reasons:
1. **Core file directly modified**: The modified file native_widget_mac_nswindow.mm is in components/remote_cocoa/app_shim/, a core component of the Remote Cocoa architecture. NativeWidgetMacNSWindow is the NSWindow subclass used by all macOS windows including WebView2Mac windows, and its sendEvent: method handles all window event dispatch.
2. **Direct conflict with Edge downstream implementation**: The Edge downstream repository already contains a functionally similar but differently implemented version, guarded by #if BUILDFLAG(MICROSOFT_EDGE_BRANDING). This will cause merge conflicts that require careful reconciliation.
3. **Significant upstream vs downstream implementation differences**:
- **Event type**: Upstream handles on mouseUp (clickCount==2); downstream handles on mouseDown (clickCount==2)
- **Area check**: Upstream additionally checks NSPointInRect(event.locationInWindow, self.contentLayoutRect); downstream only checks hitTest:==nil
- **Fill action**: Upstream adds support for "Fill" action via private API _zoomFill:; downstream does not support this
- **Execution model**: Upstream performs the action synchronously on mouseUp and returns; downstream uses dispatch_async on mouseDown and a _handledDoubleClickAction flag to swallow the subsequent mouseUp
- **Instance variable**: Downstream has a _handledDoubleClickAction BOOL ivar; upstream does not need one
4. **Merge recommendation**: The upstream implementation should replace the downstream MICROSOFT_EDGE_BRANDING-guarded code block. The _handledDoubleClickAction ivar and related logic should be removed. The upstream mouseUp-based approach is cleaner, and it adds the contentLayoutRect boundary check and Fill action support.
5. **WebView2Mac functional impact**: If WebView2Mac applications define custom draggable regions, this change will make double-click behavior in those regions consistent with the native titlebar behavior, which is a positive improvement.
1. **Core file directly modified**: The modified file native_widget_mac_nswindow.mm is in components/remote_cocoa/app_shim/, a core component of the Remote Cocoa architecture. NativeWidgetMacNSWindow is the NSWindow subclass used by all macOS windows including WebView2Mac windows, and its sendEvent: method handles all window event dispatch.
2. **Direct conflict with Edge downstream implementation**: The Edge downstream repository already contains a functionally similar but differently implemented version, guarded by #if BUILDFLAG(MICROSOFT_EDGE_BRANDING). This will cause merge conflicts that require careful reconciliation.
3. **Significant upstream vs downstream implementation differences**:
- **Event type**: Upstream handles on mouseUp (clickCount==2); downstream handles on mouseDown (clickCount==2)
- **Area check**: Upstream additionally checks NSPointInRect(event.locationInWindow, self.contentLayoutRect); downstream only checks hitTest:==nil
- **Fill action**: Upstream adds support for "Fill" action via private API _zoomFill:; downstream does not support this
- **Execution model**: Upstream performs the action synchronously on mouseUp and returns; downstream uses dispatch_async on mouseDown and a _handledDoubleClickAction flag to swallow the subsequent mouseUp
- **Instance variable**: Downstream has a _handledDoubleClickAction BOOL ivar; upstream does not need one
4. **Merge recommendation**: The upstream implementation should replace the downstream MICROSOFT_EDGE_BRANDING-guarded code block. The _handledDoubleClickAction ivar and related logic should be removed. The upstream mouseUp-based approach is cleaner, and it adds the contentLayoutRect boundary check and Fill action support.
5. **WebView2Mac functional impact**: If WebView2Mac applications define custom draggable regions, this change will make double-click behavior in those regions consistent with the native titlebar behavior, which is a positive improvement.
受影响的类:
NativeWidgetMacNSWindow
remote_cocoa::NativeWidgetNSWindowBridge