@@ -917,10 +917,29 @@ int handleContextMenuRequested(long pView, long pArgs) {
917
917
918
918
long [] locationPointer = new long [1 ];
919
919
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 );
924
943
Event event = new Event ();
925
944
event .x = pt .x ;
926
945
event .y = pt .y ;
0 commit comments