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:
WebViewDelegate::notify_new_frame_readyis called. The applications triggers a request to repaint the window that contains thisWebView.- During window repainting, the application calls
WebView::paintand the contents of theRenderingContextare updated. - If the
RenderingContextis double-buffered, the application then callscrate::RenderingContext::present()in order to swap the back buffer to the front, finally displaying the updatedWebViewcontents.
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
impl WebView
pub(crate) fn new(builder: WebViewBuilder) -> Self
fn inner(&self) -> Ref<'_, WebViewInner>
fn inner_mut(&self) -> RefMut<'_, WebViewInner>
pub(crate) fn request_create_new( &self, response_sender: GenericSender<Option<NewWebViewDetails>>, )
pub(crate) fn viewport_details(&self) -> ViewportDetails
pub(crate) fn from_weak_handle( inner: &Weak<RefCell<WebViewInner>>, ) -> Option<Self>
pub(crate) fn weak_handle(&self) -> Weak<RefCell<WebViewInner>>
Sourcepub fn delegate(&self) -> Rc<dyn WebViewDelegate>
pub fn delegate(&self) -> Rc<dyn WebViewDelegate>
Get the WebViewDelegate associated with this WebView.
Sourcepub fn clipboard_delegate(&self) -> Rc<dyn ClipboardDelegate>
pub fn clipboard_delegate(&self) -> Rc<dyn ClipboardDelegate>
Get the ClipboardDelegate associated with this WebView.
Sourcepub fn gamepad_delegate(&self) -> Rc<dyn GamepadDelegate>
pub fn gamepad_delegate(&self) -> Rc<dyn GamepadDelegate>
Get the GamepadDelegate associated with this WebView.
Sourcepub fn load_status(&self) -> LoadStatus
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.
pub(crate) fn set_load_status(self, new_value: LoadStatus)
Sourcepub fn url(&self) -> Option<Url>
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.
Sourcepub fn status_text(&self) -> Option<String>
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.
pub(crate) fn set_status_text(self, new_value: Option<String>)
Sourcepub fn page_title(&self) -> Option<String>
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.
pub(crate) fn set_page_title(self, new_value: Option<String>)
Sourcepub fn favicon(&self) -> Option<Ref<'_, Image>>
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.
pub(crate) fn set_favicon(self, new_value: Image)
Sourcepub fn focused(&self) -> bool
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.
pub(crate) fn set_focused(self, new_value: bool)
Sourcepub fn cursor(&self) -> Cursor
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.
pub(crate) fn set_cursor(self, new_value: Cursor)
Sourcepub fn animating(&self) -> bool
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.
pub(crate) fn set_animating(self, new_value: bool)
Sourcepub fn size(&self) -> DeviceSize
pub fn size(&self) -> DeviceSize
The size of this WebView’s RenderingContext.
Sourcepub fn resize(&self, new_size: PhysicalSize<u32>)
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.
Sourcepub fn hidpi_scale_factor(
&self,
) -> Scale<f32, DeviceIndependentPixel, DevicePixel>
pub fn hidpi_scale_factor( &self, ) -> Scale<f32, DeviceIndependentPixel, DevicePixel>
Get the HiDPI scale factor for this WebView.
Sourcepub fn set_hidpi_scale_factor(
&self,
new_scale_factor: Scale<f32, DeviceIndependentPixel, DevicePixel>,
)
pub fn set_hidpi_scale_factor( &self, new_scale_factor: Scale<f32, DeviceIndependentPixel, DevicePixel>, )
Sourcepub fn show(&self)
pub fn show(&self)
Make this WebView visible within its RenderingContext.
Sourcepub fn hide(&self)
pub fn hide(&self)
Hide this WebView within its RenderingContext.
Sourcepub fn notify_theme_change(&self, theme: Theme)
pub fn notify_theme_change(&self, theme: Theme)
Notify this WebView of a change to the system theme (e.g. light or dark mode).
Sourcepub fn load(&self, url: Url)
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.
Sourcepub fn load_request(&self, url_request: UrlRequest)
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.
Sourcepub fn can_go_back(&self) -> bool
pub fn can_go_back(&self) -> bool
Sourcepub fn go_back(&self, amount: usize) -> TraversalId
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.
Sourcepub fn can_go_forward(&self) -> bool
pub fn can_go_forward(&self) -> bool
Sourcepub fn go_forward(&self, amount: usize) -> TraversalId
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.
Sourcepub fn notify_scroll_event(&self, scroll: Scroll, point: WebViewPoint)
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.
Sourcepub fn notify_input_event(&self, event: InputEvent) -> InputEventId
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.
Sourcepub fn notify_media_session_action_event(&self, event: MediaSessionActionType)
pub fn notify_media_session_action_event(&self, event: MediaSessionActionType)
Notify this WebView about a media session event (e.g. play, pause, next track).
Sourcepub fn set_page_zoom(&self, new_zoom: f32)
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]).
Sourcepub fn adjust_pinch_zoom(&self, pinch_zoom_delta: f32, center: DevicePoint)
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.
Sourcepub fn pinch_zoom(&self) -> f32
pub fn pinch_zoom(&self) -> f32
Get the pinch zoom of the WebView.
Sourcepub fn device_pixels_per_css_pixel(&self) -> Scale<f32, CSSPixel, DevicePixel>
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.
Sourcepub fn exit_fullscreen(&self)
pub fn exit_fullscreen(&self)
Tell the currently active page in this WebView to exit fullscreen mode.
Sourcepub fn set_throttled(&self, throttled: bool)
pub fn set_throttled(&self, throttled: bool)
Sourcepub fn toggle_webrender_debugging(&self, debugging: WebRenderDebugOption)
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.
Sourcepub fn capture_webrender(&self)
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.
Sourcepub fn toggle_sampling_profiler(&self, rate: Duration, max_duration: Duration)
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.
Sourcepub fn paint(&self)
pub fn paint(&self)
Paint the contents of this WebView into its RenderingContext.
Sourcepub fn user_content_manager(&self) -> Option<Rc<UserContentManager>>
pub fn user_content_manager(&self) -> Option<Rc<UserContentManager>>
Get the UserContentManager associated with this WebView.
Sourcepub fn evaluate_javascript<T: ToString>(
&self,
script: T,
callback: impl FnOnce(Result<JSValue, JavaScriptEvaluationError>) + 'static,
)
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.
Sourcepub fn take_screenshot(
&self,
rect: Option<WebViewRect>,
callback: impl FnOnce(Result<RgbaImage, ScreenshotCaptureError>) + 'static,
)
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
loadevent. - 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-waitandtest-waitclasses 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.
pub(crate) fn set_history( self, new_back_forward_list: Vec<ServoUrl>, new_index: usize, )
pub(crate) fn show_embedder_control( self, control_id: EmbedderControlId, position: DeviceIntRect, embedder_control_request: EmbedderControlRequest, )
Sourcepub fn accesskit_tree_id(&self) -> Option<TreeId>
pub fn accesskit_tree_id(&self) -> Option<TreeId>
AccessKit subtree id for this WebView, if accessibility is active.
Sourcepub fn set_accessibility_active(&self, active: bool) -> Option<TreeId>
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.
pub(crate) fn notify_document_accessibility_tree_id( &self, grafted_tree_id: TreeId, )
pub(crate) fn process_accessibility_tree_update( &self, tree_update: TreeUpdate, epoch: Epoch, )
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WebView
impl !RefUnwindSafe for WebView
impl !Send for WebView
impl !Sync for WebView
impl Unpin for WebView
impl UnsafeUnpin for WebView
impl !UnwindSafe 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
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