Skip to content

Commit 08b6c05

Browse files
committed
WPF - Add Experimental ChromiumWebBrowserWithMouseCapture
Based on #2871 Use CaptureMouse/ReleaseMouseCapture instead as there's an additional check in ReleaseMouseCapture https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/UIElement.cs,d6873c5315db5dbb,references Issue #2258
1 parent bb5b60b commit 08b6c05

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

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="Experimental\ChromiumWebBrowserWithMouseCapture.cs" />
8283
<Compile Include="Experimental\ChromiumWebBrowserWithTouchSupport.cs" />
8384
<Compile Include="Internals\DragOperationMaskExtensions.cs" />
8485
<Compile Include="Internals\ImeHandler.cs" />
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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;
6+
using System.Windows.Input;
7+
8+
namespace CefSharp.Wpf.Experimental
9+
{
10+
/// <summary>
11+
/// ChromiumWebBrowserWithMouseCapture - Captures the mouse upon left button down to provide
12+
/// for dragging the scrollbars/dragging the page down outside of the browser bounds.
13+
/// See https://github.com/cefsharp/CefSharp/issues/2258 for more details.
14+
/// If using on a Device that has a touch screen you will need to disable WPF StylusAndTouchSupport
15+
/// until https://github.com/dotnet/wpf/issues/1323 is resolved.
16+
/// </summary>
17+
[Obsolete("Only here for testing purposes, will be removed soon as https://github.com/cefsharp/CefSharp/issues/2258 is resolved")]
18+
public class ChromiumWebBrowserWithMouseCapture : ChromiumWebBrowser
19+
{
20+
protected override void OnMouseDown(MouseButtonEventArgs e)
21+
{
22+
base.OnMouseDown(e);
23+
24+
//We should only need to capture the left button exiting the browser
25+
if (e.ChangedButton == MouseButton.Left && e.LeftButton == MouseButtonState.Pressed)
26+
{
27+
//Capture/Release Mouse to allow for scrolling outside bounds of browser control (#2870, #2060).
28+
//Known issue when capturing and the device has a touch screen, to workaround this issue
29+
//disable WPF StylusAndTouchSupport see for details https://github.com/dotnet/wpf/issues/1323#issuecomment-513870984
30+
CaptureMouse();
31+
}
32+
}
33+
34+
protected override void OnMouseUp(MouseButtonEventArgs e)
35+
{
36+
base.OnMouseUp(e);
37+
38+
if (e.ChangedButton == MouseButton.Left && e.LeftButton == MouseButtonState.Released)
39+
{
40+
//Release the mouse capture that we grabbed on mouse down.
41+
//We won't get here if e.g. the right mouse button is pressed and released
42+
//while the left is still held, but in that case the left mouse capture seems
43+
//to be released implicitly (even without the left mouse SendMouseClickEvent in leave below)
44+
//Use ReleaseMouseCapture over Mouse.Capture(null); as it has additional Mouse.Captured == this check
45+
ReleaseMouseCapture();
46+
}
47+
}
48+
49+
}
50+
}

0 commit comments

Comments
 (0)