Skip to content

Commit 3dad4cc

Browse files
committed
Closes #166, or so I hope. This one turned out to be far from trivial. Will write more details in the actual issue.
1 parent f3af964 commit 3dad4cc

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

CefSharp.Wpf/WebView.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ namespace CefSharp
210210
return;
211211
}
212212

213-
Point point = e->GetPosition(this);
213+
auto deviceIndependentPosition = e->GetPosition(this);
214+
auto pixelPosition = _matrix->Transform(deviceIndependentPosition);
214215

215216
CefBrowser::MouseButtonType type;
216217
if (e->ChangedButton == MouseButton::Left)
@@ -222,7 +223,7 @@ namespace CefSharp
222223

223224
bool mouseUp = e->ButtonState == MouseButtonState::Released;
224225

225-
browser->SendMouseClickEvent((int)point.X, (int)point.Y,
226+
browser->SendMouseClickEvent((int)pixelPosition.X, (int)pixelPosition.Y,
226227
type, mouseUp, e->ClickCount);
227228
}
228229

@@ -252,7 +253,7 @@ namespace CefSharp
252253
if (TryGetCefBrowser(browser))
253254
{
254255
Point point = _matrix->Transform(Point(size.Width, size.Height));
255-
browser->SetSize(PET_VIEW, (int)size.Width, (int)size.Height);
256+
browser->SetSize(PET_VIEW, (int)point.X, (int)point.Y);
256257
HidePopup();
257258
}
258259
else
@@ -303,8 +304,9 @@ namespace CefSharp
303304
CefRefPtr<CefBrowser> browser;
304305
if (TryGetCefBrowser(browser))
305306
{
306-
Point point = e->GetPosition(this);
307-
browser->SendMouseMoveEvent((int)point.X, (int)point.Y, false);
307+
auto deviceIndependentPosition = e->GetPosition(this);
308+
auto pixelPosition = _matrix->Transform(deviceIndependentPosition);
309+
browser->SendMouseMoveEvent((int)pixelPosition.X, (int)pixelPosition.Y, false);
308310
}
309311
}
310312

@@ -313,8 +315,9 @@ namespace CefSharp
313315
CefRefPtr<CefBrowser> browser;
314316
if (TryGetCefBrowser(browser))
315317
{
316-
Point point = e->GetPosition(this);
317-
browser->SendMouseWheelEvent((int)point.X, (int)point.Y, 0, e->Delta);
318+
auto deviceIndependentPosition = e->GetPosition(this);
319+
auto pixelPosition = _matrix->Transform(deviceIndependentPosition);
320+
browser->SendMouseWheelEvent((int)pixelPosition.X, (int)pixelPosition.Y, 0, e->Delta);
318321
}
319322
}
320323

@@ -646,6 +649,13 @@ namespace CefSharp
646649

647650
Content = _image = gcnew Image();
648651
RenderOptions::SetBitmapScalingMode(_image, BitmapScalingMode::NearestNeighbor);
652+
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);
649659

650660
_popup = gcnew Popup();
651661
_popup->Child = _popupImage = gcnew Image();
@@ -789,7 +799,7 @@ namespace CefSharp
789799
}
790800

791801
void WebView::SetPopupIsOpen(bool isOpen)
792-
{
802+
{
793803
if(!Dispatcher->HasShutdownStarted) {
794804
Dispatcher->BeginInvoke(gcnew Action<bool>(this, &WebView::ShowHidePopup), DispatcherPriority::Render, isOpen);
795805
}

0 commit comments

Comments
 (0)