|
| 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