From 2084034e0effae58b0ed8e38ff612864eea1683a Mon Sep 17 00:00:00 2001 From: FabianLars <30730186+FabianLars@users.noreply.github.com> Date: Sun, 22 Mar 2026 16:29:51 +0100 Subject: [PATCH] refactor!: remove WebViewAttributes from public api --- .changes/remove_webviewattributes.md | 5 +++ README.md | 2 +- src/lib.rs | 67 +++------------------------- 3 files changed, 11 insertions(+), 63 deletions(-) create mode 100644 .changes/remove_webviewattributes.md diff --git a/.changes/remove_webviewattributes.md b/.changes/remove_webviewattributes.md new file mode 100644 index 000000000..cdfeb0501 --- /dev/null +++ b/.changes/remove_webviewattributes.md @@ -0,0 +1,5 @@ +--- +wry: minor +--- + +Remove `WebViewAttributes`, `WebView::new` and `WebView::new_as_child` from public API. Use `WebViewBuilder` instead. diff --git a/README.md b/README.md index 3228a7299..495176fee 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ let webview = builder.build_gtk(window.gtk_window()).unwrap(); ### Child webviews -You can use [`WebView::new_as_child`] or [`WebViewBuilder::build_as_child`] to create the webview as a child inside another window. This is supported on +You can use [`WebViewBuilder::build_as_child`] to create the webview as a child inside another window. This is supported on macOS, Windows and Linux (X11 Only). ```rust diff --git a/src/lib.rs b/src/lib.rs index 5907f23ac..b98f12af0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,7 +74,7 @@ //! //! ## Child webviews //! -//! You can use [`WebView::new_as_child`] or [`WebViewBuilder::build_as_child`] to create the webview as a child inside another window. This is supported on +//! You can use [`WebViewBuilder::build_as_child`] to create the webview as a child inside another window. This is supported on //! macOS, Windows and Linux (X11 Only). //! //! ```no_run @@ -540,11 +540,13 @@ pub struct NewWindowFeatures { /// An id for a webview pub type WebViewId<'a> = &'a str; -pub struct WebViewAttributes<'a> { +// WebViewAttributes is not stable enough to be pub. +struct WebViewAttributes<'a> { /// An id that will be passed when this webview makes requests in certain callbacks. pub id: Option>, /// Web context to be shared with this webview. + #[allow(unused)] pub context: Option<&'a mut WebContext>, /// Whether the WebView should have a custom user-agent. @@ -772,7 +774,7 @@ pub struct WebViewAttributes<'a> { pub focused: bool, /// The webview bounds. Defaults to `x: 0, y: 0, width: 200, height: 200`. - /// This is only effective if the webview was created by [`WebView::new_as_child`] or [`WebViewBuilder::new_as_child`] + /// This is only effective if the webview was created by [`WebViewBuilder::new_as_child`] /// or on Linux, if was created by [`WebViewExtUnix::new_gtk`] or [`WebViewBuilderExtUnix::new_gtk`] with [`gtk::Fixed`]. pub bounds: Option, @@ -896,16 +898,6 @@ impl<'a> WebViewBuilder<'a> { } } - /// Create a new [`WebViewBuilder`] with the given [`WebViewAttributes`] - pub fn new_with_attributes(attrs: WebViewAttributes<'a>) -> Self { - Self { - attrs, - #[allow(clippy::default_constructed_unit_structs)] - platform_specific: PlatformSpecificWebViewAttributes::default(), - error: Ok(()), - } - } - /// Set an id that will be passed when this webview makes requests in certain callbacks. pub fn with_id(mut self, id: WebViewId<'a>) -> Self { self.attrs.id = Some(id); @@ -1992,55 +1984,6 @@ pub struct WebView { } impl WebView { - /// Create a [`WebView`] from from a type that implements [`HasWindowHandle`]. - /// Note that calling this directly loses - /// abilities to initialize scripts, add ipc handler, and many more before starting WebView. To - /// benefit from above features, create a [`WebViewBuilder`] instead. - /// - /// # Platform-specific: - /// - /// - **Linux**: Only X11 is supported, if you want to support Wayland too, use [`WebViewExtUnix::new_gtk`]. - /// - /// Although this methods only needs an X11 window handle, you use webkit2gtk, so you still need to initialize gtk - /// by callling [`gtk::init`] and advance its loop alongside your event loop using [`gtk::main_iteration_do`]. - /// Checkout the [Platform Considerations](https://docs.rs/wry/latest/wry/#platform-considerations) section in the crate root documentation. - /// - **macOS / Windows**: The webview will auto-resize when the passed handle is resized. - /// - **Linux (X11)**: Unlike macOS and Windows, the webview will not auto-resize and you'll need to call [`WebView::set_bounds`] manually. - /// - /// # Panics: - /// - /// - Panics if the provided handle was not supported or invalid. - /// - Panics on Linux, if [`gtk::init`] was not called in this thread. - pub fn new(window: &impl HasWindowHandle, attrs: WebViewAttributes) -> Result { - WebViewBuilder::new_with_attributes(attrs).build(window) - } - - /// Create [`WebViewBuilder`] as a child window inside the provided [`HasWindowHandle`]. - /// - /// ## Platform-specific - /// - /// - **Windows**: This will create the webview as a child window of the `parent` window. - /// - **macOS**: This will create the webview as a `NSView` subview of the `parent` window's - /// content view. - /// - **Linux**: This will create the webview as a child window of the `parent` window. Only X11 - /// is supported. This method won't work on Wayland. - /// - /// Although this methods only needs an X11 window handle, you use webkit2gtk, so you still need to initialize gtk - /// by callling [`gtk::init`] and advance its loop alongside your event loop using [`gtk::main_iteration_do`]. - /// Checkout the [Platform Considerations](https://docs.rs/wry/latest/wry/#platform-considerations) section in the crate root documentation. - /// - /// If you want to support child webviews on X11 and Wayland at the same time, - /// we recommend using [`WebViewBuilderExtUnix::new_gtk`] with [`gtk::Fixed`]. - /// - **Android/iOS:** Unsupported. - /// - /// # Panics: - /// - /// - Panics if the provided handle was not support or invalid. - /// - Panics on Linux, if [`gtk::init`] was not called in this thread. - pub fn new_as_child(parent: &impl HasWindowHandle, attrs: WebViewAttributes) -> Result { - WebViewBuilder::new_with_attributes(attrs).build_as_child(parent) - } - /// Returns the id of this webview. pub fn id(&self) -> WebViewId<'_> { self.webview.id()