Title: [219571] trunk
Revision
219571
Author
simon.fra...@apple.com
Date
2017-07-17 13:24:16 -0700 (Mon, 17 Jul 2017)

Log Message

clientX/clientY on TouchEvent.touches are wrong
https://bugs.webkit.org/show_bug.cgi?id=174561
Source/WebCore:

rdar://problem/33336041

Reviewed by Tim Horton.

Do some refactoring so that WebKitAdditions code that computes Touch coordinates can use
the same code that MouseRelatedEvent uses.

There is no behavior change in this patch, but the test exercises a behavior change in
WebKitAdditions code.

Test: fast/events/touch/ios/touches-client-coords-after-zoom.html

* dom/MouseRelatedEvent.cpp:
(WebCore::MouseRelatedEvent::init):
(WebCore::MouseRelatedEvent::frameViewFromDOMWindow):
(WebCore::MouseRelatedEvent::pagePointToClientPoint):
(WebCore::MouseRelatedEvent::pagePointToAbsolutePoint):
(WebCore::MouseRelatedEvent::initCoordinates):
(WebCore::MouseRelatedEvent::documentToAbsoluteScaleFactor):
(WebCore::MouseRelatedEvent::computePageLocation):
(WebCore::MouseRelatedEvent::locationInRootViewCoordinates):
(WebCore::MouseRelatedEvent::frameView): Deleted.
* dom/MouseRelatedEvent.h:

LayoutTests:

Reviewed by Tim Horton.

* fast/events/touch/ios/touches-client-coords-after-zoom-expected.txt: Added.
* fast/events/touch/ios/touches-client-coords-after-zoom.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219570 => 219571)


--- trunk/LayoutTests/ChangeLog	2017-07-17 19:53:50 UTC (rev 219570)
+++ trunk/LayoutTests/ChangeLog	2017-07-17 20:24:16 UTC (rev 219571)
@@ -1,3 +1,13 @@
+2017-07-17  Simon Fraser  <simon.fra...@apple.com>
+
+        clientX/clientY on TouchEvent.touches are wrong
+        https://bugs.webkit.org/show_bug.cgi?id=174561
+
+        Reviewed by Tim Horton.
+
+        * fast/events/touch/ios/touches-client-coords-after-zoom-expected.txt: Added.
+        * fast/events/touch/ios/touches-client-coords-after-zoom.html: Added.
+
 2017-07-17  Chris Dumez  <cdu...@apple.com>
 
         click event does not dispatch to parent when child target stops hit testing after mousedown

Added: trunk/LayoutTests/fast/events/touch/ios/touches-client-coords-after-zoom-expected.txt (0 => 219571)


--- trunk/LayoutTests/fast/events/touch/ios/touches-client-coords-after-zoom-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/ios/touches-client-coords-after-zoom-expected.txt	2017-07-17 20:24:16 UTC (rev 219571)
@@ -0,0 +1,6 @@
+
+These two events should have the same client coordinates:
+
+Received event touchstart with client coords 150, 160
+Received event click with client coords 150, 160
+

Added: trunk/LayoutTests/fast/events/touch/ios/touches-client-coords-after-zoom.html (0 => 219571)


