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

Commit: 10710bdf | 2026-01-26 22:33:31

← Back to List

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

Moderate
Commit Hash: 10710bdf689f10100f501702de77b3242c80413a
Commit Time: 2026-01-26 22:33:31
Impact Level: Moderate
Generated By: webview2-upstream-sentry

📋 Summary

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).

🎯 Impact Analysis

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.

Impacted Classes:

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