Bug 26723 - clientX,Y , screenX , Y always (0, 0) in dragstart event
Summary: clientX,Y , screenX , Y always (0, 0) in dragstart event
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows 7
: P2 Normal
Assignee: Jessie Berlin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-25 09:46 PDT by Jessie Berlin
Modified: 2009-06-26 13:30 PDT (History)
2 users (show)

See Also:


Attachments
Test case showing the clientX, pageX, and screenX values in dragstart (1.31 KB, text/html)
2009-06-25 09:47 PDT, Jessie Berlin
no flags Details
Fix: Make sure the m_mouseDown event is set correctly (6.43 KB, patch)
2009-06-26 12:36 PDT, Jessie Berlin
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jessie Berlin 2009-06-25 09:46:11 PDT
event.clientX, event.clientY, event.screenX, event.screenY, event.pageX, and event.pageY all report 0 in a dragstart handler on windows (not on mac).

This makes it difficult to use setDataImage(image, x, y) if you want to use the coordinates of the mousedown for the x and y values.
Comment 1 Jessie Berlin 2009-06-25 09:47:05 PDT
Created attachment 31861 [details]
Test case showing the clientX, pageX, and screenX values in dragstart
Comment 2 Jessie Berlin 2009-06-25 11:49:23 PDT
On windows, this can be fixed setting m_mouseDown to event.event() inside

bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)

before the following line:

        m_mouseDownMayStartDrag = dispatchDragSrcEvent(eventNames().dragstartEvent, m_mouseDown)
            && !m_frame->selection()->isInPasswordField();

Which makes sense, because it doesn't seem to be that m_mouseDown is ever initialized, so it is an empty event that is sent to 

bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTarget, const PlatformMouseEvent& event, Clipboard* clipboard)

where the actual event that is used to get information for the event.clientX and event.clientY calls is initialized with that empty event's position (aka (0,0) ).

However, I am not sure why this works on the mac. I am currently trying to see if making the change breaks anything on the mac.
Comment 3 Jessie Berlin 2009-06-25 14:36:12 PDT
I have a patch, I just need to write the test for it.
Comment 4 Jessie Berlin 2009-06-26 12:36:21 PDT
Created attachment 31943 [details]
Fix: Make sure the m_mouseDown event is set correctly
Comment 5 Mark Rowe (bdash) 2009-06-26 12:41:08 PDT
Comment on attachment 31943 [details]
Fix: Make sure the m_mouseDown event is set correctly

> Index: WebCore/page/EventHandler.cpp
> ===================================================================
> --- WebCore/page/EventHandler.cpp	(revision 45259)
> +++ WebCore/page/EventHandler.cpp	(working copy)
> @@ -354,6 +354,8 @@ bool EventHandler::handleMousePressEvent
>  
>      m_mouseDownWasSingleClickInSelection = false;
>  
> +    m_mouseDown = event.event();
> +
>      if (event.isOverWidget() && passWidgetMouseDownEventToWidget(event))
>          return true;

You should remove the now-redundant assignment to m_mouseDown from EventHandler::mouseDown in EventHandlerMac.mm.

> +    <body onload="Test.runTest()">
> +        <h3>Test for <a href='https://bugs.webkit.org/show_bug.cgi?id=26723'>WebKit bug 26723</a>: clientX,Y , screenX , Y always (0, 0) in dragstart event</h3>
> +        <div id="notDraggable" class="test">
> +            DON'T BOTHER TRYING TO DRAG ME
> +        </div>
> +        <div id="alsoNotDraggable" class="test" style="display: inline-block;">
> +            DON'T BOTHER TRYING TO DRAG ME    
> +        </div>
> +        <div id="draggable" class="test" style="display: inline-block;">
> +            DRAG ME!
> +        </div>
> +        <div id="result"></div>
> +    </body>
> +</html>

What're the two non-draggable elements about?  They don't seem to be used in the test. If they're not needed, it would make the test clearer if they weren't present.


r=me
Comment 6 Jessie Berlin 2009-06-26 13:30:47 PDT
I removed the now redundant setting of m_mouseDown from EventHandlerMac.mm and also removed the extraneous non-draggable elements from the layout test.

committed with revision 45278