mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 19:25:01 +00:00
Merge pull request #337 from brock8503/dpibug
Fixing #213 popup focus behavior and DPI transform bug.
This commit is contained in:
+63
-36
@@ -38,6 +38,7 @@ namespace CefSharp.Wpf
|
||||
private Image image;
|
||||
private Image popupImage;
|
||||
private Popup popup;
|
||||
private ScaleTransform dpiTransform;
|
||||
private readonly List<IDisposable> disposables = new List<IDisposable>();
|
||||
|
||||
public BrowserSettings BrowserSettings { get; set; }
|
||||
@@ -425,38 +426,64 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
Content = image = new Image();
|
||||
|
||||
// If the display properties is set to 125%, M11 and M22 will be 1.25.
|
||||
var factorX = matrix.M11;
|
||||
var factorY = matrix.M22;
|
||||
var scaleX = 1 / factorX;
|
||||
var scaleY = 1 / factorY;
|
||||
image.LayoutTransform = new ScaleTransform(scaleX, scaleY);
|
||||
|
||||
popup = CreatePopup();
|
||||
|
||||
AddSourceHookIfNotAlreadyPresent();
|
||||
|
||||
RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.NearestNeighbor);
|
||||
CheckIsNonStandardDpi();
|
||||
|
||||
// Create main window
|
||||
Content = image = CreateImage();
|
||||
Transform(image);
|
||||
|
||||
popup = CreatePopup();
|
||||
Transform(popup);
|
||||
}
|
||||
|
||||
image.Stretch = Stretch.None;
|
||||
image.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
image.VerticalAlignment = VerticalAlignment.Top;
|
||||
private Image CreateImage()
|
||||
{
|
||||
Image temp = new Image();
|
||||
|
||||
RenderOptions.SetBitmapScalingMode(temp, BitmapScalingMode.NearestNeighbor);
|
||||
|
||||
temp.Stretch = Stretch.None;
|
||||
temp.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
temp.VerticalAlignment = VerticalAlignment.Top;
|
||||
return temp;
|
||||
}
|
||||
|
||||
private Popup CreatePopup()
|
||||
{
|
||||
var popup = new Popup
|
||||
{
|
||||
Child = popupImage = new Image(),
|
||||
Child = popupImage = CreateImage(),
|
||||
PlacementTarget = this,
|
||||
Placement = PlacementMode.Relative
|
||||
Placement = PlacementMode.Relative,
|
||||
};
|
||||
|
||||
popup.MouseEnter += this.PopupMouseEnter;
|
||||
popup.MouseLeave += this.PopupMouseLeave;
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
private void Transform(FrameworkElement element)
|
||||
{
|
||||
if (dpiTransform != null)
|
||||
{
|
||||
element.LayoutTransform = dpiTransform;
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckIsNonStandardDpi()
|
||||
{
|
||||
if (matrix != null) // make sure it's connected
|
||||
{
|
||||
dpiTransform = new ScaleTransform(
|
||||
1 / matrix.M11,
|
||||
1 / matrix.M22
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSourceHookIfNotAlreadyPresent()
|
||||
{
|
||||
if (source != null)
|
||||
@@ -583,18 +610,7 @@ namespace CefSharp.Wpf
|
||||
{
|
||||
DoInUi(() =>
|
||||
{
|
||||
popup.Width = width;
|
||||
popup.Height = height;
|
||||
|
||||
var popupOffset = new Point(x, y);
|
||||
// TODO: Port over this from CefSharp1.
|
||||
//if (popupOffsetTransform != null)
|
||||
//{
|
||||
// popupOffset = popupOffsetTransform->GeneralTransform::Transform(popupOffset);
|
||||
//}
|
||||
|
||||
popup.HorizontalOffset = popupOffset.X;
|
||||
popup.VerticalOffset = popupOffset.Y;
|
||||
this.SetPopupSizeAndPositionImpl(width, height, x, y);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -653,14 +669,9 @@ namespace CefSharp.Wpf
|
||||
popup.Height = height;
|
||||
|
||||
var popupOffset = new Point(x, y);
|
||||
// TODO: Port over this from CefSharp1.
|
||||
//if (popupOffsetTransform != null)
|
||||
//{
|
||||
// popupOffset = popupOffsetTransform->GeneralTransform::Transform(popupOffset);
|
||||
//}
|
||||
|
||||
popup.HorizontalOffset = popupOffset.X;
|
||||
popup.VerticalOffset = popupOffset.Y;
|
||||
popup.HorizontalOffset = popupOffset.X / matrix.M11;
|
||||
popup.VerticalOffset = popupOffset.Y / matrix.M22;
|
||||
}
|
||||
|
||||
private void OnTooltipTimerTick(object sender, EventArgs e)
|
||||
@@ -776,6 +787,17 @@ namespace CefSharp.Wpf
|
||||
);
|
||||
}
|
||||
|
||||
protected void PopupMouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
Focus();
|
||||
Mouse.Capture(this);
|
||||
}
|
||||
|
||||
protected void PopupMouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
Mouse.Capture(null);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
Focus();
|
||||
@@ -789,6 +811,11 @@ namespace CefSharp.Wpf
|
||||
Mouse.Capture(null);
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseEnter(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(MouseEventArgs e)
|
||||
{
|
||||
var modifiers = GetModifiers(e);
|
||||
|
||||
Reference in New Issue
Block a user