Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CefSharp.Example/CefExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class CefExample
public const string BasicSchemeTestUrl = BaseUrl + "/SchemeTest.html";
public const string ResponseFilterTestUrl = BaseUrl + "/ResponseFilterTest.html";
public const string DraggableRegionTestUrl = BaseUrl + "/DraggableRegionTest.html";
public const string DragDropCursorsTestUrl = BaseUrl + "/DragDropCursorsTest.html";
public const string CssAnimationTestUrl = BaseUrl + "/CssAnimationTest.html";
public const string CdmSupportTestUrl = BaseUrl + "/CdmSupportTest.html";
public const string TestResourceUrl = "http://test/resource/load";
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Example/CefSharp.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<None Include="Resources\assets\js\shBrushJScript.js" />
<Content Include="Resources\assets\js\shCore.js" />
<Content Include="Resources\BindingTestSingle.html" />
<Content Include="Resources\DragDropCursorsTest.html" />
<Content Include="Resources\LegacyBindingTest.html" />
<Content Include="Resources\CdmSupportTest.html" />
<Content Include="Resources\CssAnimation.html" />
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Example/CefSharpSchemeHandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static CefSharpSchemeHandlerFactory()
{ "/ScriptedMethodsTest.html", Resources.ScriptedMethodsTest },
{ "/ResponseFilterTest.html", Resources.ResponseFilterTest },
{ "/DraggableRegionTest.html", Resources.DraggableRegionTest },
{ "/DragDropCursorsTest.html", Resources.DragDropCursorsTest },
{ "/CssAnimationTest.html", Resources.CssAnimation },
{ "/CdmSupportTest.html", Resources.CdmSupportTest },
{ "/Recaptcha.html", Resources.Recaptcha },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static InMemorySchemeAndResourceHandlerFactory()
{ "/PopupTest.html", Resources.PopupTest },
{ "/SchemeTest.html", Resources.SchemeTest },
{ "/TooltipTest.html", Resources.TooltipTest },
{ "/DragDropCursorsTest.html", Resources.DragDropCursorsTest },
{ "/FramedWebGLTest.html", Resources.FramedWebGLTest },
{ "/MultiBindingTest.html", Resources.MultiBindingTest },
{ "/ScriptedMethodsTest.html", Resources.ScriptedMethodsTest },
Expand Down
32 changes: 31 additions & 1 deletion CefSharp.Example/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CefSharp.Example/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
<data name="TooltipTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\TooltipTest.html;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="DragDropCursorsTest" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\DragDropCursorsTest.html;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="bootstrap_min_css" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\bootstrap\bootstrap.min.css;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
Expand Down
54 changes: 54 additions & 0 deletions CefSharp.Example/Resources/DragDropCursorsTest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Drag&Drop Cursors Test</title>
<style>
.dropzone {
width: 80px;
height: 70px;
padding: 10px;
display: inline-block;
border: 1px solid #aaaaaa;
background: white;
}

#drag {
width: 200px;
height: 50px;
padding: 10px;
border: 1px solid #aaaaaa;
background: wheat;
}
</style>
<script>
function allowDrop(ev, effect) {
ev.dataTransfer.dropEffect = effect;
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.effectAllowed = "all";
ev.dataTransfer.setData("text/plain", ev.target.id);
}

