pub struct View { /* private fields */ }
Expand description
The View class is used to load and display web content.
View is an offscreen web-page container that can be used to display web-content in your application.
You can load content into a View via View::load_url
or View::load_html
and interact with it via View::fire_mouse_event
and similar API.
When displaying a View, the API is different depending on whether you are using the CPU renderer or the GPU renderer:
When using the CPU renderer, you would get the underlying pixel-buffer
surface for a View via View::surface
.
When using the GPU renderer, you would get the underlying render target
and texture information via View::render_target
.
Implementations§
source§impl View
impl View
sourcepub fn url(&self) -> Result<String, CreationError>
pub fn url(&self) -> Result<String, CreationError>
Get the URL of the current page loaded into this View, if any.
sourcepub fn title(&self) -> Result<String, CreationError>
pub fn title(&self) -> Result<String, CreationError>
Get the title of the current page loaded into this View, if any.
sourcepub fn device_scale(&self) -> f64
pub fn device_scale(&self) -> f64
Get the device scale, ie. the amount to scale page units to screen pixels.
For example, a value of 1.0 is equivalent to 100% zoom. A value of 2.0 is 200% zoom.
sourcepub fn set_device_scale(&self, scale: f64)
pub fn set_device_scale(&self, scale: f64)
Set the device scale.
sourcepub fn is_accelerated(&self) -> bool
pub fn is_accelerated(&self) -> bool
Whether or not the View is GPU-accelerated. If this is false, the page will be rendered via the CPU renderer.
sourcepub fn is_transparent(&self) -> bool
pub fn is_transparent(&self) -> bool
Whether or not the View supports transparent backgrounds.
sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Check if the main frame of the page is currently loading.
sourcepub fn render_target(&self) -> Option<RenderTarget>
pub fn render_target(&self) -> Option<RenderTarget>
Get the RenderTarget for the View.
Only valid when the view is accelerated, and will return None
otherwise.
sourcepub fn surface(&self) -> Option<Surface>
pub fn surface(&self) -> Option<Surface>
Get the Surface for the View (native pixel buffer container).
Only valid when the view is not accelerated, and will return None
otherwise.
sourcepub fn load_html(&self, html: &str) -> Result<(), CreationError>
pub fn load_html(&self, html: &str) -> Result<(), CreationError>
Load a raw string of HTML, the View will navigate to it as a new page.
sourcepub fn load_url(&self, url: &str) -> Result<(), CreationError>
pub fn load_url(&self, url: &str) -> Result<(), CreationError>
Load a URL, the View will navigate to it as a new page.
You can use File URLs (eg, file:///page.html) as well.
sourcepub fn resize(&self, width: u32, height: u32)
pub fn resize(&self, width: u32, height: u32)
Resize View to a certain size.
§Arguments
width
- The new width in pixels.height
- The new height in pixels.
sourcepub fn evaluate_script(
&self,
script: &str
) -> Result<Result<String, String>, CreationError>
pub fn evaluate_script( &self, script: &str ) -> Result<Result<String, String>, CreationError>
sourcepub fn can_go_back(&self) -> bool
pub fn can_go_back(&self) -> bool
Whether or not we can navigate backwards in history
sourcepub fn can_go_forward(&self) -> bool
pub fn can_go_forward(&self) -> bool
Whether or not we can navigate forwards in history
sourcepub fn go_forward(&self)
pub fn go_forward(&self)
Navigate forwards in history
sourcepub fn go_to_history_offset(&self, offset: i32)
pub fn go_to_history_offset(&self, offset: i32)
Navigate to an arbitrary offset in history
sourcepub fn focus(&self)
pub fn focus(&self)
Give focus to the View.
You should call this to give visual indication that the View has input focus (changes active text selection colors, for example).
sourcepub fn unfocus(&self)
pub fn unfocus(&self)
Remove focus from the View and unfocus any focused input elements.
You should call this to give visual indication that the View has lost input focus.
sourcepub fn has_input_focus(&self) -> bool
pub fn has_input_focus(&self) -> bool
Whether or not the View has an input element with visible keyboard focus (indicated by a blinking caret).
You can use this to decide whether or not the View should consume keyboard input events (useful in games with mixed UI and key handling).
sourcepub fn fire_key_event(&self, key_event: KeyEvent)
pub fn fire_key_event(&self, key_event: KeyEvent)
Fire a keyboard event
Note that only KeyEventType::Char
events actually generate text in input fields.
sourcepub fn fire_mouse_event(&self, mouse_event: MouseEvent)
pub fn fire_mouse_event(&self, mouse_event: MouseEvent)
Fire a mouse event
sourcepub fn fire_scroll_event(&self, scroll_event: ScrollEvent)
pub fn fire_scroll_event(&self, scroll_event: ScrollEvent)
Fire a scroll event
sourcepub fn set_change_title_callback<F>(&self, callback: F)
pub fn set_change_title_callback<F>(&self, callback: F)
Called when the page title changes
§Callback Arguments
view: &View
- The view that fired the event (eg. self)title: String
- The new title
sourcepub fn set_change_url_callback<F>(&self, callback: F)
pub fn set_change_url_callback<F>(&self, callback: F)
Called when the page URL changes
§Callback Arguments
view: &View
- The view that fired the event (eg. self)url: String
- The new url
sourcepub fn set_change_tooltip_callback<F>(&self, callback: F)
pub fn set_change_tooltip_callback<F>(&self, callback: F)
Called when the tooltip changes (usually as result of a mouse hover)
§Callback Arguments
view: &View
- The view that fired the event (eg. self)tooltip: String
- The tooltip string
sourcepub fn set_change_cursor_callback<F>(&self, callback: F)
pub fn set_change_cursor_callback<F>(&self, callback: F)
Called when the mouse cursor changes
§Callback Arguments
view: &View
- The view that fired the event (eg. self)cursor: Cursor
- The cursor type
sourcepub fn set_add_console_message_callback<F>(&self, callback: F)where
F: FnMut(&View, ConsoleMessageSource, ConsoleMessageLevel, String, u32, u32, String) + 'static,
pub fn set_add_console_message_callback<F>(&self, callback: F)where
F: FnMut(&View, ConsoleMessageSource, ConsoleMessageLevel, String, u32, u32, String) + 'static,
Called when a message is added to the console (useful for errors / debug)
§Callback Arguments
view: &View
- The view that fired the event (eg. self)message_source: ConsoleMessageSource
- The source of the messagemessage_level: ConsoleMessageLevel
- The level of the messagemessage: String
- The messageline_number: i32
- The line number of the messagecolumn_number: i32
- The column number of the messagesource_id: String
- The source id of the message
sourcepub fn set_create_child_view_callback<F>(&self, callback: F)
pub fn set_create_child_view_callback<F>(&self, callback: F)
Set callback for when the page wants to create a new View.
This is usually the result of a user clicking a link with target=“_blank” or by JavaScript calling window.open(url).
To allow creation of these new Views, you should create a new View
in this callback (eg. Renderer::create_view
),
resize it to your container, and return it.
You are responsible for displaying the returned View.
§Callback Arguments
view: &View
- The view that fired the event (eg. self)opener_url: String
- The url of the page that initiated this requesttarget_url: String
- The url the new View will navigate tois_popup: bool
- Whether or not this was triggered by window.open()popup_rect: Rect<i32>
- Popups can optionally request certain dimensions and coordinates via window.open(). You can choose to respect these or not by resizing/moving the View to this rect.
You should return None
if you want to block the action.
sourcepub fn set_begin_loading_callback<F>(&self, callback: F)
pub fn set_begin_loading_callback<F>(&self, callback: F)
Called when the page begins loading a new URL into a frame.
§Callback Arguments
view: &View
- The view that fired the event (eg. self)frame_id: u64
- A unique ID for the frameis_main_frame: bool
- Whether or not this is the main frameurl: String
- The url that is being loaded
sourcepub fn set_finish_loading_callback<F>(&self, callback: F)
pub fn set_finish_loading_callback<F>(&self, callback: F)
Called when the page finishes loading a URL into a frame.
§Callback Arguments
view: &View
- The view that fired the event (eg. self)frame_id: u64
- A unique ID for the frameis_main_frame: bool
- Whether or not this is the main frameurl: String
- The url that is being loaded
sourcepub fn set_fail_loading_callback<F>(&self, callback: F)
pub fn set_fail_loading_callback<F>(&self, callback: F)
Called when an error occurs while loading a URL into a frame.
§Callback Arguments
view: &View
- The view that fired the event (eg. self)frame_id: u64
- A unique ID for the frameis_main_frame: bool
- Whether or not this is the main frameurl: String
- The url that is being loadeddescription: String
- A human-readable description of the error.error_domain: String
- The name of the module that triggered the error.error_code: u32
- Internal error code generated by the module
sourcepub fn set_window_object_ready_callback<F>(&self, callback: F)
pub fn set_window_object_ready_callback<F>(&self, callback: F)
Set callback for when the JavaScript window object is reset for a new page load.
This is called before any scripts are executed on the page and is the earliest time to setup any initial JavaScript state or bindings.
The document is not guaranteed to be loaded/parsed at this point. If you need to make any JavaScript calls that are dependent on DOM elements or scripts on the page, use DOMReady instead.
The window object is lazily initialized (this will not be called on pages with no scripts).
§Callback Arguments
view: &View
- The view that fired the event (eg. self)frame_id: u64
- A unique ID for the frameis_main_frame: bool
- Whether or not this is the main frameurl: String
- The url that is being loaded
sourcepub fn set_dom_ready_callback<F>(&self, callback: F)
pub fn set_dom_ready_callback<F>(&self, callback: F)
Called when all JavaScript has been parsed and the document is ready.
This is the best time to make any JavaScript calls that are dependent on DOM elements or scripts on the page.
§Callback Arguments
view: &View
- The view that fired the event (eg. self)frame_id: u64
- A unique ID for the frameis_main_frame: bool
- Whether or not this is the main frameurl: String
- The url that is being loaded
sourcepub fn set_update_history_callback<F>(&self, callback: F)
pub fn set_update_history_callback<F>(&self, callback: F)
Called when the session history (back/forward state) is modified.
§Callback Arguments
view: &View
- The view that fired the event (eg. self)
sourcepub fn set_needs_paint(&self, needs_paint: bool)
pub fn set_needs_paint(&self, needs_paint: bool)
Set whether or not this View should be repainted during the next call
to Renderer::render
.
This flag is automatically set whenever the page content changes but you can set it directly in case you need to force a repaint.
sourcepub fn needs_paint(&self) -> bool
pub fn needs_paint(&self) -> bool
Whether or not this View should be repainted during the next call to
Renderer::render
.