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

Allow browser context menu when possible #7369

Merged
merged 1 commit into from
Oct 5, 2018
Merged

Conversation

mourner
Copy link
Member

@mourner mourner commented Oct 5, 2018

Closes #2301. Enables standard browser context menu on maps where rotation is disabled and there are no contextmenu listeners.

Unfortunately I don't see a way to enable it by default because it's not compatible with rotation — on Mac, contextmenu is fired together with mousedown (not mouseup like in other OS), and at this point we don't know if it's a start of a rotation gesture or a simple right click. cc @jplante

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page

e.preventDefault();
// prevent browser context menu when necessary; we don't allow it with rotation
// because we can't discern rotation gesture start from contextmenu on Mac
if (map.dragRotate.isEnabled() || map.listens('contextmenu')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the first part of this conditional but am I thinking about it correctly that map.listens('contextmenu') would be true if a contextmenu listener has been set up on the map? Why would having a listener prevent the event? It seems like odd behavior that I could disable drag rotate, set up a listener for contextmenu and then the context menu wouldn't actually open.

Also, the docs say that listens should return false if no listener is set up, but I actually get undefined.

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 original reason for having Map contextmenu event is to allow specifying custom behavior on right click, such as opening your own HTML-styled app-specific context menu, and in this case it doesn't make sense to also show the browser default one.

Leaflet does the same thing and no one raised concerns about it yet, so I think it's safe to do the same logic here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok that makes sense. I tested this on Mac with Safari, Firefox and Chrome and they all worked as expected so I think this is good.

Choose a reason for hiding this comment

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

This is not working in ios WKWebView.

@mourner mourner merged commit 287e330 into master Oct 5, 2018
@mourner mourner deleted the improve-context-menu branch October 6, 2018 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants