Skip to content

Commit 6692749

Browse files
joaompnevesamaitland
authored andcommitted
WPF - Implement UpdateDragCursor (#2691)
* Close cefsharp subprocess if main process dies * Implemented UpdateDragCursor * Fixed braces position * Added license header * Fixed cursor flickering * Added test * Fixed build * Fixed move cursor * Fixed braces * Simplified solution * Fixed dropping Link effect * Fixed encoding + Removed leftovers
1 parent dfb2cd5 commit 6692749

File tree

11 files changed

+174
-64
lines changed

11 files changed

+174
-64
lines changed

CefSharp.Example/CefExample.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static class CefExample
2424
public const string BasicSchemeTestUrl = BaseUrl + "/SchemeTest.html";
2525
public const string ResponseFilterTestUrl = BaseUrl + "/ResponseFilterTest.html";
2626
public const string DraggableRegionTestUrl = BaseUrl + "/DraggableRegionTest.html";
27+
public const string DragDropCursorsTestUrl = BaseUrl + "/DragDropCursorsTest.html";
2728
public const string CssAnimationTestUrl = BaseUrl + "/CssAnimationTest.html";
2829
public const string CdmSupportTestUrl = BaseUrl + "/CdmSupportTest.html";
2930
public const string TestResourceUrl = "http://test/resource/load";

CefSharp.Example/CefSharp.Example.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<None Include="Resources\assets\js\shBrushJScript.js" />
153153
<Content Include="Resources\assets\js\shCore.js" />
154154
<Content Include="Resources\BindingTestSingle.html" />
155+
<Content Include="Resources\DragDropCursorsTest.html" />
155156
<Content Include="Resources\LegacyBindingTest.html" />
156157
<Content Include="Resources\CdmSupportTest.html" />
157158
<Content Include="Resources\CssAnimation.html" />

CefSharp.Example/CefSharpSchemeHandlerFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static CefSharpSchemeHandlerFactory()
4747
{ "/ScriptedMethodsTest.html", Resources.ScriptedMethodsTest },
4848
{ "/ResponseFilterTest.html", Resources.ResponseFilterTest },
4949
{ "/DraggableRegionTest.html", Resources.DraggableRegionTest },
50+
{ "/DragDropCursorsTest.html", Resources.DragDropCursorsTest },
5051
{ "/CssAnimationTest.html", Resources.CssAnimation },
5152
{ "/CdmSupportTest.html", Resources.CdmSupportTest },
5253
{ "/Recaptcha.html", Resources.Recaptcha },

CefSharp.Example/InMemorySchemeAndResourceHandlerFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static InMemorySchemeAndResourceHandlerFactory()
4545
{ "/PopupTest.html", Resources.PopupTest },
4646
{ "/SchemeTest.html", Resources.SchemeTest },
4747
{ "/TooltipTest.html", Resources.TooltipTest },
48+
{ "/DragDropCursorsTest.html", Resources.DragDropCursorsTest },
4849
{ "/FramedWebGLTest.html", Resources.FramedWebGLTest },
4950
{ "/MultiBindingTest.html", Resources.MultiBindingTest },
5051
{ "/ScriptedMethodsTest.html", Resources.ScriptedMethodsTest },

CefSharp.Example/Properties/Resources.Designer.cs

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CefSharp.Example/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
<data name="TooltipTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
134134
<value>..\Resources\TooltipTest.html;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
135135
</data>
136+
<data name="DragDropCursorsTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
137+
<value>..\Resources\DragDropCursorsTest.html;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
138+
</data>
136139
<data name="bootstrap_min_css" type="System.Resources.ResXFileRef, System.Windows.Forms">
137140
<value>..\Resources\bootstrap\bootstrap.min.css;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
138141
</data>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2+
<html>
3+
<head>
4+
<title>Drag&Drop Cursors Test</title>
5+
<style>
6+
.dropzone {
7+
width: 80px;
8+
height: 70px;
9+
padding: 10px;
10+
display: inline-block;
11+
border: 1px solid #aaaaaa;
12+
background: white;
13+
}
14+
15+
#drag {
16+
width: 200px;
17+
height: 50px;
18+
padding: 10px;
19+
border: 1px solid #aaaaaa;
20+
background: wheat;
21+
}
22+
</style>
23+
<script>
24+
function allowDrop(ev, effect) {
25+
ev.dataTransfer.dropEffect = effect;
26+
ev.preventDefault();
27+
}
28+
29+
function drag(ev) {
30+
ev.dataTransfer.effectAllowed = "all";
31+
ev.dataTransfer.setData("text/plain", ev.target.id);
32+
}
33+
34+
function drop(ev) {
35+
ev.preventDefault();
36+
var data = ev.dataTransfer.getData("text/plain");
37+
var element = document.getElementById(data);
38+
if (element) {
39+
ev.target.appendChild(element);
40+
}
41+
alert(ev.dataTransfer.dropEffect + " | " + data);
42+
}
43+
</script>
44+
</head>
45+
<body>
46+
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'none')">None</div>
47+
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'copy')">Copy</div>
48+
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'move')">Move</div>
49+
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'link')">Link</div>
50+
<br>
51+
<br>
52+
<div id="drag" draggable="true" ondragstart="drag(event)">Drag me over the drop zones</div>
53+
</body>
54+
</html>

