3
3
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4
4
5
5
using System ;
6
+ using System . Collections . Generic ;
6
7
using System . Runtime . CompilerServices ;
7
8
using System . Threading ;
8
9
using System . Threading . Tasks ;
@@ -133,7 +134,7 @@ public partial class ChromiumWebBrowser : Control, IRenderWebBrowser, IWpfWebBro
133
134
/// <summary>
134
135
/// Keep the current drag&drop effects to return the appropriate effects on drag over.
135
136
/// </summary>
136
- private DragDropEffects currentDragDropEffects ;
137
+ private DragDropEffects ? currentDragDropEffects ;
137
138
/// <summary>
138
139
/// A flag that indicates whether or not the designer is active
139
140
/// NOTE: Needs to be static for OnApplicationExit
@@ -919,15 +920,25 @@ protected virtual bool StartDragging(IDragData dragData, DragOperationsMask allo
919
920
{
920
921
if ( browser != null )
921
922
{
922
- //DoDragDrop will fire DragEnter event
923
+ // DoDragDrop will fire DragEnter event
923
924
var result = DragDrop . DoDragDrop ( this , dataObject , allowedOps . GetDragEffects ( ) ) ;
925
+ var dragEffects = currentDragDropEffects . HasValue ? currentDragDropEffects . Value : DragDropEffects . None ;
924
926
925
- //DragData was stored so when DoDragDrop fires DragEnter we reuse a clone of the IDragData provided here
927
+ // Ensure the drag and drop operation wasn't cancelled
928
+ var finalEffectMask = dragEffects . GetDragOperationsMask ( ) & result . GetDragOperationsMask ( ) ;
929
+
930
+ // We shouldn't have an instance where finalEffectMask signfies multiple effects, as the operation
931
+ // set by UpdateDragCursor should only ever be none, move, copy, or link. However, if it does, we'll
932
+ // just default to copy, as that reflects the defaulting behavior of GetDragEffects.
933
+ var finalSingleEffect = finalEffectMask . HasFlag ( DragOperationsMask . Every ) ? DragOperationsMask . Copy : finalEffectMask ;
934
+
935
+ // DragData was stored so when DoDragDrop fires DragEnter we reuse a clone of the IDragData provided here
926
936
currentDragData = null ;
937
+ currentDragDropEffects = null ;
927
938
928
- //If result == DragDropEffects.None then we'll send DragOperationsMask .None
929
- //effectively cancelling the drag operation
930
- browser . GetHost ( ) . DragSourceEndedAt ( x , y , result . GetDragOperationsMask ( ) ) ;
939
+ // If result or the last recorded drag drop effect were DragDropEffects .None
940
+ // then we'll send DragOperationsMask.None, effectively cancelling the drag operation
941
+ browser . GetHost ( ) . DragSourceEndedAt ( x , y , finalSingleEffect ) ;
931
942
browser . GetHost ( ) . DragSourceSystemDragEnded ( ) ;
932
943
}
933
944
} ) ;
@@ -1683,7 +1694,6 @@ private void OnDrop(object sender, DragEventArgs e)
1683
1694
{
1684
1695
var mouseEvent = GetMouseEvent ( e ) ;
1685
1696
var effect = e . AllowedEffects . GetDragOperationsMask ( ) ;
1686
-
1687
1697
browser . GetHost ( ) . DragTargetDragOver ( mouseEvent , effect ) ;
1688
1698
browser . GetHost ( ) . DragTargetDragDrop ( mouseEvent ) ;
1689
1699
}
@@ -1713,7 +1723,7 @@ private void OnDragOver(object sender, DragEventArgs e)
1713
1723
{
1714
1724
browser . GetHost ( ) . DragTargetDragOver ( GetMouseEvent ( e ) , e . AllowedEffects . GetDragOperationsMask ( ) ) ;
1715
1725
}
1716
- e . Effects = currentDragDropEffects ;
1726
+ e . Effects = currentDragDropEffects . HasValue ? currentDragDropEffects . Value : DragDropEffects . None ;
1717
1727
e . Handled = true ;
1718
1728
}
1719
1729
@@ -1731,6 +1741,7 @@ private void OnDragEnter(object sender, DragEventArgs e)
1731
1741
1732
1742
//DoDragDrop will fire this handler for internally sourced Drag/Drop operations
1733
1743
//we use the existing IDragData (cloned copy)
1744
+
1734
1745
var dragData = currentDragData ?? e . GetDragData ( ) ;
1735
1746
1736
1747
browser . GetHost ( ) . DragTargetDragEnter ( dragData , mouseEvent , effect ) ;
@@ -2323,7 +2334,7 @@ protected override void OnMouseWheel(MouseWheelEventArgs e)
2323
2334
deltaX : isShiftKeyDown ? e . Delta : 0 ,
2324
2335
deltaY : ! isShiftKeyDown ? e . Delta : 0 ,
2325
2336
modifiers : modifiers ) ;
2326
-
2337
+
2327
2338
e . Handled = true ;
2328
2339
}
2329
2340
@@ -2469,7 +2480,7 @@ private void OnMouseButton(MouseButtonEventArgs e)
2469
2480
{
2470
2481
clickCount = 1 ;
2471
2482
}
2472
-
2483
+
2473
2484
MousePositionTransform . TransformMousePoint ( ref point ) ;
2474
2485
browser . GetHost ( ) . SendMouseClickEvent ( ( int ) point . X , ( int ) point . Y , ( MouseButtonType ) e . ChangedButton , mouseUp , clickCount , modifiers ) ;
2475
2486
}
0 commit comments