Skip to content

Commit 2ce9fdd

Browse files
committed
Fixed move cursor
1 parent 10f32eb commit 2ce9fdd

File tree

4 files changed

+88
-70
lines changed

4 files changed

+88
-70
lines changed

CefSharp.Wpf/CefSharp.Wpf.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
</ItemGroup>
8080
<ItemGroup>
8181
<Compile Include="CefSettings.cs" />
82-
<Compile Include="DragCursorProvider.cs" />
82+
<Compile Include="Internals\DragCursorProvider.cs" />
83+
<Compile Include="Internals\DragOperationMaskExtensions.cs" />
8384
<Compile Include="Internals\MonitorInfo.cs" />
8485
<Compile Include="Internals\MonitorInfoEx.cs" />
8586
<Compile Include="Internals\RectStruct.cs" />

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,14 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo
763763
if (browser != null)
764764
{
765765
//DoDragDrop will fire DragEnter event
766-
var result = DragDrop.DoDragDrop(this, dataObject, GetDragEffects(allowedOps));
766+
var result = DragDrop.DoDragDrop(this, dataObject, allowedOps.GetDragEffects());
767767

768768
//DragData was stored so when DoDragDrop fires DragEnter we reuse a clone of the IDragData provided here
769769
currentDragData = null;
770770

771771
//If result == DragDropEffects.None then we'll send DragOperationsMask.None
772772
//effectively cancelling the drag operation
773-
browser.GetHost().DragSourceEndedAt(x, y, GetDragOperationsMask(result));
773+
browser.GetHost().DragSourceEndedAt(x, y, result.GetDragOperationsMask());
774774
browser.GetHost().DragSourceSystemDragEnded();
775775
}
776776
});
@@ -1501,7 +1501,7 @@ private void OnDrop(object sender, DragEventArgs e)
15011501
if (browser != null)
15021502
{
15031503
var mouseEvent = GetMouseEvent(e);
1504-
var effect = GetDragOperationsMask(e.AllowedEffects);
1504+
var effect = e.AllowedEffects.GetDragOperationsMask();
15051505

15061506
browser.GetHost().DragTargetDragOver(mouseEvent, effect);
15071507
browser.GetHost().DragTargetDragDrop(mouseEvent);
@@ -1530,7 +1530,7 @@ private void OnDragOver(object sender, DragEventArgs e)
15301530
{
15311531
if (browser != null)
15321532
{
1533-
browser.GetHost().DragTargetDragOver(GetMouseEvent(e), GetDragOperationsMask(e.AllowedEffects));
1533+
browser.GetHost().DragTargetDragOver(GetMouseEvent(e), e.AllowedEffects.GetDragOperationsMask());
15341534
}
15351535
}
15361536

@@ -1554,7 +1554,7 @@ private void OnDragEnter(object sender, DragEventArgs e)
15541554
if (browser != null)
15551555
{
15561556
var mouseEvent = GetMouseEvent(e);
1557-
var effect = GetDragOperationsMask(e.AllowedEffects);
1557+
var effect = e.AllowedEffects.GetDragOperationsMask();
15581558

15591559
//DoDragDrop will fire this handler for internally sourced Drag/Drop operations
15601560
//we use the existing IDragData (cloned copy)
@@ -1565,62 +1565,6 @@ private void OnDragEnter(object sender, DragEventArgs e)
15651565
}
15661566
}
15671567

1568-
/// <summary>
1569-
/// Converts .NET drag drop effects to CEF Drag Operations
1570-
/// </summary>
1571-
/// <param name="dragDropEffects">The drag drop effects.</param>
1572-
/// <returns>DragOperationsMask.</returns>
1573-
/// s
1574-
private static DragOperationsMask GetDragOperationsMask(DragDropEffects dragDropEffects)
1575-
{
1576-
var operations = DragOperationsMask.None;
1577-
1578-
if (dragDropEffects.HasFlag(DragDropEffects.All))
1579-
{
1580-
operations |= DragOperationsMask.Every;
1581-
}
1582-
if (dragDropEffects.HasFlag(DragDropEffects.Copy))
1583-
{
1584-
operations |= DragOperationsMask.Copy;
1585-
}
1586-
if (dragDropEffects.HasFlag(DragDropEffects.Move))
1587-
{
1588-
operations |= DragOperationsMask.Move;
1589-
}
1590-
if (dragDropEffects.HasFlag(DragDropEffects.Link))
1591-
{
1592-
operations |= DragOperationsMask.Link;
1593-
}
1594-
1595-
return operations;
1596-
}
1597-
1598-
/// <summary>
1599-
/// Gets the drag effects.
1600-
/// </summary>
1601-
/// <param name="mask">The mask.</param>
1602-
/// <returns>DragDropEffects.</returns>
1603-
private static DragDropEffects GetDragEffects(DragOperationsMask mask)
1604-
{
1605-
if ((mask & DragOperationsMask.Every) == DragOperationsMask.Every)
1606-
{
1607-
return DragDropEffects.All;
1608-
}
1609-
if ((mask & DragOperationsMask.Copy) == DragOperationsMask.Copy)
1610-
{
1611-
return DragDropEffects.Copy;
1612-
}
1613-
if ((mask & DragOperationsMask.Move) == DragOperationsMask.Move)
1614-
{
1615-
return DragDropEffects.Move;
1616-
}
1617-
if ((mask & DragOperationsMask.Link) == DragOperationsMask.Link)
1618-
{
1619-
return DragDropEffects.Link;
1620-
}
1621-
return DragDropEffects.None;
1622-
}
1623-
16241568
/// <summary>
16251569
/// PresentationSource changed handler.
16261570
/// </summary>

