Skip to content

Commit 209d75a

Browse files
committed
Edge: Use display-relative coordinates in ContextMenuRequested
1 parent ff514e8 commit 209d75a

File tree

1 file changed

+23
-4
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser

1 file changed

+23
-4
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,29 @@ int handleContextMenuRequested(long pView, long pArgs) {
917917

918918
long[] locationPointer = new long[1];
919919
args.get_Location(locationPointer);
920-
POINT pt = new POINT();
921-
OS.MoveMemory(pt, locationPointer, POINT.sizeof);
922-
pt.x = DPIUtil.autoScaleDown(pt.x); // To Points
923-
pt.y = DPIUtil.autoScaleDown(pt.y); // To Points
920+
POINT win32Point = new POINT();
921+
OS.MoveMemory(win32Point, locationPointer, POINT.sizeof);
922+
923+
// From WebView2 we receive widget-relative win32 POINTs.
924+
// The Event we create here will be mapped to a
925+
// MenuDetectEvent used with SWT.MenuDetect eventually, which
926+
// uses display-relative DISPLAY coordinates.
927+
// Thefore, we
928+
// - first, explicitly scale up the the win32 POINT values from edge
929+
// to PIXEL coordinates with the real native zoom value
930+
// independent from the swt.autoScale property:
931+
Point pt = new Point( //
932+
DPIUtil.scaleUp(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
933+
DPIUtil.scaleUp(win32Point.y, DPIUtil.getNativeDeviceZoom()));
934+
// - then, scale back down from PIXEL to DISPLAY coordinates, taking
935+
// swt.autoScale property into account
936+
// which is also later considered in Menu#setLocation()
937+
pt = new Point( //
938+
DPIUtil.scaleDown(pt.x, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)), //
939+
DPIUtil.scaleDown(pt.y, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)));
940+
// - finally, translate the POINT from widget-relative
941+
// to DISPLAY-relative coordinates
942+
pt = browser.toDisplay(pt.x, pt.y);
924943
Event event = new Event();
925944
event.x = pt.x;
926945
event.y = pt.y;

0 commit comments

Comments
 (0)