apache/incubator-cordova-wp7 — pull request #3 by sgrebnov (2012-06-28 14:08:26+00:00)
Title: Minor improvement for CB-953 mouse events fired twice

Reviewed Jesse’s implementation – looks great. But there is a case where we still get click event fired twice – explained below with the fix.

For situations where we have only little mouse move IE still generates own mouse events – pls take a look on this demo video http://dl.dropbox.com/u/23085338/CordovaDoubleClickSample.avi . So we both generates the events. The workaround is to add the following. This means that if we already handled mouse move then prevent IE to generate own events.
void Border_Tap(object sender, GestureEventArgs e)
{
// prevents generating duplicated mouse events
// firstMouseMove == FALSE means we already handled this situation and generated mouse events
e.Handled = ! this.firstMouseMove;
}

But I found out that when you press something your clicks are not ideal so in many cases there is still move event fired with 1-5px delta. In such cases we generate our own events and prevents native so sometimes we encounter with our previous problem when text field is not focused. The workaround for this problem is to add small delta threshold to consider move as a real move. This guaranties that for some “not ideal” user touches which have some delta (so generate move event) we still use browser generated native events instead of our custom. It seems to work very well.

if (firstMouseMove)
{
// even for simple tap there are situations where ui control generates move with some little delta value
// we should avoid such situations allowing to browser control generate native js mousedown/up/click events
if (Math.Abs(pos.X - mouseDownPos.X) + Math.Abs(pos.Y - mouseDownPos.Y) <= MouseMoveDeltaThreshold)
{
return;
}

Final version in action http://dl.dropbox.com/u/23085338/CordovaDoubleClickSample2.avi