function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text/plain");
var element = document.getElementById(data);
if (element) {
ev.target.appendChild(element);
}
alert(ev.dataTransfer.dropEffect + " | " + data);
}
</script>
</head>
<body>
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'none')">None</div>
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'copy')">Copy</div>
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'move')">Move</div>
<div class="dropzone" ondrop="drop(event)" ondragover="allowDrop(event, 'link')">Link</div>
<br>
<br>
<div id="drag" draggable="true" ondragstart="drag(event)">Drag me over the drop zones</div>
</body>
</html>
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<MenuItem Header="_LegacyBinding Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.LegacyBindingTestUrl}}"/>
<MenuItem Header="_List Plugins" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.PluginsTestUrl}}"/>
<MenuItem Header="_Tooltip Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.TooltipTestUrl}}"/>
<MenuItem Header="D_rag&amp;Drop Cursors Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.DragDropCursorsTestUrl}}"/>
<MenuItem Header="_Popup Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.PopupParentUrl}}"/>
<MenuItem Header="_Popup Test Custom Scheme" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.PopupTestUrl}}"/>
<MenuItem Header="_Basic Scheme Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.BasicSchemeTestUrl}}"/>
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf/CefSharp.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CefSettings.cs" />
<Compile Include="Internals\DragOperationMaskExtensions.cs" />
<Compile Include="Internals\MonitorInfo.cs" />
<Compile Include="Internals\MonitorInfoEx.cs" />
<Compile Include="Internals\RectStruct.cs" />
Expand Down
75 changes: 12 additions & 63 deletions CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public class ChromiumWebBrowser : Control, IRenderWebBrowser, IWpfWebBrowser
/// we can reuse the drag data provided from CEF
/// </summary>
private IDragData currentDragData;

/// <summary>
/// Keep the current drag&drop effects to return the appropriate effects on drag over.
/// </summary>
private DragDropEffects currentDragDropEffects;
/// <summary>
/// A flag that indicates whether or not the designer is active
/// NOTE: Needs to be static for OnApplicationExit
Expand Down Expand Up @@ -787,14 +790,14 @@ bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask allo
if (browser != null)
{
//DoDragDrop will fire DragEnter event
var result = DragDrop.DoDragDrop(this, dataObject, GetDragEffects(allowedOps));
var result = DragDrop.DoDragDrop(this, dataObject, allowedOps.GetDragEffects());

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

//If result == DragDropEffects.None then we'll send DragOperationsMask.None
//effectively cancelling the drag operation
browser.GetHost().DragSourceEndedAt(x, y, GetDragOperationsMask(result));
browser.GetHost().DragSourceEndedAt(x, y, result.GetDragOperationsMask());
browser.GetHost().DragSourceSystemDragEnded();
}
});
Expand All @@ -813,7 +816,7 @@ void IRenderWebBrowser.UpdateDragCursor(DragOperationsMask operation)
/// <param name="operation">describes the allowed operation (none, move, copy, link). </param>
protected virtual void UpdateDragCursor(DragOperationsMask operation)
{
//TODO: Someone should implement this
currentDragDropEffects = operation.GetDragEffects();
}

/// <summary>
Expand Down Expand Up @@ -1524,7 +1527,7 @@ private void OnDrop(object sender, DragEventArgs e)
if (browser != null)
{
var mouseEvent = GetMouseEvent(e);
var effect = GetDragOperationsMask(e.AllowedEffects);
var effect = e.AllowedEffects.GetDragOperationsMask();

browser.GetHost().DragTargetDragOver(mouseEvent, effect);
browser.GetHost().DragTargetDragDrop(mouseEvent);
Expand Down Expand Up @@ -1553,8 +1556,10 @@ private void OnDragOver(object sender, DragEventArgs e)
{
if (browser != null)
{
browser.GetHost().DragTargetDragOver(GetMouseEvent(e), GetDragOperationsMask(e.AllowedEffects));
browser.GetHost().DragTargetDragOver(GetMouseEvent(e), e.AllowedEffects.GetDragOperationsMask());
}
e.Effects = currentDragDropEffects;
e.Handled = true;
}

/// <summary>
Expand All @@ -1567,7 +1572,7 @@ private void OnDragEnter(object sender, DragEventArgs e)
if (browser != null)
{
var mouseEvent = GetMouseEvent(e);
var effect = GetDragOperationsMask(e.AllowedEffects);
var effect = e.AllowedEffects.GetDragOperationsMask();

//DoDragDrop will fire this handler for internally sourced Drag/Drop operations
//we use the existing IDragData (cloned copy)
Expand All @@ -1578,62 +1583,6 @@ private void OnDragEnter(object sender, DragEventArgs e)
}
}