CefSharp.Wpf.Example/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<MenuItem Header="_LegacyBinding Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.LegacyBindingTestUrl}}"/>
3030
<MenuItem Header="_List Plugins" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.PluginsTestUrl}}"/>
3131
<MenuItem Header="_Tooltip Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.TooltipTestUrl}}"/>
32+
<MenuItem Header="D_rag&amp;Drop Cursors Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.DragDropCursorsTestUrl}}"/>
3233
<MenuItem Header="_Popup Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.PopupParentUrl}}"/>
3334
<MenuItem Header="_Popup Test Custom Scheme" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.PopupTestUrl}}"/>
3435
<MenuItem Header="_Basic Scheme Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.BasicSchemeTestUrl}}"/>

CefSharp.Wpf/CefSharp.Wpf.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
</ItemGroup>
8080
<ItemGroup>
8181
<Compile Include="CefSettings.cs" />
82+
<Compile Include="Internals\DragOperationMaskExtensions.cs" />
8283
<Compile Include="Internals\MonitorInfo.cs" />
8384
<Compile Include="Internals\MonitorInfoEx.cs" />
8485
<Compile Include="Internals\RectStruct.cs" />

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ public class ChromiumWebBrowser : Control, IRenderWebBrowser, IWpfWebBrowser
108108
/// we can reuse the drag data provided from CEF
109109
/// </summary>
110110
private IDragData currentDragData;
111-
111+
/// <summary>
112+
/// Keep the current drag&drop effects to return the appropriate effects on drag over.
113+
/// </summary>
114+
private DragDropEffects currentDragDropEffects;
112115
/// <summary>
113116
/// A flag that indicates whether or not the designer is active
114117
/// NOTE: Needs to be static for OnApplicationExit
@@ -798,14 +801,14 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo
798801
if (browser != null)
799802
{
800803
//DoDragDrop will fire DragEnter event
801-
var result = DragDrop.DoDragDrop(this, dataObject, GetDragEffects(allowedOps));
804+
var result = DragDrop.DoDragDrop(this, dataObject, allowedOps.GetDragEffects());
802805

803806
//DragData was stored so when DoDragDrop fires DragEnter we reuse a clone of the IDragData provided here
804807
currentDragData = null;
805808

806809
//If result == DragDropEffects.None then we'll send DragOperationsMask.None
807810
//effectively cancelling the drag operation
808-
browser.GetHost().DragSourceEndedAt(x, y, GetDragOperationsMask(result));
811+
browser.GetHost().DragSourceEndedAt(x, y, result.GetDragOperationsMask());
809812
browser.GetHost().DragSourceSystemDragEnded();
810813
}
811814
});
@@ -824,7 +827,7 @@ void IRenderWebBrowser.UpdateDragCursor(DragOperationsMask operation)
824827
/// <param name="operation">describes the allowed operation (none, move, copy, link). </param>
825828
protected virtual void UpdateDragCursor(DragOperationsMask operation)
826829
{
827-
//TODO: Someone should implement this
830+
currentDragDropEffects = operation.GetDragEffects();
828831
}
829832

