Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge: Use display-relative coordinates in ContextMenuRequested #1462

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

sratz
Copy link
Member

@sratz sratz commented Sep 10, 2024

No description provided.

@sratz sratz marked this pull request as ready for review September 10, 2024 14:47
@sratz sratz requested a review from niraj-modi as a code owner September 10, 2024 14:47
@sratz
Copy link
Member Author

sratz commented Sep 10, 2024

@akoch-yatta Thanks for catching this in #1450 (comment)

Copy link
Contributor

github-actions bot commented Sep 10, 2024

Test Results

   486 files  ±0     486 suites  ±0   7m 54s ⏱️ +43s
 4 154 tests ±0   4 146 ✅ ±0   8 💤 ±0  0 ❌ ±0 
16 370 runs  ±0  16 278 ✅ ±0  92 💤 ±0  0 ❌ ±0 

Results for commit 17e6a4c. ± Comparison against base commit ff514e8.

♻️ This comment has been updated with latest results.

@sratz sratz added the edge Edge Browser label Sep 10, 2024
@sratz sratz added this to the 4.34 M1 milestone Sep 10, 2024
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, but @akoch-yatta should definitely have a look at this.

Comment on lines 716 to 717
ptWidgetRelative.x = DPIUtil.autoScaleDown(ptWidgetRelative.x); // To Points
ptWidgetRelative.y = DPIUtil.autoScaleDown(ptWidgetRelative.y); // To Points
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may take the change to correct the usage of autoScaleDown to use the proper context zoom. It should be something like this:

Suggested change
ptWidgetRelative.x = DPIUtil.autoScaleDown(ptWidgetRelative.x); // To Points
ptWidgetRelative.y = DPIUtil.autoScaleDown(ptWidgetRelative.y); // To Points
ptWidgetRelative.x = DPIUtil.scaleDown(ptWidgetRelative.x, browser.getShell().nativeZoom); // To Points
ptWidgetRelative.y = DPIUtil.scaleDown(ptWidgetRelative.y, browser.getShell().nativeZoom); // To Points

Copy link
Member Author

@sratz sratz Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, since the pt information comes from the WebView2 C library, isn't the actual device zoom irrelevant here? We always have to map to 100% pixel coordinates because that's what the SWT API works with?

Copy link
Member Author

@sratz sratz Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I can't get this to work correctly in all combinations of

  • -Dswt.autoScale=[false|exact]
  • -Dswt.autoScale.updateOnRuntime=[false|true]
  • DPI in windows = [100|150|200]

Menu.setLocation(), calls org.eclipse.swt.widgets.Widget.getZoom(), which uses org.eclipse.swt.internal.DPIUtil.getZoomForAutoscaleProperty(int), which depends on swt.autoScale.

Menu.setLocationInPixels() is not visible from the .browser package.

The coordinates returned from Edge for the pt are relative to the WebView2, but are not zoomed.

I can't really put my head around all this scaling / DPI craziness involved here :O.

Maybe there even is a problem in how these methods currently work?

@akoch-yatta Would be great, if you could take a look here!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look into it. The conversion between points and pixels is always a bit messy. I think there is something wrong in Control::toDisplay and Control::toControl, to cover all cases, but I need to have a deeper look into that topic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that Edge knows nothing about the swt.autoScale property, so we have to deal with 3 different coordinate systems here:

  • Win32 POINTs received from Edge
  • SWT Display coordinates (these are affected by the swt.autoScale)
  • Pixels

So this has to be done in a 2-step manner:

  • Up from Win32 POINTs to Pixel (enforcing the native zoom value, ignoring swt.autoScale)
  • Down to SWT Display (respecting swt.autoScale)

With the latest force-push things work fine for me in all possible combinations I tried. I guess #1536 also helped.

@sratz sratz modified the milestones: 4.34 M1, 4.34 M2 Oct 4, 2024
@sratz sratz force-pushed the edge-menu-displaycoordinates branch from 9a5032f to fb406f4 Compare October 15, 2024 14:52
@sratz
Copy link
Member Author

sratz commented Oct 15, 2024

I'd also like to get this into M2 as the current behavior is completely broken with anything other than 100% OS zoom level.

@HeikoKlare
Copy link
Contributor

I'd also like to get this into M2 as the current behavior is completely broken with anything other than 100% OS zoom level.

I agree that we should just merge this for M2. Maybe @amartya4256 can have another look into this? @akoch-yatta may also review the latest change after the merge (when he's back from vacation).

@sratz sratz force-pushed the edge-menu-displaycoordinates branch from fb406f4 to a39f3ec Compare October 15, 2024 18:01
@sratz sratz force-pushed the edge-menu-displaycoordinates branch from a39f3ec to 17e6a4c Compare October 16, 2024 07:58
@sratz
Copy link
Member Author

sratz commented Oct 16, 2024

Test failures are unrelated.

@sratz sratz merged commit 209d75a into master Oct 16, 2024
10 of 14 checks passed
@sratz sratz deleted the edge-menu-displaycoordinates branch October 16, 2024 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edge Edge Browser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants