This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch feature/MXRoyale
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 908b4e9ffdbb8c73f6a06c00a99fde6e149ff76c
Author: Alex Harui <aha...@apache.org>
AuthorDate: Thu Apr 12 15:47:50 2018 -0700

    use getBoundingClientRect instead of offsets and handle floating point 
values
---
 .../java/marmotinni/DispatchMouseClickEvent.java   | 57 +++++++++++++-------
 .../main/java/marmotinni/DispatchMouseEvent.java   | 63 ++++++++++++++--------
 2 files changed, 79 insertions(+), 41 deletions(-)

diff --git a/mustella/src/main/java/marmotinni/DispatchMouseClickEvent.java 
b/mustella/src/main/java/marmotinni/DispatchMouseClickEvent.java
index 0a98ecc..70869a2 100644
--- a/mustella/src/main/java/marmotinni/DispatchMouseClickEvent.java
+++ b/mustella/src/main/java/marmotinni/DispatchMouseClickEvent.java
@@ -40,22 +40,40 @@ public class DispatchMouseClickEvent extends TestStep {
     protected void doStep()
     {
                
-               Long x;
-               Long y;
+               Double x;
+               Double y;
                if (hasLocal)
                {
                        StringBuilder script = new StringBuilder();
                        insertTargetScript(script, target);
-                       script.append("return target.element.offsetLeft");
+                       script.append("return 
target.element.getBoundingClientRect().left");
                        if (TestStep.showScripts)
                                System.out.println(script);
-                       x = 
(Long)((JavascriptExecutor)webDriver).executeScript(script.toString());
+            Object any = 
((JavascriptExecutor)webDriver).executeScript(script.toString());
+            if (any instanceof Long)
+                x = ((Long)any).doubleValue();
+            else if (any instanceof Double)
+                x = (Double)any;
+            else
+            {
+                System.out.println("x is not Long or Double");
+                x = 0.0;
+            }
                        script = new StringBuilder();
                        insertTargetScript(script, target);
-                       script.append("return target.element.offsetTop");
+                       script.append("return 
target.element.getBoundingClientRect().top");
                        if (TestStep.showScripts)
                                System.out.println(script);
-                       y = 
(Long)((JavascriptExecutor)webDriver).executeScript(script.toString());
+            any = 
((JavascriptExecutor)webDriver).executeScript(script.toString());
+            if (any instanceof Long)
+                y = ((Long)any).doubleValue();
+            else if (any instanceof Double)
+                y = (Double)any;
+            else
+            {
+                System.out.println("y is not Long or Double");
+                y = 0.0;
+            }
                        x += localX;
                        y += localY;
                }
@@ -71,7 +89,8 @@ public class DispatchMouseClickEvent extends TestStep {
                script.append("var n = all.length;");
                script.append("for(var i=n-1;i>=0;i--) { ");
                script.append("    var e = all[i];");
-               script.append("     if (" + x + " >= e.offsetLeft && " + x + " 
<= e.offsetLeft + e.offsetWidth && " + y + " >= e.offsetTop && " + y + " <= 
e.offsetTop + e.offsetHeight)");
+        script.append("    var bounds = e.getBoundingClientRect();");
+               script.append("     if (" + x + " >= bounds.left && " + x + " 
<= bounds.right && " + y + " >= bounds.top && " + y + " <= bounds.bottom)");
                script.append("         return e;");
                script.append("};");
                script.append("return null;");
@@ -117,25 +136,25 @@ public class DispatchMouseClickEvent extends TestStep {
         *  The localX property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long localX;
+       public double localX;
        
        /**
         *  The localY property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long localY;
+       public double localY;
        
        /**
         *  The stageX property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long stageX;
+       public double stageX;
        
        /**
         *  The stageY property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long stageY;
+       public double stageY;
        
        /**
         *  The shiftKey property on the MouseEvent (optional)
@@ -157,13 +176,13 @@ public class DispatchMouseClickEvent extends TestStep {
                s += target;
                if (hasLocal)
                {
-                       s += ", localX = " + Long.toString(localX);
-                       s += ", localY = " + Long.toString(localY);
+                       s += ", localX = " + Double.toString(localX);
+                       s += ", localY = " + Double.toString(localY);
                }
                if (hasStage)
                {
-                       s += ", stageX = " + Long.toString(stageX);
-                       s += ", stageY = " + Long.toString(stageY);
+                       s += ", stageX = " + Double.toString(stageX);
+                       s += ", stageY = " + Double.toString(stageY);
                }
                if (shiftKey)
                        s += ", shiftKey = true";
@@ -184,25 +203,25 @@ public class DispatchMouseClickEvent extends TestStep {
                String value = attributes.getValue("localX");
                if (value != null)
                {
-                       localX = Long.parseLong(value);
+                       localX = Double.parseDouble(value);
                        hasLocal = true;
                }
                value = attributes.getValue("localY");
                if (value != null)
                {
-                       localY = Long.parseLong(value);
+                       localY = Double.parseDouble(value);
                        hasLocal = true;
                }
                value = attributes.getValue("stageX");
                if (value != null)
                {
-                       stageX = Long.parseLong(value);
+                       stageX = Double.parseDouble(value);
                        hasStage = true;
                }
                value = attributes.getValue("stageY");
                if (value != null)
                {
-                       stageY = Long.parseLong(value);
+                       stageY = Double.parseDouble(value);
                        hasStage = true;
                }
        }
diff --git a/mustella/src/main/java/marmotinni/DispatchMouseEvent.java 
b/mustella/src/main/java/marmotinni/DispatchMouseEvent.java
index 0f9a874..82d3387 100644
--- a/mustella/src/main/java/marmotinni/DispatchMouseEvent.java
+++ b/mustella/src/main/java/marmotinni/DispatchMouseEvent.java
@@ -40,22 +40,40 @@ public class DispatchMouseEvent extends TestStep {
     protected void doStep()
     {
                
-               Long x;
-               Long y;
+               Double x;
+               Double y;
                if (hasLocal)
                {
                        StringBuilder script = new StringBuilder();
                        insertTargetScript(script, target);
-                       script.append("return target.element.offsetLeft");
+            script.append("return 
target.element.getBoundingClientRect().left");
                        if (TestStep.showScripts)
                                System.out.println(script);
-                       x = 
(Long)((JavascriptExecutor)webDriver).executeScript(script.toString());
+            Object any = 
((JavascriptExecutor)webDriver).executeScript(script.toString());
+            if (any instanceof Long)
+                x = ((Long)any).doubleValue();
+            else if (any instanceof Double)
+                x = (Double)any;
+            else
+            {
+                System.out.println("x is not Long or Double");
+                x = 0.0;
+            }
                        script = new StringBuilder();
                        insertTargetScript(script, target);
-                       script.append("return target.element.offsetTop");
+            script.append("return target.element.getBoundingClientRect().top");
                        if (TestStep.showScripts)
                                System.out.println(script);
-                       y = 
(Long)((JavascriptExecutor)webDriver).executeScript(script.toString());
+            any = 
((JavascriptExecutor)webDriver).executeScript(script.toString());
+            if (any instanceof Long)
+                y = ((Long)any).doubleValue();
+            else if (any instanceof Double)
+                y = (Double)any;
+            else
+            {
+                System.out.println("y is not Long or Double");
+                y = 0.0;
+            }
                        x += localX;
                        y += localY;
                }
@@ -71,10 +89,11 @@ public class DispatchMouseEvent extends TestStep {
                script.append("var n = all.length;");
                script.append("for(var i=n-1;i>=0;i--) { ");
                script.append("    var e = all[i];");
-               script.append("     if (" + x + " >= e.offsetLeft && " + x + " 
<= e.offsetLeft + e.offsetWidth && " + y + " >= e.offsetTop && " + y + " <= 
e.offsetTop + e.offsetHeight) {");
-               script.append("         if (!e.id) e.id = 
Math.random().toString();");
-               script.append("         return e;");
-               script.append("     }");
+        script.append("    var bounds = e.getBoundingClientRect();");
+        script.append("     if (" + x + " >= bounds.left && " + x + " <= 
bounds.right && " + y + " >= bounds.top && " + y + " <= bounds.bottom) {");
+        script.append("         if (!e.id) e.id = Math.random().toString();");
+        script.append("         return e;");
+        script.append("     }");
                script.append("};");
                script.append("return null;");
                if (TestStep.showScripts)
@@ -128,25 +147,25 @@ public class DispatchMouseEvent extends TestStep {
         *  The localX property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long localX;
+       public double localX;
        
        /**
         *  The localY property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long localY;
+       public double localY;
        
        /**
         *  The stageX property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long stageX;
+       public double stageX;
        
        /**
         *  The stageY property on the MouseEvent (optional)
         *  Either set stageX/stageY or localX/localY, but not both.
         */
-       public long stageY;
+       public double stageY;
        
        /**
         *  The shiftKey property on the MouseEvent (optional)
@@ -168,13 +187,13 @@ public class DispatchMouseEvent extends TestStep {
                s += target;
                if (hasLocal)
                {
-                       s += ", localX = " + Long.toString(localX);
-                       s += ", localY = " + Long.toString(localY);
+                       s += ", localX = " + Double.toString(localX);
+                       s += ", localY = " + Double.toString(localY);
                }
                if (hasStage)
                {
-                       s += ", stageX = " + Long.toString(stageX);
-                       s += ", stageY = " + Long.toString(stageY);
+                       s += ", stageX = " + Double.toString(stageX);
+                       s += ", stageY = " + Double.toString(stageY);
                }
                if (shiftKey)
                        s += ", shiftKey = true";
@@ -196,25 +215,25 @@ public class DispatchMouseEvent extends TestStep {
                String value = attributes.getValue("localX");
                if (value != null)
                {
-                       localX = Long.parseLong(value);
+                       localX = Double.parseDouble(value);
                        hasLocal = true;
                }
                value = attributes.getValue("localY");
                if (value != null)
                {
-                       localY = Long.parseLong(value);
+                       localY = Double.parseDouble(value);
                        hasLocal = true;
                }
                value = attributes.getValue("stageX");
                if (value != null)
                {
-                       stageX = Long.parseLong(value);
+                       stageX = Double.parseDouble(value);
                        hasStage = true;
                }
                value = attributes.getValue("stageY");
                if (value != null)
                {
-                       stageY = Long.parseLong(value);
+                       stageY = Double.parseDouble(value);
                        hasStage = true;
                }
        }

-- 
To stop receiving notification emails like this one, please contact
aha...@apache.org.

Reply via email to