2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
27 #include "core/events/EventDispatchMediator.h"
28 #include "core/events/MouseRelatedEvent.h"
33 class EventDispatcher;
34 class PlatformMouseEvent;
36 struct MouseEventInit : public UIEventInit {
47 unsigned short button;
48 RefPtrWillBeMember<EventTarget> relatedTarget;
51 class MouseEvent : public MouseRelatedEvent {
53 static PassRefPtrWillBeRawPtr<MouseEvent> create()
55 return adoptRefWillBeNoop(new MouseEvent);
58 static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
59 int detail, int screenX, int screenY, int pageX, int pageY,
60 int movementX, int movementY,
61 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
62 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<DataTransfer>, bool isSimulated = false);
64 static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget);
66 static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, const MouseEventInit&);
68 virtual ~MouseEvent();
70 void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
71 int detail, int screenX, int screenY, int clientX, int clientY,
72 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
73 unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget);
75 // WinIE uses 1,4,2 for left/middle/right but not for click (just for mousedown/up, maybe others),
76 // but we will match the standard DOM.
77 unsigned short button() const { return m_button; }
78 bool buttonDown() const { return m_buttonDown; }
79 EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
80 void setRelatedTarget(PassRefPtrWillBeRawPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; }
82 Node* toElement() const;
83 Node* fromElement() const;
85 DataTransfer* dataTransfer() const { return isDragEvent() ? m_dataTransfer.get() : 0; }
87 virtual const AtomicString& interfaceName() const OVERRIDE;
89 virtual bool isMouseEvent() const OVERRIDE;
90 virtual bool isDragEvent() const OVERRIDE FINAL;
91 virtual int which() const OVERRIDE FINAL;
93 virtual void trace(Visitor*) OVERRIDE;
96 MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
97 int detail, int screenX, int screenY, int pageX, int pageY,
98 int movementX, int movementY,
99 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
100 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<DataTransfer>, bool isSimulated);
102 MouseEvent(const AtomicString& type, const MouseEventInit&);
107 unsigned short m_button;
109 RefPtrWillBeMember<EventTarget> m_relatedTarget;
110 RefPtrWillBeMember<DataTransfer> m_dataTransfer;
113 class SimulatedMouseEvent FINAL : public MouseEvent {
115 static PassRefPtrWillBeRawPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent);
116 virtual ~SimulatedMouseEvent();
118 virtual void trace(Visitor*) OVERRIDE;
121 SimulatedMouseEvent(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent);
124 class MouseEventDispatchMediator FINAL : public EventDispatchMediator {
126 enum MouseEventType { SyntheticMouseEvent, NonSyntheticMouseEvent};
127 static PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> create(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType = NonSyntheticMouseEvent);
130 explicit MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType);
131 MouseEvent* event() const;
133 virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
134 bool isSyntheticMouseEvent() const { return m_mouseEventType == SyntheticMouseEvent; }
135 MouseEventType m_mouseEventType;
138 DEFINE_EVENT_TYPE_CASTS(MouseEvent);
142 #endif // MouseEvent_h