Take pageScaleFactor into account for MouseRelatedEvents.
authorjknotten@chromium.org <jknotten@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Oct 2011 10:10:07 +0000 (10:10 +0000)
committerjknotten@chromium.org <jknotten@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Oct 2011 10:10:07 +0000 (10:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67592

Reviewed by Tony Gentilcore.

Source/WebCore:

Tests: fast/events/page-scaled-mouse-click-iframe.html
       fast/events/page-scaled-mouse-click.html

* dom/MouseRelatedEvent.cpp:
(WebCore::contentsScrollOffset):
(WebCore::MouseRelatedEvent::MouseRelatedEvent):
(WebCore::frameScaleFactor):
(WebCore::MouseRelatedEvent::computePageLocation):
(WebCore::MouseRelatedEvent::computeRelativePosition):

LayoutTests:

* fast/events/page-scaled-mouse-click-expected.txt: Added.
* fast/events/page-scaled-mouse-click-iframe-expected.txt: Added.
* fast/events/page-scaled-mouse-click-iframe.html: Added.
* fast/events/page-scaled-mouse-click.html: Added.
* fast/events/resources/page-scaled-mouse-click-iframe-inner.html: Added.
* fast/events/script-tests/page-scaled-mouse-click-iframe.js: Added.
():
(clearEventLog):
(testEvents):
(iframeLoaded):
* fast/events/script-tests/page-scaled-mouse-click.js: Added.
():
(clearEventLog):
(sendEvents):
(testEvents):

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

LayoutTests/ChangeLog
LayoutTests/fast/events/page-scaled-mouse-click-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/page-scaled-mouse-click-iframe-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/page-scaled-mouse-click-iframe.html [new file with mode: 0644]
LayoutTests/fast/events/page-scaled-mouse-click.html [new file with mode: 0644]
LayoutTests/fast/events/resources/page-scaled-mouse-click-iframe-inner.html [new file with mode: 0644]
LayoutTests/fast/events/script-tests/page-scaled-mouse-click-iframe.js [new file with mode: 0644]
LayoutTests/fast/events/script-tests/page-scaled-mouse-click.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/MouseRelatedEvent.cpp

index 9756850..d309308 100644 (file)
@@ -1,3 +1,26 @@
+2011-10-06  John Knottenbelt  <jknotten@chromium.org>
+
+        Take pageScaleFactor into account for MouseRelatedEvents.
+        https://bugs.webkit.org/show_bug.cgi?id=67592
+
+        Reviewed by Tony Gentilcore.
+
+        * fast/events/page-scaled-mouse-click-expected.txt: Added.
+        * fast/events/page-scaled-mouse-click-iframe-expected.txt: Added.
+        * fast/events/page-scaled-mouse-click-iframe.html: Added.
+        * fast/events/page-scaled-mouse-click.html: Added.
+        * fast/events/resources/page-scaled-mouse-click-iframe-inner.html: Added.
+        * fast/events/script-tests/page-scaled-mouse-click-iframe.js: Added.
+        ():
+        (clearEventLog):
+        (testEvents):
+        (iframeLoaded):
+        * fast/events/script-tests/page-scaled-mouse-click.js: Added.
+        ():
+        (clearEventLog):
+        (sendEvents):
+        (testEvents):
+
 2011-10-06  Sergio Villar Senin  <svillar@igalia.com>
 
         Unreviewed. Skipped a test that lacks a console message.
diff --git a/LayoutTests/fast/events/page-scaled-mouse-click-expected.txt b/LayoutTests/fast/events/page-scaled-mouse-click-expected.txt
new file mode 100644 (file)
index 0000000..7fe51b0
--- /dev/null
@@ -0,0 +1,15 @@
+This tests that page scaling does not affect mouse event pageX and pageY coordinates.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Unscaled
+PASS eventLog is "click(10, 10)"
+
+setPageScale(0.5)
+PASS eventLog is "click(20, 20)"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/page-scaled-mouse-click-iframe-expected.txt b/LayoutTests/fast/events/page-scaled-mouse-click-iframe-expected.txt
new file mode 100644 (file)
index 0000000..aecf06a
--- /dev/null
@@ -0,0 +1,22 @@
+
+This tests that page scaling and CSS transforms do not affect mouse event pageX and pageY coordinates for content embedded in an iframe.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Unscaled
+PASS eventLog is "click(10, 10)"
+
+setPageScale(0.5)
+PASS eventLog is "click(20, 20)"
+
+CSS scale(0.5, 2.0)
+PASS eventLog is "click(20, 5)"
+
+setPageScale(0.5), CSS scale(0.5, 2.0)
+PASS eventLog is "click(40, 10)"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/page-scaled-mouse-click-iframe.html b/LayoutTests/fast/events/page-scaled-mouse-click-iframe.html
new file mode 100644 (file)
index 0000000..d564dd1
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html style="background-color: red; ">
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body style="margin: 0px;">
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/page-scaled-mouse-click-iframe.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/page-scaled-mouse-click.html b/LayoutTests/fast/events/page-scaled-mouse-click.html
new file mode 100644 (file)
index 0000000..353d4ef
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body style="margin:0px">
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/page-scaled-mouse-click.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/resources/page-scaled-mouse-click-iframe-inner.html b/LayoutTests/fast/events/resources/page-scaled-mouse-click-iframe-inner.html
new file mode 100644 (file)
index 0000000..055c04d
--- /dev/null
@@ -0,0 +1,2 @@
+<body onload="parent.iframeLoaded()" style="margin: 0px;">
+</body>
diff --git a/LayoutTests/fast/events/script-tests/page-scaled-mouse-click-iframe.js b/LayoutTests/fast/events/script-tests/page-scaled-mouse-click-iframe.js
new file mode 100644 (file)
index 0000000..2689fdf
--- /dev/null
@@ -0,0 +1,83 @@
+description("This tests that page scaling and CSS transforms do not affect mouse event pageX and pageY coordinates for " +
+            "content embedded in an iframe.");
+
+var html = document.documentElement;
+
+var iframe = document.createElement("iframe");
+iframe.style.border = "none";
+iframe.style.width = "200px";
+iframe.style.height = "200px";
+iframe.style.background = "green";
+
+var div = document.createElement("div");
+div.style.width = "100px";
+div.style.height = "100px";
+div.style.backgroundColor = "blue";
+
+var eventLog = "";
+
+function appendEventLog(event) {
+    var msg = event.type + "(" + event.pageX + ", " + event.pageY + ")";
+
+    if (window.eventSender) {
+        eventLog += msg;
+    } else {
+        debug(msg);
+    }
+}
+
+function clearEventLog() {
+    eventLog = "";
+}
+
+function sendEvents(button) {
+    if (!window.eventSender) {
+        debug("This test requires the EventSender API (provided by, for example, DumpRenderTree or WebKitTestRunner). Click on the blue rect with the left mouse button to log the mouse coordinates.")
+        return;
+    }
+    eventSender.mouseDown(button);
+    eventSender.mouseUp(button);
+}
+
+function testEvents(button, description, expectedString) {
+    sendEvents(button);
+    debug(description);
+    shouldBeEqualToString("eventLog", expectedString);
+    clearEventLog();
+    debug("");
+}
+
+function iframeLoaded() {
+  // Add the div to the iframe.
+  div.addEventListener("click", appendEventLog, false);
+  iframe.contentWindow.document.body.insertBefore(div, iframe.contentWindow.document.body.firstChild);
+
+  if (window.eventSender) {
+    eventSender.mouseMoveTo(10, 10);
+    // We are clicking in the same position on screen. As we scale or transform the page,
+    // we expect the pageX and pageY event coordinates to change because different
+    // parts of the document are under the mouse.
+
+    testEvents(0, "Unscaled", "click(10, 10)");
+
+    eventSender.scalePageBy(0.5, 0, 0);
+    testEvents(0, "setPageScale(0.5)", "click(20, 20)");
+
+    eventSender.scalePageBy(1.0, 0, 0);
+    html.style["-webkit-transform"] = "scale(0.5, 2.0)";
+    html.style["-webkit-transform-origin"] = "0 0";
+    testEvents(0, "CSS scale(0.5, 2.0)", "click(20, 5)");
+
+    eventSender.scalePageBy(0.5, 0, 0);
+    testEvents(0, "setPageScale(0.5), CSS scale(0.5, 2.0)", "click(40, 10)");
+  }
+
+  finishJSTest();
+}
+
+// Add the iframe to the document.
+iframe.src = "resources/page-scaled-mouse-click-iframe-inner.html";
+document.body.insertBefore(iframe, document.body.firstChild);
+
+window.jsTestIsAsync = true;
+window.successfullyParsed = true;
diff --git a/LayoutTests/fast/events/script-tests/page-scaled-mouse-click.js b/LayoutTests/fast/events/script-tests/page-scaled-mouse-click.js
new file mode 100644 (file)
index 0000000..22d774d
--- /dev/null
@@ -0,0 +1,57 @@
+description("This tests that page scaling does not affect mouse event pageX and pageY coordinates.");
+
+var html = document.documentElement;
+
+var div = document.createElement("div");
+div.style.width = "100px";
+div.style.height = "100px";
+div.style.backgroundColor = "blue";
+
+var eventLog = "";
+
+function appendEventLog() {
+    var msg = event.type + "(" + event.pageX + ", " + event.pageY + ")";
+
+    if (window.eventSender) {
+        eventLog += msg;
+    } else {
+        debug(msg);
+    }
+}
+
+function clearEventLog() {
+    eventLog = "";
+}
+
+div.addEventListener("click", appendEventLog, false);
+document.body.insertBefore(div, document.body.firstChild);
+
+function sendEvents(button) {
+    if (!window.eventSender) {
+        debug("This test requires DumpRenderTree.  Click on the blue rect with the left mouse button to log the mouse coordinates.")
+        return;
+    }
+    eventSender.mouseDown(button);
+    eventSender.mouseUp(button);
+}
+
+function testEvents(button, description, expectedString) {
+    sendEvents(button);
+    debug(description);
+    shouldBeEqualToString("eventLog", expectedString);
+    debug("");
+    clearEventLog();
+}
+
+if (window.eventSender) {
+    eventSender.mouseMoveTo(10, 10);
+    // We are clicking in the same position on screen. As we scale or transform the page,
+    // we expect the pageX and pageY event coordinates to change because different
+    // parts of the document are under the mouse.
+    testEvents(0, "Unscaled", "click(10, 10)");
+
+    eventSender.scalePageBy(0.5, 0, 0);
+    testEvents(0, "setPageScale(0.5)", "click(20, 20)");
+}
+
+var successfullyParsed = true;
index 2c85dd7..39bf29b 100644 (file)
@@ -1,3 +1,20 @@
+2011-10-06  John Knottenbelt  <jknotten@chromium.org>
+
+        Take pageScaleFactor into account for MouseRelatedEvents.
+        https://bugs.webkit.org/show_bug.cgi?id=67592
+
+        Reviewed by Tony Gentilcore.
+
+        Tests: fast/events/page-scaled-mouse-click-iframe.html
+               fast/events/page-scaled-mouse-click.html
+
+        * dom/MouseRelatedEvent.cpp:
+        (WebCore::contentsScrollOffset):
+        (WebCore::MouseRelatedEvent::MouseRelatedEvent):
+        (WebCore::frameScaleFactor):
+        (WebCore::MouseRelatedEvent::computePageLocation):
+        (WebCore::MouseRelatedEvent::computeRelativePosition):
+
 2011-10-03  Hans Wennborg  <hans@chromium.org>
 
         IndexedDB: Remove SQLite-LevelDB migration code
index 216fe28..ccaec73 100644 (file)
@@ -48,8 +48,8 @@ static LayoutSize contentsScrollOffset(AbstractView* abstractView)
     FrameView* frameView = frame->view();
     if (!frameView)
         return LayoutSize();
-    return LayoutSize(frameView->scrollX() / frame->pageZoomFactor(),
-        frameView->scrollY() / frame->pageZoomFactor());
+    float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
+    return LayoutSize(frameView->scrollX() / scaleFactor, frameView->scrollY() / scaleFactor);
 }
 
 MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtr<AbstractView> abstractView,