CefSharp.Wpf/DragCursorProvider.cs renamed to CefSharp.Wpf/Internals/DragCursorProvider.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Runtime.InteropServices;
8+
using System.Windows;
89
using System.Windows.Input;
910
using System.Windows.Interop;
1011
using CefSharp.Enums;
1112
using Microsoft.Win32.SafeHandles;
1213

13-
namespace CefSharp.Wpf
14+
namespace CefSharp.Wpf.Internals
1415
{
1516

1617
internal static class DragCursorProvider
@@ -21,17 +22,17 @@ internal static class DragCursorProvider
2122
[DllImport("user32.dll")]
2223
private static extern IntPtr LoadCursor(IntPtr hInstance, ushort lpCursorName);
2324

24-
private static readonly Dictionary<DragOperationsMask, Cursor> DragCursors;
25+
private static readonly Dictionary<DragDropEffects, Cursor> DragCursors;
2526

2627
static DragCursorProvider()
2728
{
2829
var library = LoadLibrary("ole32.dll");
29-
DragCursors = new Dictionary<DragOperationsMask, Cursor>()
30+
DragCursors = new Dictionary<DragDropEffects, Cursor>()
3031
{
31-
{ DragOperationsMask.None, GetCursorFromLib(library, 1) },
32-
{ DragOperationsMask.Move, GetCursorFromLib(library, 2) },
33-
{ DragOperationsMask.Copy, GetCursorFromLib(library, 3) },
34-
{ DragOperationsMask.Link, GetCursorFromLib(library, 4) }
32+
{ DragDropEffects.None, GetCursorFromLib(library, 1) },
33+
{ DragDropEffects.Move, GetCursorFromLib(library, 2) },
34+
{ DragDropEffects.Copy, GetCursorFromLib(library, 3) },
35+
{ DragDropEffects.Link, GetCursorFromLib(library, 4) }
3536
// TODO: support black cursors
3637
};
3738
}
@@ -49,8 +50,10 @@ private static Cursor GetCursorFromLib(IntPtr library, ushort cursorIndex)
4950
/// <returns>The drop cursor based on the specified drag operation effect</returns>
5051
public static Cursor GetCursor(DragOperationsMask operation)
5152
{
53+
var effects = operation.GetDragEffects();
54+
5255
Cursor cursor;
53-
if (DragCursors.TryGetValue(operation, out cursor))
56+
if (DragCursors.TryGetValue(effects, out cursor))
5457
{
5558
return cursor;
5659
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright © 2019 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
using System.Windows;
6+
using CefSharp.Enums;
7+
8+
namespace CefSharp.Wpf.Internals
9+
{
10+
11+
internal static class DragOperationMaskExtensions
12+
{
13+
14+
/// <summary>
15+
/// Converts .NET drag drop effects to CEF Drag Operations
16+
/// </summary>
17+
/// <param name="dragDropEffects">The drag drop effects.</param>
18+
/// <returns>DragOperationsMask.</returns>
19+
/// s
20+
public static DragOperationsMask GetDragOperationsMask(this DragDropEffects dragDropEffects)
21+
{
22+
var operations = DragOperationsMask.None;
23+
24+
if (dragDropEffects.HasFlag(DragDropEffects.All))
25+
{
26+
operations |= DragOperationsMask.Every;
27+
}
28+
if (dragDropEffects.HasFlag(DragDropEffects.Copy))
29+
{
30+
operations |= DragOperationsMask.Copy;
31+
}
32+
if (dragDropEffects.HasFlag(DragDropEffects.Move))
33+
{
34+
operations |= DragOperationsMask.Move;
35+
}
36+
if (dragDropEffects.HasFlag(DragDropEffects.Link))
37+
{
38+
operations |= DragOperationsMask.Link;
39+
}
40+
41+
return operations;
42+
}
43+
44+
/// <summary>
45+
/// Gets the drag effects.
46+
/// </summary>
47+
/// <param name="mask">The mask.</param>
48+
/// <returns>DragDropEffects.</returns>
49+
public static DragDropEffects GetDragEffects(this DragOperationsMask mask)
50+
{
51+
if ((mask & DragOperationsMask.Every) == DragOperationsMask.Every)
52+
{
53+
return DragDropEffects.All;
54+
}
55+
if ((mask & DragOperationsMask.Copy) == DragOperationsMask.Copy)
56+
{
57+
return DragDropEffects.Copy;
58+
}
59+
if ((mask & DragOperationsMask.Move) == DragOperationsMask.Move)
60+
{
61+
return DragDropEffects.Move;
62+
}
63+
if ((mask & DragOperationsMask.Link) == DragOperationsMask.Link)
64+
{
65+
return DragDropEffects.Link;
66+
}
67+
return DragDropEffects.None;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)