[−][src]Trait webview2_sys::ICoreWebView2Host
This interface is the owner of the CoreWebView2 object, and provides support for resizing, showing and hiding, focusing, and other functionality related to windowing and composition. The CoreWebView2Host owns the CoreWebView2, and if all references to the CoreWebView2Host go away, the WebView will be closed.
Required methods
unsafe fn get_is_visible(&self, is_visible: *mut BOOL) -> HRESULT
The IsVisible property determines whether to show or hide the webview. If IsVisible is set to false, the webview will be transparent and will not be rendered. However, this will not affect the window containing the webview (the HWND parameter that was passed to CreateCoreWebView2Host). If you want that window to disappear too, call ShowWindow on it directly in addition to modifying the IsVisible property. WebView as a child window won't get window messages when the top window is minimized or restored. For performance reason, developer should set IsVisible property of the WebView to false when the app window is minimized and back to true when app window is restored. App window can do this by handling SC_MINIMIZE and SC_RESTORE command upon receiving WM_SYSCOMMAND message.
\snippet ViewComponent.cpp ToggleIsVisible
unsafe fn put_is_visible(&self, is_visible: BOOL) -> HRESULT
Set the IsVisible property.
\snippet ViewComponent.cpp ToggleIsVisibleOnMinimize
unsafe fn get_bounds(&self, bounds: *mut RECT) -> HRESULT
The webview bounds. Bounds are relative to the parent HWND. The app has two ways it can position a WebView:
- Create a child HWND that is the WebView parent HWND. Position this window where the WebView should be. In this case, use (0, 0) for the WebView's Bound's top left corner (the offset).
- Use the app's top most window as the WebView parent HWND. Set the WebView's Bound's top left corner so that the WebView is positioned correctly in the app. The Bound's values are in the host's coordinate space.
unsafe fn put_bounds(&self, bounds: RECT) -> HRESULT
Set the Bounds property.
\snippet ViewComponent.cpp ResizeWebView
unsafe fn get_zoom_factor(&self, zoom_factor: *mut f64) -> HRESULT
The zoom factor for the WebView.
Note that changing zoom factor could cause window.innerWidth/innerHeight
and page layout to change.
A zoom factor that is applied by the host by calling put_ZoomFactor
becomes the new default zoom for the WebView. This zoom factor applies
across navigations and is the zoom factor WebView is returned to when the
user presses ctrl+0. When the zoom factor is changed by the user
(resulting in the app receiving ZoomFactorChanged), that zoom applies
only for the current page. Any user applied zoom is only for the current
page and is reset on a navigation.
Specifying a zoomFactor less than or equal to 0 is not allowed.
WebView also has an internal supported zoom factor range. When a specified
zoom factor is out of that range, it will be normalized to be within the
range, and a ZoomFactorChanged event will be fired for the real
applied zoom factor. When this range normalization happens, the
ZoomFactor property will report the zoom factor specified during the
previous modification of the ZoomFactor property until the
ZoomFactorChanged event is received after webview applies the normalized
zoom factor.
unsafe fn put_zoom_factor(&self, zoom_factor: f64) -> HRESULT
Set the ZoomFactor property.
unsafe fn add_zoom_factor_changed(
&self,
event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
&self,
event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
Add an event handler for the ZoomFactorChanged event. The event fires when the ZoomFactor property of the WebView changes. The event could fire because the caller modified the ZoomFactor property, or due to the user manually modifying the zoom. When it is modified by the caller via the ZoomFactor property, the internal zoom factor is updated immediately and there will be no ZoomFactorChanged event. WebView associates the last used zoom factor for each site. Therefore, it is possible for the zoom factor to change when navigating to a different page. When the zoom factor changes due to this, the ZoomFactorChanged event fires right after the ContentLoading event.
\snippet ViewComponent.cpp ZoomFactorChanged
unsafe fn remove_zoom_factor_changed(
&self,
token: EventRegistrationToken
) -> HRESULT
&self,
token: EventRegistrationToken
) -> HRESULT
Remove an event handler previously added with add_ZoomFactorChanged.
unsafe fn set_bounds_and_zoom_factor(
&self,
bounds: RECT,
zoom_factor: f64
) -> HRESULT
&self,
bounds: RECT,
zoom_factor: f64
) -> HRESULT
Update Bounds and ZoomFactor properties at the same time. This operation is atomic from the host's perspecive. After returning from this function, the Bounds and ZoomFactor properties will have both been updated if the function is successful, or neither will be updated if the function fails. If Bounds and ZoomFactor are both updated by the same scale (i.e. Bounds and ZoomFactor are both doubled), then the page will not see a change in window.innerWidth/innerHeight and the WebView will render the content at the new size and zoom without intermediate renderings. This function can also be used to update just one of ZoomFactor or Bounds by passing in the new value for one and the current value for the other.
\snippet ViewComponent.cpp SetBoundsAndZoomFactor
unsafe fn move_focus(&self, reason: MoveFocusReason) -> HRESULT
Move focus into WebView. WebView will get focus and focus will be set to correspondent element in the page hosted in the WebView. For Programmatic reason, focus is set to previously focused element or the default element if there is no previously focused element. For Next reason, focus is set to the first element. For Previous reason, focus is set to the last element. WebView can also got focus through user interaction like clicking into WebView or Tab into it. For tabbing, the app can call MoveFocus with Next or Previous to align with tab and shift+tab respectively when it decides the WebView is the next tabbable element. Or, the app can call IsDialogMessage as part of its message loop to allow the platform to auto handle tabbing. The platform will rotate through all windows with WS_TABSTOP. When the WebView gets focus from IsDialogMessage, it will internally put the focus on the first or last element for tab and shift+tab respectively.
\snippet App.cpp MoveFocus0
\snippet ControlComponent.cpp MoveFocus1
\snippet ControlComponent.cpp MoveFocus2
unsafe fn add_move_focus_requested(
&self,
event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
&self,
event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
Add an event handler for the MoveFocusRequested event. MoveFocusRequested fires when user tries to tab out of the WebView. The WebView's focus has not changed when this event is fired.
\snippet ControlComponent.cpp MoveFocusRequested
unsafe fn remove_move_focus_requested(
&self,
token: EventRegistrationToken
) -> HRESULT
&self,
token: EventRegistrationToken
) -> HRESULT
Remove an event handler previously added with add_MoveFocusRequested.
unsafe fn add_got_focus(
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
Add an event handler for the GotFocus event. GotFocus fires when WebView got focus.
unsafe fn remove_got_focus(&self, token: EventRegistrationToken) -> HRESULT
Remove an event handler previously added with add_GotFocus.
unsafe fn add_lost_focus(
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
Add an event handler for the LostFocus event. LostFocus fires when WebView lost focus. In the case where MoveFocusRequested event is fired, the focus is still on WebView when MoveFocusRequested event fires. Lost focus only fires afterwards when app's code or default action of MoveFocusRequested event set focus away from WebView.
unsafe fn remove_lost_focus(&self, token: EventRegistrationToken) -> HRESULT
Remove an event handler previously added with add_LostFocus.
unsafe fn add_accelerator_key_pressed(
&self,
event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
&self,
event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
Add an event handler for the AcceleratorKeyPressed event. AcceleratorKeyPressed fires when an accelerator key or key combo is pressed or released while the WebView is focused. A key is considered an accelerator if either:
- Ctrl or Alt is currently being held, or
- the pressed key does not map to a character. A few specific keys are never considered accelerators, such as Shift. The Escape key is always considered an accelerator.
Autorepeated key events caused by holding the key down will also fire this event. You can filter these out by checking the event args' KeyEventLParam or PhysicalKeyStatus.
In windowed mode, this event handler is called synchronously. Until you call Handle() on the event args or the event handler returns, the browser process will be blocked and outgoing cross-process COM calls will fail with RPC_E_CANTCALLOUT_ININPUTSYNCCALL. All CoreWebView2 API methods will work, however.
In windowless mode, the event handler is called asynchronously. Further input will not reach the browser until the event handler returns or Handle() is called, but the browser process itself will not be blocked, and outgoing COM calls will work normally.
It is recommended to call Handle(TRUE) as early as you can know that you want to handle the accelerator key.
\snippet ControlComponent.cpp AcceleratorKeyPressed
unsafe fn remove_accelerator_key_pressed(
&self,
token: EventRegistrationToken
) -> HRESULT
&self,
token: EventRegistrationToken
) -> HRESULT
Remove an event handler previously added with add_AcceleratorKeyPressed.
unsafe fn get_parent_window(&self, top_level_window: *mut HWND) -> HRESULT
The parent window provided by the app that this WebView is using to render content. This API initially returns the window passed into CreateCoreWebView2Host.
unsafe fn put_parent_window(&self, top_level_window: HWND) -> HRESULT
Set the parent window for the WebView. This will cause the WebView to reparent its window to the newly provided window.
unsafe fn notify_parent_window_position_changed(&self) -> HRESULT
This is a notification separate from put_Bounds that tells WebView its parent (or any ancestor) HWND moved. This is needed for accessibility and certain dialogs in WebView to work correctly. \snippet AppWindow.cpp NotifyParentWindowPositionChanged
unsafe fn close(&self) -> HRESULT
Closes the WebView and cleans up the underlying browser instance. Cleaning up the browser instace will release the resources powering the WebView. The browser instance will be shut down if there are no other WebViews using it.
After calling Close, all method calls will fail and event handlers will stop firing. Specifically, the WebView will release its references to its event handlers when Close is called.
Close is implicitly called when the CoreWebView2Host loses its final reference and is destructed. But it is best practice to explicitly call Close to avoid any accidental cycle of references between the WebView and the app code. Specifically, if you capture a reference to the WebView in an event handler you will create a reference cycle between the WebView and the event handler. Calling Close will break this cycle by releasing all event handlers. But to avoid this situation it is best practice both to explicitly call Close on the WebView and to not capture a reference to the WebView to ensure the WebView can be cleaned up correctly.
\snippet AppWindow.cpp Close
unsafe fn get_core_web_view2(
&self,
core_web_view2: *mut *mut *mut ICoreWebView2VTable
) -> HRESULT
&self,
core_web_view2: *mut *mut *mut ICoreWebView2VTable
) -> HRESULT
Gets the CoreWebView2 associated with this CoreWebView2Host.
Trait Implementations
impl ComInterface for dyn ICoreWebView2Host[src]
type VTable = ICoreWebView2HostVTable
A COM compatible V-Table
type Super = dyn IUnknown
The interface that this interface inherits from
const IID: IID[src]
fn is_iid_in_inheritance_chain(riid: &GUID) -> bool[src]
impl<C: ICoreWebView2Host> ProductionComInterface<C> for dyn ICoreWebView2Host[src]
Implementations on Foreign Types
impl<T: ICoreWebView2Host + ComInterface + ?Sized> ICoreWebView2Host for ComRc<T>[src]
unsafe fn get_is_visible(&self, is_visible: *mut BOOL) -> HRESULT[src]
unsafe fn put_is_visible(&self, is_visible: BOOL) -> HRESULT[src]
unsafe fn get_bounds(&self, bounds: *mut RECT) -> HRESULT[src]
unsafe fn put_bounds(&self, bounds: RECT) -> HRESULT[src]
unsafe fn get_zoom_factor(&self, zoom_factor: *mut f64) -> HRESULT[src]
unsafe fn put_zoom_factor(&self, zoom_factor: f64) -> HRESULT[src]
unsafe fn add_zoom_factor_changed(
&self,
event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_zoom_factor_changed(
&self,
token: EventRegistrationToken
) -> HRESULT[src]
&self,
token: EventRegistrationToken
) -> HRESULT
unsafe fn set_bounds_and_zoom_factor(
&self,
bounds: RECT,
zoom_factor: f64
) -> HRESULT[src]
&self,
bounds: RECT,
zoom_factor: f64
) -> HRESULT
unsafe fn move_focus(&self, reason: MoveFocusReason) -> HRESULT[src]
unsafe fn add_move_focus_requested(
&self,
event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_move_focus_requested(
&self,
token: EventRegistrationToken
) -> HRESULT[src]
&self,
token: EventRegistrationToken
) -> HRESULT
unsafe fn add_got_focus(
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_got_focus(&self, token: EventRegistrationToken) -> HRESULT[src]
unsafe fn add_lost_focus(
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_lost_focus(&self, token: EventRegistrationToken) -> HRESULT[src]
unsafe fn add_accelerator_key_pressed(
&self,
event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_accelerator_key_pressed(
&self,
token: EventRegistrationToken
) -> HRESULT[src]
&self,
token: EventRegistrationToken
) -> HRESULT
unsafe fn get_parent_window(&self, top_level_window: *mut HWND) -> HRESULT[src]
unsafe fn put_parent_window(&self, top_level_window: HWND) -> HRESULT[src]
unsafe fn notify_parent_window_position_changed(&self) -> HRESULT[src]
unsafe fn close(&self) -> HRESULT[src]
unsafe fn get_core_web_view2(
&self,
core_web_view2: *mut *mut *mut ICoreWebView2VTable
) -> HRESULT[src]
&self,
core_web_view2: *mut *mut *mut ICoreWebView2VTable
) -> HRESULT
impl<T: ICoreWebView2Host + ComInterface + ?Sized> ICoreWebView2Host for ComPtr<T>[src]
unsafe fn get_is_visible(&self, is_visible: *mut BOOL) -> HRESULT[src]
unsafe fn put_is_visible(&self, is_visible: BOOL) -> HRESULT[src]
unsafe fn get_bounds(&self, bounds: *mut RECT) -> HRESULT[src]
unsafe fn put_bounds(&self, bounds: RECT) -> HRESULT[src]
unsafe fn get_zoom_factor(&self, zoom_factor: *mut f64) -> HRESULT[src]
unsafe fn put_zoom_factor(&self, zoom_factor: f64) -> HRESULT[src]
unsafe fn add_zoom_factor_changed(
&self,
event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2ZoomFactorChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_zoom_factor_changed(
&self,
token: EventRegistrationToken
) -> HRESULT[src]
&self,
token: EventRegistrationToken
) -> HRESULT
unsafe fn set_bounds_and_zoom_factor(
&self,
bounds: RECT,
zoom_factor: f64
) -> HRESULT[src]
&self,
bounds: RECT,
zoom_factor: f64
) -> HRESULT
unsafe fn move_focus(&self, reason: MoveFocusReason) -> HRESULT[src]
unsafe fn add_move_focus_requested(
&self,
event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2MoveFocusRequestedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_move_focus_requested(
&self,
token: EventRegistrationToken
) -> HRESULT[src]
&self,
token: EventRegistrationToken
) -> HRESULT
unsafe fn add_got_focus(
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_got_focus(&self, token: EventRegistrationToken) -> HRESULT[src]
unsafe fn add_lost_focus(
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2FocusChangedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_lost_focus(&self, token: EventRegistrationToken) -> HRESULT[src]
unsafe fn add_accelerator_key_pressed(
&self,
event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT[src]
&self,
event_handler: *mut *mut ICoreWebView2AcceleratorKeyPressedEventHandlerVTable,
token: *mut EventRegistrationToken
) -> HRESULT
unsafe fn remove_accelerator_key_pressed(
&self,
token: EventRegistrationToken
) -> HRESULT[src]
&self,
token: EventRegistrationToken
) -> HRESULT
unsafe fn get_parent_window(&self, top_level_window: *mut HWND) -> HRESULT[src]
unsafe fn put_parent_window(&self, top_level_window: HWND) -> HRESULT[src]
unsafe fn notify_parent_window_position_changed(&self) -> HRESULT[src]
unsafe fn close(&self) -> HRESULT[src]
unsafe fn get_core_web_view2(
&self,
core_web_view2: *mut *mut *mut ICoreWebView2VTable
) -> HRESULT[src]
&self,
core_web_view2: *mut *mut *mut ICoreWebView2VTable
) -> HRESULT