mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
WPF - Workaround for Cursors not loading correctly
- For cursors that are embedded in libcef.dll the OnCursorChange method is passing in IntPtr.Zero so we're unable to load the cursor. This commit adds a manual mapping of CursorType to resource Id and loads the cursors manually - Adds a basic test to assert the cursors load, should validate if the resource ids change This needs to be fixed upstream https://bitbucket.org/chromiumembedded/cef/issues/3270/osr-pan-icon-missing-when-pressing-the Test url https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#values Issue #4021
This commit is contained in:
@@ -60,5 +60,23 @@ namespace CefSharp
|
||||
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle & ~WS_EX_NOACTIVATE);
|
||||
}
|
||||
}
|
||||
|
||||
IntPtr NativeMethodWrapper::LoadCursorFromLibCef(int resourceIdentifier)
|
||||
{
|
||||
auto moduleName = L"libcef.dll";
|
||||
|
||||
HMODULE hModule = GetModuleHandle(moduleName);
|
||||
|
||||
if (hModule == nullptr)
|
||||
{
|
||||
return IntPtr::Zero;
|
||||
}
|
||||
|
||||
auto lpCursorName = MAKEINTRESOURCE(resourceIdentifier);
|
||||
|
||||
auto cursor = LoadCursor(hModule, lpCursorName);
|
||||
|
||||
return static_cast<IntPtr>(cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace CefSharp
|
||||
static void SetWindowPosition(IntPtr handle, int x, int y, int width, int height);
|
||||
static void SetWindowParent(IntPtr child, IntPtr newParent);
|
||||
static void RemoveExNoActivateStyle(IntPtr browserHwnd);
|
||||
static IntPtr LoadCursorFromLibCef(int resourceIdentifier);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,5 +38,10 @@ namespace CefSharp
|
||||
{
|
||||
CefSharp.Core.NativeMethodWrapper.RemoveExNoActivateStyle(browserHwnd);
|
||||
}
|
||||
|
||||
public static IntPtr LoadCursorFromLibCef(int resourceIdentifier)
|
||||
{
|
||||
return CefSharp.Core.NativeMethodWrapper.LoadCursorFromLibCef(resourceIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright © 2022 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;
|
||||
using CefSharp.Enums;
|
||||
using CefSharp.Wpf.Internals;
|
||||
using Xunit;
|
||||
|
||||
namespace CefSharp.Test.Wpf
|
||||
{
|
||||
//NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle
|
||||
/// <summary>
|
||||
/// Issue #4021
|
||||
/// Validate Cursor resource Ids
|
||||
/// </summary>
|
||||
[Collection(CefSharpFixtureCollection.Key)]
|
||||
public class EmbeddedCursorLoadTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(CursorType.Alias)]
|
||||
[InlineData(CursorType.Cell)]
|
||||
[InlineData(CursorType.ColumnResize)]
|
||||
[InlineData(CursorType.Copy)]
|
||||
[InlineData(CursorType.Grab)]
|
||||
[InlineData(CursorType.Grabbing)]
|
||||
[InlineData(CursorType.EastPanning)]
|
||||
[InlineData(CursorType.MiddlePanning)]
|
||||
[InlineData(CursorType.MiddlePanningHorizontal)]
|
||||
[InlineData(CursorType.MiddlePanningVertical)]
|
||||
[InlineData(CursorType.NorthPanning)]
|
||||
[InlineData(CursorType.NortheastPanning)]
|
||||
[InlineData(CursorType.NorthwestPanning)]
|
||||
[InlineData(CursorType.SouthPanning)]
|
||||
[InlineData(CursorType.SoutheastPanning)]
|
||||
[InlineData(CursorType.SouthwestPanning)]
|
||||
[InlineData(CursorType.WestPanning)]
|
||||
[InlineData(CursorType.RowResize)]
|
||||
[InlineData(CursorType.VerticalText)]
|
||||
[InlineData(CursorType.ZoomIn)]
|
||||
[InlineData(CursorType.ZoomOut)]
|
||||
public void CanGetEmbeddedCursors(CursorType cursorType)
|
||||
{
|
||||
var actual = EmbeddedCursor.TryLoadCursor(cursorType, out IntPtr cursorPtr);
|
||||
|
||||
Assert.True(actual);
|
||||
Assert.NotEqual(IntPtr.Zero, cursorPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1007,7 +1007,16 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
UiThreadRunAsync(() =>
|
||||
{
|
||||
Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false));
|
||||
//Workaround for upstream issue
|
||||
//See #4021
|
||||
if (EmbeddedCursor.TryLoadCursor(type, out IntPtr cursorHandle))
|
||||
{
|
||||
Cursor = CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, ownsHandle: false));
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// Copyright © 2022 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;
|
||||
using System.Collections.Generic;
|
||||
using CefSharp.Enums;
|
||||
|
||||
namespace CefSharp.Wpf.Internals
|
||||
{
|
||||
// Workaround for upstream issue
|
||||
// It's possible resources Ids might change between versions, so this might need to be updated
|
||||
// for different builds, will need to test after upgrading
|
||||
// See #4021
|
||||
public static class EmbeddedCursor
|
||||
{
|
||||
//const int IDC_ALIAS = 35610;
|
||||
//const int IDC_CELL = 35611;
|
||||
//const int IDC_COLRESIZE = 35612;
|
||||
//const int IDC_COPYCUR = 35613;
|
||||
//const int IDC_HAND_GRAB = 35614;
|
||||
//const int IDC_HAND_GRABBING = 35615;
|
||||
//const int IDC_PAN_EAST = 35616;
|
||||
//const int IDC_PAN_MIDDLE = 35617;
|
||||
//const int IDC_PAN_MIDDLE_HORIZONTAL = 35618;
|
||||
//const int IDC_PAN_MIDDLE_VERTICAL = 35619;
|
||||
//const int IDC_PAN_NORTH = 35620;
|
||||
//const int IDC_PAN_NORTH_EAST = 35621;
|
||||
//const int IDC_PAN_NORTH_WEST = 35622;
|
||||
//const int IDC_PAN_SOUTH = 35623;
|
||||
//const int IDC_PAN_SOUTH_EAST = 35624;
|
||||
//const int IDC_PAN_SOUTH_WEST = 35625;
|
||||
//const int IDC_PAN_WEST = 35626;
|
||||
//const int IDC_ROWRESIZE = 35627;
|
||||
//const int IDC_VERTICALTEXT = 35628;
|
||||
//const int IDC_ZOOMIN = 35629;
|
||||
//const int IDC_ZOOMOUT = 35630;
|
||||
|
||||
private static Dictionary<CursorType, int> EmbeddedCursors = new Dictionary<CursorType, int>
|
||||
{
|
||||
{ CursorType.Alias, 35610 },
|
||||
{ CursorType.Cell, 35611 },
|
||||
{ CursorType.ColumnResize, 35612 },
|
||||
{ CursorType.Copy, 35613 },
|
||||
{ CursorType.Grab, 35614 },
|
||||
{ CursorType.Grabbing, 35615 },
|
||||
{ CursorType.EastPanning, 35616 },
|
||||
{ CursorType.MiddlePanning, 35617 },
|
||||
{ CursorType.MiddlePanningHorizontal, 35618 },
|
||||
{ CursorType.MiddlePanningVertical, 35619 },
|
||||
{ CursorType.NorthPanning, 35620 },
|
||||
{ CursorType.NortheastPanning, 35621 },
|
||||
{ CursorType.NorthwestPanning, 35622 },
|
||||
{ CursorType.SouthPanning, 35623 },
|
||||
{ CursorType.SoutheastPanning, 35624 },
|
||||
{ CursorType.SouthwestPanning, 35625 },
|
||||
{ CursorType.WestPanning, 35626 },
|
||||
{ CursorType.RowResize, 35627 },
|
||||
{ CursorType.VerticalText, 35628 },
|
||||
{ CursorType.ZoomIn, 35629 },
|
||||
{ CursorType.ZoomOut, 35630 }
|
||||
};
|
||||
|
||||
public static bool TryLoadCursor(CursorType cursorType, out IntPtr cursor)
|
||||
{
|
||||
cursor = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
if (EmbeddedCursors.TryGetValue(cursorType, out int key))
|
||||
{
|
||||
cursor = NativeMethodWrapper.LoadCursorFromLibCef(key);
|
||||
|
||||
return cursor != IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user