incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject wp7 commit: CB-953 mouse events fired twice
Date Wed, 27 Jun 2012 23:33:35 GMT
Updated Branches:
  refs/heads/master 6543eb830 -> 769a66be8


CB-953 mouse events fired twice


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/769a66be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/769a66be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/769a66be

Branch: refs/heads/master
Commit: 769a66be801c57de47cb0e0c301ce76cfbf88f73
Parents: 6543eb8
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed Jun 27 16:32:09 2012 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed Jun 27 16:32:09 2012 -0700

----------------------------------------------------------------------
 framework/Cordova/BrowserMouseHelper.cs |   57 ++++++++++++++++++--------
 1 files changed, 40 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/769a66be/framework/Cordova/BrowserMouseHelper.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/BrowserMouseHelper.cs b/framework/Cordova/BrowserMouseHelper.cs
index 7d5ef98..281bff6 100644
--- a/framework/Cordova/BrowserMouseHelper.cs
+++ b/framework/Cordova/BrowserMouseHelper.cs
@@ -42,11 +42,13 @@ namespace WP7CordovaClassLib
         /*
         private static string mouseScript =
         @"(function(win,doc){
-            Object.defineProperty( MouseEvent.prototype, 'pageX', {
+            var mPro = MouseEvent.prototype;
+            var def = Object.defineProperty;
+            def( mPro, 'pageX', {
                configurable: true,
                get: function(){ return this.clientX }
             });
-            Object.defineProperty( MouseEvent.prototype, 'pageY', {
+            def( mPro, 'pageY', {
                configurable: true,
                get: function(){ return this.clientY }
             });
@@ -59,7 +61,11 @@ namespace WP7CordovaClassLib
                     var xPos =  doc.body.scrollLeft + Math.round(xMod * x);
                     var yPos =  doc.body.scrollTop + Math.round(yMod * y);
                     var element = doc.elementFromPoint(xPos,yPos);
-                    evt.initMouseEvent(type, true, true, win, 1, xPos, yPos, xPos, yPos,
false, false, false, false, 0, element);
+                    
+                    evt.initMouseEvent(type, true, true, win, 1, xPos, yPos, xPos, yPos,
false, false, false, false, -1, null);
+                    evt.timeStamp = +new Date;
+                    evt.isCordovaEvent = true;
+                    
                     var canceled = element ? !element.dispatchEvent(evt) : !doc.dispatchEvent(evt);
                     return canceled ? 'true' : 'false';
                 }
@@ -68,9 +74,9 @@ namespace WP7CordovaClassLib
         })(window,document);";
         */
 
-        private static string MinifiedMouseScript = "(function(f,a){Object.defineProperty(MouseEvent.prototype,'pageX',{configurable:!0,get:function(){return
this.clientX}});Object.defineProperty(MouseEvent.prototype,'pageY',{configurable:!0,get:function(){return
this.clientY}});f.onNativeMouseEvent=function(g,h,i)" 
-        + "{try{var j=screen.logicalXDPI/screen.deviceXDPI,k=screen.logicalYDPI/screen.deviceYDPI,b=a.createEvent('MouseEvents'),c=a.body.scrollLeft+Math.round(j*h),d=a.body.scrollTop+Math.round(k*i),e=a.elementFromPoint(c,d);b.initMouseEvent(g,!0,!0,"
-        + "f,1,c,d,c,d,!1,!1,!1,!1,0,e);return(e?!e.dispatchEvent(b):!a.dispatchEvent(b))?'true':'false'}catch(l){return
l}}})(window,document);";
+        private static string MinifiedMouseScript = "(function(g,a){var c=MouseEvent.prototype,d=Object.defineProperty;d(c,'pageX',{configurable:!0,get:function(){return
this.clientX}});d(c,'pageY',{configurable:!0,get:function(){return this.clientY}});g.onNativeMouseEvent=function(c,d,i)"
+        + "{try{var j=screen.logicalXDPI/screen.deviceXDPI,k=screen.logicalYDPI/screen.deviceYDPI,b=a.createEvent('MouseEvents'),e=a.body.scrollLeft+Math.round(j*d),f=a.body.scrollTop+Math.round(k*i),h=a.elementFromPoint(e,f);b.initMouseEvent(c,!0,!0,g,1,e,f,e,f,!1,!1,!1,!1,-1,"
+        + "null);b.timeStamp=+new Date;b.isCordovaEvent=!0;return(h?!h.dispatchEvent(b):!a.dispatchEvent(b))?'true':'false'}catch(l){return
l}}})(window,document);";
 
 
         private WebBrowser _browser;
