WebCore:
authorddkilzer <ddkilzer@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Jun 2006 20:37:37 +0000 (20:37 +0000)
committerddkilzer <ddkilzer@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Jun 2006 20:37:37 +0000 (20:37 +0000)
        Reviewed by Darin.

        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=8707:
        event.clientX and event.clientY should be relative to the viewport, not the canvas

        Make sure clientX and clientY take into account the scroll offsets
        of the view.

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::dispatchMouseEvent):
        * dom/MouseEvent.cpp:
        (WebCore::MouseEvent::MouseEvent):
        * dom/MouseEvent.h:
        * dom/MouseRelatedEvent.cpp:
        (WebCore::MouseRelatedEvent::MouseRelatedEvent):
        (WebCore::MouseRelatedEvent::initCoordinates):
        * dom/MouseRelatedEvent.h:
        * dom/WheelEvent.cpp:
        (WebCore::WheelEvent::WheelEvent):
        * page/FrameView.cpp:
        (WebCore::FrameView::dispatchDragEvent):

LayoutTests:

        Reviewed by Darin.

        Test cases for
        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8707>
        event.clientX and event.clientY should be relative to the viewport, not the canvas

        * fast/dom/window-xy-properties-expected.txt: Added.
        * fast/dom/window-xy-properties.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/window-xy-properties-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/window-xy-properties.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/EventTargetNode.cpp
WebCore/dom/MouseEvent.cpp
WebCore/dom/MouseEvent.h
WebCore/dom/MouseRelatedEvent.cpp
WebCore/dom/MouseRelatedEvent.h
WebCore/dom/WheelEvent.cpp
WebCore/page/FrameView.cpp

index 57b6f8788859a1be7de5fce3e735604b9a189949..415024c51f4656f7f3bcdd6ae0f44815f3ba7b02 100644 (file)
@@ -1,3 +1,14 @@
+2006-06-25  Rob Buis  <buis@kde.org>
+
+        Reviewed by Darin.
+
+        Test cases for
+        <http://bugzilla.opendarwin.org/show_bug.cgi?id=8707>
+        event.clientX and event.clientY should be relative to the viewport, not the canvas
+
+        * fast/dom/window-xy-properties-expected.txt: Added.
+        * fast/dom/window-xy-properties.html: Added.
+
 2006-06-25  Timothy Hatcher  <timothy@apple.com>
 
         http://bugzilla.opendarwin.org/show_bug.cgi?id=9560
diff --git a/LayoutTests/fast/dom/window-xy-properties-expected.txt b/LayoutTests/fast/dom/window-xy-properties-expected.txt
new file mode 100644 (file)
index 0000000..07d786e
--- /dev/null
@@ -0,0 +1,30 @@
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+PASS event.clientX is 50
+PASS event.clientY is 50
+PASS event.pageX is 50
+PASS event.pageY is 50
+PASS event.layerX is 50
+PASS event.layerY is 50
+PASS event.offsetX is 42
+PASS event.offsetY is 42
+PASS event.clientX is 50
+PASS event.clientY is 50
+PASS event.pageX is 50
+PASS event.pageY is 550
+PASS event.layerX is 50
+PASS event.layerY is 550
+PASS event.offsetX is 42
+PASS event.offsetY is 542
+PASS event.clientX is 50
+PASS event.clientY is 50
+PASS event.pageX is 550
+PASS event.pageY is 50
+PASS event.layerX is 550
+PASS event.layerY is 50
+PASS event.offsetX is 542
+PASS event.offsetY is 42
+
diff --git a/LayoutTests/fast/dom/window-xy-properties.html b/LayoutTests/fast/dom/window-xy-properties.html
new file mode 100644 (file)
index 0000000..19aeca1
--- /dev/null
@@ -0,0 +1,62 @@
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+<script>
+var nrmouseclicks = 0; // small hack to distinguish between clicks
+function mouseev(event) {
+    if (nrmouseclicks == 0) {
+        shouldBe("event.clientX", "50");
+        shouldBe("event.clientY", "50");
+        shouldBe("event.pageX", "50");
+        shouldBe("event.pageY", "50");
+        shouldBe("event.layerX", "50");
+        shouldBe("event.layerY", "50");
+        shouldBe("event.offsetX", "42");
+        shouldBe("event.offsetY", "42");
+        nrmouseclicks++;
+    } else if (nrmouseclicks == 1) {
+        shouldBe("event.clientX", "50");
+        shouldBe("event.clientY", "50");
+        shouldBe("event.pageX", "50");
+        shouldBe("event.pageY", "550");
+        shouldBe("event.layerX", "50");
+        shouldBe("event.layerY", "550");
+        shouldBe("event.offsetX", "42");
+        shouldBe("event.offsetY", "542");
+        nrmouseclicks++;
+    } else {
+        shouldBe("event.clientX", "50");
+        shouldBe("event.clientY", "50");
+        shouldBe("event.pageX", "550");
+        shouldBe("event.pageY", "50");
+        shouldBe("event.layerX", "550");
+        shouldBe("event.layerY", "50");
+        shouldBe("event.offsetX", "542");
+        shouldBe("event.offsetY", "42");
+    }
+}
+function test() {
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        // test a normal mouse to
+        eventSender.mouseMoveTo(50, 50);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+
+        // now scroll a bit down and verify that clientY does not change
+        window.scrollTo(0, 500);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+
+        // now scroll a bit to the right and verify that clientX does not change
+        window.scrollTo(500, 0);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+}
+</script>
+</head>
+<body onload="test()">
+<div style="background: red; width:2000px; height: 2000px" onmousedown="mouseev(event)">
+</div>
+<div id="console"></div>
+</body>
index 250796d8dfb7027050b77130e6a9c2e6bbd5063f..569ec33c6e7d58316d85a22811bb882095ab0abd 100644 (file)
@@ -1,3 +1,27 @@
+2006-06-25  Rob Buis  <buis@kde.org>
+
+        Reviewed by Darin.
+
+        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=8707:
+        event.clientX and event.clientY should be relative to the viewport, not the canvas
+
+        Make sure clientX and clientY take into account the scroll offsets
+        of the view.
+
+        * dom/EventTargetNode.cpp:
+        (WebCore::EventTargetNode::dispatchMouseEvent):
+        * dom/MouseEvent.cpp:
+        (WebCore::MouseEvent::MouseEvent):
+        * dom/MouseEvent.h:
+        * dom/MouseRelatedEvent.cpp:
+        (WebCore::MouseRelatedEvent::MouseRelatedEvent):
+        (WebCore::MouseRelatedEvent::initCoordinates):
+        * dom/MouseRelatedEvent.h:
+        * dom/WheelEvent.cpp:
+        (WebCore::WheelEvent::WheelEvent):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::dispatchDragEvent):
+
 2006-06-25  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Darin.
