pub struct WebView { /* private fields */ }Expand description
A WebKit-rendered view that can be embedded into an LTK widget tree
via WebView::element.
Implementations§
Source§impl WebView
impl WebView
Sourcepub fn load_html(&self, html: &str, base_uri: Option<&str>)
pub fn load_html(&self, html: &str, base_uri: Option<&str>)
Replace the page with html. base_uri resolves relative links.
pub fn go_back(&self)
pub fn go_forward(&self)
pub fn reload(&self)
pub fn stop(&self)
pub fn can_go_back(&self) -> bool
pub fn can_go_forward(&self) -> bool
pub fn is_loading(&self) -> bool
Sourcepub fn load_progress(&self) -> f64
pub fn load_progress(&self) -> f64
Load progress of the current page in [0.0, 1.0].
Sourcepub fn session_state(&self) -> Option<Vec<u8>>
pub fn session_state(&self) -> Option<Vec<u8>>
The view’s session history — back / forward list, scroll positions,
form data — as opaque bytes for Self::restore_session_state. A
host persists them so back keeps working after a relaunch. The
format belongs to WebKit and may change between its versions.
Sourcepub fn restore_session_state(&self, saved: &[u8]) -> bool
pub fn restore_session_state(&self, saved: &[u8]) -> bool
Replace the session history with one saved by Self::session_state
and load its current entry. Returns false when WebKit does not
recognise the bytes or the saved list is empty; the host then loads
a URL instead. Meant for a view that has not loaded anything yet:
see WebView::new with an empty URL.
pub fn zoom(&self) -> f64
pub fn set_zoom(&self, level: f64)
Sourcepub fn set_user_agent(&self, user_agent: &str)
pub fn set_user_agent(&self, user_agent: &str)
What the view sends as User-Agent from the next load on. Empty restores WebKit’s default.
Sourcepub fn find(&self, text: &str)
pub fn find(&self, text: &str)
Highlight every case-insensitive match of text, wrapping around.
An empty text clears the search.
pub fn find_next(&self)
pub fn find_previous(&self)
pub fn find_finish(&self)
Sourcepub fn set_visible(&self, visible: bool)
pub fn set_visible(&self, visible: bool)
Show or hide the page. A hidden page stops producing frames and has its timers throttled by WebKit, which is what a background tab wants.
Sourcepub fn set_dark_mode(&self, dark: bool)
pub fn set_dark_mode(&self, dark: bool)
What pages see in prefers-color-scheme. WPE takes it from the
platform settings of the view’s display, not from WebKitSettings.
Sourcepub fn set_scale(&self, scale: f64)
pub fn set_scale(&self, scale: f64)
Set the device scale factor: physical pixels of the host surface per
CSS pixel. Pass the value of App::on_scale_changed so a HiDPI panel
lays pages out at their logical width instead of the physical one.
Sourcepub fn contains(&self, x: f32, y: f32) -> bool
pub fn contains(&self, x: f32, y: f32) -> bool
Whether (x, y), in physical pixels of the host surface, falls inside
the rect the view was last laid out at.
Sourcepub fn take_new_window_requests(&self) -> Vec<String>
pub fn take_new_window_requests(&self) -> Vec<String>
URIs the page asked to open in a new window since the previous call
(target="_blank" links). The navigation itself is cancelled; the
host decides where to load them — typically a new tab.
Source§impl WebView
impl WebView
Sourcepub fn take_copied_text(&self) -> Option<String>
pub fn take_copied_text(&self) -> Option<String>
Text the page put in its clipboard, by Copy, Cut or a script, since the previous call: for the host to make it the system’s.
Sourcepub fn set_clipboard_text(&self, text: &str)
pub fn set_clipboard_text(&self, text: &str)
What the page pastes next, which the host takes from the system’s clipboard before it passes Ctrl+V on.
Sourcepub fn selected_text(&self, done: impl FnOnce(String) + 'static)
pub fn selected_text(&self, done: impl FnOnce(String) + 'static)
The text selected in the page, in a text field too, for the primary selection; empty with none.
Source§impl WebView
impl WebView
Ask what is at (x, y) with a secondary click there; the page sees it as one, and the answer comes through WebView::take_page_target.
Sourcepub fn take_page_target(&self) -> Option<PageTarget>
pub fn take_page_target(&self) -> Option<PageTarget>
The target of the last secondary press, once. None as well when the page handled the press itself.
Source§impl WebView
impl WebView
Sourcepub fn favicon(&self) -> Option<ImageData>
pub fn favicon(&self) -> Option<ImageData>
The icon found by the last WebView::request_favicon that finished.
Sourcepub fn request_favicon(&self)
pub fn request_favicon(&self)
Look for the current page’s icon. The previous one stays until the answer arrives.
Source§impl WebView
impl WebView
Sourcepub fn take_file_request(&self) -> Option<FileRequest>
pub fn take_file_request(&self) -> Option<FileRequest>
The page’s pending request for files, if it made one since the previous call.
Source§impl WebView
impl WebView
Sourcepub fn take_fullscreen_request(&self) -> Option<bool>
pub fn take_fullscreen_request(&self) -> Option<bool>
The fullscreen state the page asked for since the previous call: true to enter, false to leave.
Sourcepub fn exit_fullscreen(&self)
pub fn exit_fullscreen(&self)
Tell the page that the host left fullscreen, so its element goes back to its place.
Source§impl WebView
impl WebView
Sourcepub fn hovered_link(&self) -> Option<String>
pub fn hovered_link(&self) -> Option<String>
The address of the link the pointer is over, as of its last motion over the page.
Source§impl WebView
impl WebView
Sourcepub fn editable_focused(&self) -> bool
pub fn editable_focused(&self) -> bool
Whether an editable element of the page holds the focus.
Sourcepub fn commit_text(&self, text: &str)
pub fn commit_text(&self, text: &str)
Insert text committed by the host’s input method at the page’s cursor.
Sourcepub fn delete_surrounding_text(&self, before: u32, after: u32)
pub fn delete_surrounding_text(&self, before: u32, after: u32)
Delete before characters before the page’s cursor and after after it.
Source§impl WebView
impl WebView
Ask handler before every main-frame navigation starts; returning false cancels it. It runs inside WebView::tick, on the main thread.
Sourcepub fn take_load_events(&self) -> Vec<LoadEvent>
pub fn take_load_events(&self) -> Vec<LoadEvent>
Load events since the previous call, in order.
Source§impl WebView
impl WebView
Sourcepub fn take_created_views(&self) -> Vec<WebView>
pub fn take_created_views(&self) -> Vec<WebView>
Views the page opened with window.open(), related to this one, for the host to show.
Sourcepub fn take_close_request(&self) -> bool
pub fn take_close_request(&self) -> bool
Whether the page called window.close() since the previous call.
Source§impl WebView
impl WebView
Sourcepub fn print_to_pdf(
&self,
settings: &PrintSettings,
done: impl FnOnce(Result<Vec<u8>, PrintError>) + 'static,
)
pub fn print_to_pdf( &self, settings: &PrintSettings, done: impl FnOnce(Result<Vec<u8>, PrintError>) + 'static, )
The page laid out for print as a whole PDF in memory; done gets it from a later WebView::tick, unless the view is dropped first. One print at a time per view, else PrintError::Busy. The view must be visible: a hidden page runs no frames to lay itself out in.
Sourcepub fn print_preview(
&self,
settings: &PrintSettings,
width: u32,
done: impl FnOnce(Result<Preview, PrintError>) + 'static,
)
pub fn print_preview( &self, settings: &PrintSettings, width: u32, done: impl FnOnce(Result<Preview, PrintError>) + 'static, )
The pages settings choose as they would be printed, each sheet width pixels wide with its margins, and how many pages the document has; as WebView::print_to_pdf otherwise, which it is busy with as well.
Sourcepub fn take_print_request(&self) -> bool
pub fn take_print_request(&self) -> bool
The page called window.print() since the previous call; no dialog of the engine’s opens, the host shows its own.
Source§impl WebView
impl WebView
pub fn set_javascript_enabled(&self, enabled: bool)
pub fn javascript_enabled(&self) -> bool
Sourcepub fn evaluate_javascript(
&self,
script: &str,
done: impl FnOnce(Result<String, String>) + 'static,
)
pub fn evaluate_javascript( &self, script: &str, done: impl FnOnce(Result<String, String>) + 'static, )
Run script in the page’s main world. done gets the result as JSON (null for undefined) or the error message, from a later WebView::tick.
Source§impl WebView
impl WebView
Sourcepub fn snapshot_document(
&self,
done: impl FnOnce(Result<Snapshot, String>) + 'static,
)
pub fn snapshot_document( &self, done: impl FnOnce(Result<Snapshot, String>) + 'static, )
The whole document, what is scrolled out of view included; done gets it from a later WebView::tick.
Source§impl WebView
impl WebView
Sourcepub fn terminate_web_process(&self)
pub fn terminate_web_process(&self)
Kill the page’s web process, freeing its memory at once. Views related to this one share the process and lose it too.
Sourcepub fn take_termination(&self) -> Option<Termination>
pub fn take_termination(&self) -> Option<Termination>
Why the web process went away, once, if it did since the previous call.
Source§impl WebView
impl WebView
Sourcepub fn new(width: f32, height: f32, url: &str) -> Result<Self, String>
pub fn new(width: f32, height: f32, url: &str) -> Result<Self, String>
Create a new WebView, connect it to the user’s Wayland session,
and start loading url. The view does not render until tick
is pumped from the host application’s event loop. An empty url
loads nothing, for a view about to receive
restore_session_state.
Sourcepub fn resize(&self, width: f32, height: f32)
pub fn resize(&self, width: f32, height: f32)
Resize the embedded view. Updates both the reserved space the
LTK [External] widget claims and the WPEView buffer
dimensions, so click coordinates keep mapping 1:1 and WebKit
re-renders to the new size.
Sourcepub fn tick(&self)
pub fn tick(&self)
Drive WPE’s GMainLoop forward by one non-blocking iteration. Call
this from the host application’s per-frame poll (LTK’s
App::poll_external is the obvious place), or when
wake_on_events wakes it, whose watch it re-arms.
Sourcepub fn pointer_press(&self, x: f64, y: f64)
pub fn pointer_press(&self, x: f64, y: f64)
Forward a left-button press to the embedded view at WPEView
pixel coordinates (x, y). Pair with Self::pointer_release
for a click; intermediate Self::pointer_move calls between
the two construct a drag (which WebKit interprets as text
selection over selectable content).
Sourcepub fn pointer_release(&self, x: f64, y: f64)
pub fn pointer_release(&self, x: f64, y: f64)
Forward a left-button release to the embedded view.
Sourcepub fn click_at(&self, x: f64, y: f64)
pub fn click_at(&self, x: f64, y: f64)
Convenience: synthesise a complete press + release click at
(x, y). Useful for tests / scripted interactions; real user
clicks should go through Self::pointer_press /
Self::pointer_release so drags work.
Sourcepub fn touch_down(&self, id: u32, x: f64, y: f64)
pub fn touch_down(&self, id: u32, x: f64, y: f64)
Forward a touchscreen finger-down to the embedded view. The
touch stream (touch_down / touch_move / touch_up per
finger id) feeds WebKit’s own gesture recognition: tap becomes
click, drag becomes kinetic scroll, two fingers pinch-zoom —
none of which the mouse-event path can express.
Sourcepub fn touch_move(&self, id: u32, x: f64, y: f64)
pub fn touch_move(&self, id: u32, x: f64, y: f64)
See Self::touch_down.
Sourcepub fn touch_cancel(&self, id: u32, x: f64, y: f64)
pub fn touch_cancel(&self, id: u32, x: f64, y: f64)
End a finger’s sequence without a release: the page gets no tap out of it.
Sourcepub fn scroll(&self, x: f64, y: f64, dx: f64, dy: f64)
pub fn scroll(&self, x: f64, y: f64, dx: f64, dy: f64)
Forward a wheel / touchpad scroll event to the embedded view.
x, y are in WPEView pixel coordinates (same as the host
pointer), dx/dy are scroll deltas in pixels (positive =
down/right, matching WPE convention).
Sourcepub fn pointer_move(&self, x: f64, y: f64)
pub fn pointer_move(&self, x: f64, y: f64)
Forward a pointer-move event to the embedded view at WPEView
pixel coordinates (x, y). WebKit needs this to update hover
state, fire mouseenter / mouseleave, and decide which
cursor it wants — without it the cursor query through
Self::cursor_shape stays at Default.
Sourcepub fn send_key(
&self,
keysym: u32,
keycode: u32,
pressed: bool,
ctrl: bool,
shift: bool,
)
pub fn send_key( &self, keysym: u32, keycode: u32, pressed: bool, ctrl: bool, shift: bool, )
Forward a keyboard event to the embedded view. keysym is the
xkbcommon keysym (the symbol the user effectively pressed,
after xkb layout translation); keycode is the raw hardware
scancode the compositor delivered. pressed selects DOWN vs
UP; ctrl and shift populate the WPEModifiers bitfield.
Sourcepub fn take_redraw_request(&self) -> bool
pub fn take_redraw_request(&self) -> bool
Returns true once for every new buffer WebKit has produced
since the previous call. The host’s invalidate_after should
return InvalidationScope::All whenever this is true so LTK
redraws and the new frame becomes visible — keeping the
surface from getting stuck on a stale (sometimes black) frame
when the compositor’s frame-callback chain pauses during a
resize. Idle ticks return false, so static pages cost zero
redraws.
Sourcepub fn cursor_shape(&self) -> CursorShape
pub fn cursor_shape(&self) -> CursorShape
The cursor shape WebKit currently wants for the embedded view.
Mirrors the most recent mouse-target-changed signal payload.
The host application surfaces this through
[ltk::App::cursor_override].
Sourcepub fn element<Msg: Clone + 'static>(&self) -> Element<Msg>
pub fn element<Msg: Clone + 'static>(&self) -> Element<Msg>
Build an LTK [Element] that composites this WebView’s pixels
into the parent widget tree. Uses the dimensions most recently
passed to Self::resize (or the constructor) as the
preferred size; the actual laid-out rect is captured by the
draw closure on every frame and used to drive auto-resize +
input coordinate translation.
Auto Trait Implementations§
impl Freeze for WebView
impl RefUnwindSafe for WebView
impl Send for WebView
impl Sync for WebView
impl Unpin 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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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