This source file includes following definitions.
- relatedTarget
- create
- create
- create
- m_buttonDown
- m_clipboard
- m_clipboard
- initMouseEvent
- interfaceName
- isMouseEvent
- isDragEvent
- which
- toElement
- fromElement
- trace
- create
- trace
- create
- m_mouseEventType
- event
- dispatchEvent
#include "config.h"
#include "core/events/MouseEvent.h"
#include "core/clipboard/Clipboard.h"
#include "core/dom/Element.h"
#include "core/events/EventDispatcher.h"
#include "platform/PlatformMouseEvent.h"
namespace WebCore {
MouseEventInit::MouseEventInit()
: screenX(0)
, screenY(0)
, clientX(0)
, clientY(0)
, ctrlKey(false)
, altKey(false)
, shiftKey(false)
, metaKey(false)
, button(0)
, relatedTarget(nullptr)
{
}
PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, const MouseEventInit& initializer)
{
return adoptRefWillBeNoop(new MouseEvent(type, initializer));
}
PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtr<Node> relatedTarget)
{
ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButton);
bool isMouseEnterOrLeave = eventType == EventTypeNames::mouseenter || eventType == EventTypeNames::mouseleave;
bool isCancelable = !isMouseEnterOrLeave;
bool isBubbling = !isMouseEnterOrLeave;
return MouseEvent::create(
eventType, isBubbling, isCancelable, view,
detail, event.globalPosition().x(), event.globalPosition().y(), event.position().x(), event.position().y(),
event.movementDelta().x(), event.movementDelta().y(),
event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(),
relatedTarget, nullptr, false);
}
PassRefPtrWillBeRawPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
int detail, int screenX, int screenY, int pageX, int pageY,
int movementX, int movementY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
PassRefPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<Clipboard> clipboard, bool isSimulated)
{
return adoptRefWillBeNoop(new MouseEvent(type, canBubble, cancelable, view,
detail, screenX, screenY, pageX, pageY,
movementX, movementY,
ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, clipboard, isSimulated));
}
MouseEvent::MouseEvent()
: m_button(0)
, m_buttonDown(false)
{
ScriptWrappable::init(this);
}
MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
int detail, int screenX, int screenY, int pageX, int pageY,
int movementX, int movementY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
unsigned short button, PassRefPtr<EventTarget> relatedTarget,
PassRefPtrWillBeRawPtr<Clipboard> clipboard, bool isSimulated)
: MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, IntPoint(screenX, screenY),
IntPoint(pageX, pageY),
IntPoint(movementX, movementY),
ctrlKey, altKey, shiftKey, metaKey, isSimulated)
, m_button(button == (unsigned short)-1 ? 0 : button)
, m_buttonDown(button != (unsigned short)-1)
, m_relatedTarget(relatedTarget)
, m_clipboard(clipboard)
{
ScriptWrappable::init(this);
}
MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& initializer)
: MouseRelatedEvent(eventType, initializer.bubbles, initializer.cancelable, initializer.view, initializer.detail, IntPoint(initializer.screenX, initializer.screenY),
IntPoint(0 , 0 ),
IntPoint(0 , 0 ),
initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializer.metaKey, false )
, m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button)
, m_buttonDown(initializer.button != (unsigned short)-1)
, m_relatedTarget(initializer.relatedTarget)
, m_clipboard(nullptr )
{
ScriptWrappable::init(this);
initCoordinates(IntPoint(initializer.clientX, initializer.clientY));
}
MouseEvent::~MouseEvent()
{
}
void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView> view,
int detail, int screenX, int screenY, int clientX, int clientY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
unsigned short button, PassRefPtr<EventTarget> relatedTarget)
{
if (dispatched())
return;
initUIEvent(type, canBubble, cancelable, view, detail);
m_screenLocation = IntPoint(screenX, screenY);
m_ctrlKey = ctrlKey;
m_altKey = altKey;
m_shiftKey = shiftKey;
m_metaKey = metaKey;
m_button = button == (unsigned short)-1 ? 0 : button;
m_buttonDown = button != (unsigned short)-1;
m_relatedTarget = relatedTarget;
initCoordinates(IntPoint(clientX, clientY));
}
const AtomicString& MouseEvent::interfaceName() const
{
return EventNames::MouseEvent;
}
bool MouseEvent::isMouseEvent() const
{
return true;
}
bool MouseEvent::isDragEvent() const
{
const AtomicString& t = type();
return t == EventTypeNames::dragenter || t == EventTypeNames::dragover || t == EventTypeNames::dragleave || t == EventTypeNames::drop
|| t == EventTypeNames::dragstart|| t == EventTypeNames::drag || t == EventTypeNames::dragend;
}
int MouseEvent::which() const
{
if (!m_buttonDown)
return 0;
return m_button + 1;
}
Node* MouseEvent::toElement() const
{
if (type() == EventTypeNames::mouseout || type() == EventTypeNames::mouseleave)
return relatedTarget() ? relatedTarget()->toNode() : 0;
return target() ? target()->toNode() : 0;
}
Node* MouseEvent::fromElement() const
{
if (type() != EventTypeNames::mouseout && type() != EventTypeNames::mouseleave)
return relatedTarget() ? relatedTarget()->toNode() : 0;
return target() ? target()->toNode() : 0;
}
void MouseEvent::trace(Visitor* visitor)
{
visitor->trace(m_clipboard);
MouseRelatedEvent::trace(visitor);
}
PassRefPtrWillBeRawPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent)
{
return adoptRefWillBeNoop(new SimulatedMouseEvent(eventType, view, underlyingEvent));
}
SimulatedMouseEvent::~SimulatedMouseEvent()
{
}
SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent)
: MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0,
0, 0,
false, false, false, false, 0, nullptr, nullptr, true)
{
if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) {
m_ctrlKey = keyStateEvent->ctrlKey();
m_altKey = keyStateEvent->altKey();
m_shiftKey = keyStateEvent->shiftKey();
m_metaKey = keyStateEvent->metaKey();
}
setUnderlyingEvent(underlyingEvent);
if (this->underlyingEvent() && this->underlyingEvent()->isMouseEvent()) {
MouseEvent* mouseEvent = toMouseEvent(this->underlyingEvent());
m_screenLocation = mouseEvent->screenLocation();
initCoordinates(mouseEvent->clientLocation());
}
}
void SimulatedMouseEvent::trace(Visitor* visitor)
{
MouseEvent::trace(visitor);
}
PassRefPtr<MouseEventDispatchMediator> MouseEventDispatchMediator::create(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent, MouseEventType mouseEventType)
{
return adoptRef(new MouseEventDispatchMediator(mouseEvent, mouseEventType));
}
MouseEventDispatchMediator::MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<MouseEvent> mouseEvent, MouseEventType mouseEventType)
: EventDispatchMediator(mouseEvent), m_mouseEventType(mouseEventType)
{
}
MouseEvent* MouseEventDispatchMediator::event() const
{
return toMouseEvent(EventDispatchMediator::event());
}
bool MouseEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
{
if (isSyntheticMouseEvent()) {
event()->eventPath().adjustForRelatedTarget(dispatcher->node(), event()->relatedTarget());
return dispatcher->dispatch();
}
if (isDisabledFormControl(dispatcher->node()))
return false;
if (event()->type().isEmpty())
return true;
ASSERT(!event()->target() || event()->target() != event()->relatedTarget());
EventTarget* relatedTarget = event()->relatedTarget();
event()->eventPath().adjustForRelatedTarget(dispatcher->node(), relatedTarget);
dispatcher->dispatch();
bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented();
if (event()->type() != EventTypeNames::click || event()->detail() != 2)
return !swallowEvent;
RefPtrWillBeRawPtr<MouseEvent> doubleClickEvent = MouseEvent::create();
doubleClickEvent->initMouseEvent(EventTypeNames::dblclick, event()->bubbles(), event()->cancelable(), event()->view(),
event()->detail(), event()->screenX(), event()->screenY(), event()->clientX(), event()->clientY(),
event()->ctrlKey(), event()->altKey(), event()->shiftKey(), event()->metaKey(),
event()->button(), relatedTarget);
if (event()->defaultHandled())
doubleClickEvent->setDefaultHandled();
EventDispatcher::dispatchEvent(dispatcher->node(), MouseEventDispatchMediator::create(doubleClickEvent));
if (doubleClickEvent->defaultHandled() || doubleClickEvent->defaultPrevented())
return false;
return !swallowEvent;
}
}