index da2571b17ef80f82685c5ae9b3aae71ad50c6b3f..0ce268a1d12a05b4ecffa11769f4b91ca8c36f27 100644 (file)
@@ -407,9 +407,16 @@ bool EventTargetNode::dispatchMouseEvent(const AtomicString& eventType, int butt
     
     // Attempting to dispatch with a non-EventTarget relatedTarget causes the relatedTarget to be silently ignored.
     EventTargetNode *relatedTarget = (relatedTargetArg && relatedTargetArg->isEventTargetNode()) ? static_cast<EventTargetNode*>(relatedTargetArg) : 0;
-    
+
+    int pageX = clientX; 
+    int pageY = clientY; 
+    if (FrameView* view = document()->view()) {
+        pageX -= view->contentsX();
+        pageY -= view->contentsY();
+    }
     RefPtr<Event> me = new MouseEvent(eventType, true, cancelable, document()->defaultView(),
-                                              detail, screenX, screenY, clientX, clientY,
+                                              detail, screenX, screenY,
+                                              pageX, pageY, clientX, clientY,
                                               ctrlKey, altKey, shiftKey, metaKey, button,
                                               relatedTarget, 0, isSimulated);
     
@@ -424,7 +431,8 @@ bool EventTargetNode::dispatchMouseEvent(const AtomicString& eventType, int butt
     // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same.
     if (eventType == clickEvent && detail == 2) {
         me = new MouseEvent(dblclickEvent, true, cancelable, document()->defaultView(),
-                                detail, screenX, screenY, clientX, clientY,
+                                detail, screenX, screenY,
+                                pageX, pageY, clientX, clientY,
                                 ctrlKey, altKey, shiftKey, metaKey, button,
                                 relatedTarget, 0, isSimulated);
         if (defaultHandled)
index b6d2b2dcfbb8098af52a003b39473fc0431bbe6e..3cd40581db6c6e7efffd492d5b455d3c18f7ac50 100644 (file)
@@ -37,10 +37,11 @@ MouseEvent::MouseEvent()
 
 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, AbstractView* view,
                        int detail, int screenX, int screenY, int clientX, int clientY,
-                       bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
+                       int pageX, int pageY, bool ctrlKey, bool altKey,
+                       bool shiftKey, bool metaKey, unsigned short button,
                        EventTargetNode* relatedTarget, Clipboard* clipboard, bool isSimulated)
     : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, screenX, screenY,
-                        clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, isSimulated)
+                        clientX, clientY, pageX, pageY, ctrlKey, altKey, shiftKey, metaKey, isSimulated)
     , m_button(button)
     , m_relatedTarget(relatedTarget)
     , m_clipboard(clipboard)
