Skip to content

webview: Clip native views without resizing the page - #3499

Merged
huacnlee merged 3 commits into
longbridge:mainfrom
pioneerdotai:fix/webview-clipping
Oct 14, 2026
Merged

huacnlee merged 3 commits into
longbridge:mainfrom
pioneerdotai:fix/webview-clipping

Conversation

@superoskin

@superoskin superoskin commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

When a WebView sits inside a scrolling container, its native view can extend beyond the parent's visible area and cover nearby controls. This change applies GPUI's inherited content mask to the WebView element and its mouse hitbox.

On macOS and Linux X11/XWayland, the existing native composition container follows the visible rectangle while the browser keeps its full document bounds. Scrolling clips the page without changing its layout width or height. An empty visible area hides the native view while keeping the document loaded, and hidden preparation can still give the document its actual layout width.

The implementation stays within gpui-webview. Windows retains its existing bounds behavior; this change adds neither Windows clipping nor native Wayland support. Partial clipping on macOS and Linux requires native window composition.

Review correction awaiting integration

Review found that the current PR head rejects all visible geometry without composition, including fully visible documents, then changes the caller's visibility setting to false. This breaks Linux WebView::new and the existing composition-failure fallback, and prevents subsequent frames from recovering.

The correction is available in commit 01eab2e5 on longbridge/gpui-kit:fix/webview-clipping-review-3499. It restores the existing bounds path for fully visible documents without composition, keeps temporary native hiding separate from the caller's visibility preference, and initializes Linux display scaling before geometry updates. Unsupported partial clipping still reports an error and hides the native view; later frames can recover when clipping is no longer needed.

Direct pushes to the PR's fork branch were rejected by GitHub with HTTP 403, despite the PR allowing maintainer edits. This correction still needs to be applied to pioneerdotai/gpui-kit:fix/webview-clipping.

Public API

gpui-webview

pub fn set_geometry(
    &self,
    document: Bounds<Pixels>,
    clip: Bounds<Pixels>,
) -> anyhow::Result<()>

Sets the full document bounds and visible clip independently, preserving the DOM viewport while clipping through native composition. Existing build, new, set_bounds, and set_visible signatures remain unchanged.

Validation

  • The original PR head passed all reported CI checks.
  • The review correction passes cargo fmt --all --check and git diff --check.
  • Local cargo check -p gpui-webview --locked was blocked while fetching the workspace's quickjs-jit dependency; an offline retry confirmed the required checkout was unavailable.
  • No local tests or native window interaction checks were run for the correction.

AI assistance

AI assisted with the geometry implementation in crates/webview/src/lib.rs, composition.rs, and linux.rs, the visibility and fallback correction in lib.rs, and this description.

@huacnlee huacnlee changed the title fix(webview): respect parent clipping without resizing the page webview: Clip native views without resizing the page Oct 14, 2026
@huacnlee

Copy link
Copy Markdown
Member

The compatibility fix is ready in 01eab2e5 on branch fix/webview-clipping-review-3499. GitHub rejects maintainer pushes to this organization-owned fork with HTTP 403, even though maintainer edits are enabled, so I could not apply it directly to this PR.

Please cherry-pick the fix onto fix/webview-clipping:

git fetch https://github.com/longbridge/gpui-kit.git fix/webview-clipping-review-3499
git cherry-pick 01eab2e5

The fix restores fully visible WebViews without composition and keeps temporary geometry failures from permanently changing the caller’s visibility setting. Formatting and diff checks pass, and the WebView example builds and launches successfully on Linux.

@huacnlee

Copy link
Copy Markdown
Member

For future PRs, please submit from a fork under your personal account rather than an organization, and keep “Allow edits from maintainers” enabled. Organization-owned forks prevent me from pushing fixes directly, which makes it harder to quickly adjust the code and move the PR forward. Thanks!

huacnlee
huacnlee previously approved these changes Oct 14, 2026

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clipping approach looks good. Please cherry-pick 01eab2e5 before merging to preserve the existing no-composition fallback and allow recovery after temporary geometry failures. The correction passes formatting and diff checks, and the WebView example builds and launches on Linux.

@huacnlee
huacnlee enabled auto-merge (squash) October 14, 2026 11:05
@huacnlee
huacnlee merged commit baf03ed into longbridge:main Oct 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants