pub trait Engine {
Show 33 methods
// Required methods
fn update(&mut self);
fn render(&mut self, size: Size<u32>);
fn request_render(&mut self, id: ViewId, size: Size<u32>);
fn new_view(&mut self, size: Size<u32>, content: Option<PageType>) -> ViewId;
fn remove_view(&mut self, id: ViewId);
fn focus(&mut self);
fn unfocus(&self);
fn resize(&mut self, size: Size<u32>);
fn handle_keyboard_event(&mut self, id: ViewId, event: Event);
fn handle_mouse_event(&mut self, id: ViewId, point: Point, event: Event);
fn scroll(&mut self, id: ViewId, delta: ScrollDelta);
fn goto(&mut self, id: ViewId, page_type: PageType);
fn refresh(&mut self, id: ViewId);
fn go_forward(&mut self, id: ViewId);
fn go_back(&mut self, id: ViewId);
fn get_url(&self, id: ViewId) -> String;
fn get_title(&self, id: ViewId) -> String;
fn get_cursor(&self, id: ViewId) -> Interaction;
fn get_view(&self, id: ViewId) -> &ImageInfo;
// Provided methods
fn has_view(&self, _id: ViewId) -> bool { ... }
fn set_scale_factor(&mut self, _scale: f32) { ... }
fn handles_urls(&self) -> bool { ... }
fn get_scroll_y(&self, _id: ViewId) -> f32 { ... }
fn get_content_height(&self, _id: ViewId) -> f32 { ... }
fn get_selected_text(&self, _id: ViewId) -> Option<String> { ... }
fn get_selection_rects(&self, _id: ViewId) -> &[[f32; 4]] { ... }
fn take_anchor_click(&mut self, _id: ViewId) -> Option<String> { ... }
fn scroll_to_fragment(&mut self, _id: ViewId, _fragment: &str) -> bool { ... }
fn take_pending_images(&mut self) -> Vec<(ViewId, String, String, bool)> { ... }
fn set_css_cache(&mut self, _id: ViewId, _cache: HashMap<String, String>) { ... }
fn load_image_from_bytes(
&mut self,
_id: ViewId,
_url: &str,
_bytes: &[u8],
_redraw_on_ready: bool,
) { ... }
fn flush_staged_images(&mut self, _id: ViewId, _size: Size<u32>) { ... }
fn view_ids(&self) -> Vec<ViewId> ⓘ { ... }
}Expand description
Trait to handle multiple browser engines Currently only supports cpu renders via pixel_buffer Passing a View id that does not exist is handled gracefully (no-op / defaults)
Required Methods§
Sourcefn request_render(&mut self, id: ViewId, size: Size<u32>)
fn request_render(&mut self, id: ViewId, size: Size<u32>)
Flush a pending render for a specific view, if one is needed.
This does not force an unconditional render. It only performs the
(potentially expensive) render work when the view has been marked dirty
by a prior state change (goto, resize, refresh, update, etc.).
Callers should treat this as a “render-if-dirty” flush point, not a
“render right now regardless” command.
Sourcefn new_view(&mut self, size: Size<u32>, content: Option<PageType>) -> ViewId
fn new_view(&mut self, size: Size<u32>, content: Option<PageType>) -> ViewId
Creates new a new (possibly blank) view and returns the ViewId to interact with it
Sourcefn remove_view(&mut self, id: ViewId)
fn remove_view(&mut self, id: ViewId)
Removes desired view
Sourcefn handle_keyboard_event(&mut self, id: ViewId, event: Event)
fn handle_keyboard_event(&mut self, id: ViewId, event: Event)
lets the engine handle keyboard events
Sourcefn handle_mouse_event(&mut self, id: ViewId, point: Point, event: Event)
fn handle_mouse_event(&mut self, id: ViewId, point: Point, event: Event)
lets the engine handle mouse events
Sourcefn scroll(&mut self, id: ViewId, delta: ScrollDelta)
fn scroll(&mut self, id: ViewId, delta: ScrollDelta)
Handles scrolling on view
Sourcefn go_forward(&mut self, id: ViewId)
fn go_forward(&mut self, id: ViewId)
Moves forward on view
Sourcefn get_cursor(&self, id: ViewId) -> Interaction
fn get_cursor(&self, id: ViewId) -> Interaction
Gets current cursor status from view
Provided Methods§
Sourcefn set_scale_factor(&mut self, _scale: f32)
fn set_scale_factor(&mut self, _scale: f32)
Set the display scale factor for HiDPI rendering. Default is no-op.
Sourcefn handles_urls(&self) -> bool
fn handles_urls(&self) -> bool
Whether this engine can fetch and render URLs natively.
Engines that return false rely on the webview layer to fetch HTML.
Sourcefn get_scroll_y(&self, _id: ViewId) -> f32
fn get_scroll_y(&self, _id: ViewId) -> f32
Current vertical scroll offset (logical pixels).
Sourcefn get_content_height(&self, _id: ViewId) -> f32
fn get_content_height(&self, _id: ViewId) -> f32
Total content height (logical pixels). Zero means the engine manages scrolling.
Sourcefn get_selected_text(&self, _id: ViewId) -> Option<String>
fn get_selected_text(&self, _id: ViewId) -> Option<String>
Gets the currently selected text from a view, if any.
Sourcefn get_selection_rects(&self, _id: ViewId) -> &[[f32; 4]]
fn get_selection_rects(&self, _id: ViewId) -> &[[f32; 4]]
Selection highlight rectangles for overlay rendering.
Returns [x, y, width, height] in logical coordinates, scroll-adjusted.
Sourcefn take_anchor_click(&mut self, _id: ViewId) -> Option<String>
fn take_anchor_click(&mut self, _id: ViewId) -> Option<String>
Take the last anchor click URL from a view, if any. Called after mouse events to detect link navigation.
Sourcefn scroll_to_fragment(&mut self, _id: ViewId, _fragment: &str) -> bool
fn scroll_to_fragment(&mut self, _id: ViewId, _fragment: &str) -> bool
Scroll to a named fragment (e.g. "section2" for #section2).
Returns true if the fragment was found and the view scrolled.
Sourcefn take_pending_images(&mut self) -> Vec<(ViewId, String, String, bool)>
fn take_pending_images(&mut self) -> Vec<(ViewId, String, String, bool)>
Return image URLs discovered during layout that still need fetching.
Each entry is (view_id, raw_src, baseurl, redraw_on_ready) — the
consumer resolves URLs against baseurl and threads redraw_on_ready
back through load_image_from_bytes.
Sourcefn set_css_cache(&mut self, _id: ViewId, _cache: HashMap<String, String>)
fn set_css_cache(&mut self, _id: ViewId, _cache: HashMap<String, String>)
Pre-load a CSS cache into a view’s container so import_css can
resolve stylesheets without network access during parsing.
Sourcefn load_image_from_bytes(
&mut self,
_id: ViewId,
_url: &str,
_bytes: &[u8],
_redraw_on_ready: bool,
)
fn load_image_from_bytes( &mut self, _id: ViewId, _url: &str, _bytes: &[u8], _redraw_on_ready: bool, )
Inject fetched image bytes into a view’s container, keyed by the
raw src value from the HTML. When redraw_on_ready is true, the
image doesn’t affect layout (CSS background or <img> with explicit
dimensions) so doc.render() can be skipped — only a redraw is needed.
Sourcefn flush_staged_images(&mut self, _id: ViewId, _size: Size<u32>)
fn flush_staged_images(&mut self, _id: ViewId, _size: Size<u32>)
Flush all staged images into the document and redraw. Called when all in-flight image fetches have completed so the full batch is processed in a single redraw.