Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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.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="DragCursorProvider.cs" />
<Compile Include="Internals\MonitorInfo.cs" />
<Compile Include="Internals\MonitorInfoEx.cs" />
<Compile Include="Internals\RectStruct.cs" />
Expand Down
3 changes: 2 additions & 1 deletion CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,8 @@ 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
var dragCursor = DragCursorProvider.GetCursor(operation);
UiThreadRunSync(() => Mouse.SetCursor(dragCursor));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is run Sync? If so please add a comment as to the reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an attempt to reduce the flicker, but it still exists.

}

/// <summary>
Expand Down
56 changes: 56 additions & 0 deletions CefSharp.Wpf/DragCursorProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Input;
using System.Windows.Interop;
using CefSharp.Enums;
using Microsoft.Win32.SafeHandles;

namespace CefSharp.Wpf
{

internal static class DragCursorProvider
{
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);

[DllImport("user32.dll")]
private static extern IntPtr LoadCursor(IntPtr hInstance, ushort lpCursorName);

private static readonly Dictionary<DragOperationsMask, Cursor> DragCursors;

static DragCursorProvider()
{
var library = LoadLibrary("ole32.dll");
DragCursors = new Dictionary<DragOperationsMask, Cursor>()
{
{ DragOperationsMask.None, GetCursorFromLib(library, 1) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this None cursor and Cursors.None? Be better to use the built in one where possible

https://docs.microsoft.com/en-us/dotnet/api/system.windows.input.cursors.none?view=netframework-4.7.2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursors.None is an invisible cursor as the None in drag&drop is a forbidden one.

{ DragOperationsMask.Move, GetCursorFromLib(library, 2) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Move substantially different from SizeAll? Be better to use the built in cursor where possible.

https://docs.microsoft.com/en-us/dotnet/api/system.windows.input.cursors.sizeall?view=netframework-4.7.2#System_Windows_Input_Cursors_SizeAll

Copy link
Contributor Author

@joaompneves joaompneves Mar 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drag&drop cursors don't exist in the built-in collection.

These are the ones we get from ole32:
Cursors

{ DragOperationsMask.Copy, GetCursorFromLib(library, 3) },
{ DragOperationsMask.Link, GetCursorFromLib(library, 4) }
// TODO: support black cursors
};
}

private static Cursor GetCursorFromLib(IntPtr library, ushort cursorIndex)
{
var cursorHandle = LoadCursor(library, cursorIndex);
return CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, false));
}

/// <summary>
/// Get the Windows cursor for the drag effect specified.
/// </summary>
/// <param name="operation"></param>
/// <returns>The drop cursor based on the specified drag operation effect</returns>
public static Cursor GetCursor(DragOperationsMask operation)
{
Cursor cursor;
if (DragCursors.TryGetValue(operation, out cursor))
{
return cursor;
}
return Cursors.Arrow;
}
}
}