@@ -116,6 +122,9 @@ namespace WP7CordovaClassLib
 
         }
 
+
+
+
         void ParseViewportMeta()
         {
             string metaScript = "(function() { return document.querySelector('meta[name=viewport]').content;
})()";
@@ -192,7 +201,7 @@ namespace WP7CordovaClassLib
 
         void Border_Hold(object sender, GestureEventArgs e)
         {
-            Debug.WriteLine("Border_Hold");
+            //Debug.WriteLine("Border_Hold");
             e.Handled = true;
         }
 
@@ -202,7 +211,7 @@ namespace WP7CordovaClassLib
 
         void Border_DoubleTap(object sender, GestureEventArgs e)
         {
-            Debug.WriteLine("Border_DoubleTap");
+            //Debug.WriteLine("Border_DoubleTap");
             e.Handled = true;
         }
 
@@ -212,32 +221,42 @@ namespace WP7CordovaClassLib
 
         void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
+            //Debug.WriteLine("Border_MouseLeftButtonDown");
             border.MouseMove += new MouseEventHandler(Border_MouseMove);
             border.MouseLeftButtonUp += new MouseButtonEventHandler(Border_MouseLeftButtonUp);
-
+            // don't fire the down event until we know if this is a 'move' or not
             firstMouseMove = true;
-
-            Point pos = e.GetPosition(_browser);
-            InvokeSimulatedMouseEvent("mousedown", pos);
         }
-
+        //
         void Border_MouseMove(object sender, MouseEventArgs e)
         {
+            //Debug.WriteLine("Border_MouseMove");
             Point pos = e.GetPosition(_browser);
-            bool retVal = InvokeSimulatedMouseEvent("mousemove", pos);
             // only the return value from the first mouse move event should be used to determine
if scrolling is prevented.
             if (firstMouseMove)
             {
-                ScrollDisabled = retVal;
+                InvokeSimulatedMouseEvent("mousedown", pos);
+                firstMouseMove = false;
+                ScrollDisabled = InvokeSimulatedMouseEvent("mousemove", pos);
             }
+            else
+            {
+                InvokeSimulatedMouseEvent("mousemove", pos);
+            }
+
         }
 
         void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
         {
+            //Debug.WriteLine("Border_MouseLeftButtonUp");
             border.MouseMove -= new MouseEventHandler(Border_MouseMove);
             border.MouseLeftButtonUp -= new MouseButtonEventHandler(Border_MouseLeftButtonUp);
-            Point pos = e.GetPosition(_browser);
-            e.Handled = InvokeSimulatedMouseEvent("mouseup", pos);
+            // if firstMouseMove is false, then we have sent our simulated mousedown, so
we should also send a matching mouseup 
+            if (!firstMouseMove)
+            {
+                Point pos = e.GetPosition(_browser);
+                e.Handled = InvokeSimulatedMouseEvent("mouseup", pos);
+            }
             ScrollDisabled = false;
         }
 
@@ -248,6 +267,8 @@ namespace WP7CordovaClassLib
 
         void Border_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
         {
+            //Debug.WriteLine("Border_ManipulationStarted");
+            
             if (ScrollDisabled)
             {
                 e.Handled = true;
@@ -257,6 +278,7 @@ namespace WP7CordovaClassLib
 
         private void Border_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
         {
+            //Debug.WriteLine("Border_ManipulationDelta");
             // optionally suppress zoom
             if ((ScrollDisabled || !userScalable) && (e.DeltaManipulation.Scale.X
!= 0.0 || e.DeltaManipulation.Scale.Y != 0.0))
             {
@@ -273,6 +295,7 @@ namespace WP7CordovaClassLib
 
         private void Border_ManipulationCompleted(object sender, ManipulationCompletedEventArgs
e)
         {
+            //Debug.WriteLine("Border_ManipulationCompleted");
             // suppress zoom
             if (!userScalable && e.FinalVelocities != null)
             {


Mime
View raw message