Skip to main content

WebView

Struct WebView 

Source
pub struct WebView(Rc<RefCell<WebViewInner>>);
Expand description

A handle to a Servo webview. If you clone this handle, it does not create a new webview, but instead creates a new handle to the webview. Once the last handle is dropped, Servo considers that the webview has closed and will clean up all associated resources related to this webview.

§Creating a WebView

To create a WebView, use WebViewBuilder.

§Rendering Model

Every WebView has a RenderingContext. The embedder manages when the contents of the WebView paint to the RenderingContext. When a WebView needs to be painted, for instance, because its contents have changed, Servo will call WebViewDelegate::notify_new_frame_ready in order to signal that it is time to repaint the WebView using WebView::paint.

An example of how this flow might work is:

  1. WebViewDelegate::notify_new_frame_ready is called. The applications triggers a request to repaint the window that contains this WebView.
  2. During window repainting, the application calls WebView::paint and the contents of the RenderingContext are updated.
  3. If the RenderingContext is double-buffered, the application then calls crate::RenderingContext::present() in order to swap the back buffer to the front, finally displaying the updated WebView contents.

In cases where the WebView contents have not been updated, but a repaint is necessary, for instance when repainting a window due to damage, an application may simply perform the final two steps and Servo will repaint even without first calling the WebViewDelegate::notify_new_frame_ready method.

Tuple Fields§

§0: Rc<RefCell<WebViewInner>>

Implementations§

Source§

impl WebView

Source

pub(crate) fn new(builder: WebViewBuilder) -> Self

Source

fn inner(&self) -> Ref<'_, WebViewInner>

Source

fn inner_mut(&self) -> RefMut<'_, WebViewInner>

Source

pub(crate) fn request_create_new( &self, response_sender: GenericSender<Option<NewWebViewDetails>>, )

Source

pub(crate) fn viewport_details(&self) -> ViewportDetails

Source

pub(crate) fn from_weak_handle( inner: &Weak<RefCell<WebViewInner>>, ) -> Option<Self>

Source

pub(crate) fn weak_handle(&self) -> Weak<RefCell<WebViewInner>>

Source

pub fn delegate(&self) -> Rc<dyn WebViewDelegate>

Get the WebViewDelegate associated with this WebView.

Source

pub fn clipboard_delegate(&self) -> Rc<dyn ClipboardDelegate>

Get the ClipboardDelegate associated with this WebView.

Source

pub fn gamepad_delegate(&self) -> Rc<dyn GamepadDelegate>

Get the GamepadDelegate associated with this WebView.

Source

pub fn id(&self) -> WebViewId

Get the unique identifier for this WebView.

Source

pub fn load_status(&self) -> LoadStatus

Get the load status for the page that is currently loading or loaded in this WebView.

The embedder can use WebViewDelegate::notify_load_status_changed to subscribe to changes in the load status.

Source

pub(crate) fn set_load_status(self, new_value: LoadStatus)

Source

pub fn url(&self) -> Option<Url>

Get the URL of the currently active page in this WebView’s navigation history. Returns None if no page is currently loaded.

Source

pub fn status_text(&self) -> Option<String>

Get the current status text for this WebView. Returns None if there is no status text.

The status text changes as the user interacts with the page, for example, by hovering over a link. The embedder can use WebViewDelegate::notify_status_text_changed to subscribe to changes in the status text.

Source

pub(crate) fn set_status_text(self, new_value: Option<String>)

Source

pub fn page_title(&self) -> Option<String>

Get the title of the currently active page in this WebView. Returns None if the page has no title.

The embedder can use WebViewDelegate::notify_page_title_changed to subscribe to changes in the WebView’s page title.

Source

pub(crate) fn set_page_title(self, new_value: Option<String>)

Source

pub fn favicon(&self) -> Option<Ref<'_, Image>>

Get a read-only reference to the image data for the favicon of the currently active page in this WebView. Returns None if no favicon is available for the currently active page.

The embedder can use WebViewDelegate::notify_favicon_changed to subscribe to changes in the WebView’s favicon.

Source

pub(crate) fn set_favicon(self, new_value: Image)

Source

pub fn focused(&self) -> bool

Whether or not this WebView currently has the keyboard focus.

The embedder can use WebViewDelegate::notify_focus_changed to subscribe to changes in the WebView’s focus state.

Source

pub(crate) fn set_focused(self, new_value: bool)

Source

pub fn cursor(&self) -> Cursor

Get the current Cursor for this WebView.

The cursor can change as the user interacts with page content. The embedder can use WebViewDelegate::notify_cursor_changed to subscribe to changes in the WebView’s cursor.

