pub struct WebView { /* private fields */ }Expand description
A webview based on wry WebView.
With the gpui-fast feature, macOS and Linux host the native view in a window
composition surface, so deferred GPUI overlays render above the page. Without it, the
native view covers GPUI content in its bounds and extends past a container that clips it.
[experimental]
Implementations§
Source§impl WebView
impl WebView
Sourcepub fn new(webview: WebView, window: &mut Window, cx: &mut App) -> Self
pub fn new(webview: WebView, window: &mut Window, cx: &mut App) -> Self
Create a new WebView from a wry WebView.
Sourcepub fn build(
builder: WebViewBuilder<'_>,
window: &mut Window,
cx: &mut App,
) -> Result<Self>
pub fn build( builder: WebViewBuilder<'_>, window: &mut Window, cx: &mut App, ) -> Result<Self>
Build a webview as a child of window, performing the platform setup Wry requires.
On Linux the window must run on X11 or XWayland: start the application with
gpui_kit::platform::linux(WindowingModes::X11). A Wayland window returns an error.
This also initializes GTK and drives its main loop from GPUI. With the gpui-fast feature,
the webview is built in a window composition surface so GPUI overlays can render above it.
Sourcepub fn set_bounds(&self, bounds: Rect) -> Result<()>
pub fn set_bounds(&self, bounds: Rect) -> Result<()>
Set window-relative bounds, including offscreen loading bounds. With window composition, position the managed container and its child together.
Sourcepub fn set_geometry(
&self,
document: Bounds<Pixels>,
clip: Bounds<Pixels>,
) -> Result<()>
pub fn set_geometry( &self, document: Bounds<Pixels>, clip: Bounds<Pixels>, ) -> Result<()>
Apply full document bounds and an inherited clip without changing the DOM viewport. Empty clips hide the native surface while preserving the loaded document. Partial clipping requires native window composition; without it, the native view takes the full document bounds and extends past the clip.
Sourcepub fn set_visible(&self, visible: bool) -> Result<()>
pub fn set_visible(&self, visible: bool) -> Result<()>
Set visibility and report native errors without discarding the loaded page.
Sourcepub fn set_theme(&self, theme: Theme) -> Result<()>
pub fn set_theme(&self, theme: Theme) -> Result<()>
Set the colour scheme the page sees in prefers-color-scheme and draws its
native controls in. Theme::Auto follows the system again.
On Linux this is GTK’s process-wide gtk-application-prefer-dark-theme, so it
applies to every webview in the application.
Sourcepub fn set_zoom(&self, zoom: f64) -> Result<()>
pub fn set_zoom(&self, zoom: f64) -> Result<()>
Zoom the page, where 1.0 is its natural size. The engine scales the page
itself, without the relayout and repaint a CSS zoom causes, and keeps the
factor across navigations.
Sourcepub fn zoom(&self) -> f64
pub fn zoom(&self) -> f64
The page zoom last set with WebView::set_zoom.
Sourcepub fn handle(&self) -> WebViewHandle
pub fn handle(&self) -> WebViewHandle
Get an owned, UI-thread-local handle to the raw wry webview.
Methods from Deref<Target = WebView>§
Sourcepub fn evaluate_script_with_callback(
&self,
js: &str,
callback: impl Fn(String) + Send + 'static,
) -> Result<(), Error>
pub fn evaluate_script_with_callback( &self, js: &str, callback: impl Fn(String) + Send + 'static, ) -> Result<(), Error>
Evaluate and run javascript code with callback function. The evaluation result will be serialized into a JSON string and passed to the callback function.
Exception is ignored because of the limitation on windows. You can catch it yourself and return as string as a workaround.
- ** Android:** Not implemented yet.
Get a list of cookies for specific url.
Sourcepub fn open_devtools(&self)
pub fn open_devtools(&self)
Open the web inspector which is usually called dev tool.
§Platform-specific
- Android / iOS: Not supported.
Sourcepub fn close_devtools(&self)
pub fn close_devtools(&self)
Close the web inspector which is usually called dev tool.
§Platform-specific
- Windows / Android / iOS: Not supported.
Sourcepub fn is_devtools_open(&self) -> bool
pub fn is_devtools_open(&self) -> bool
Gets the devtool window’s current visibility state.
§Platform-specific
- Windows / Android / iOS: Not supported.
Sourcepub fn zoom(&self, scale_factor: f64) -> Result<(), Error>
pub fn zoom(&self, scale_factor: f64) -> Result<(), Error>
Set the webview zoom level
§Platform-specific:
- Android: Not supported.
- macOS: available on macOS 11+ only.
- iOS: available on iOS 14+ only.
Sourcepub fn set_background_color(
&self,
background_color: (u8, u8, u8, u8),
) -> Result<(), Error>
pub fn set_background_color( &self, background_color: (u8, u8, u8, u8), ) -> Result<(), Error>
Specify the webview background color.
The color uses the RGBA format.
§Platfrom-specific:
- macOS: Not implemented.
- Windows:
- On Windows 7, transparency is not supported and the alpha value will be ignored.
- On Windows higher than 7: translucent colors are not supported so any alpha value other than
0will be replaced by255
Sourcepub fn load_url_with_headers(
&self,
url: &str,
headers: HeaderMap,
) -> Result<(), Error>
pub fn load_url_with_headers( &self, url: &str, headers: HeaderMap, ) -> Result<(), Error>
Navigate to the specified url using the specified headers
Sourcepub fn clear_all_browsing_data(&self) -> Result<(), Error>
pub fn clear_all_browsing_data(&self) -> Result<(), Error>
Clear all browsing data
pub fn bounds(&self) -> Result<Rect, Error>
Sourcepub fn set_bounds(&self, bounds: Rect) -> Result<(), Error>
pub fn set_bounds(&self, bounds: Rect) -> Result<(), Error>
Set the webview bounds.
This is only effective if the webview was created as a child
or created using [WebViewBuilderExtUnix::new_gtk] with gtk::Fixed.
Trait Implementations§
impl EventEmitter<DismissEvent> for WebView
Source§impl Focusable for WebView
impl Focusable for WebView
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
Auto Trait Implementations§
impl !Freeze for WebView
impl !RefUnwindSafe for WebView
impl !Send for WebView
impl !Sync for WebView
impl !UnwindSafe for WebView
impl Unpin for WebView
impl UnsafeUnpin for WebView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more