Skip to content

Commit b3dc1e3

Browse files
committed
Responding to feedback
1 parent 8c06cb6 commit b3dc1e3

File tree

1 file changed

+33
-43
lines changed

1 file changed

+33
-43
lines changed

specs/DragStarting.md

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rarely used in .NET apps.
1616
# Examples
1717
## DragStarting
1818
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
2020
to start their own drag. Notably the `Deferral` can be used to execute any async
2121
drag logic and call back into the WebView at a later time. The `Handled`
2222
property lets the WebView2 know whether to exercise its own drag logic or not.
@@ -30,37 +30,24 @@ CHECK_FAILURE(m_compController5->add_DragStarting(
3030
[this](ICoreWebView2CompositionController5* sender,
3131
ICoreWebView2DragStartingEventArgs* args)
3232
{
33-
COREWEBVIEW2_DRAG_EFFECTS allowedEffects =
34-
COREWEBVIEW2_DRAG_EFFECTS_NONE;
33+
DWORD allowedEffects = COREWEBVIEW2_DROP_EFFECTS_NONE;
3534
POINT dragPosition = {0, 0};
3635
wil::com_ptr<IDataObject> dragData;
3736

38-
CHECK_FAILURE(args->get_AllowedOperations(&allowedEffects));
37+
CHECK_FAILURE(args->get_AllowedDropEffects(&allowedEffects));
3938
CHECK_FAILURE(args->get_Position(&dragPosition));
4039
CHECK_FAILURE(args->get_Data(&dragData));
4140

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
4244
if (!m_dropSource)
4345
{
4446
m_dropSource = Make<ScenarioDragDropOverrideDropSource>();
4547
}
4648

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-
6249
HRESULT hr = DoDragDrop(
63-
dragData.get(), m_dropSource.get(), okEffects, &effect);
50+
dragData.get(), m_dropSource.get(), allowedEffects, &effect);
6451

6552
args->put_Handled(SUCCEEDED(hr));
6653

@@ -89,36 +76,29 @@ CHECK_FAILURE(m_compController5->add_DragStarting(
8976

9077
# API Details
9178
```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;
10888

10989
/// Event args for the `DragStarting` event.
11090
[uuid(edb6b243-334f-59d0-b3b3-de87dd401adc), object, pointer_default(unique)]
11191
interface ICoreWebView2DragStartingEventArgs : IUnknown {
11292
/// 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);
11595

11696

11797
/// The data being dragged.
11898
[propget] HRESULT Data([out, retval] IDataObject** value);
11999

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.
122102
[propget] HRESULT Position([out, retval] POINT* value);
123103

124104

@@ -160,11 +140,21 @@ interface ICoreWebView2DragStartingEventHandler : IUnknown {
160140
[uuid(975d6824-6a02-5e98-ab7c-e4679d5357f4), object, pointer_default(unique)]
161141
interface ICoreWebView2CompositionController5 : IUnknown {
162142
/// 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.
164145
/// WebView2's default drag behavior is to synchronously call DoDragDrop when
165146
/// it detects drag. This event's args expose the data WebView2 uses to call
166147
/// DoDragDrop to allow users to implement their own drag logic and override
167148
/// 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.
168158
HRESULT add_DragStarting(
169159
[in] ICoreWebView2DragStartingEventHandler* eventHandler,
170160
[out] EventRegistrationToken* token);
@@ -181,13 +171,13 @@ interface ICoreWebView2CompositionController5 : IUnknown {
181171
/// This interface is implemented by the
182172
/// Microsoft.Web.WebView2.Core.CoreWebView2CompositionController runtime class.
183173
[uuid(7a4daef9-1701-463f-992d-2136460cf76e), object, pointer_default(unique)]
184-
interface ICoreWebView2StagingCompositionControllerInterop : IUnknown {
174+
interface ICoreWebView2CompositionControllerInterop3 : ICoreWebView2CompositionControllerInterop2 {
185175
/// Adds an event handler for the `DragStarting` event. `DragStarting` is
186176
/// raised when the WebView2 detects a drag started within the WebView2.
187177
/// This event can be used to override WebView2's default drag starting
188178
/// logic.
189179
HRESULT add_DragStarting(
190-
[in] ICoreWebView2StagingDragStartingEventHandler* eventHandler,
180+
[in] ICoreWebView2DragStartingEventHandler* eventHandler,
191181
[out] EventRegistrationToken* token);
192182

193183
/// Removes an event handler previously added with `add_DragStarting`.

0 commit comments

Comments
 (0)