diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index f66e4e08d..b7b35ecbf 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -3,6 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; +using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -133,7 +134,7 @@ namespace CefSharp.Wpf /// /// Keep the current drag&drop effects to return the appropriate effects on drag over. /// - private DragDropEffects currentDragDropEffects; + private DragDropEffects? currentDragDropEffects; /// /// A flag that indicates whether or not the designer is active /// NOTE: Needs to be static for OnApplicationExit @@ -919,15 +920,25 @@ namespace CefSharp.Wpf { if (browser != null) { - //DoDragDrop will fire DragEnter event + // DoDragDrop will fire DragEnter event var result = DragDrop.DoDragDrop(this, dataObject, allowedOps.GetDragEffects()); + var dragEffects = currentDragDropEffects.HasValue ? currentDragDropEffects.Value : DragDropEffects.None; - //DragData was stored so when DoDragDrop fires DragEnter we reuse a clone of the IDragData provided here + // Ensure the drag and drop operation wasn't cancelled + var finalEffectMask = dragEffects.GetDragOperationsMask() & result.GetDragOperationsMask(); + + // We shouldn't have an instance where finalEffectMask signfies multiple effects, as the operation + // set by UpdateDragCursor should only ever be none, move, copy, or link. However, if it does, we'll + // just default to copy, as that reflects the defaulting behavior of GetDragEffects. + var finalSingleEffect = finalEffectMask.HasFlag(DragOperationsMask.Every) ? DragOperationsMask.Copy : finalEffectMask; + + // DragData was stored so when DoDragDrop fires DragEnter we reuse a clone of the IDragData provided here currentDragData = null; + currentDragDropEffects = null; - //If result == DragDropEffects.None then we'll send DragOperationsMask.None - //effectively cancelling the drag operation - browser.GetHost().DragSourceEndedAt(x, y, result.GetDragOperationsMask()); + // If result or the last recorded drag drop effect were DragDropEffects.None + // then we'll send DragOperationsMask.None, effectively cancelling the drag operation + browser.GetHost().DragSourceEndedAt(x, y, finalSingleEffect); browser.GetHost().DragSourceSystemDragEnded(); } }); @@ -1683,7 +1694,6 @@ namespace CefSharp.Wpf { var mouseEvent = GetMouseEvent(e); var effect = e.AllowedEffects.GetDragOperationsMask(); - browser.GetHost().DragTargetDragOver(mouseEvent, effect); browser.GetHost().DragTargetDragDrop(mouseEvent); } @@ -1713,7 +1723,7 @@ namespace CefSharp.Wpf { browser.GetHost().DragTargetDragOver(GetMouseEvent(e), e.AllowedEffects.GetDragOperationsMask()); } - e.Effects = currentDragDropEffects; + e.Effects = currentDragDropEffects.HasValue ? currentDragDropEffects.Value : DragDropEffects.None; e.Handled = true; } @@ -1731,6 +1741,7 @@ namespace CefSharp.Wpf //DoDragDrop will fire this handler for internally sourced Drag/Drop operations //we use the existing IDragData (cloned copy) + var dragData = currentDragData ?? e.GetDragData(); browser.GetHost().DragTargetDragEnter(dragData, mouseEvent, effect); @@ -2323,7 +2334,7 @@ namespace CefSharp.Wpf deltaX: isShiftKeyDown ? e.Delta : 0, deltaY: !isShiftKeyDown ? e.Delta : 0, modifiers: modifiers); - + e.Handled = true; } @@ -2469,7 +2480,7 @@ namespace CefSharp.Wpf { clickCount = 1; } - + MousePositionTransform.TransformMousePoint(ref point); browser.GetHost().SendMouseClickEvent((int)point.X, (int)point.Y, (MouseButtonType)e.ChangedButton, mouseUp, clickCount, modifiers); }