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: |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 53 | static PassRefPtrWillBeRawPtr<MouseEvent> create() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 54 | { |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame^] | 55 | return adoptRefWillBeNoop(new MouseEvent); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 58 | static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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, |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 62 | PassRefPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<Clipboard>, bool isSimulated = false); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 63 | |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 64 | static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtr<Node> relatedTarget); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 65 | |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 66 | static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, const MouseEventInit&); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 67 | |
| 68 | virtual ~MouseEvent(); |
| 69 | |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 70 | void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 71 | int detail, int screenX, int screenY, int clientX, int clientY, |
| 72 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
| 73 | unsigned short button, PassRefPtr<EventTarget> relatedTarget); |
| 74 | |
| 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) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 80 | 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] | 81 | void setRelatedTarget(PassRefPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; } |
| 82 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 83 | Node* toElement() const; |
| 84 | Node* fromElement() const; |
| 85 | |
| 86 | Clipboard* dataTransfer() const { return isDragEvent() ? m_clipboard.get() : 0; } |
| 87 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 88 | virtual const AtomicString& interfaceName() const OVERRIDE; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 89 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 90 | virtual bool isMouseEvent() const OVERRIDE; |
| 91 | virtual bool isDragEvent() const OVERRIDE FINAL; |
| 92 | virtual int which() const OVERRIDE FINAL; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 93 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 94 | virtual void trace(Visitor*) OVERRIDE; |
| 95 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 96 | protected: |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 97 | MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 98 | int detail, int screenX, int screenY, int pageX, int pageY, |
| 99 | int movementX, int movementY, |
| 100 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 101 | PassRefPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<Clipboard>, bool isSimulated); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 102 | |
| 103 | MouseEvent(const AtomicString& type, const MouseEventInit&); |
| 104 | |
| 105 | MouseEvent(); |
| 106 | |
| 107 | private: |
| 108 | unsigned short m_button; |
| 109 | bool m_buttonDown; |
| 110 | RefPtr<EventTarget> m_relatedTarget; |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 111 | RefPtrWillBeMember<Clipboard> m_clipboard; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 112 | }; |
| 113 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 114 | class SimulatedMouseEvent FINAL : public MouseEvent { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 115 | public: |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame^] | 116 | static PassRefPtrWillBeRawPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 117 | virtual ~SimulatedMouseEvent(); |
| 118 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 119 | virtual void trace(Visitor*) OVERRIDE; |
| 120 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 121 | private: |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame^] | 122 | SimulatedMouseEvent(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 125 | class MouseEventDispatchMediator FINAL : public EventDispatchMediator { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 126 | public: |
| 127 | enum MouseEventType { SyntheticMouseEvent, NonSyntheticMouseEvent}; |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame^] | 128 | static PassRefPtr<MouseEventDispatchMediator> create(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType = NonSyntheticMouseEvent); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 129 | |
| 130 | private: |
Ben Murdoch | a9984bf | 2014-04-10 11:22:39 +0100 | [diff] [blame^] | 131 | explicit MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 132 | MouseEvent* event() const; |
| 133 | |
| 134 | virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE; |
| 135 | bool isSyntheticMouseEvent() const { return m_mouseEventType == SyntheticMouseEvent; } |
| 136 | MouseEventType m_mouseEventType; |
| 137 | }; |
| 138 | |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 139 | DEFINE_EVENT_TYPE_CASTS(MouseEvent); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 140 | |
| 141 | } // namespace WebCore |
| 142 | |
| 143 | #endif // MouseEvent_h |