@@ -16,7 +16,7 @@ rarely used in .NET apps.
16
16
# Examples
17
17
## DragStarting
18
18
Users can use ` add_DragStarting ` on the CompositionController to add an event
19
- handler that is invoked when drag is starting. They can use the the event args
19
+ handler that is invoked when drag is starting. They can use the event args
20
20
to start their own drag. Notably the ` Deferral ` can be used to execute any async
21
21
drag logic and call back into the WebView at a later time. The ` Handled `
22
22
property lets the WebView2 know whether to exercise its own drag logic or not.
@@ -30,37 +30,24 @@ CHECK_FAILURE(m_compController5->add_DragStarting(
30
30
[ this] (ICoreWebView2CompositionController5* sender,
31
31
ICoreWebView2DragStartingEventArgs* args)
32
32
{
33
- COREWEBVIEW2_DRAG_EFFECTS allowedEffects =
34
- COREWEBVIEW2_DRAG_EFFECTS_NONE;
33
+ DWORD allowedEffects = COREWEBVIEW2_DROP_EFFECTS_NONE;
35
34
POINT dragPosition = {0, 0};
36
35
wil::com_ptr<IDataObject > dragData;
37
36
38
- CHECK_FAILURE(args->get_AllowedOperations (&allowedEffects));
37
+ CHECK_FAILURE(args->get_AllowedDropEffects (&allowedEffects));
39
38
CHECK_FAILURE(args->get_Position(&dragPosition));
40
39
CHECK_FAILURE(args->get_Data(&dragData));
41
40
41
+ // This member refers to an implementation of IDropSource. It is an
42
+ // OLE interface that is necessary to initiate drag in an application.
43
+ // https://learn.microsoft.com/en-us/windows/win32/api/oleidl/nn-oleidl-idropsource
42
44
if (!m_dropSource)
43
45
{
44
46
m_dropSource = Make<ScenarioDragDropOverrideDropSource>();
45
47
}
46
48
47
- DWORD effect;
48
- DWORD okEffects = DROPEFFECT_NONE;
49
- if (allowedEffects & COREWEBVIEW2_DRAG_EFFECTS_COPY)
50
- {
51
- okEffects |= DROPEFFECT_COPY;
52
- }
53
- if (allowedEffects & COREWEBVIEW2_DRAG_EFFECTS_MOVE)
54
- {
55
- okEffects |= DROPEFFECT_MOVE;
56
- }
57
- if (allowedEffects & COREWEBVIEW2_DRAG_EFFECTS_LINK)
58
- {
59
- okEffects |= DROPEFFECT_LINK;
60
- }
61
-
62
49
HRESULT hr = DoDragDrop(
63
- dragData.get(), m_dropSource.get(), okEffects , &effect);
50
+ dragData.get(), m_dropSource.get(), allowedEffects , &effect);
64
51
65
52
args->put_Handled(SUCCEEDED(hr));
66
53
@@ -89,36 +76,29 @@ CHECK_FAILURE(m_compController5->add_DragStarting(
89
76
90
77
# API Details
91
78
``` C++
92
- // / Flags enum that represents the effects that a given WebView2 drag drop
93
- // / operation can have. The values of this enum align with the ole DROPEFFECT
94
- // / constant with the exception of DROPEFFECT_SCROLL which is only relevant for
95
- // / drop and therefore unsupported.
96
- [v1_enum]
97
- typedef enum COREWEBVIEW2_DRAG_EFFECTS {
98
- /// Drag operation supports no effect.
99
- COREWEBVIEW2_DRAG_EFFECTS_NONE = 0x0,
100
- /// Drag operation supports copying data.
101
- COREWEBVIEW2_DRAG_EFFECTS_COPY = 0x1,
102
- /// Drag operation supports moving data.
103
- COREWEBVIEW2_DRAG_EFFECTS_MOVE = 0x2,
104
- /// Drag operation supports linking data.
105
- COREWEBVIEW2_DRAG_EFFECTS_LINK = 0x4,
106
- } COREWEBVIEW2_DRAG_EFFECTS;
107
- cpp_quote ("DEFINE_ENUM_FLAG_OPERATORS(COREWEBVIEW2_DRAG_EFFECTS)")
79
+ // / DWORD constants that represent the effects that a given WebView2 drag drop
80
+ // / operation can have. The values of this enum align with the
81
+ // / [OLE DROPEFFECT constant](https://learn.microsoft.com/en-us/windows/win32/com/dropeffect-constants)
82
+ // / with the exception of DROPEFFECT_SCROLL which is unused in WebView2 drag
83
+ // / drop scenarios.
84
+ const DWORD COREWEBVIEW2_DROP_EFFECTS_NONE = 0 ;
85
+ const DWORD COREWEBVIEW2_DROP_EFFECTS_COPY = 1 ;
86
+ const DWORD COREWEBVIEW2_DROP_EFFECTS_MOVE = 2 ;
87
+ const DWORD COREWEBVIEW2_DROP_EFFECTS_LINK = 4 ;
108
88
109
89
// / Event args for the `DragStarting` event.
110
90
[uuid(edb6b243-334f -59d0-b3b3-de87dd401adc), object, pointer_default(unique)]
111
91
interface ICoreWebView2DragStartingEventArgs : IUnknown {
112
92
/// The operations this drag data supports.
113
- [ propget] HRESULT AllowedOperations (
114
- [ out, retval] COREWEBVIEW2_DRAG_EFFECTS * value);
93
+ [ propget] HRESULT AllowedDropEffects (
94
+ [ out, retval] COREWEBVIEW2_DROP_EFFECTS * value);
115
95
116
96
117
97
/// The data being dragged.
118
98
[ propget] HRESULT Data([ out, retval] IDataObject** value);
119
99
120
- /// The position at which drag was detected. This position is given in
121
- /// screen pixel coordinates as opposed to WebView2 relative coordinates.
100
+ /// The position at which drag was detected given in WebView2 relative
101
+ /// coordinates.
122
102
[ propget] HRESULT Position([ out, retval] POINT* value);
123
103
124
104
@@ -160,11 +140,21 @@ interface ICoreWebView2DragStartingEventHandler : IUnknown {
160
140
[uuid(975d6824-6a02-5e98 -ab7c-e4679d5357f4), object, pointer_default(unique)]
161
141
interface ICoreWebView2CompositionController5 : IUnknown {
162
142
/// Adds an event handler for the ` DragStarting ` event. ` DragStarting ` is
163
- /// raised when the WebView2 detects a drag started within the WebView2.
143
+ /// a deferrable event that is raised when the WebView2 detects a drag started
144
+ /// within the WebView2.
164
145
/// WebView2's default drag behavior is to synchronously call DoDragDrop when
165
146
/// it detects drag. This event's args expose the data WebView2 uses to call
166
147
/// DoDragDrop to allow users to implement their own drag logic and override
167
148
/// WebView2's.
149
+ /// Handlers of this event must set the ` Handled ` event to true in order to
150
+ /// override WebView2's default logic. When invoking drag logic asynchronously
151
+ /// using a deferral, handlers must take care to follow these steps in order:
152
+ /// * Invoke asynchronous drag logic
153
+ /// * Set the event args ` Handled ` property true
154
+ /// * Complete the deferral
155
+ /// In the asynchronous case, WebView2 decides whether or not to invoke its
156
+ /// default drag logic when the deferral completes. So the event args'
157
+ /// ` Handled ` property must be true when the deferral is completed.
168
158
HRESULT add_DragStarting(
169
159
[ in] ICoreWebView2DragStartingEventHandler* eventHandler,
170
160
[ out] EventRegistrationToken* token);
@@ -181,13 +171,13 @@ interface ICoreWebView2CompositionController5 : IUnknown {
181
171
// / This interface is implemented by the
182
172
// / Microsoft.Web.WebView2.Core.CoreWebView2CompositionController runtime class.
183
173
[uuid(7a4daef9-1701 -463f -992d-2136460cf76e), object, pointer_default(unique)]
184
- interface ICoreWebView2StagingCompositionControllerInterop : IUnknown {
174
+ interface ICoreWebView2CompositionControllerInterop3 : ICoreWebView2CompositionControllerInterop2 {
185
175
/// Adds an event handler for the ` DragStarting ` event. ` DragStarting ` is
186
176
/// raised when the WebView2 detects a drag started within the WebView2.
187
177
/// This event can be used to override WebView2's default drag starting
188
178
/// logic.
189
179
HRESULT add_DragStarting(
190
- [ in] ICoreWebView2StagingDragStartingEventHandler * eventHandler,
180
+ [ in] ICoreWebView2DragStartingEventHandler * eventHandler,
191
181
[ out] EventRegistrationToken* token);
192
182
193
183
/// Removes an event handler previously added with ` add_DragStarting ` .
0 commit comments