Table of Contents

Class CoreWebView2CompositionController

Namespace
Microsoft.Web.WebView2.Core
Assembly
Microsoft.Web.WebView2.Core.dll

This class is an extension of the CoreWebView2Controller class to support visual hosting.

public class CoreWebView2CompositionController
Inheritance
CoreWebView2CompositionController
Inherited Members

Properties

Cursor

Gets the current cursor that WebView thinks it should be.

public nint Cursor { get; }

Property Value

nint

Remarks

The cursor should be set in WM_SETCURSOR through Mouse.SetCursor or set on the corresponding parent/ancestor HWND of the WebView through ::SetClassLongPtr. The HCURSOR can be freed so CopyCursor/DestroyCursor is recommended to keep your own copy if you are doing more than immediately setting the cursor.

RootVisualTarget

Gets or sets the root visual in the hosting app's visual tree.

public object RootVisualTarget { get; set; }

Property Value

object

Remarks

This visual is where the WebView will connect its visual tree. The app uses this visual to position the WebView within the app. The app still needs to use the Bounds property to size the WebView. The RootVisualTarget property can be an IDCompositionVisual or a Windows::UI::Composition::ContainerVisual. WebView will connect its visual tree to the provided visual before returning from the property setter. The app needs to commit on its device setting the RootVisualTarget property. The RootVisualTarget property supports being set to null to disconnect the WebView from the app's visual tree.

SystemCursorId

Gets the current system cursor ID reported by the underlying rendering engine for WebView.

public uint SystemCursorId { get; }

Property Value

uint

Methods

DragLeave()

Call this method to inform the CoreWebView2CompositionController that a drag operation has left the WebView.

public void DragLeave()

Remarks

Corresponds to the ICoreDropOperationTarget.LeaveAsync method when performing a drag operation into the WebView.

GetNonClientRegionAtPoint(Point)

Call this method to perform hit-testing inside of your message loop when the message is WM_NCHITTEST.

public CoreWebView2NonClientRegionKind GetNonClientRegionAtPoint(Point point)

Parameters

point Point

The point parameter is expected to be in the client coordinate space of the WebView2.

Returns

CoreWebView2NonClientRegionKind

The type of CoreWebView2NonClientRegionKind region which contains the point.

QueryNonClientRegion(CoreWebView2NonClientRegionKind)

This method retrieves the non-client regions on the page which corresponds to a given kind CoreWebView2NonClientRegionKind.

public IReadOnlyList<Rectangle> QueryNonClientRegion(CoreWebView2NonClientRegionKind Kind)

Parameters

Kind CoreWebView2NonClientRegionKind

The kind of non-client region.

Returns

IReadOnlyList<Rectangle>

This method returns a vector of rectangles.

Remarks

This method can be used inside the NonClientRegionChanged event handler to get the list of rects for the specific region that changed.

SendMouseInput(CoreWebView2MouseEventKind, CoreWebView2MouseEventVirtualKeys, uint, Point)

Sends mouse input to the WebView.

public void SendMouseInput(CoreWebView2MouseEventKind eventKind, CoreWebView2MouseEventVirtualKeys virtualKeys, uint mouseData, Point point)

Parameters

eventKind CoreWebView2MouseEventKind

The mouse event kind.

virtualKeys CoreWebView2MouseEventVirtualKeys

The virtual keys associated with the eventKind.

mouseData uint

The amount of wheel movement.

point Point

The absolute position of the mouse, or the amount of motion since the last mouse event was generated, depending on the eventKind.

Remarks

If eventKind is HorizontalWheel or Wheel, then mouseData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120. If eventKind is XButtonDoubleClick, XButtonDown, or XButtonUp, then mouseData specifies which X buttons were pressed or released. This value should be 1 if the first X button is pressed/released and 2 if the second X button is pressed/released. If eventKind is Leave, then virtualKeys, mouseData, and point should all be zero. If eventKind is any other value, then mouseData should be zero. point is expected to be in the client coordinate space of the WebView. To track mouse events that start in the WebView and can potentially move outside of the WebView and host application, calling SetCapture and ReleaseCapture is recommended. To dismiss hover popups, it is also recommended to send Leave messages.

SendPointerInput(CoreWebView2PointerEventKind, CoreWebView2PointerInfo)

Sends pen or pointer input to the WebView.

public void SendPointerInput(CoreWebView2PointerEventKind eventKind, CoreWebView2PointerInfo pointerInfo)

Parameters

eventKind CoreWebView2PointerEventKind

The pointer event kind.

pointerInfo CoreWebView2PointerInfo

The pointer information.

Remarks

Accepts touch or pen pointer input of kinds defined in CoreWebView2PointerEventKind. Any pointer input from the system must be converted into a CoreWebView2PointerInfo first.

Events

CursorChanged

The event is raised when WebView thinks the cursor should be changed.

public event EventHandler<object> CursorChanged

Event Type

EventHandler<object>

Remarks

For example, when the mouse cursor is currently the default cursor but is then moved over text, it may try to change to the IBeam cursor. It is expected for the developer to send Leave messages (in addition to Move messages) through SendMouseInput(CoreWebView2MouseEventKind, CoreWebView2MouseEventVirtualKeys, uint, Point). This is to ensure that the mouse is actually within the WebView that sends out CursorChanged events.

NonClientRegionChanged

This event is raised when elements on the page with "app-region" CSS property values corresponding to non-client regions change. Use the RegionKind to see the kind of non-client region that changed.

public event EventHandler<CoreWebView2NonClientRegionChangedEventArgs> NonClientRegionChanged

Event Type

EventHandler<CoreWebView2NonClientRegionChangedEventArgs>