/// <summary>
/// Converts .NET drag drop effects to CEF Drag Operations
/// </summary>
/// <param name="dragDropEffects">The drag drop effects.</param>
/// <returns>DragOperationsMask.</returns>
/// s
private static DragOperationsMask GetDragOperationsMask(DragDropEffects dragDropEffects)
{
var operations = DragOperationsMask.None;

if (dragDropEffects.HasFlag(DragDropEffects.All))
{
operations |= DragOperationsMask.Every;
}
if (dragDropEffects.HasFlag(DragDropEffects.Copy))
{
operations |= DragOperationsMask.Copy;
}
if (dragDropEffects.HasFlag(DragDropEffects.Move))
{
operations |= DragOperationsMask.Move;
}
if (dragDropEffects.HasFlag(DragDropEffects.Link))
{
operations |= DragOperationsMask.Link;
}

return operations;
}

/// <summary>
/// Gets the drag effects.
/// </summary>
/// <param name="mask">The mask.</param>
/// <returns>DragDropEffects.</returns>
private static DragDropEffects GetDragEffects(DragOperationsMask mask)
{
if ((mask & DragOperationsMask.Every) == DragOperationsMask.Every)
{
return DragDropEffects.All;
}
if ((mask & DragOperationsMask.Copy) == DragOperationsMask.Copy)
{
return DragDropEffects.Copy;
}
if ((mask & DragOperationsMask.Move) == DragOperationsMask.Move)
{
return DragDropEffects.Move;
}
if ((mask & DragOperationsMask.Link) == DragOperationsMask.Link)
{
return DragDropEffects.Link;
}
return DragDropEffects.None;
}

/// <summary>
/// PresentationSource changed handler.
/// </summary>
Expand Down
68 changes: 68 additions & 0 deletions CefSharp.Wpf/Internals/DragOperationMaskExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright © 2019 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System.Windows;
using CefSharp.Enums;

namespace CefSharp.Wpf.Internals
{
internal static class DragOperationMaskExtensions
{
/// <summary>
/// Converts .NET drag drop effects to CEF Drag Operations
/// </summary>
/// <param name="dragDropEffects">The drag drop effects.</param>
/// <returns>DragOperationsMask.</returns>
public static DragOperationsMask GetDragOperationsMask(this DragDropEffects dragDropEffects)
{
var operations = DragOperationsMask.None;

if (dragDropEffects.HasFlag(DragDropEffects.All))
{
operations |= DragOperationsMask.Every;
}
if (dragDropEffects.HasFlag(DragDropEffects.Copy))
{
operations |= DragOperationsMask.Copy;
}
if (dragDropEffects.HasFlag(DragDropEffects.Move))
{
operations |= DragOperationsMask.Move;
}
if (dragDropEffects.HasFlag(DragDropEffects.Link))
{
operations |= DragOperationsMask.Link;
}

return operations;
}

/// <summary>
/// Gets the drag effects.
/// </summary>
/// <param name="mask">The mask.</param>
/// <returns>DragDropEffects.</returns>
public static DragDropEffects GetDragEffects(this DragOperationsMask mask)
{
if ((mask & DragOperationsMask.Every) == DragOperationsMask.Every)
{
// return all effects (!= DragDropEffects.All, which doesn't include Link)
return DragDropEffects.Scroll | DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link;
}
if ((mask & DragOperationsMask.Copy) == DragOperationsMask.Copy)
{
return DragDropEffects.Copy;
}
if ((mask & DragOperationsMask.Move) == DragOperationsMask.Move)
{
return DragDropEffects.Move;
}
if ((mask & DragOperationsMask.Link) == DragOperationsMask.Link)
{
return DragDropEffects.Link;
}
return DragDropEffects.None;
}
}
}