ltk_webkit

Struct WebView

Source
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

Source

pub fn load_uri(&self, uri: &str)

Start loading uri in this view.

Source

pub fn load_html(&self, html: &str, base_uri: Option<&str>)

Replace the page with html. base_uri resolves relative links.

Source

pub fn go_back(&self)

Source

pub fn go_forward(&self)

Source

pub fn reload(&self)

Source

pub fn stop(&self)

Source

pub fn can_go_back(&self) -> bool

Source

pub fn can_go_forward(&self) -> bool

Source

pub fn uri(&self) -> String

URI of the current page; empty before the first load commits.

Source

pub fn title(&self) -> String

Title of the current page; empty when the page declares none.

Source

pub fn is_loading(&self) -> bool

Source

pub fn load_progress(&self) -> f64

Load progress of the current page in [0.0, 1.0].

Source

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.

Source

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.

Source

pub fn zoom(&self) -> f64

Source

pub fn set_zoom(&self, level: f64)

Source

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.

Source

pub fn find(&self, text: &str)

Highlight every case-insensitive match of text, wrapping around. An empty text clears the search.

Source

pub fn find_next(&self)

Source

pub fn find_previous(&self)

Source

pub fn find_finish(&self)

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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

pub fn paste_at(&self, x: f64, y: f64, text: &str)

Insert text into the editable at ( x, y ), in host pixels, as the middle button pastes.

Source§

impl WebView

Source

pub fn request_context_menu(&self, x: f64, y: f64)

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.

Source

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

Source

pub fn favicon(&self) -> Option<ImageData>

The icon found by the last WebView::request_favicon that finished.

Source

pub fn request_favicon(&self)

Look for the current page’s icon. The previous one stays until the answer arrives.

Source§

impl WebView

Source

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

Source

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.

Source

pub fn exit_fullscreen(&self)

Tell the page that the host left fullscreen, so its element goes back to its place.

Source§

impl WebView

The address of the link the pointer is over, as of its last motion over the page.

Source§

impl WebView

Source

pub fn editable_focused(&self) -> bool

Whether an editable element of the page holds the focus.

Source

pub fn commit_text(&self, text: &str)

Insert text committed by the host’s input method at the page’s cursor.

Source

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

Source

pub fn set_navigation_handler( &self, handler: impl FnMut(&Navigation) -> bool + 'static, )

Ask handler before every main-frame navigation starts; returning false cancels it. It runs inside WebView::tick, on the main thread.

Source

pub fn take_load_events(&self) -> Vec<LoadEvent>

Load events since the previous call, in order.

Source§

impl WebView

Source

pub fn take_created_views(&self) -> Vec<WebView>

Views the page opened with window.open(), related to this one, for the host to show.

Source

pub fn take_close_request(&self) -> bool

Whether the page called window.close() since the previous call.

Source§

impl WebView

Source

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.

Source

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.

Source

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

Source

pub fn set_javascript_enabled(&self, enabled: bool)

Source

pub fn javascript_enabled(&self) -> bool

Source

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

Source

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

Source

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.

Source

pub fn take_termination(&self) -> Option<Termination>

Why the web process went away, once, if it did since the previous call.

Source§

impl WebView

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn pointer_release(&self, x: f64, y: f64)

Forward a left-button release to the embedded view.

Source

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.

Source

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.

Source

pub fn touch_move(&self, id: u32, x: f64, y: f64)

Source

pub fn touch_up(&self, id: u32, x: f64, y: f64)

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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].

Source

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§

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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, 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.
§

impl<T> Upcast<T> for T

§

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

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

§

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

§

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