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

Event handler / interaction cleanup #1598

Merged
merged 20 commits into from
Nov 20, 2015
Merged

Event handler / interaction cleanup #1598

merged 20 commits into from
Nov 20, 2015

Conversation

@jfirebaugh
Copy link
Contributor

@bhousel Want to think about / prototype something for #1550? (You can say no.)

return _setOffset(el);
};
exports.mousePos = function (el, e) {
var offset = _cachedOffset || _setOffset(el);
Copy link
Member

Choose a reason for hiding this comment

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

You can call exports.setOffset directly instead of defining an additional function.

@mourner
Copy link
Member

mourner commented Oct 7, 2015

Aside from these two minor remarks, the offset caching code looks good to me.

@bhousel
Copy link
Contributor Author

bhousel commented Oct 7, 2015

Want to think about / prototype something for #1550? (You can say no.)

Yeah I think it makes sense to roll event testing (#1550) into this if I can get something working in a few days. Selenium looks promising..

@mourner
Copy link
Member

mourner commented Oct 7, 2015

@bhousel proper event testing can be a big lift so I'd prefer having it as a separate PR.

@bhousel
Copy link
Contributor Author

bhousel commented Oct 7, 2015

proper event testing can be a big lift so I'd prefer having it as a separate PR.

ok, sounds good

@bhousel
Copy link
Contributor Author

bhousel commented Nov 18, 2015

I'm pretty happy with this now. There are some more things I could add to it, but want to avoid any additional scope creep on this PR.

@jfirebaugh @mourner want to take a look?

@lucaswoj
Copy link
Contributor

This looks great! One minor thing: I see some console warnings when I rotate the map. These warnings are not present on master. Worth looking into (:no_entry_sign: log spew), but not a blocker if there's no easy fix.

screen shot 2015-11-18 at 10 19 10 am

(the message traces to util.js:184)

@bhousel
Copy link
Contributor Author

bhousel commented Nov 18, 2015

I see some console warnings when I rotate the map.

@lucaswoj Yeah I did notice those too - it's from 73a15d8 where I'm making a copy of the MouseEvent from the compass button and redispatching it with the right button pressed so the DragRotate handler will handle it instead. The original event has those deprecated properties, so the copy does too. I can do a smarter copy so we don't get console warnings.

@@ -51,10 +51,19 @@ exports.suppressClick = function() {
}, 0);
};

exports.mousePos = function (el, e) {
var cachedOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is effectively a global variable, and it makes me nervous about bugs on pages with multiple maps. Are you sure setOffset always gets called when necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We call setOffset on mouseenter of the canvas container:

https://github.com/mapbox/mapbox-gl-js/pull/1598/files#diff-274e90d38623e2e16a5e7d34414f33c7R649

So it should be ok for mouse, but might be a problem for touch?

@jfirebaugh
Copy link
Contributor

Rotating with control + drag is not working on this branch.

@bhousel
Copy link
Contributor Author

bhousel commented Nov 18, 2015

Rotating with control + drag is not working on this branch.

Oh interesting - I did not try that.

This worked before because control-click is a Mac operating system shortcut for right click, and the rotation handler was relying on contextmenu event. I moved away from relying on contextmenu because that event can fire differently on Windows. Anyway I'll fix this, thanks!

@mourner
Copy link
Member

mourner commented Nov 18, 2015

I moved away from relying on contextmenu because that event can fire differently on Windows.

Can you clarify? It always worked in Leaflet at least.

@bhousel
Copy link
Contributor Author

bhousel commented Nov 18, 2015

Can you clarify? It always worked in Leaflet at least.

Sometimes it fires coincident with mousedown (which would be fine for a rotation handler) and other times it fires with mouseup (which would be a problem).

But I was using this page for guidance, which is admittedly kind of old, so by now browsers might have standardized on a mousedown contextmenu.

@bhousel
Copy link
Contributor Author

bhousel commented Nov 18, 2015

By the way, this gist is what I use when I'm testing the event handlers. Might be helpful for others:

['mousedown', 'mouseup', 'click', 'dblclick', 'contextmenu', 
 'dragstart', 'dragend',
 'movestart', 'moveend',
 'rotatestart', 'rotateend',
 'boxzoomstart', 'boxzoomend', 'boxzoomcancel'
].forEach(function (s) {
  map.off(s).on(s, function(data) { 
    var e = data && data.originalEvent;
    console.log(s + (e ? ' buttons = ' + e.buttons + ', button = ' + e.button : '')); 
  });
});

@bhousel
Copy link
Contributor Author

bhousel commented Nov 19, 2015

Can you clarify? It always worked in Leaflet at least.

Sometimes it fires coincident with mousedown (which would be fine for a rotation handler) and other times it fires with mouseup (which would be a problem).

Just tested this with IE11 and Edge, and indeed on Windows the contextmenu event fires on mouseup. It's really more of an OS design decision than a browser one.

A mouseup contextmenu means that on Windows, you don't get into rotation mode until after you release your right click, and then you are stuck in rotation mode until another mouseup happens. You can see this behavior on the master branch, or any of the maps on our examples page.

So that's one other thing that this PR fixes: rotation now works like right-click + drag on Windows too.

if (map.boxZoom && map.boxZoom.active) return;
if (map.dragRotate && map.dragRotate.active) return;
if (e.touches && e.touches.length > 1) return;
if (!e.touches && e.button !== 0) return;
Copy link
Member

Choose a reason for hiding this comment

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

this is repeated two times so maybe worth separating into a method that returns boolean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree, good idea..

@mourner
Copy link
Member

mourner commented Nov 19, 2015

Thanks for explanations about contextmenu — let's try to fix ctrl-drag (will probably require relying on both contextmenu and e.button). The changes generally look good, added some minor comments.

@bhousel
Copy link
Contributor Author

bhousel commented Nov 20, 2015

From @jfirebaugh:

This is effectively a global variable, and it makes me nervous about bugs on pages with multiple maps. Are you sure setOffset always gets called when necessary?

You are right that caching the getBoundingClientRect dimensions causes issues when there are multiple maps, so I'm going to revert 32eb42b and consider #854 as wontfix.

Here is what it looks like when you move from one map to another and mouseenter switches the cached offset:

cached offset issue

* Split out methods to
1. drain inertia buffer
2. ignore events
@bhousel
Copy link
Contributor Author

bhousel commented Nov 20, 2015

I think I addressed all the issues raised - @mourner @jfirebaugh @lucaswoj want to take another look?

@jfirebaugh
Copy link
Contributor

👍

@lucaswoj
Copy link
Contributor

:shipit: 🚢

bhousel added a commit that referenced this pull request Nov 20, 2015
Event handler / interaction cleanup
@bhousel bhousel merged commit 684a170 into master Nov 20, 2015
@bhousel bhousel deleted the event-stuff branch November 20, 2015 19:17
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.

4 participants