blob: 94d14559b340682e7ab3f752bb1da45200ec27dc [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
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.
6 *
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.
11 *
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.
16 *
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.
21 *
22 */
23
24#ifndef MouseEvent_h
25#define MouseEvent_h
26
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +010027#include "core/events/EventDispatchMediator.h"
28#include "core/events/MouseRelatedEvent.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010029
30namespace WebCore {
31
Ben Murdoch197021e2014-07-20 18:26:29 -070032class DataTransfer;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010033class EventDispatcher;
34class PlatformMouseEvent;
35
36struct MouseEventInit : public UIEventInit {
37 MouseEventInit();
38
39 int screenX;
40 int screenY;
41 int clientX;
42 int clientY;
43 bool ctrlKey;
44 bool altKey;
45 bool shiftKey;
46 bool metaKey;
47 unsigned short button;
Torne (Richard Coles)f6b7aed2014-06-09 12:01:17 +010048 RefPtrWillBeMember<EventTarget> relatedTarget;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010049};
50
51class MouseEvent : public MouseRelatedEvent {
52public:
Ben Murdoch07a852d2014-03-31 11:51:52 +010053 static PassRefPtrWillBeRawPtr<MouseEvent> create()
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010054 {
Ben Murdocha9984bf2014-04-10 11:22:39 +010055 return adoptRefWillBeNoop(new MouseEvent);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010056 }
57
Ben Murdoch07a852d2014-03-31 11:51:52 +010058 static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010059 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,
Ben Murdoch197021e2014-07-20 18:26:29 -070062 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<DataTransfer>, bool isSimulated = false);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010063
Torne (Richard Coles)f6b7aed2014-06-09 12:01:17 +010064 static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010065
Ben Murdoch07a852d2014-03-31 11:51:52 +010066 static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, const MouseEventInit&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010067
68 virtual ~MouseEvent();
69
Ben Murdoch07a852d2014-03-31 11:51:52 +010070 void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010071 int detail, int screenX, int screenY, int clientX, int clientY,
72 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
Torne (Richard Coles)f6b7aed2014-06-09 12:01:17 +010073 unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010074
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(); }
Torne (Richard Coles)f6b7aed2014-06-09 12:01:17 +010080 void setRelatedTarget(PassRefPtrWillBeRawPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010081
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010082 Node* toElement() const;
83 Node* fromElement() const;
84
Ben Murdoch197021e2014-07-20 18:26:29 -070085 DataTransfer* dataTransfer() const { return isDragEvent() ? m_dataTransfer.get() : 0; }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010086
Torne (Richard Coles)09380292014-02-21 12:17:33 +000087 virtual const AtomicString& interfaceName() const OVERRIDE;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010088
Torne (Richard Coles)09380292014-02-21 12:17:33 +000089 virtual bool isMouseEvent() const OVERRIDE;
90 virtual bool isDragEvent() const OVERRIDE FINAL;
91 virtual int which() const OVERRIDE FINAL;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010092
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000093 virtual void trace(Visitor*) OVERRIDE;
94
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010095protected:
Ben Murdoch07a852d2014-03-31 11:51:52 +010096 MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010097 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,
Ben Murdoch197021e2014-07-20 18:26:29 -0700100 PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<DataTransfer>, bool isSimulated);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100101
102 MouseEvent(const AtomicString& type, const MouseEventInit&);
103
104 MouseEvent();
105
106private:
107 unsigned short m_button;
108 bool m_buttonDown;
Torne (Richard Coles)f6b7aed2014-06-09 12:01:17 +0100109 RefPtrWillBeMember<EventTarget> m_relatedTarget;
Ben Murdoch197021e2014-07-20 18:26:29 -0700110 RefPtrWillBeMember<DataTransfer> m_dataTransfer;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100111};
112
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000113class SimulatedMouseEvent FINAL : public MouseEvent {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100114public:
Ben Murdocha9984bf2014-04-10 11:22:39 +0100115 static PassRefPtrWillBeRawPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100116 virtual ~SimulatedMouseEvent();
117
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000118 virtual void trace(Visitor*) OVERRIDE;
119
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100120private:
Ben Murdocha9984bf2014-04-10 11:22:39 +0100121 SimulatedMouseEvent(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100122};
123
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000124class MouseEventDispatchMediator FINAL : public EventDispatchMediator {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100125public:
126 enum MouseEventType { SyntheticMouseEvent, NonSyntheticMouseEvent};
Torne (Richard Coles)5d92fed2014-06-20 14:52:37 +0100127 static PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> create(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType = NonSyntheticMouseEvent);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100128
129private:
Ben Murdocha9984bf2014-04-10 11:22:39 +0100130 explicit MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100131 MouseEvent* event() const;
132
133 virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
134 bool isSyntheticMouseEvent() const { return m_mouseEventType == SyntheticMouseEvent; }
135 MouseEventType m_mouseEventType;
136};
137
Torne (Richard Coles)f79f16f2013-10-31 11:16:44 +0000138DEFINE_EVENT_TYPE_CASTS(MouseEvent);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100139
140} // namespace WebCore
141
142#endif // MouseEvent_h