diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index a325b0c821..84e095653a 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -63,10 +63,6 @@ public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrow /// private int browserInitialized; /// - /// The matrix - /// - private Matrix matrix; - /// /// The image that represents this browser instances /// private Image image; @@ -339,6 +335,13 @@ public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrow /// public bool CanExecuteJavascriptInMainFrame { get; private set; } + /// + /// The dpi scale factor, if the browser has already been initialized + /// you must manually call IBrowserHost.NotifyScreenInfoChanged for the + /// browser to be notified of the change. + /// + public double DpiScaleFactor { get; set; } + /// /// Initializes static members of the class. /// @@ -568,7 +571,7 @@ ScreenInfo IRenderWebBrowser.GetScreenInfo() /// ScreenInfo containing the current DPI scale factor protected virtual ScreenInfo GetScreenInfo() { - var screenInfo = new ScreenInfo(scaleFactor: (float)matrix.M11); + var screenInfo = new ScreenInfo(scaleFactor: (float)DpiScaleFactor); return screenInfo; } @@ -636,7 +639,7 @@ protected virtual BitmapInfo CreateBitmapInfo(bool isPopup) { throw new Exception("BitmapFactory cannot be null"); } - return BitmapFactory.CreateBitmap(isPopup, matrix.M11); + return BitmapFactory.CreateBitmap(isPopup, DpiScaleFactor); } /// @@ -1514,18 +1517,16 @@ private void PresentationSourceChangedHandler(object sender, SourceChangedEventA if (source != null) { - var notifyDpiChanged = !matrix.Equals(source.CompositionTarget.TransformToDevice); + var matrix = source.CompositionTarget.TransformToDevice; + var notifyDpiChanged = DpiScaleFactor > 0 && !DpiScaleFactor.Equals(matrix.M11); - matrix = source.CompositionTarget.TransformToDevice; + DpiScaleFactor = source.CompositionTarget.TransformToDevice.M11; sourceHook = SourceHook; source.AddHook(sourceHook); - if (notifyDpiChanged) + if (notifyDpiChanged && browser != null) { - if(browser != null) - { - browser.GetHost().NotifyScreenInfoChanged(); - } + browser.GetHost().NotifyScreenInfoChanged(); } var window = source.RootVisual as Window; @@ -1860,8 +1861,8 @@ private void SetPopupSizeAndPositionImpl(int width, int height, int x, int y) var popupOffset = new Point(x, y); var locationFromScreen = PointToScreen(popupOffset); - popup.HorizontalOffset = locationFromScreen.X / matrix.M11; - popup.VerticalOffset = locationFromScreen.Y / matrix.M22; + popup.HorizontalOffset = locationFromScreen.X / DpiScaleFactor; + popup.VerticalOffset = locationFromScreen.Y / DpiScaleFactor; } ///