Return vector icons to context menus with new isContextMenu parameter

提交: 6e481f22 | 2026-05-08 20:32:39

← 返回列表

Return vector icons to context menus with new isContextMenu parameter

Moderate
提交哈希: 6e481f2206691ac4eafb858ec5d58d08e232c63f
提交时间: 2026-05-08 20:32:39
影响等级: Moderate
生成工具: chromium-watcher
上游审核链接: 查看上游审核 🔗

📋 摘要

This commit modifies MenuControllerCocoa's initializer by adding an isContextMenu: parameter and introduces a class method +initializeWithNewMenuIconScheme: to control context menu icon display policy. Key changes:
1. Init signature changed from initWithModel:delegate: to initWithModel:isContextMenu:delegate: — a breaking API change.
2. Refactored SetMenuItemIcon function to conditionally show vector icons based on is_context_menu and the global g_use_new_menu_icon_scheme flag.
3. On macOS 26+, swizzles NSContextMenuItemView's _imageWidthSharingForItem: to enable symbol-style indentation alignment for menu icons.
4. All callers of MenuControllerCocoa's initializer are updated, including context_menu_runner.mm in the remote_cocoa component.

🎯 影响分析

This commit has a moderate impact on WebView2Mac, primarily in the following areas:

**Build-breaking API change**: MenuControllerCocoa's initializer signature changed (added isContextMenu: parameter). Three downstream Edge call sites are directly affected:
- components/remote_cocoa/app_shim/context_menu_runner.mm — the core context menu path for WebView2, currently using the old initWithModel:delegate: signature. Will fail to compile after merge.
- ui/views/controls/menu/menu_runner_impl_cocoa.mm — also uses the old signature, needs isContextMenu: parameter added.
- ui/menus/cocoa/menu_controller.mm — Edge downstream has extensive custom modifications (MenuControllerCocoaModelDelegate, rebuildMenu, Edge-branded conditional icon handling), which will create significant merge conflicts.

**Icon handling logic conflict**: Upstream refactored icon handling into a SetMenuItemIcon free function, while Edge downstream uses inline Edge-branded conditional code in addItemToMenu: and validateUserInterfaceItem: (including ui::edge::NSImageFromVectorIcon and ui::edge::GetTransparentPlaceholderImage). These two approaches will produce significant merge conflicts requiring careful reconciliation.

**New swizzle behavior**: On macOS 26+, the commit swizzles NSContextMenuItemView's _imageWidthSharingForItem: for symbol-style indentation. This would affect context menu visual appearance in WebView2, but only activates when +initializeWithNewMenuIconScheme:YES is called (currently only in Chrome's app_controller_mac.mm). WebView2 does not call this method, so the swizzle will not immediately affect WebView2 context menus.

**Remediation**: During merge, add isContextMenu: parameter to downstream context_menu_runner.mm and menu_runner_impl_cocoa.mm, and resolve conflicts between Edge's custom icon logic and upstream's refactored SetMenuItemIcon function.

受影响的类:

MenuControllerCocoa remote_cocoa::ContextMenuRunner views::internal::MenuRunnerImplCocoa