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
impl Controller
Sourcepub fn webview(&self) -> Result<WebView>
pub fn webview(&self) -> Result<WebView>
Returns the WebView used to navigate and script the hosted browser.
Sourcepub fn set_bounds(
&self,
left: i32,
top: i32,
right: i32,
bottom: i32,
) -> Result<()>
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.
Sourcepub fn set_visible(&self, visible: bool) -> Result<()>
pub fn set_visible(&self, visible: bool) -> Result<()>
Shows or hides the browser.
Sourcepub fn notify_parent_window_position_changed(&self) -> Result<()>
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.
Sourcepub fn allow_external_drop(&self) -> Result<bool>
pub fn allow_external_drop(&self) -> Result<bool>
Returns true if files dragged from outside the application can be
dropped onto the browser.
Sourcepub fn set_allow_external_drop(&self, allow: bool) -> Result<()>
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.
Sourcepub fn zoom_factor(&self) -> f64
pub fn zoom_factor(&self) -> f64
Returns the zoom factor applied to the page, where 1.0 is 100%.
Sourcepub fn set_zoom_factor(&self, zoom_factor: f64) -> Result<()>
pub fn set_zoom_factor(&self, zoom_factor: f64) -> Result<()>
Sets the zoom factor applied to the page, where 1.0 is 100%.
Sourcepub fn default_background_color(&self) -> Result<Color>
pub fn default_background_color(&self) -> Result<Color>
Returns the color painted behind the page before content loads and wherever the page is transparent.
Sourcepub fn set_default_background_color(&self, color: Color) -> Result<()>
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.
Sourcepub fn rasterization_scale(&self) -> Result<f64>
pub fn rasterization_scale(&self) -> Result<f64>
Returns the scale used to rasterize page content, which the browser derives from the monitor DPI.
Sourcepub fn set_rasterization_scale(&self, scale: f64) -> Result<()>
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.
Sourcepub fn should_detect_monitor_scale_changes(&self) -> Result<bool>
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.
Sourcepub fn set_should_detect_monitor_scale_changes(
&self,
detect: bool,
) -> Result<()>
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.
Sourcepub fn move_focus(&self, reason: MoveFocusReason) -> Result<()>
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.
Sourcepub fn on_got_focus<F: FnMut() + 'static>(
&self,
handler: F,
) -> Result<EventRegistration>
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.
Sourcepub fn on_lost_focus<F: FnMut() + 'static>(
&self,
handler: F,
) -> Result<EventRegistration>
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.
Sourcepub fn on_move_focus_requested<F: FnMut(MoveFocusRequestedArgs) + 'static>(
&self,
handler: F,
) -> Result<EventRegistration>
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.
Sourcepub fn on_accelerator_key_pressed<F: FnMut(AcceleratorKeyPressedArgs) + 'static>(
&self,
handler: F,
) -> Result<EventRegistration>
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.