Skip to content

Commit 8f78977

Browse files
committed
Minor cleanup of #162.
1 parent c1e2dc3 commit 8f78977

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CefSharp.Wpf/WebView.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,10 @@ namespace CefSharp
650650
Content = _image = gcnew Image();
651651
RenderOptions::SetBitmapScalingMode(_image, BitmapScalingMode::NearestNeighbor);
652652

653-
// If the display properties is set to 125%, M11 and M22 will be 1.25.
654-
auto factorX = _matrix->M11;
655-
auto factorY = _matrix->M22;
656-
auto scaleX = 1 / factorX;
657-
auto scaleY = 1 / factorY;
658-
_image->LayoutTransform = gcnew ScaleTransform(scaleX, scaleY);
653+
if (IsNonStandardDpi())
654+
{
655+
_image->LayoutTransform = GetScaleTransform();
656+
}
659657

660658
_popup = gcnew Popup();
661659
_popup->Child = _popupImage = gcnew Image();
@@ -678,6 +676,22 @@ namespace CefSharp
678676
_popupImage->VerticalAlignment = ::VerticalAlignment::Top;
679677
}
680678

679+
bool WebView::IsNonStandardDpi()
680+
{
681+
// If the display properties is set to e.g. 125%, M11 and M22 will be 1.25.
682+
return _matrix->M11 != 1 ||
683+
_matrix->M22 != 1;
684+
}
685+
686+
Transform^ WebView::GetScaleTransform()
687+
{
688+
auto factorX = _matrix->M11;
689+
auto factorY = _matrix->M22;
690+
auto scaleX = 1 / factorX;
691+
auto scaleY = 1 / factorY;
692+
return gcnew ScaleTransform(scaleX, scaleY);
693+
}
694+
681695
void WebView::SetCursor(IntPtr cursor)
682696
{
683697
SafeFileHandle^ handle = gcnew SafeFileHandle(cursor, false);

CefSharp.Wpf/WebView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ namespace CefSharp
9090

9191
void HidePopup();
9292
void AddSourceHook();
93+
bool IsNonStandardDpi();
94+
Transform^ GetScaleTransform();
9395

9496
public protected: // a.k.a protected internal
9597
virtual void OnVisualParentChanged(DependencyObject^ oldParent) override;

0 commit comments

Comments
 (0)