Ticket #3133 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

click handler should distinguish between pinches, clicks, and double-clicks

Reported by: tschaub Owned by: tschaub
Priority: minor Milestone: 2.11 Release
Component: Handler.Click Version: 2.10
Keywords: mobile Cc: rangoy, xavier.mamano@…
State: Commit

Description (last modified by tschaub) (diff)

The click handler should be made configurable so that it only calls the dblclick callback if two clicks are within the given pixel tolerance. In addition, the existing pixelTolerance property should be used to check displacements at the end of a touchstart, touchmove, touchend sequence. The click callback should not be called if touches move more than the provided tolerance.

Attachments

3133.patch Download (31.9 KB) - added by tschaub 2 years ago.
click & pinch improvements
3133.2.patch Download (32.2 KB) - added by tschaub 2 years ago.
click and pinch overhaul

Change History

Changed 2 years ago by tschaub

  • state set to Review

The intention of this patch is to add a dblclickTolerance to the click handler and to improve the separation of touch and mouse event handling. This handler was getting twisted with touch event listeners calling mouse event listeners. Instead, we only use the methods named like browser events as listeners for those events.

This will likely take some more tweaking, but if anybody wants to take a stab at reviewing, the tests pass.

Changed 2 years ago by ahocevar

  • state changed from Review to Commit

Thanks Tim for the hard work on this. The tests are now easily readable, and the touch flag in the Click handler not only simplifies things, but also improves code readability. I tested the patch with several examples on my Android 2.1 phone, the iOS simulator and Safari5 (Desktop), and everything works as expected.

Please commit.

Changed 2 years ago by tschaub

  • keywords mobile added

Changed 2 years ago by tschaub

  • state Commit deleted
  • description modified (diff)
  • summary changed from click handler calls dblclick callback even if clicks are very far away to click handler should distinguish between pinches, clicks, and double-clicks

Changed 2 years ago by tschaub

This patch turned up a number of additional issues with the click handler, pinch handler, and the touch navigation control. Since these components must play well together, I've continued to work in changes to the  click sandbox surrounding these issues.

Changed 2 years ago by tschaub

click & pinch improvements

Changed 2 years ago by tschaub

  • state set to Review

Changed 2 years ago by tschaub

Basically, the click handler and the pinch handler do not play well together. This patch is meant to make things better.

Summary of changes:

  • tests/Control/TouchNavigation.html - Tests added to confirm that click handler options can be set via the control's options. By default, the touch navigation control creates a click handler with a 2 pixel tolerance for clicks.
  • tests/Handler/Click.html - These changes confirm that the new dblclickTolerance property works as expected and that the existing pixelTolerance property is used. The tests needed an overhaul to make it so assertions were not conditionally run.
  • lib/OpenLayers/Control/PinchZoom.js - The pinch zoom control needs to start tracking the current center on pinch start (in case there is no pinch move before done). Then in the done callback, we only call setCenter if either the zoom or the center actually changed.
  • lib/OpenLayers/Control/TouchNavigation.js - Added support for passing options to the click handler. By default, the click handler in the touch navigation control will have a non-zero pixel tolerance. This allows sloppy fingers to click.
  • lib/OpenLayers/Handler/Click.js - The dblclickTolerance property is added to make it so the double-click callback is not called for clicks that are very far away from one another. The rest of the event handling code is refactored to cleanly separate device event listeners from common handler methods (touch event listeners don't call mouse event listeners, instead both call common methods). With this change, we can immediately unregister mouse listeners in a touch environment, preventing duplicate handling when touch and mouse events propagate. In addition, the pixelTolerance property is now used to determine if a multi-touch event is a click.
  • lib/OpenLayers/Handler/Pinch.js - The pinch handler needs to prevent the default behavior of a touchstart (to avoid document scrolling), but it does not need to stop propagation to other listeners. This allows the pinch handler and the click handler to work well together regardless of which is activated first. Because the click handler now properly uses pixelTolerance and dblclickTolerance, we can safely let touch events be handled there even when they are part of a pinch.

Changed 2 years ago by rangoy

  • cc rangoy added

Changed 2 years ago by jorix

  • cc xavier.mamano@… added

Changed 2 years ago by ahocevar

  • state changed from Review to Commit

Patch is not up to date, but I looked at the current version in the sandbox and what I see there is good to commit. Thanks Tim for your ongoing efforts on this!

Changed 2 years ago by tschaub

click and pinch overhaul

Changed 2 years ago by bbinet

I also think the patch is good for commit, and the following points are minor or could be adressed in separate tickets:

* in touchmove method we could check first that this.down is set (as it is done for touchend method) since we don't need to update this.last if we haven't received any touchstart.

* currently, when making a double tap which does not passesDblclickTolerance, neither the click callback nor the dblclick callback are called. Don't you think the single click callback should rather get called twice instead?

* as Andreas mentioned, the patch would need to be updated with the last commits from the sandbox.

Changed 2 years ago by tschaub

  • status changed from new to closed
  • resolution set to fixed

(In [11695]) Reworking click and pinch handling to get better behavior on multi-touch devices. r=ahocevar +testing from others (closes #3133)

Note: See TracTickets for help on using tickets.