summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/MouseEvent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/dom/MouseEvent.cpp')
-rw-r--r--Source/WebCore/dom/MouseEvent.cpp195
1 files changed, 58 insertions, 137 deletions
diff --git a/Source/WebCore/dom/MouseEvent.cpp b/Source/WebCore/dom/MouseEvent.cpp
index 5682f8a53..b240a7dbf 100644
--- a/Source/WebCore/dom/MouseEvent.cpp
+++ b/Source/WebCore/dom/MouseEvent.cpp
@@ -2,7 +2,7 @@
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
- * Copyright (C) 2003, 2005, 2006, 2008, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2016 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -23,7 +23,7 @@
#include "config.h"
#include "MouseEvent.h"
-#include "Clipboard.h"
+#include "DataTransfer.h"
#include "EventNames.h"
#include "Frame.h"
#include "FrameView.h"
@@ -33,29 +33,13 @@
namespace WebCore {
-MouseEventInit::MouseEventInit()
- : screenX(0)
- , screenY(0)
- , clientX(0)
- , clientY(0)
- , ctrlKey(false)
- , altKey(false)
- , shiftKey(false)
- , metaKey(false)
- , button(0)
- , relatedTarget(0)
+Ref<MouseEvent> MouseEvent::create(const AtomicString& type, const MouseEventInit& initializer, IsTrusted isTrusted)
{
+ return adoptRef(*new MouseEvent(type, initializer, isTrusted));
}
-PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& type, const MouseEventInit& initializer)
+Ref<MouseEvent> MouseEvent::create(const AtomicString& eventType, DOMWindow* view, const PlatformMouseEvent& event, int detail, Node* relatedTarget)
{
- return adoptRef(new MouseEvent(type, initializer));
-}
-
-PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& eventType, PassRefPtr<AbstractView> view, const PlatformMouseEvent& event, int detail, PassRefPtr<Node> relatedTarget)
-{
- ASSERT(event.type() == PlatformEvent::MouseMoved || event.button() != NoButton);
-
bool isMouseEnterOrLeave = eventType == eventNames().mouseenterEvent || eventType == eventNames().mouseleaveEvent;
bool isCancelable = eventType != eventNames().mousemoveEvent && !isMouseEnterOrLeave;
bool canBubble = !isMouseEnterOrLeave;
@@ -66,92 +50,79 @@ PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& eventType, PassRef
event.movementDelta().x(), event.movementDelta().y(),
#endif
event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(),
- relatedTarget);
+ relatedTarget, event.force(), event.syntheticClickType());
}
-PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, double timestamp, PassRefPtr<AbstractView> view,
- int detail, int screenX, int screenY, int pageX, int pageY,
+Ref<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, double timestamp, DOMWindow* view, int detail, int screenX, int screenY, int pageX, int pageY,
#if ENABLE(POINTER_LOCK)
int movementX, int movementY,
#endif
- bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
- PassRefPtr<EventTarget> relatedTarget)
-
+ bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* dataTransfer, bool isSimulated)
{
- return MouseEvent::create(type, canBubble, cancelable, timestamp, view,
- detail, screenX, screenY, pageX, pageY,
+ return adoptRef(*new MouseEvent(type, canBubble, cancelable, timestamp, view,
+ detail, { screenX, screenY }, { pageX, pageY },
#if ENABLE(POINTER_LOCK)
- movementX, movementY,
+ { movementX, movementY },
#endif
- ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, 0, false);
+ ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, force, syntheticClickType, dataTransfer, isSimulated));
}
-PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& type, bool canBubble, bool cancelable, double timestamp, PassRefPtr<AbstractView> view,
- int detail, int screenX, int screenY, int pageX, int pageY,
-#if ENABLE(POINTER_LOCK)
- int movementX, int movementY,
-#endif
- bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
- PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard> clipboard, bool isSimulated)
+Ref<MouseEvent> MouseEvent::create(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow* view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short syntheticClickType, EventTarget* relatedTarget)
{
- return adoptRef(new MouseEvent(type, canBubble, cancelable, timestamp, view,
- detail, screenX, screenY, pageX, pageY,
-#if ENABLE(POINTER_LOCK)
- movementX, movementY,
-#endif
- ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, clipboard, isSimulated));
+ return adoptRef(*new MouseEvent(eventType, canBubble, cancelable, view, detail, { screenX, screenY }, { clientX, clientY }, ctrlKey, altKey, shiftKey, metaKey, button, syntheticClickType, relatedTarget));
}
MouseEvent::MouseEvent()
- : m_button(0)
- , m_buttonDown(false)
{
}
-MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double timestamp, PassRefPtr<AbstractView> view,
- int detail, int screenX, int screenY, int pageX, int pageY,
+MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double timestamp, DOMWindow* view, int detail, const IntPoint& screenLocation, const IntPoint& windowLocation,
#if ENABLE(POINTER_LOCK)
- int movementX, int movementY,
+ const IntPoint& movementDelta,
#endif
- bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
- unsigned short button, PassRefPtr<EventTarget> relatedTarget,
- PassRefPtr<Clipboard> clipboard, bool isSimulated)
- : MouseRelatedEvent(eventType, canBubble, cancelable, timestamp, view, detail, IntPoint(screenX, screenY),
- IntPoint(pageX, pageY),
+ bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* dataTransfer, bool isSimulated)
+ : MouseRelatedEvent(eventType, canBubble, cancelable, timestamp, view, detail, screenLocation, windowLocation,
#if ENABLE(POINTER_LOCK)
- IntPoint(movementX, movementY),
+ movementDelta,
#endif
- ctrlKey, altKey, shiftKey, metaKey, isSimulated)
+ ctrlKey, altKey, shiftKey, metaKey, isSimulated)
, m_button(button == (unsigned short)-1 ? 0 : button)
+ , m_syntheticClickType(button == (unsigned short)-1 ? 0 : syntheticClickType)
, m_buttonDown(button != (unsigned short)-1)
, m_relatedTarget(relatedTarget)
- , m_clipboard(clipboard)
+ , m_force(force)
+ , m_dataTransfer(dataTransfer)
{
}
-MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& initializer)
- : MouseRelatedEvent(eventType, initializer.bubbles, initializer.cancelable, currentTime(), initializer.view, initializer.detail, IntPoint(initializer.screenX, initializer.screenY),
- IntPoint(0 /* pageX */, 0 /* pageY */),
+MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, DOMWindow* view, int detail, const IntPoint& screenLocation, const IntPoint& clientLocation, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, unsigned short syntheticClickType, EventTarget* relatedTarget)
+ : MouseRelatedEvent(eventType, canBubble, cancelable, WTF::currentTime(), view, detail, screenLocation, { },
#if ENABLE(POINTER_LOCK)
- IntPoint(0 /* movementX */, 0 /* movementY */),
+ { },
#endif
- initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializer.metaKey, false /* isSimulated */)
+ ctrlKey, altKey, shiftKey, metaKey, false)
+ , m_button(button == (unsigned short)-1 ? 0 : button)
+ , m_syntheticClickType(button == (unsigned short)-1 ? 0 : syntheticClickType)
+ , m_buttonDown(button != (unsigned short)-1)
+ , m_relatedTarget(relatedTarget)
+{
+ initCoordinates(clientLocation);
+}
+
+MouseEvent::MouseEvent(const AtomicString& eventType, const MouseEventInit& initializer, IsTrusted isTrusted)
+ : MouseRelatedEvent(eventType, initializer, isTrusted)
, m_button(initializer.button == (unsigned short)-1 ? 0 : initializer.button)
, m_buttonDown(initializer.button != (unsigned short)-1)
, m_relatedTarget(initializer.relatedTarget)
- , m_clipboard(0 /* clipboard */)
{
- initCoordinates(IntPoint(initializer.clientX, initializer.clientY));
+ initCoordinates({ initializer.clientX, initializer.clientY });
}
MouseEvent::~MouseEvent()
{
}
-void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<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)
+void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, DOMWindow* view, int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, EventTarget* relatedTarget)
{
if (dispatched())
return;
@@ -164,13 +135,14 @@ void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool c
m_shiftKey = shiftKey;
m_metaKey = metaKey;
m_button = button == (unsigned short)-1 ? 0 : button;
+ m_syntheticClickType = 0;
m_buttonDown = button != (unsigned short)-1;
m_relatedTarget = relatedTarget;
initCoordinates(IntPoint(clientX, clientY));
// FIXME: m_isSimulated is not set to false here.
- // FIXME: m_clipboard is not set to 0 here.
+ // FIXME: m_dataTransfer is not set to 0 here.
}
EventInterface MouseEvent::eventInterface() const
@@ -185,15 +157,28 @@ bool MouseEvent::isMouseEvent() const
bool MouseEvent::isDragEvent() const
{
- const AtomicString& t = type();
- return t == eventNames().dragenterEvent || t == eventNames().dragoverEvent || t == eventNames().dragleaveEvent || t == eventNames().dropEvent
- || t == eventNames().dragstartEvent|| t == eventNames().dragEvent || t == eventNames().dragendEvent;
+ // This function is only used to decide to return nullptr for dataTransfer even when m_dataTransfer is non-null.
+ // FIXME: Is that really valuable? Why will m_dataTransfer be non-null but we need to return null for dataTransfer?
+ // Quite peculiar to decide based on the type string; may have been be provided by call to JavaScript constructor.
+ auto& type = this->type();
+ return type == eventNames().dragEvent
+ || type == eventNames().dragendEvent
+ || type == eventNames().dragenterEvent
+ || type == eventNames().dragleaveEvent
+ || type == eventNames().dragoverEvent
+ || type == eventNames().dragstartEvent
+ || type == eventNames().dropEvent;
+}
+
+bool MouseEvent::canTriggerActivationBehavior(const Event& event)
+{
+ return event.type() == eventNames().clickEvent && (!is<MouseEvent>(event) || downcast<MouseEvent>(event).button() != RightButton);
}
int MouseEvent::which() const
{
// For the DOM, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
- // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
+ // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
// So we must add 1.
if (!m_buttonDown)
return 0;
@@ -222,68 +207,4 @@ Node* MouseEvent::fromElement() const
return target() ? target()->toNode() : nullptr;
}
-// FIXME: Fix positioning. e.g. We need to consider border/padding.
-// https://bugs.webkit.org/show_bug.cgi?id=93696
-inline static int adjustedClientX(int innerClientX, HTMLIFrameElement* iframe, FrameView* frameView)
-{
- return iframe->offsetLeft() - frameView->scrollX() + innerClientX;
-}
-
-inline static int adjustedClientY(int innerClientY, HTMLIFrameElement* iframe, FrameView* frameView)
-{
- return iframe->offsetTop() - frameView->scrollY() + innerClientY;
-}
-
-PassRefPtr<Event> MouseEvent::cloneFor(HTMLIFrameElement* iframe) const
-{
- ASSERT(iframe);
- RefPtr<MouseEvent> clonedMouseEvent = MouseEvent::create();
- Frame* frame = iframe->document().frame();
- FrameView* frameView = frame ? frame->view() : 0;
- clonedMouseEvent->initMouseEvent(type(), bubbles(), cancelable(),
- iframe->document().defaultView(),
- detail(), screenX(), screenY(),
- frameView ? adjustedClientX(clientX(), iframe, frameView) : 0,
- frameView ? adjustedClientY(clientY(), iframe, frameView) : 0,
- ctrlKey(), altKey(), shiftKey(), metaKey(),
- button(),
- // Nullifies relatedTarget.
- 0);
- return clonedMouseEvent.release();
-}
-
-PassRefPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const AtomicString& eventType, PassRefPtr<AbstractView> view, PassRefPtr<Event> underlyingEvent, Element* target)
-{
- return adoptRef(new SimulatedMouseEvent(eventType, view, underlyingEvent, target));
-}
-
-SimulatedMouseEvent::~SimulatedMouseEvent()
-{
-}
-
-SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<AbstractView> view, PassRefPtr<Event> underlyingEvent, Element* target)
- : MouseEvent(eventType, true, true, underlyingEvent ? underlyingEvent->timeStamp() : currentTime(), view, 0, 0, 0, 0, 0,
-#if ENABLE(POINTER_LOCK)
- 0, 0,
-#endif
- false, false, false, false, 0, 0, 0, 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 = static_cast<MouseEvent*>(this->underlyingEvent());
- m_screenLocation = mouseEvent->screenLocation();
- initCoordinates(mouseEvent->clientLocation());
- } else if (target) {
- m_screenLocation = target->screenRect().center();
- initCoordinates(LayoutPoint(target->clientRect().center()));
- }
-}
-
} // namespace WebCore