Source

pub(crate) fn set_cursor(self, new_value: Cursor)

Source

pub fn focus(&self)

Notify Servo that this WebView has gained keyboard focus.

Source

pub fn blur(&self)

Notify Servo that this WebView has lost keyboard focus.

Source

pub fn animating(&self) -> bool

Whether or not this WebView has animating content, such as a CSS animation or transition or is running requestAnimationFrame callbacks. This indicates that the embedding application should be spinning the Servo event loop on regular intervals in order to trigger animation updates.

Source

pub(crate) fn set_animating(self, new_value: bool)

Source

pub fn size(&self) -> DeviceSize

The size of this WebView’s RenderingContext.

Source

pub fn resize(&self, new_size: PhysicalSize<u32>)

Request that the given WebView’s RenderingContext be resized. Note that the minimum size for a WebView is 1 pixel by 1 pixel so any requested size will be clamped by that value.

This will also resize any other WebView using the same RenderingContext. A WebView is always as big as its RenderingContext.

Source

pub fn hidpi_scale_factor( &self, ) -> Scale<f32, DeviceIndependentPixel, DevicePixel>

Get the HiDPI scale factor for this WebView.

Source

pub fn set_hidpi_scale_factor( &self, new_scale_factor: Scale<f32, DeviceIndependentPixel, DevicePixel>, )

Set the HiDPI scale factor for this WebView.

This scale factor determines how device-independent pixels map to physical device pixels and therefore depends on which device this WebView is being displayed.

Source

pub fn show(&self)

Make this WebView visible within its RenderingContext.

Source

pub fn hide(&self)

Hide this WebView within its RenderingContext.

Source

pub fn notify_theme_change(&self, theme: Theme)

Notify this WebView of a change to the system theme (e.g. light or dark mode).

Source

pub fn load(&self, url: Url)

Load the given URL into this WebView using the default request headers.

This pushes a new entry onto the navigation history, so the user can navigate back to the previous page.

Source

pub fn load_request(&self, url_request: UrlRequest)

Load a UrlRequest with custom headers into this WebView.

This pushes a new entry onto the navigation history, so the user can navigate back to the previous page.

Source

pub fn reload(&self)

Reload the currently loaded page in this WebView.

Source

pub fn can_go_back(&self) -> bool

Whether or not this WebView can go backward in its navigation history.

This is false if the currently active page is the oldest entry in the WebView’s navigation history.

Source

pub fn go_back(&self, amount: usize) -> TraversalId

Go backward in this WebView’s navigation history by the given number of steps.

Returns a TraversalId that can be used with the WebViewDelegate::notify_traversal_complete callback to determine when the traversal is complete.

Source

pub fn can_go_forward(&self) -> bool

Whether or not this WebView can go forward in its navigation history.

This is false if the currently active page is the most recent entry in the WebView’s navigation history.

Source

pub fn go_forward(&self, amount: usize) -> TraversalId

Go forward in this WebView’s navigation history by the given number of steps.

Returns a TraversalId that can be used with the WebViewDelegate::notify_traversal_complete callback to determine when the traversal is complete.

Source

pub fn notify_scroll_event(&self, scroll: Scroll, point: WebViewPoint)

Ask the WebView to scroll the scrollable area under point to the given scroll destination.

Source

pub fn notify_input_event(&self, event: InputEvent) -> InputEventId

Notify this WebView about an InputEvent such as a mouse click, touch event, or key press.

Returns an InputEventId that can be used with the WebViewDelegate::notify_input_event_handled callback to determine the result of processing of the event by the page content.

Source

pub fn notify_media_session_action_event(&self, event: MediaSessionActionType)

Notify this WebView about a media session event (e.g. play, pause, next track).

Source

pub fn set_page_zoom(&self, new_zoom: f32)

Set the page zoom of the WebView. This sets the final page zoom value of the WebView. Unlike WebView::pinch_zoom it is not multiplied by the current page zoom value, but overrides it.

WebViews have two types of zoom, pinch zoom and page zoom. This adjusts page zoom, which will adjust the devicePixelRatio of the page and cause it to modify its layout.

These values will be clamped internally to the inclusive range [0.1, 10.0]).

Source

pub fn page_zoom(&self) -> f32

Get the page zoom of the WebView.

Source

pub fn adjust_pinch_zoom(&self, pinch_zoom_delta: f32, center: DevicePoint)

Adjust the pinch zoom on this WebView multiplying the current pinch zoom level with the provided pinch_zoom_delta.