index b210ba10857bdb1ecc550bbec27a288ac16a7089..9d33d60336a35263c728c3e6c0b076384b0747a2 100644 (file)
@@ -38,7 +38,8 @@ namespace WebCore {
         MouseEvent();
         MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view,
                    int detail, int screenX, int screenY, int clientX, int clientY,
-                   bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
+                   int pageX, int pageY, bool ctrlKey, bool altKey,
+                   bool shiftKey, bool metaKey, unsigned short button,
                    EventTargetNode* relatedTarget, Clipboard* clipboard = 0, bool isSimulated = false);
         virtual ~MouseEvent();
 
index 0d16ab7d3fc8fe641a68cabd5cca5cb352e4e831..0046f65a003bac02596f4cf9f262a802a1b97993 100644 (file)
@@ -50,12 +50,15 @@ MouseRelatedEvent::MouseRelatedEvent()
 
 MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, AbstractView* view,
                                      int detail, int screenX, int screenY, int clientX, int clientY,
-                                     bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool isSimulated)
+                                     int pageX, int pageY, bool ctrlKey, bool altKey,
+                                     bool shiftKey, bool metaKey, bool isSimulated)
     : UIEventWithKeyState(eventType, canBubble, cancelable, view, detail, ctrlKey, altKey, shiftKey, metaKey)
     , m_screenX(screenX)
     , m_screenY(screenY)
     , m_clientX(clientX)
     , m_clientY(clientY)
+    , m_pageX(pageX)
+    , m_pageY(pageY)
     , m_isSimulated(isSimulated)
 {
     initCoordinates();
@@ -66,8 +69,6 @@ void MouseRelatedEvent::initCoordinates()
     // Set up initial values for coordinates.
     // Correct values can't be computed until we have at target, so receivedTarget
     // does the "real" computation.
-    m_pageX = m_clientX;
-    m_pageY = m_clientY;
     m_layerX = m_pageX;
     m_layerY = m_pageY;
     m_offsetX = m_pageX;
index a709eb544e966870386b71e1fdb75b0ebd0ad40f..fd4687257c5484de7592657c5f6b6fc74ed87f40 100644 (file)
@@ -40,7 +40,8 @@ namespace WebCore {
         MouseRelatedEvent();
         MouseRelatedEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view,
                           int detail, int screenX, int screenY, int clientX, int clientY,
-                          bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool isSimulated = false);
+                          int pageX, int pageY, bool ctrlKey, bool altKey,
+                          bool shiftKey, bool metaKey, bool isSimulated = false);
 
         int screenX() const { return m_screenX; }
         int screenY() const { return m_screenY; }
index dc3fe0687ee36a963119174ed397d8187414a4b2..08416ec7474cdb105e75b1a6b89214921566e5d4 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "config.h"
 #include "WheelEvent.h"
+#include "Frame.h"
 
 #include "EventNames.h"
 
@@ -42,6 +43,8 @@ WheelEvent::WheelEvent(bool horizontal, int wheelDelta, AbstractView* view,
                        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
     : MouseRelatedEvent(horizontal ? khtmlHorizontalmousewheelEvent : mousewheelEvent,
                         true, true, view, 0, screenX, screenY, clientX, clientY, 
+                        clientX - (view && view->frame() && view->frame()->view()) ? view->frame()->view()->contentsX() : 0,
+                        clientY - (view && view->frame() && view->frame()->view()) ? view->frame()->view()->contentsY() : 0,
                         ctrlKey, altKey, shiftKey, metaKey)
     , m_horizontal(horizontal)
     , m_wheelDelta(wheelDelta)
index 4a17b465c4aa173e506eda3917070723a9a19165..fb8fa81cc27fdcaa27bf7056f8061339d67fb0af 100644 (file)
@@ -759,9 +759,17 @@ bool FrameView::dispatchDragEvent(const AtomicString& eventType, Node *dragTarge
 {
     IntPoint clientPos = viewportToContents(event.pos());
     
+    int clientX = clientPos.x(); 
+    int clientY = clientPos.y(); 
+    int pageX = clientX; 
+    int pageY = clientY; 
+    if (FrameView* view = m_frame->document()->view()) {
+        pageX -= view->contentsX();
+        pageY -= view->contentsY();
+    }
     RefPtr<MouseEvent> me = new MouseEvent(eventType,
         true, true, m_frame->document()->defaultView(),
-        0, event.globalX(), event.globalY(), clientPos.x(), clientPos.y(),
+        0, event.globalX(), event.globalY(), pageX, pageY, clientX, clientY,
         event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(),
         0, 0, clipboard);