--- trunk/LayoutTests/fast/events/touch/ios/touches-client-coords-after-zoom.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/ios/touches-client-coords-after-zoom.html	2017-07-17 20:24:16 UTC (rev 219571)
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<style>
+body {
+    margin: 0;
+    height: 2000px;
+}
+
+button {
+    width: 400px;
+    height: 500px;
+    border: 1px solid black;
+    background-color: silver;
+}
+</style>
+
+<script>
+
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+function logString(s)
+{
+    document.getElementById('log').textContent += s + '\n';
+}
+
+function getUIScript()
+{
+    return `
+    (function() {
+        uiController.zoomToScale(1.2, function() {
+            uiController.singleTapAtPoint(150, 160, function() {
+                uiController.uiScriptComplete();
+            });
+        });
+    })();`
+}
+
+var gotTouch = false;
+var gotClick = false;
+var eventsComplete = false;
+
+function checkForCompletion()
+{
+    if (gotTouch && gotClick && eventsComplete) {
+        if (window.testRunner)
+            testRunner.notifyDone();
+    }
+}
+
+function doTest()
+{
+    var button = document.getElementById('button');
+    button.addEventListener('touchstart', function(event) {
+        logString('Received event ' + event.type + ' with client coords ' + event.touches[0].clientX + ', ' + event.touches[0].clientY);
+        gotTouch = true;
+        checkForCompletion();
+    });
+
+    button.addEventListener('click', function(event) {
+        logString('Received event ' + event.type + ' with client coords ' + event.clientX + ', ' + event.clientY);
+        gotClick = true;
+        checkForCompletion();
+    });
+
+    if (window.testRunner && testRunner.runUIScript) {
+        testRunner.runUIScript(getUIScript(), function() {
+            eventsComplete = true;
+            checkForCompletion();
+        });
+    }
+}
+
+window.addEventListener('load', doTest, false);
+</script>
+</head>
+
+<body>
+    <button id="button"></button>
+    <p>These two events should have the same client coordinates:</p>
+<pre id="log"></pre>
+</body>
+
+</html>

Modified: trunk/Source/WebCore/ChangeLog (219570 => 219571)


--- trunk/Source/WebCore/ChangeLog	2017-07-17 19:53:50 UTC (rev 219570)
+++ trunk/Source/WebCore/ChangeLog	2017-07-17 20:24:16 UTC (rev 219571)
@@ -1,3 +1,31 @@
+2017-07-17  Simon Fraser  <simon.fra...@apple.com>
+
+        clientX/clientY on TouchEvent.touches are wrong
+        https://bugs.webkit.org/show_bug.cgi?id=174561
+        rdar://problem/33336041
+
+        Reviewed by Tim Horton.
+        
+        Do some refactoring so that WebKitAdditions code that computes Touch coordinates can use
+        the same code that MouseRelatedEvent uses.
+        
+        There is no behavior change in this patch, but the test exercises a behavior change in
+        WebKitAdditions code.
+
+        Test: fast/events/touch/ios/touches-client-coords-after-zoom.html
+
+        * dom/MouseRelatedEvent.cpp:
+        (WebCore::MouseRelatedEvent::init):
+        (WebCore::MouseRelatedEvent::frameViewFromDOMWindow):
+        (WebCore::MouseRelatedEvent::pagePointToClientPoint):
+        (WebCore::MouseRelatedEvent::pagePointToAbsolutePoint):
+        (WebCore::MouseRelatedEvent::initCoordinates):
+        (WebCore::MouseRelatedEvent::documentToAbsoluteScaleFactor):
+        (WebCore::MouseRelatedEvent::computePageLocation):
+        (WebCore::MouseRelatedEvent::locationInRootViewCoordinates):
+        (WebCore::MouseRelatedEvent::frameView): Deleted.
+        * dom/MouseRelatedEvent.h:
+
 2017-07-17  Jeremy Jones  <jere...@apple.com>
 
         Add video fullscreen transition logging.

Modified: trunk/Source/WebCore/dom/MouseRelatedEvent.cpp (219570 => 219571)


