Add Safari-like middle ellipsis truncation for long menu item titles on macOS

提交: 10710bdf | 2026-01-26 22:33:31

← 返回列表

Add Safari-like middle ellipsis truncation for long menu item titles on macOS

Moderate
提交哈希: 10710bdf689f10100f501702de77b3242c80413a
提交时间: 2026-01-26 22:33:31
影响等级: Moderate
生成工具: webview2-upstream-sentry

📋 摘要

This commit adds a new gfx::ElideMenuItemTitle() API (in ui/gfx/mac/menu_text_elider_mac.h) that performs Safari-like middle ellipsis truncation (~400px max width) for overly long menu item titles on macOS, preventing menu items from extending beyond the screen edge. The truncation is applied to: bookmarks menu (bookmark_menu_bridge.mm), history menu (history_menu_bridge.mm), tab items in Window menu (tab_menu_bridge.mm), browser window titles for Dock menu (native_widget_ns_window_bridge.mm's SetWindowTitle), and the "Look Up" context menu item (views_text_services_context_menu_mac.mm).

🎯 影响分析

This change has a notable impact on WebView2Mac that requires attention. Upstream adds a gfx::ElideMenuItemTitle() call in NativeWidgetNSWindowBridge::SetWindowTitle to truncate window titles. Edge downstream's HostingNSWindowBridge overrides SetWindowTitle: in is_embedded_webview_ mode it's a no-op (embedded WebView doesn't need to set window titles); in non-embedded mode it calls SetWindowTitleWithoutEliding() — a method specifically added by Edge downstream that skips ElideMenuItemTitle() truncation because WebView2 Mac clients don't load ICU data, which ElideMenuItemTitle requires. This indicates the downstream is already aware of this upstream change and has adapted accordingly. The current downstream implementation is correct and no additional patch is needed. However, if the upstream truncation logic in SetWindowTitle changes in the future, the downstream SetWindowTitleWithoutEliding method should be reviewed for consistency.

受影响的类:

remote_cocoa::NativeWidgetNSWindowBridge gfx::ElideMenuItemTitle embedded_browser_webview::HostingNSWindowBridge