Commit 859a5f97 authored by akling@apple.com's avatar akling@apple.com

CTTE: Drag events are only dispatched on Elements.

<https://webkit.org/b/122250>

Reviewed by Antti Koivisto.

We never dispatch drag events on non-Element nodes so tighten up the
code to operate on Elements instead.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156815 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent be1a3748
2013-10-02 Andreas Kling <akling@apple.com>
CTTE: Drag events are only dispatched on Elements.
<https://webkit.org/b/122250>
Reviewed by Antti Koivisto.
We never dispatch drag events on non-Element nodes so tighten up the
code to operate on Elements instead.
2013-10-02 Hans Muller <hmuller@adobe.com>
[CSS Shapes] Implement the shape-image-threshold property
......@@ -1965,7 +1965,7 @@ bool EventHandler::handlePasteGlobalSelection(const PlatformMouseEvent& mouseEve
#if ENABLE(DRAG_SUPPORT)
bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTarget, const PlatformMouseEvent& event, Clipboard* clipboard)
bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Element& dragTarget, const PlatformMouseEvent& event, Clipboard* clipboard)
{
FrameView* view = m_frame.view();
......@@ -1983,7 +1983,7 @@ bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTa
event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(),
0, 0, clipboard);
dragTarget->dispatchEvent(me.get(), IGNORE_EXCEPTION);
dragTarget.dispatchEvent(me.get(), IGNORE_EXCEPTION);
return me->defaultPrevented();
}
......@@ -2097,10 +2097,14 @@ bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard*
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::DisallowShadowContent);
MouseEventWithHitTestResults mev = prepareMouseEvent(request, event);
// Drag events should never go to text nodes (following IE, and proper mouseover/out dispatch)
RefPtr<Node> newTarget = mev.targetNode();
if (newTarget && newTarget->isTextNode())
newTarget = newTarget->parentOrShadowHostElement();
RefPtr<Element> newTarget;
if (Node* targetNode = mev.targetNode()) {
// Drag events should never go to non-element nodes (following IE, and proper mouseover/out dispatch)
if (!targetNode->isElementNode())
newTarget = targetNode->parentOrShadowHostElement();
else
newTarget = toElement(targetNode);
}
m_autoscrollController->updateDragAndDrop(newTarget.get(), event.position(), event.timestamp());
......@@ -2120,7 +2124,7 @@ bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard*
// for now we don't care if event handler cancels default behavior, since there is none
dispatchDragSrcEvent(eventNames().dragEvent, event);
}
accept = dispatchDragEvent(eventNames().dragenterEvent, newTarget.get(), event, clipboard);
accept = dispatchDragEvent(eventNames().dragenterEvent, *newTarget, event, clipboard);
if (!accept)
accept = findDropZone(newTarget.get(), clipboard);
}
......@@ -2129,7 +2133,7 @@ bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard*
if (targetFrame)
accept = targetFrame->eventHandler().updateDragAndDrop(event, clipboard);
} else if (m_dragTarget)
dispatchDragEvent(eventNames().dragleaveEvent, m_dragTarget.get(), event, clipboard);
dispatchDragEvent(eventNames().dragleaveEvent, *m_dragTarget, event, clipboard);
if (newTarget) {
// We do not explicitly call dispatchDragEvent here because it could ultimately result in the appearance that
......@@ -2147,14 +2151,13 @@ bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard*
// for now we don't care if event handler cancels default behavior, since there is none
dispatchDragSrcEvent(eventNames().dragEvent, event);
}
accept = dispatchDragEvent(eventNames().dragoverEvent, newTarget.get(), event, clipboard);
accept = dispatchDragEvent(eventNames().dragoverEvent, *newTarget, event, clipboard);
if (!accept)
accept = findDropZone(newTarget.get(), clipboard);
m_shouldOnlyFireDragOverEvent = false;
}
}
m_dragTarget = newTarget;
m_dragTarget = newTarget.release();
return accept;
}
......@@ -2164,10 +2167,10 @@ void EventHandler::cancelDragAndDrop(const PlatformMouseEvent& event, Clipboard*
if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
if (targetFrame)
targetFrame->eventHandler().cancelDragAndDrop(event, clipboard);
} else if (m_dragTarget.get()) {
} else if (m_dragTarget) {
if (dragState().source && dragState().shouldDispatchEvents)
dispatchDragSrcEvent(eventNames().dragEvent, event);
dispatchDragEvent(eventNames().dragleaveEvent, m_dragTarget.get(), event, clipboard);
dispatchDragEvent(eventNames().dragleaveEvent, *m_dragTarget, event, clipboard);
}
clearDragState();
}
......@@ -2179,8 +2182,8 @@ bool EventHandler::performDragAndDrop(const PlatformMouseEvent& event, Clipboard
if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
if (targetFrame)
preventedDefault = targetFrame->eventHandler().performDragAndDrop(event, clipboard);
} else if (m_dragTarget.get())
preventedDefault = dispatchDragEvent(eventNames().dropEvent, m_dragTarget.get(), event, clipboard);
} else if (m_dragTarget)
preventedDefault = dispatchDragEvent(eventNames().dropEvent, *m_dragTarget, event, clipboard);
clearDragState();
return preventedDefault;
}
......@@ -2188,7 +2191,7 @@ bool EventHandler::performDragAndDrop(const PlatformMouseEvent& event, Clipboard
void EventHandler::clearDragState()
{
stopAutoscrollTimer();
m_dragTarget = 0;
m_dragTarget = nullptr;
m_capturingMouseEventsElement = nullptr;
m_shouldOnlyFireDragOverEvent = false;
#if PLATFORM(MAC)
......@@ -3535,7 +3538,7 @@ void EventHandler::updateDragStateAfterEditDragIfNeeded(Element* rootEditableEle
// Return value indicates if we should continue "default processing", i.e., whether event handler canceled.
bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const PlatformMouseEvent& event)
{
return !dispatchDragEvent(eventType, dragState().source.get(), event, dragState().clipboard.get());
return !dispatchDragEvent(eventType, *dragState().source, event, dragState().clipboard.get());
}
static bool ExactlyOneBitSet(DragSourceAction n)
......
......@@ -328,7 +328,7 @@ private:
bool dispatchMouseEvent(const AtomicString& eventType, Node* target, bool cancelable, int clickCount, const PlatformMouseEvent&, bool setUnder);
#if ENABLE(DRAG_SUPPORT)
bool dispatchDragEvent(const AtomicString& eventType, Node* target, const PlatformMouseEvent&, Clipboard*);
bool dispatchDragEvent(const AtomicString& eventType, Element& target, const PlatformMouseEvent&, Clipboard*);
void freeClipboard();
......@@ -461,7 +461,7 @@ private:
RefPtr<Node> m_clickNode;
#if ENABLE(DRAG_SUPPORT)
RefPtr<Node> m_dragTarget;
RefPtr<Element> m_dragTarget;
bool m_shouldOnlyFireDragOverEvent;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment