Skip to main content

Controller

Struct Controller 

Source
pub struct Controller(/* private fields */);
Expand description

Hosts a WebView2 browser inside a parent window, controlling its bounds, visibility, and lifetime.

Implementations§

Source§

impl Controller

Source

pub fn webview(&self) -> Result<WebView>

Returns the WebView used to navigate and script the hosted browser.

Source

pub fn set_bounds( &self, left: i32, top: i32, right: i32, bottom: i32, ) -> Result<()>

Sets the bounds of the browser within the parent window, in pixels.

Source

pub fn set_visible(&self, visible: bool) -> Result<()>

Shows or hides the browser.

Source

pub fn close(&self) -> Result<()>

Closes the browser and releases its resources.

Source

pub fn notify_parent_window_position_changed(&self) -> Result<()>

Tells the browser that the parent window moved, so it can reposition any popups and dialogs it owns. Call this from the host’s WM_MOVE handler.

Source

pub fn allow_external_drop(&self) -> Result<bool>

Returns true if files dragged from outside the application can be dropped onto the browser.

Source

pub fn set_allow_external_drop(&self, allow: bool) -> Result<()>

Sets whether files dragged from outside the application can be dropped onto the browser. Disable it when the host wants to handle drops itself.

Source

pub fn zoom_factor(&self) -> f64

Returns the zoom factor applied to the page, where 1.0 is 100%.

Source

pub fn set_zoom_factor(&self, zoom_factor: f64) -> Result<()>

Sets the zoom factor applied to the page, where 1.0 is 100%.

Source

pub fn default_background_color(&self) -> Result<Color>

Returns the color painted behind the page before content loads and wherever the page is transparent.

Source

pub fn set_default_background_color(&self, color: Color) -> Result<()>

Sets the color painted behind the page before content loads and wherever the page is transparent. Use Color::TRANSPARENT to let the host window show through; only fully opaque (a = 255) and fully transparent (a = 0) colors are supported.

Source

pub fn rasterization_scale(&self) -> Result<f64>

Returns the scale used to rasterize page content, which the browser derives from the monitor DPI.

Source

pub fn set_rasterization_scale(&self, scale: f64) -> Result<()>

Sets the scale used to rasterize page content.

Disable monitor-scale detection first so browser DPI changes do not override this value.

Source

pub fn should_detect_monitor_scale_changes(&self) -> Result<bool>

Returns true if the browser updates the rasterization scale automatically as the monitor DPI changes.

Source

pub fn set_should_detect_monitor_scale_changes( &self, detect: bool, ) -> Result<()>

Sets whether the browser updates the rasterization scale automatically as the monitor DPI changes. Disable it to manage the scale yourself.

Source

pub fn move_focus(&self, reason: MoveFocusReason) -> Result<()>

Moves focus into the browser, as if focus arrived for the given reason. Call this from the host’s WM_SETFOCUS handler so the browser takes keyboard focus.

Source

pub fn on_got_focus<F: FnMut() + 'static>( &self, handler: F, ) -> Result<EventRegistration>

Subscribes to the got-focus event, raised when the browser gains focus.

Source

pub fn on_lost_focus<F: FnMut() + 'static>( &self, handler: F, ) -> Result<EventRegistration>

Subscribes to the lost-focus event, raised when the browser loses focus.

Source

pub fn on_move_focus_requested<F: FnMut(MoveFocusRequestedArgs) + 'static>( &self, handler: F, ) -> Result<EventRegistration>

Subscribes to the move-focus-requested event, raised when focus is leaving the browser (for example the user tabbed past the last element). Move focus to the appropriate host control and call MoveFocusRequestedArgs::set_handled. Wiring this is what keeps Tab navigation and screen readers working when the browser is embedded.

Source

pub fn on_accelerator_key_pressed<F: FnMut(AcceleratorKeyPressedArgs) + 'static>( &self, handler: F, ) -> Result<EventRegistration>

Subscribes to the accelerator-key-pressed event, raised for browser-level keys (such as function keys or a key combined with Ctrl or Alt) before the page handles them. Inspect AcceleratorKeyPressedArgs to implement application keyboard shortcuts.

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.