MouseEvent.offsetX/Y should just return 0,0 for simulated clicks.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Feb 2014 18:44:10 +0000 (18:44 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Feb 2014 18:44:10 +0000 (18:44 +0000)
<https://webkit.org/b/129477>

Source/WebCore:

There's no need to compute the exact target-relative coordinates for
simulated mouse events, e.g those fired by HTMLElement.click().

The offsetX/Y properties are not supported by Firefox.

Test: fast/events/relative-offset-of-simulated-click.html

Reviewed by Alexey Proskuryakov.

* dom/MouseRelatedEvent.cpp:
(WebCore::MouseRelatedEvent::offsetX):
(WebCore::MouseRelatedEvent::offsetY):

LayoutTests:

Add a test documenting the behavior of offsetX/Y on the simulated
mouse events that get sent by HTMLElement.click().

Reviewed by Alexey Proskuryakov.

* fast/events/relative-offset-of-simulated-click-expected.txt: Added.
* fast/events/relative-offset-of-simulated-click.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164871 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/events/relative-offset-of-simulated-click-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/relative-offset-of-simulated-click.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/MouseRelatedEvent.cpp

index d481345ae2092935920e2579f973924477bd995a..613511d076a4a5e826bd5d6fbda5fa395f98d423 100644 (file)
@@ -1,3 +1,16 @@
+2014-02-28  Andreas Kling  <akling@apple.com>
+
+        MouseEvent.offsetX/Y should just return 0,0 for simulated clicks.
+        <https://webkit.org/b/129477>
+
+        Add a test documenting the behavior of offsetX/Y on the simulated
+        mouse events that get sent by HTMLElement.click().
+
+        Reviewed by Alexey Proskuryakov.
+
+        * fast/events/relative-offset-of-simulated-click-expected.txt: Added.
+        * fast/events/relative-offset-of-simulated-click.html: Added.
+
 2014-02-27  Sergio Villar Senin  <svillar@igalia.com>
 
         [CSS Grid Layout] Fix positioning grid items using named grid lines/areas
diff --git a/LayoutTests/fast/events/relative-offset-of-simulated-click-expected.txt b/LayoutTests/fast/events/relative-offset-of-simulated-click-expected.txt
new file mode 100644 (file)
index 0000000..6a83fe1
--- /dev/null
@@ -0,0 +1,18 @@
+This test documents the behavior of MouseEvent.offsetX/Y in response to HTMLElement.click().
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Simulated click with .click():
+PASS event.offsetX is 0
+PASS event.offsetY is 0
+Click with mouse at 0,0:
+PASS event.offsetX is 0
+PASS event.offsetY is 0
+Click with mouse at 40,50:
+PASS event.offsetX is 40
+PASS event.offsetY is 50
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/relative-offset-of-simulated-click.html b/LayoutTests/fast/events/relative-offset-of-simulated-click.html
new file mode 100644 (file)
index 0000000..2a9dd66
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+
+description("This test documents the behavior of MouseEvent.offsetX/Y in response to HTMLElement.click().");
+
+var testDiv = document.createElement("div");
+testDiv.setAttribute("style", "background: green; width: 100px; height: 100px; position: absolute; top: 100px; left: 100px;");
+document.body.appendChild(testDiv);
+
+testDiv.addEventListener("click", function(e) {
+    event = e;
+    shouldBe("event.offsetX", expectedX);
+    shouldBe("event.offsetY", expectedY);
+});
+
+debug("Simulated click with .click():");
+expectedX = "0";
+expectedY = "0";
+testDiv.click();
+
+if (!window.eventSender)
+    debug("This part of the test requires eventSender!");
+else {
+    debug("Click with mouse at 0,0:");
+    expectedX = "0";
+    expectedY = "0";
+    eventSender.mouseMoveTo(100, 100);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+
+    debug("Click with mouse at 40,50:");
+    expectedX = "40";
+    expectedY = "50";
+    eventSender.mouseMoveTo(140, 150);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+}
+
+testDiv.remove();
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index b418bff79f663a4c81a4afae9c248aced48fea26..dae761fdca7cd1308bc6230335986b478b8a64c4 100644 (file)
@@ -1,3 +1,21 @@
+2014-02-28  Andreas Kling  <akling@apple.com>
+
+        MouseEvent.offsetX/Y should just return 0,0 for simulated clicks.
+        <https://webkit.org/b/129477>
+
+        There's no need to compute the exact target-relative coordinates for
+        simulated mouse events, e.g those fired by HTMLElement.click().
+
+        The offsetX/Y properties are not supported by Firefox.
+
+        Test: fast/events/relative-offset-of-simulated-click.html
+
+        Reviewed by Alexey Proskuryakov.
+
+        * dom/MouseRelatedEvent.cpp:
+        (WebCore::MouseRelatedEvent::offsetX):
+        (WebCore::MouseRelatedEvent::offsetY):
+
 2014-02-27  Sergio Villar Senin  <svillar@igalia.com>
 
         [CSS Grid Layout] Fix positioning grid items using named grid lines/areas
index 88000f5f3f1fc3f98a50bb72b2d61272a5352026..1dbef3b67004d16388deead7b55f5c06cc1dfe34 100644 (file)
@@ -208,6 +208,8 @@ int MouseRelatedEvent::layerY()
 
 int MouseRelatedEvent::offsetX()
 {
+    if (isSimulated())
+        return 0;
     if (!m_hasCachedRelativePosition)
         computeRelativePosition();
     return roundToInt(m_offsetLocation.x());
@@ -215,6 +217,8 @@ int MouseRelatedEvent::offsetX()
 
 int MouseRelatedEvent::offsetY()
 {
+    if (isSimulated())
+        return 0;
     if (!m_hasCachedRelativePosition)
         computeRelativePosition();
     return roundToInt(m_offsetLocation.y());