Add middle ellipsis truncation for menu item titles on macOS

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

← Back to List

Add middle ellipsis truncation for menu item titles on macOS

Minor
Commit Hash: 10710bdf689f10100f501702de77b3242c80413a
Commit Time: 2026-01-26 22:33:31+00:00
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This commit adds Safari-like middle ellipsis truncation for overly long menu item titles on the macOS platform. Key changes include:

1. Added gfx::ElideMenuItemTitle() API (in ui/gfx/mac/menu_text_elider_mac.h) as a shared truncation utility accessible by both chrome/browser/ and components/ layers
2. Applied truncation in the SetWindowTitle() method of components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm
3. Applied truncation to Bookmarks menu items, History menu items, Tab menu items in Window menu, browser window titles in Dock menu, and "Look Up" context menu items

The implementation uses gfx::ElideText with ELIDE_MIDDLE behavior and the system menu font, with a default maximum width of approximately 400 pixels to match native macOS menu appearance and prevent menu items from extending beyond the screen edge.

🎯 Impact Analysis

This change has a **Minor** impact on WebView2Mac.

**Affected Components:**
- The NativeWidgetNSWindowBridge::SetWindowTitle() method now applies truncation to incoming window titles (approximately 400 pixels width)
- This method is used in upstream code to set the NSWindow title, affecting display in Dock menu and window title bar

**Specific Impact on WebView2Mac:**
1. **Window Title Display**: WebView2Mac uses HostingNSWindowBridge (which inherits from NativeWidgetNSWindowBridge) to manage windows. If the host application sets an overly long window title (exceeding approximately 400 pixels), the title will be truncated in the middle with an ellipsis. This primarily affects the window title bar and macOS Dock menu display
2. **Functional Integrity**: This change does not affect WebView2Mac's core embedded web content functionality, only the visual presentation of window titles
3. **User Experience**: For applications that set extremely long window titles, this change may improve display by preventing titles from extending beyond screen boundaries
4. **API Behavior**: The behavior change in SetWindowTitle() is silent and will not produce errors or warnings, but may result in title display that differs from the host application's expectations

**Unaffected Components:**
- Bookmark, history, and tab menu item truncation only affects browser UI and does not impact the WebView2Mac control
- WebView2Mac itself does not involve complex menu management (such as bookmark menus, history menus, etc.), so these changes do not directly affect its functionality
- All other Remote Cocoa functionality (window management, event handling, fullscreen mode, etc.) remains unaffected

**Recommendations:**
- Host application developers should be aware that extremely long window titles may be truncated during display
- If necessary, window title length can be pre-processed at the host application layer to ensure important information is not hidden by the ellipsis

Impacted Classes:

remote_cocoa::NativeWidgetNSWindowBridge gfx::ElideMenuItemTitle (新增 API / new API)