PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& eventType, PassRefPtr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtr<Node> relatedTarget) { ASSERT(event.eventType() == MouseEventMoved || event.button() != NoButton); bool isCancelable = eventType != eventNames().mousemoveEvent; return MouseEvent::create(eventType, true, isCancelable, view, detail, event.globalX(), event.globalY(), event.x(), event.y(), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(), relatedTarget, 0, false); }
bool EventTargetNode::dispatchMouseEvent(const PlatformMouseEvent& event, const AtomicString& eventType, int detail, Node* relatedTarget) { ASSERT(!eventDispatchForbidden()); IntPoint contentsPos; if (FrameView* view = document()->view()) contentsPos = view->windowToContents(event.pos()); short button = event.button(); ASSERT(event.eventType() == MouseEventMoved || button != NoButton); return dispatchMouseEvent(eventType, button, detail, contentsPos.x(), contentsPos.y(), event.globalX(), event.globalY(), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), false, relatedTarget); }
void WebPage::mouseEvent(const PlatformMouseEvent& event) { if (!m_mainFrame->coreFrame()->view()) return; switch (event.eventType()) { case WebCore::MouseEventPressed: m_mainFrame->coreFrame()->eventHandler()->handleMousePressEvent(event); break; case WebCore::MouseEventReleased: m_mainFrame->coreFrame()->eventHandler()->handleMouseReleaseEvent(event); break; case WebCore::MouseEventMoved: m_mainFrame->coreFrame()->eventHandler()->mouseMoved(event); break; default: ASSERT_NOT_REACHED(); break; } }
bool EventDispatcher::dispatchMouseEvent(Node* node, const PlatformMouseEvent& event, const AtomicString& eventType, int detail, Node* relatedTargetArg) { ASSERT(!eventDispatchForbidden()); ASSERT(event.eventType() == MouseEventMoved || event.button() != NoButton); if (node->disabled()) // Don't even send DOM events for disabled controls.. return true; if (eventType.isEmpty()) return false; // Shouldn't happen. EventDispatcher dispatcher(node); // Attempting to dispatch with a non-EventTarget relatedTarget causes the relatedTarget to be silently ignored. RefPtr<Node> relatedTarget = pullOutOfShadow(relatedTargetArg); RefPtr<MouseEvent> mouseEvent = MouseEvent::create(eventType, node->document()->defaultView(), event, detail, relatedTarget); bool swallowEvent = false; dispatcher.dispatchEvent(mouseEvent); bool defaultHandled = mouseEvent->defaultHandled(); bool defaultPrevented = mouseEvent->defaultPrevented(); if (defaultHandled || defaultPrevented) swallowEvent = true; // Special case: If it's a double click event, we also send the dblclick event. This is not part // of the DOM specs, but is used for compatibility with the ondblclick="" attribute. This is treated // as a separate event in other DOM-compliant browsers like Firefox, and so we do the same. if (eventType == eventNames().clickEvent && detail == 2) { RefPtr<Event> doubleClickEvent = MouseEvent::create(eventNames().dblclickEvent, node->document()->defaultView(), event, detail, relatedTarget); if (defaultHandled) doubleClickEvent->setDefaultHandled(); dispatcher.dispatchEvent(doubleClickEvent); if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented()) swallowEvent = true; } return swallowEvent; }