openlayers/openlayers — pull request #742 by gregersrygg (2012-11-02 15:08:54+00:00)
Title: Fixed problems with touch events on a scrollable page

Some versions of iOS and Android have bugs for clientX/clientY when the page is scrolled. This was previously "fixed" in OpenLayers by hoping the user would not scroll the page. So when the map is on a scrollable page, touch events does not work correctly.

I modified the mobile example to reproduce the bug:
http://jsbin.com/efucop/1

Scroll down to the map. When tapping (clicking) in the map, a pin should appear where clicked. Because of the bug, the pin appears far away from where clicked. Usually outside of the map. Pinch-zooming is also not working correctly.

iOS 4: includes scroll offset in clientX/Y
iOS 6: wrong clientX/clientY when page is zoomed & scrolled in x-axis
Android 4.0 Browser: wrong clientX/clientY when page is scrolled
Android Chrome: wrong clientX/clientY when page is scrolled
The Android Browser also sends single-touch events during a multi-touch pinch

This fix detects when these bugs are present, and calculates correct values. Since the clientX and clientY values are read-only in recent versions of WebKit I decided to add new properties for the fixed values; olClientX and olClientY. So handlers have to use these properties to get the correct values. Have updated Click and Pinch handlers.

Added tests for the new functionality. The test_callbacks in Pinch.html test page is really horrible! I lost count of how many tests was planned, and it's impossible to count without doing a step-debug with common sense to analyze when the callbacks should be called and not. Found some of the existing callbacks that should have been called never was, and the # of planned tests was wrong. Fixed the error, # of planned tests and added a comment for each test # to make it easier to keep track of planned tests.

Have tested and verified that this works on an iPhone 4 with iOS5 and iOS6. Samsung Galaxy Nexus with Android 4.1, Samsung Galaxy S II with android 4.0 and an old LG phone with Android 2.3 (no multi-touch).