A start. Need to test popups and test on high dpi screen.

This commit is contained in:
Bjarte Skogøy
2015-08-18 14:17:20 +02:00
parent 65d44b3962
commit 4bbd9e7b09
5 changed files with 31 additions and 14 deletions
@@ -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;
+5 -7
View File
@@ -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;
}
+14 -3
View File
@@ -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 };
}
}
}
}
+11 -1
View File
@@ -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;
}
+1 -1
View File
@@ -8,6 +8,6 @@ namespace CefSharp
{
public interface IBitmapFactory
{
BitmapInfo CreateBitmap(bool isPopup);
BitmapInfo CreateBitmap(bool isPopup, double dpiScale);
}
}