WebViews have two types of zoom, pinch zoom and page zoom. This adjusts pinch zoom, which is a type of zoom which does not modify layout, and instead simply magnifies the view in the viewport.

The final pinch zoom values will be clamped to defaults (the inclusive range [1.0, 10.0]). The values used for clamping can be adjusted by page content when <meta viewport> parsing is enabled via Prefs::viewport_meta_enabled, exclusively on mobile devices.

Source

pub fn pinch_zoom(&self) -> f32

Get the pinch zoom of the WebView.

Source

pub fn device_pixels_per_css_pixel(&self) -> Scale<f32, CSSPixel, DevicePixel>

Get the ratio of physical device pixels to CSS pixels for this WebView.

The returned scale factor takes into account page zoom, pinch zoom and the HiDPI scaling factor.

Source

pub fn exit_fullscreen(&self)

Tell the currently active page in this WebView to exit fullscreen mode.

Source

pub fn set_throttled(&self, throttled: bool)

Set whether resource usage of this WebView should be throttled or not.

A throttled WebView attempts to use less system resources by stopping animations and running timers at a heavily limited rate.

Source

pub fn toggle_webrender_debugging(&self, debugging: WebRenderDebugOption)

Toggle the given WebRenderDebugOption from its current state.

Note that this method toggles the debugging options globally i.e., it affects all WebViews managed by Servo and not just the WebView on which this method is invoked.

Source

pub fn capture_webrender(&self)

Capture the current WebRender state for this WebView for debugging.

Note that the captured state includes information about all WebViews that share this WebView’s RenderingContext.

Source

pub fn toggle_sampling_profiler(&self, rate: Duration, max_duration: Duration)

Enable the sampling profiler for debugging performance issues.

The rate determines how often samples are taken and max_duration is the maximum period for which sampling is enabled.

Note that the profiler is enabled globally i.e., for all WebViews managed by Servo rather than just the WebView on which this method is invoked.

Source

pub fn paint(&self)

Paint the contents of this WebView into its RenderingContext.

Source

pub fn user_content_manager(&self) -> Option<Rc<UserContentManager>>

Get the UserContentManager associated with this WebView.

Source

pub fn evaluate_javascript<T: ToString>( &self, script: T, callback: impl FnOnce(Result<JSValue, JavaScriptEvaluationError>) + 'static, )

Evaluate the specified string of JavaScript code. Once execution is complete or an error occurs, Servo will call callback.

Source

pub fn take_screenshot( &self, rect: Option<WebViewRect>, callback: impl FnOnce(Result<RgbaImage, ScreenshotCaptureError>) + 'static, )

Asynchronously take a screenshot of the WebView contents, given a rect or the whole viewport, if no rect is given.

This method will wait until the WebView is ready before the screenshot is taken. This includes waiting for:

  • all frames to fire their load event.
  • all render blocking elements, such as stylesheets included via the <link> element, to stop blocking the rendering.
  • all images to be loaded and displayed.
  • all web fonts are loaded.
  • the reftest-wait and test-wait classes have been removed from the root element.
  • the rendering is up-to-date

Once all these conditions are met and the rendering does not have any pending frames to render, the provided callback will be called with the results of the screenshot operation.

Source

pub(crate) fn set_history( self, new_back_forward_list: Vec<ServoUrl>, new_index: usize, )

Source

pub(crate) fn show_embedder_control( self, control_id: EmbedderControlId, position: DeviceIntRect, embedder_control_request: EmbedderControlRequest, )

Source

pub fn accesskit_tree_id(&self) -> Option<TreeId>

AccessKit subtree id for this WebView, if accessibility is active.

Source

pub fn set_accessibility_active(&self, active: bool) -> Option<TreeId>

Activate or deactivate accessibility features for this WebView, returning the AccessKit subtree id if accessibility is now active.

After accessibility is activated, you must graft (with set_tree_id()) the returned TreeId into your application’s main AccessKit tree as soon as possible, before sending any tree updates from the webview to your AccessKit adapter. Otherwise you may violate AccessKit’s subtree invariants and panic.

If your impl for WebViewDelegate::notify_accessibility_tree_update() can’t create the graft node (and send that update to AccessKit) before sending any updates from this webview to AccessKit, then it must queue those updates until it can guarantee that.

Source

pub(crate) fn notify_document_accessibility_tree_id( &self, grafted_tree_id: TreeId, )

Source

pub(crate) fn process_accessibility_tree_update( &self, tree_update: TreeUpdate, epoch: Epoch, )

Trait Implementations§

Source§

impl Clone for WebView

Source§

fn clone(&self) -> WebView

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Hash for WebView

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for WebView

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,