ICoreWebView2Controller

Undocumented in source.
version(Windows && inline_webview2_bindings && all)
interface ICoreWebView2Controller : IUnknown {
static const
GUID iid;
}

Members

Functions

Close
HRESULT Close()

Closes the WebView and cleans up the underlying browser instance. Cleaning up the browser instance releases the resources powering the WebView. The browser instance is shut down if no other WebViews are using it.

MoveFocus
HRESULT MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON reason)

Moves focus into WebView. WebView gets focus and focus is 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 no previously focused element exists. For Next reason, focus is set to the first element. For Previous reason, focus is set to the last element. WebView changes focus through user interaction including selecting into a WebView or Tab into it. For tabbing, the app runs MoveFocus with Next or Previous to align with Tab and Shift+Tab respectively when it decides the WebView is the next element that may exist in a tab. Or, the app runs IsDialogMessage as part of the associated message loop to allow the platform to auto handle tabbing. The platform rotates through all windows with WS_TABSTOP. When the WebView gets focus from IsDialogMessage, it is internally put the focus on the first or last element for tab and Shift+Tab respectively.

NotifyParentWindowPositionChanged
HRESULT NotifyParentWindowPositionChanged()

This is a notification separate from Bounds that tells WebView that the main WebView parent (or any ancestor) HWND moved. This is needed for accessibility and certain dialogs in WebView to work correctly.

SetBoundsAndZoomFactor
HRESULT SetBoundsAndZoomFactor(RECT bounds, double zoomFactor)

Updates Bounds and ZoomFactor properties at the same time. This operation is atomic from the perspective of the host. After returning from this function, the Bounds and ZoomFactor properties are both updated if the function is successful, or neither is updated if the function fails. If Bounds and ZoomFactor are both updated by the same scale (for example, Bounds and ZoomFactor are both doubled), then the page does not display a change in window.innerWidth or window.innerHeight and the WebView renders the content at the new size and zoom without intermediate renderings. This function also updates just one of ZoomFactor or Bounds by passing in the new value for one and the current value for the other.

add_AcceleratorKeyPressed
HRESULT add_AcceleratorKeyPressed(ICoreWebView2AcceleratorKeyPressedEventHandler eventHandler, EventRegistrationToken* token)

Adds an event handler for the AcceleratorKeyPressed event. AcceleratorKeyPressed runs when an accelerator key or key combo is pressed or released while the WebView is focused. A key is considered an accelerator if either of the following conditions are true.

add_GotFocus
HRESULT add_GotFocus(ICoreWebView2FocusChangedEventHandler eventHandler, EventRegistrationToken* token)

Adds an event handler for the GotFocus event. GotFocus runs when WebView has focus.

add_LostFocus
HRESULT add_LostFocus(ICoreWebView2FocusChangedEventHandler eventHandler, EventRegistrationToken* token)

Adds an event handler for the LostFocus event. LostFocus runs when WebView loses focus. In the case where MoveFocusRequested event is run, the focus is still on WebView when MoveFocusRequested event runs. LostFocus only runs afterwards when code of the app or default action of MoveFocusRequested event set focus away from WebView.

add_MoveFocusRequested
HRESULT add_MoveFocusRequested(ICoreWebView2MoveFocusRequestedEventHandler eventHandler, EventRegistrationToken* token)

Adds an event handler for the MoveFocusRequested event. MoveFocusRequested runs when user tries to tab out of the WebView. The focus of the WebView has not changed when this event is run.

add_ZoomFactorChanged
HRESULT add_ZoomFactorChanged(ICoreWebView2ZoomFactorChangedEventHandler eventHandler, EventRegistrationToken* token)

Adds an event handler for the ZoomFactorChanged event. ZoomFactorChanged runs when the ZoomFactor property of the WebView changes. The event may run because the ZoomFactor property was modified, or due to the user manually modifying the zoom. When it is modified using the ZoomFactor property, the internal zoom factor is updated immediately and no ZoomFactorChanged event is triggered. WebView associates the last used zoom factor for each site. It is possible for the zoom factor to change when navigating to a different page. When the zoom factor changes due to a navigation change, the ZoomFactorChanged event runs right after the ContentLoading event.

get_Bounds
HRESULT get_Bounds(RECT* bounds)

The WebView bounds. Bounds are relative to the parent HWND. The app has two ways to position a WebView.

get_CoreWebView2
HRESULT get_CoreWebView2(ICoreWebView2* coreWebView2)

Gets the CoreWebView2 associated with this CoreWebView2Controller.

get_IsVisible
HRESULT get_IsVisible(BOOL* isVisible)

The IsVisible property determines whether to show or hide the WebView2. If IsVisible is set to FALSE, the WebView2 is transparent and is not rendered. However, this does not affect the window containing the WebView2 (the HWND parameter that was passed to CreateCoreWebView2Controller). If you want that window to disappear too, run ShowWindow on it directly in addition to modifying the IsVisible property. WebView2 as a child window does not get window messages when the top window is minimized or restored. For performance reasons, developers should set the IsVisible property of the WebView to FALSE when the app window is minimized and back to TRUE when the app window is restored. The app window does this by handling SIZE_MINIMIZED and SIZE_RESTORED command upon receiving WM_SIZE message.

get_ParentWindow
HRESULT get_ParentWindow(HWND* parentWindow)

The parent window provided by the app that this WebView is using to render content. This API initially returns the window passed into CreateCoreWebView2Controller.

get_ZoomFactor
HRESULT get_ZoomFactor(double* zoomFactor)

The zoom factor for the WebView.

put_Bounds
HRESULT put_Bounds(RECT bounds)

Sets the Bounds property.

put_IsVisible
HRESULT put_IsVisible(BOOL isVisible)

Sets the IsVisible property.

put_ParentWindow
HRESULT put_ParentWindow(HWND parentWindow)

Sets the parent window for the WebView. This causes the WebView to re-parent the main WebView window to the newly provided window.

put_ZoomFactor
HRESULT put_ZoomFactor(double zoomFactor)

Sets the ZoomFactor property.

remove_AcceleratorKeyPressed
HRESULT remove_AcceleratorKeyPressed(EventRegistrationToken token)

Removes an event handler previously added with add_AcceleratorKeyPressed.

remove_GotFocus
HRESULT remove_GotFocus(EventRegistrationToken token)

Removes an event handler previously added with add_GotFocus.

remove_LostFocus
HRESULT remove_LostFocus(EventRegistrationToken token)

Removes an event handler previously added with add_LostFocus.

remove_MoveFocusRequested
HRESULT remove_MoveFocusRequested(EventRegistrationToken token)

Removes an event handler previously added with add_MoveFocusRequested.

remove_ZoomFactorChanged
HRESULT remove_ZoomFactorChanged(EventRegistrationToken token)

Remove an event handler previously added with add_ZoomFactorChanged.

Meta