Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/remove_webviewattributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
wry: minor
---

Remove `WebViewAttributes`, `WebView::new` and `WebView::new_as_child` from public API. Use `WebViewBuilder` instead.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 5 additions & 62 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<WebViewId<'a>>,

/// 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.
Expand Down Expand Up @@ -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<Rect>,

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Self> {
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<Self> {
WebViewBuilder::new_with_attributes(attrs).build_as_child(parent)
}

/// Returns the id of this webview.
pub fn id(&self) -> WebViewId<'_> {
self.webview.id()
Expand Down
Loading