mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 19:54:53 +00:00
A start. Need to test popups and test on high dpi screen.
This commit is contained in:
@@ -56,8 +56,6 @@ namespace CefSharp
|
||||
// CefRenderHandler
|
||||
virtual DECL bool GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo& screen_info) OVERRIDE
|
||||
{
|
||||
return false;
|
||||
|
||||
if ((IRenderWebBrowser^)_renderWebBrowser == nullptr)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace CefSharp.Wpf
|
||||
public class ChromiumWebBrowser : ContentControl, IRenderWebBrowser, IWpfWebBrowser
|
||||
{
|
||||
private readonly List<IDisposable> disposables = new List<IDisposable>();
|
||||
private readonly ScaleTransform imageTransform;
|
||||
|
||||
private HwndSource source;
|
||||
private HwndSourceHook sourceHook;
|
||||
@@ -144,7 +143,6 @@ namespace CefSharp.Wpf
|
||||
UndoCommand = new DelegateCommand(this.Undo);
|
||||
RedoCommand = new DelegateCommand(this.Redo);
|
||||
|
||||
imageTransform = new ScaleTransform();
|
||||
managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
|
||||
|
||||
disposables.Add(managedCefBrowserAdapter);
|
||||
@@ -248,7 +246,7 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
throw new Exception("BitmapFactory cannot be null");
|
||||
}
|
||||
return BitmapFactory.CreateBitmap(isPopup);
|
||||
return BitmapFactory.CreateBitmap(isPopup, matrix.M11);
|
||||
}
|
||||
|
||||
void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo)
|
||||
@@ -764,13 +762,14 @@ namespace CefSharp.Wpf
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
var notifyDpiChanged = !matrix.Equals(source.CompositionTarget.TransformToDevice);
|
||||
|
||||
matrix = source.CompositionTarget.TransformToDevice;
|
||||
sourceHook = SourceHook;
|
||||
source.AddHook(sourceHook);
|
||||
|
||||
managedCefBrowserAdapter.NotifyScreenInfoChanged();
|
||||
imageTransform.ScaleX = 1 / matrix.M11;
|
||||
imageTransform.ScaleY = 1 / matrix.M22;
|
||||
if (notifyDpiChanged)
|
||||
managedCefBrowserAdapter.NotifyScreenInfoChanged();
|
||||
}
|
||||
}
|
||||
else if (args.OldSource != null)
|
||||
@@ -861,7 +860,6 @@ namespace CefSharp.Wpf
|
||||
img.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
img.VerticalAlignment = VerticalAlignment.Top;
|
||||
//Scale Image based on DPI settings
|
||||
img.LayoutTransform = imageTransform;
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,21 @@ namespace CefSharp.Wpf.Rendering
|
||||
{
|
||||
public class BitmapFactory : IBitmapFactory
|
||||
{
|
||||
public BitmapInfo CreateBitmap(bool isPopup)
|
||||
public const int DefaultDpi = 96;
|
||||
|
||||
public BitmapInfo CreateBitmap(bool isPopup, double dpiScale)
|
||||
{
|
||||
//return new WritableBitmapInfo { IsPopup = isPopup };
|
||||
return new InteropBitmapInfo { IsPopup = isPopup };
|
||||
if (dpiScale > 1.0)
|
||||
{
|
||||
return new WritableBitmapInfo(DefaultDpi * dpiScale, DefaultDpi * dpiScale)
|
||||
{
|
||||
IsPopup = isPopup
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new InteropBitmapInfo { IsPopup = isPopup };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,19 @@ namespace CefSharp.Wpf.Rendering
|
||||
private static readonly PixelFormat PixelFormat = PixelFormats.Bgra32;
|
||||
|
||||
public WriteableBitmap Bitmap { get; private set; }
|
||||
public double DpiX { get; private set; }
|
||||
public double DpiY { get; private set; }
|
||||
|
||||
public WritableBitmapInfo()
|
||||
: this(BitmapFactory.DefaultDpi, BitmapFactory.DefaultDpi)
|
||||
{
|
||||
}
|
||||
|
||||
public WritableBitmapInfo(double dpiX, double dpiY)
|
||||
{
|
||||
DpiX = dpiX;
|
||||
DpiY = dpiY;
|
||||
|
||||
BytesPerPixel = PixelFormat.BitsPerPixel / 8;
|
||||
DirtyRectSupport = true;
|
||||
}
|
||||
@@ -48,7 +58,7 @@ namespace CefSharp.Wpf.Rendering
|
||||
|
||||
public override BitmapSource CreateBitmap()
|
||||
{
|
||||
Bitmap = new WriteableBitmap(Width, Height, 96, 96, PixelFormat, null);
|
||||
Bitmap = new WriteableBitmap(Width, Height, DpiX, DpiY, PixelFormat, null);
|
||||
|
||||
return Bitmap;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ namespace CefSharp
|
||||
{
|
||||
public interface IBitmapFactory
|
||||
{
|
||||
BitmapInfo CreateBitmap(bool isPopup);
|
||||
BitmapInfo CreateBitmap(bool isPopup, double dpiScale);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user