mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-27 11:02:33 +01:00
f4fe0be1f8
## Summary Adds `NativeView` to GPUI: an element that places a platform view (an `NSView` on macOS) in a window and composites it with the rest of the scene, so that GPUI content can be drawn both under and over it. Delta uses this to show a `WKWebView` in a pane tab with GPUI dialogs and toolbars drawn over the page. What it covers on macOS: - **Compositing.** The native view sits behind the window's Metal layer, and the renderer cuts a hole in the scene where the view shows, so GPUI elements painted after it appear above it. The window's layer is non-opaque only while a scene shows a native view. - **Keyboard input.** Keys go to a focused native view first. An embedder can reserve actions that must keep working whatever the view does with keys, including the first key of a multi-key binding. AppKit controls beside a native view keep their own input. - **Pointer.** GPUI elements over a native view block clicks to it, and the native view chooses the cursor while the pointer is over an unobscured part of it. - **Accessibility.** VoiceOver can reach a native view that is shown. Other platforms get the element and a no-op implementation: `NativeView::new` reports that the window cannot show native views. Also included is a small `div` fix that the embedder needed: an item a scroll handle is asked to scroll to before the handle's first frame is now scrolled to once it has been laid out. ## Testing - Two examples: `cargo run -p gpui --example native_view` and `--example native_view_appkit_field`, which show native views with GPUI drawn over them. - The test platform's window records native view placement, with unit tests for the placement, input-routing policy and reserved-action logic. - Exercised through Delta's browser tabs on macOS 26: typing, shortcuts, splits, zoom, dialogs drawn over the page, and hiding and showing tabs. - Not exercised by hand: the black-flash, stale-cursor and VoiceOver fixes in the last two commits. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [ ] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A - [GPUI] Added `NativeView`, an element that composites an `NSView` into a window's scene with GPUI content drawn over it. Only macOS supports it for now; `NativeView::new` returns an error on other platforms. - [GPUI] Fixed `ScrollHandle::scroll_to_item` being ignored when called before the handle's first frame. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com> Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>