--- trunk/Source/WebCore/dom/MouseRelatedEvent.cpp	2017-07-17 19:53:50 UTC (rev 219570)
+++ trunk/Source/WebCore/dom/MouseRelatedEvent.cpp	2017-07-17 20:24:16 UTC (rev 219571)
@@ -61,11 +61,11 @@
 void MouseRelatedEvent::init(bool isSimulated, const IntPoint& windowLocation)
 {
     if (!isSimulated) {
-        if (auto* frameView = this->frameView()) {
+        if (auto* frameView = frameViewFromDOMWindow(view())) {
             FloatPoint absolutePoint = frameView->windowToContents(windowLocation);
             FloatPoint documentPoint = frameView->absoluteToDocumentPoint(absolutePoint);
             m_pageLocation = flooredLayoutPoint(documentPoint);
-            m_clientLocation = flooredLayoutPoint(frameView->documentToClientPoint(documentPoint));
+            m_clientLocation = pagePointToClientPoint(m_pageLocation, frameView);
         }
     }
 
@@ -83,12 +83,37 @@
     m_hasCachedRelativePosition = false;
 }
 
+FrameView* MouseRelatedEvent::frameViewFromDOMWindow(DOMWindow* window)
+{
+    auto* frame = window ? window->frame() : nullptr;
+    if (!frame)
+        return nullptr;
+
+    return frame->view();
+}
+
+LayoutPoint MouseRelatedEvent::pagePointToClientPoint(LayoutPoint pagePoint, FrameView* frameView)
+{
+    if (!frameView)
+        return pagePoint;
+
+    return flooredLayoutPoint(frameView->documentToClientPoint(pagePoint));
+}
+
+LayoutPoint MouseRelatedEvent::pagePointToAbsolutePoint(LayoutPoint pagePoint, FrameView* frameView)
+{
+    if (!frameView)
+        return pagePoint;
+    
+    return pagePoint.scaled(frameView->documentToAbsoluteScaleFactor());
+}
+
 void MouseRelatedEvent::initCoordinates(const LayoutPoint& clientLocation)
 {
     // Set up initial values for coordinates.
     // Correct values are computed lazily, see computeRelativePosition.
     FloatSize documentToClientOffset;
-    if (auto* frameView = this->frameView())
+    if (auto* frameView = frameViewFromDOMWindow(view()))
         documentToClientOffset = frameView->documentToClientOffset();
 
     m_clientLocation = clientLocation;
@@ -101,18 +126,9 @@
     m_hasCachedRelativePosition = false;
 }
 
-FrameView* MouseRelatedEvent::frameView() const
-{
-    auto* frame = view() ? view()->frame() : nullptr;
-    if (!frame)
-        return nullptr;
-
-    return frame->view();
-}
-
 float MouseRelatedEvent::documentToAbsoluteScaleFactor() const
 {
-    if (auto* frameView = this->frameView())
+    if (auto* frameView = frameViewFromDOMWindow(view()))
         return frameView->documentToAbsoluteScaleFactor();
 
     return 1;
@@ -120,7 +136,7 @@
 
 void MouseRelatedEvent::computePageLocation()
 {
-    m_absoluteLocation = m_pageLocation.scaled(documentToAbsoluteScaleFactor());
+    m_absoluteLocation = pagePointToAbsolutePoint(m_pageLocation, frameViewFromDOMWindow(view()));
 }
 
 void MouseRelatedEvent::receivedTarget()
@@ -169,7 +185,10 @@
     
 FloatPoint MouseRelatedEvent::locationInRootViewCoordinates() const
 {
-    return frameView()->contentsToRootView(roundedIntPoint(m_absoluteLocation));
+    if (auto* frameView = frameViewFromDOMWindow(view()))
+        return frameView->contentsToRootView(roundedIntPoint(m_absoluteLocation));
+
+    return m_absoluteLocation;
 }
 
 int MouseRelatedEvent::layerX()

Modified: trunk/Source/WebCore/dom/MouseRelatedEvent.h (219570 => 219571)


--- trunk/Source/WebCore/dom/MouseRelatedEvent.h	2017-07-17 19:53:50 UTC (rev 219570)
+++ trunk/Source/WebCore/dom/MouseRelatedEvent.h	2017-07-17 20:24:16 UTC (rev 219571)
@@ -65,7 +65,12 @@
     // Page point in "absolute" coordinates (i.e. post-zoomed, page-relative coords,
     // usable with RenderObject::absoluteToLocal).
     const LayoutPoint& absoluteLocation() const { return m_absoluteLocation; }
+    
+    static FrameView* frameViewFromDOMWindow(DOMWindow*);
 
+    static LayoutPoint pagePointToClientPoint(LayoutPoint pagePoint, FrameView*);
+    static LayoutPoint pagePointToAbsolutePoint(LayoutPoint pagePoint, FrameView*);
+
 protected:
     MouseRelatedEvent() = default;
     MouseRelatedEvent(const AtomicString& type, bool canBubble, bool cancelable, double timestamp, DOMWindow*,
@@ -84,7 +89,6 @@
     void computeRelativePosition();
 
     float documentToAbsoluteScaleFactor() const;
-    FrameView* frameView() const;
 
     // Expose these so MouseEvent::initMouseEvent can set them.
     IntPoint m_screenLocation;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to