@@ -67,15 +67,15 @@ MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubb
         if (FrameView* frameView = frame->view()) {
             scrollPosition = frameView->scrollPosition();
             adjustedPageLocation = frameView->windowToContents(windowLocation);
-            float pageZoom = frame->pageZoomFactor();
-            if (pageZoom != 1.0f) {
+            float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
+            if (scaleFactor != 1.0f) {
                 // Adjust our pageX and pageY to account for the page zoom.
-                adjustedPageLocation.scale(1 / pageZoom, 1 / pageZoom);
+                adjustedPageLocation.scale(1 / scaleFactor, 1 / scaleFactor);
 
                 // FIXME: Change this to use float math and proper rounding (or
                 // better yet, use LayoutPoint::scale).
-                scrollPosition.setX(scrollPosition.x() / pageZoom);
-                scrollPosition.setY(scrollPosition.y() / pageZoom);
+                scrollPosition.setX(scrollPosition.x() / scaleFactor);
+                scrollPosition.setY(scrollPosition.y() / scaleFactor);
             }
         }
     }
@@ -122,10 +122,21 @@ static float pageZoomFactor(const UIEvent* event)
     return frame->pageZoomFactor();
 }
 
+static float frameScaleFactor(const UIEvent* event)
+{
+    DOMWindow* window = event->view();
+    if (!window)
+        return 1;
+    Frame* frame = window->frame();
+    if (!frame)
+        return 1;
+    return frame->frameScaleFactor();
+}
+
 void MouseRelatedEvent::computePageLocation()
 {
-    float zoomFactor = pageZoomFactor(this);
-    setAbsoluteLocation(roundedLayoutPoint(FloatPoint(pageX() * zoomFactor, pageY() * zoomFactor)));
+    float scaleFactor = pageZoomFactor(this) * frameScaleFactor(this);
+    setAbsoluteLocation(roundedLayoutPoint(FloatPoint(pageX() * scaleFactor, pageY() * scaleFactor)));
 }
 
 void MouseRelatedEvent::receivedTarget()
@@ -151,7 +162,7 @@ void MouseRelatedEvent::computeRelativePosition()
         if (RenderObject* r = targetNode->renderer()) {
             FloatPoint localPos = r->absoluteToLocal(absoluteLocation(), false, true);
             m_offsetLocation = roundedLayoutPoint(localPos);
-            float scaleFactor = 1 / pageZoomFactor(this);
+            float scaleFactor = 1 / (pageZoomFactor(this) * frameScaleFactor(this));
             if (scaleFactor != 1.0f)
                 m_offsetLocation.scale(scaleFactor, scaleFactor);
         }