830833
/// <summary>
@@ -1550,7 +1553,7 @@ private void OnDrop(object sender, DragEventArgs e)
15501553
if (browser != null)
15511554
{
15521555
var mouseEvent = GetMouseEvent(e);
1553-
var effect = GetDragOperationsMask(e.AllowedEffects);
1556+
var effect = e.AllowedEffects.GetDragOperationsMask();
15541557

15551558
browser.GetHost().DragTargetDragOver(mouseEvent, effect);
15561559
browser.GetHost().DragTargetDragDrop(mouseEvent);
@@ -1579,8 +1582,10 @@ private void OnDragOver(object sender, DragEventArgs e)
15791582
{
15801583
if (browser != null)
15811584
{
1582-
browser.GetHost().DragTargetDragOver(GetMouseEvent(e), GetDragOperationsMask(e.AllowedEffects));
1585+
browser.GetHost().DragTargetDragOver(GetMouseEvent(e), e.AllowedEffects.GetDragOperationsMask());
15831586
}
1587+
e.Effects = currentDragDropEffects;
1588+
e.Handled = true;
15841589
}
15851590

15861591
/// <summary>
@@ -1593,7 +1598,7 @@ private void OnDragEnter(object sender, DragEventArgs e)
15931598
if (browser != null)
15941599
{
15951600
var mouseEvent = GetMouseEvent(e);
1596-
var effect = GetDragOperationsMask(e.AllowedEffects);
1601+
var effect = e.AllowedEffects.GetDragOperationsMask();
15971602

15981603
//DoDragDrop will fire this handler for internally sourced Drag/Drop operations
15991604
//we use the existing IDragData (cloned copy)
@@ -1604,62 +1609,6 @@ private void OnDragEnter(object sender, DragEventArgs e)
16041609
}
16051610
}
16061611

1607-
/// <summary>
1608-
/// Converts .NET drag drop effects to CEF Drag Operations
1609-
/// </summary>
1610-
/// <param name="dragDropEffects">The drag drop effects.</param>
1611-
/// <returns>DragOperationsMask.</returns>
1612-
/// s
1613-
private static DragOperationsMask GetDragOperationsMask(DragDropEffects dragDropEffects)
1614-
{
1615-
var operations = DragOperationsMask.None;
1616-
1617-
if (dragDropEffects.HasFlag(DragDropEffects.All))
1618-
{
1619-
operations |= DragOperationsMask.Every;
1620-
}
1621-
if (dragDropEffects.HasFlag(DragDropEffects.Copy))
1622-
{
1623-
operations |= DragOperationsMask.Copy;
1624-
}
1625-
if (dragDropEffects.HasFlag(DragDropEffects.Move))
1626-
{
1627-
operations |= DragOperationsMask.Move;
1628-
}
1629-
if (dragDropEffects.HasFlag(DragDropEffects.Link))
1630-
{
1631-
operations |= DragOperationsMask.Link;
1632-
}
1633-
1634-
return operations;
1635-
}
1636-
1637-
/// <summary>
1638-
/// Gets the drag effects.
1639-
/// </summary>
1640-
/// <param name="mask">The mask.</param>
1641-
/// <returns>DragDropEffects.</returns>
1642-
private static DragDropEffects GetDragEffects(DragOperationsMask mask)
1643-
{
1644-
if ((mask & DragOperationsMask.Every) == DragOperationsMask.Every)
1645-
{
1646-
return DragDropEffects.All;
1647-
}
1648-
if ((mask & DragOperationsMask.Copy) == DragOperationsMask.Copy)
1649-
{
1650-
return DragDropEffects.Copy;
1651-
}
1652-
if ((mask & DragOperationsMask.Move) == DragOperationsMask.Move)
1653-
{
1654-
return DragDropEffects.Move;
1655-
}
1656-
if ((mask & DragOperationsMask.Link) == DragOperationsMask.Link)
1657-
{
1658-
return DragDropEffects.Link;
1659-
}
1660-
return DragDropEffects.None;
1661-
}
1662-
16631612
/// <summary>
16641613
/// PresentationSource changed handler.
16651614
/// </summary>

0 commit comments

Comments
 (0)