Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 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) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 27 | #include "core/events/EventDispatchMediator.h" |
| 28 | #include "core/events/MouseRelatedEvent.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | class Clipboard; |
| 33 | class EventDispatcher; |
| 34 | class PlatformMouseEvent; |
| 35 | |
| 36 | struct 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; |
| 48 | RefPtr<EventTarget> relatedTarget; |
| 49 | }; |
| 50 | |
| 51 | class MouseEvent : public MouseRelatedEvent { |
| 52 | public: |
| 53 | static PassRefPtr<MouseEvent> create() |
| 54 | { |
| 55 | return adoptRef(new MouseEvent); |
| 56 | } |
| 57 | |
| 58 | static PassRefPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<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 | PassRefPtr<EventTarget> relatedTarget); |
| 63 | |
| 64 | static PassRefPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, |
| 65 | int detail, int screenX, int screenY, int pageX, int pageY, |
| 66 | int movementX, int movementY, |
| 67 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, |
| 68 | PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard>, bool isSimulated = false); |
| 69 | |
| 70 | static PassRefPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtr<Node> relatedTarget); |
| 71 | |
| 72 | static PassRefPtr<MouseEvent> create(const AtomicString& eventType, const MouseEventInit&); |
| 73 | |
| 74 | virtual ~MouseEvent(); |
| 75 | |
| 76 | void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, |
| 77 | int detail, int screenX, int screenY, int clientX, int clientY, |
| 78 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
| 79 | unsigned short button, PassRefPtr<EventTarget> relatedTarget); |
| 80 | |
| 81 | // WinIE uses 1,4,2 for left/middle/right but not for click (just for mousedown/up, maybe others), |
| 82 | // but we will match the standard DOM. |
| 83 | unsigned short button() const { return m_button; } |
| 84 | bool buttonDown() const { return m_buttonDown; } |
| 85 | EventTarget* relatedTarget() const { return m_relatedTarget.get(); } |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 86 | EventTarget* relatedTarget(bool& isNull) const { isNull = !m_relatedTarget; return m_relatedTarget.get(); } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 87 | void setRelatedTarget(PassRefPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; } |
| 88 | |
| 89 | Clipboard* clipboard() const { return m_clipboard.get(); } |
| 90 | |
| 91 | Node* toElement() const; |
| 92 | Node* fromElement() const; |
| 93 | |
| 94 | Clipboard* dataTransfer() const { return isDragEvent() ? m_clipboard.get() : 0; } |
| 95 | |
| 96 | virtual const AtomicString& interfaceName() const; |
| 97 | |
| 98 | virtual bool isMouseEvent() const; |
| 99 | virtual bool isDragEvent() const; |
| 100 | virtual int which() const; |
| 101 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 102 | protected: |
| 103 | MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, |
| 104 | int detail, int screenX, int screenY, int pageX, int pageY, |
| 105 | int movementX, int movementY, |
| 106 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, |
| 107 | PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard>, bool isSimulated); |
| 108 | |
| 109 | MouseEvent(const AtomicString& type, const MouseEventInit&); |
| 110 | |
| 111 | MouseEvent(); |
| 112 | |
| 113 | private: |
| 114 | unsigned short m_button; |
| 115 | bool m_buttonDown; |
| 116 | RefPtr<EventTarget> m_relatedTarget; |
| 117 | RefPtr<Clipboard> m_clipboard; |
| 118 | }; |
| 119 | |
| 120 | class SimulatedMouseEvent : public MouseEvent { |
| 121 | public: |
| 122 | static PassRefPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent); |
| 123 | virtual ~SimulatedMouseEvent(); |
| 124 | |
| 125 | private: |
| 126 | SimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent); |
| 127 | }; |
| 128 | |
| 129 | class MouseEventDispatchMediator : public EventDispatchMediator { |
| 130 | public: |
| 131 | enum MouseEventType { SyntheticMouseEvent, NonSyntheticMouseEvent}; |
| 132 | static PassRefPtr<MouseEventDispatchMediator> create(PassRefPtr<MouseEvent>, MouseEventType = NonSyntheticMouseEvent); |
| 133 | |
| 134 | private: |
| 135 | explicit MouseEventDispatchMediator(PassRefPtr<MouseEvent>, MouseEventType); |
| 136 | MouseEvent* event() const; |
| 137 | |
| 138 | virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE; |
| 139 | bool isSyntheticMouseEvent() const { return m_mouseEventType == SyntheticMouseEvent; } |
| 140 | MouseEventType m_mouseEventType; |
| 141 | }; |
| 142 | |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 143 | DEFINE_EVENT_TYPE_CASTS(MouseEvent); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 144 | |
| 145 | } // namespace WebCore |
| 146 | |
| 147 | #endif // MouseEvent_h |