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-2016 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 | #pragma once |
25 | |
26 | #include "EventTarget.h" |
27 | #include "MouseEventInit.h" |
28 | #include "MouseRelatedEvent.h" |
29 | |
30 | #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY) |
31 | #include "PlatformTouchEventIOS.h" |
32 | #endif |
33 | |
34 | namespace WebCore { |
35 | |
36 | class DataTransfer; |
37 | class Node; |
38 | class PlatformMouseEvent; |
39 | |
40 | class MouseEvent : public MouseRelatedEvent { |
41 | public: |
42 | WEBCORE_EXPORT static Ref<MouseEvent> create(const AtomicString& type, CanBubble, IsCancelable, IsComposed, MonotonicTime timestamp, RefPtr<WindowProxy>&&, int detail, |
43 | const IntPoint& screenLocation, const IntPoint& windowLocation, const IntPoint& movementDelta, OptionSet<Modifier>, unsigned short button, unsigned short buttons, |
44 | EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer* = nullptr, IsSimulated = IsSimulated::No, IsTrusted = IsTrusted::Yes); |
45 | |
46 | WEBCORE_EXPORT static Ref<MouseEvent> create(const AtomicString& eventType, RefPtr<WindowProxy>&&, const PlatformMouseEvent&, int detail, Node* relatedTarget); |
47 | |
48 | static Ref<MouseEvent> create(const AtomicString& eventType, CanBubble, IsCancelable, IsComposed, RefPtr<WindowProxy>&&, int detail, |
49 | int screenX, int screenY, int clientX, int clientY, OptionSet<Modifier>, unsigned short button, unsigned short buttons, |
50 | unsigned short syntheticClickType, EventTarget* relatedTarget); |
51 | |
52 | static Ref<MouseEvent> createForBindings() { return adoptRef(*new MouseEvent); } |
53 | |
54 | static Ref<MouseEvent> create(const AtomicString& eventType, const MouseEventInit&); |
55 | |
56 | #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY) |
57 | static Ref<MouseEvent> create(const PlatformTouchEvent&, unsigned touchIndex, Ref<WindowProxy>&&); |
58 | #endif |
59 | |
60 | virtual ~MouseEvent(); |
61 | |
62 | WEBCORE_EXPORT void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, RefPtr<WindowProxy>&&, |
63 | int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
64 | unsigned short button, EventTarget* relatedTarget); |
65 | |
66 | void initMouseEventQuirk(JSC::ExecState&, ScriptExecutionContext&, const AtomicString& type, bool canBubble, bool cancelable, RefPtr<WindowProxy>&&, |
67 | int detail, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, |
68 | unsigned short button, JSC::JSValue relatedTarget); |
69 | |
70 | unsigned short button() const { return m_button; } |
71 | unsigned short buttons() const { return m_buttons; } |
72 | unsigned short syntheticClickType() const { return m_syntheticClickType; } |
73 | bool buttonDown() const { return m_buttonDown; } |
74 | EventTarget* relatedTarget() const final { return m_relatedTarget.get(); } |
75 | double force() const { return m_force; } |
76 | void setForce(double force) { m_force = force; } |
77 | |
78 | WEBCORE_EXPORT RefPtr<Node> toElement() const; |
79 | WEBCORE_EXPORT RefPtr<Node> fromElement() const; |
80 | |
81 | DataTransfer* dataTransfer() const { return isDragEvent() ? m_dataTransfer.get() : nullptr; } |
82 | |
83 | static bool canTriggerActivationBehavior(const Event&); |
84 | |
85 | int which() const final; |
86 | |
87 | protected: |
88 | MouseEvent(const AtomicString& type, CanBubble, IsCancelable, IsComposed, MonotonicTime timestamp, RefPtr<WindowProxy>&&, int detail, |
89 | const IntPoint& screenLocation, const IntPoint& windowLocation, const IntPoint& movementDelta, OptionSet<Modifier>, unsigned short button, unsigned short buttons, |
90 | EventTarget* relatedTarget, double force, unsigned short syntheticClickType, DataTransfer*, IsSimulated, IsTrusted); |
91 | |
92 | MouseEvent(const AtomicString& type, CanBubble, IsCancelable, IsComposed, RefPtr<WindowProxy>&&, int detail, |
93 | const IntPoint& screenLocation, const IntPoint& clientLocation, OptionSet<Modifier>, unsigned short button, unsigned short buttons, |
94 | unsigned short syntheticClickType, EventTarget* relatedTarget); |
95 | |
96 | MouseEvent(const AtomicString& type, const MouseEventInit&); |
97 | |
98 | MouseEvent(); |
99 | |
100 | private: |
101 | bool isMouseEvent() const final; |
102 | EventInterface eventInterface() const override; |
103 | |
104 | bool isDragEvent() const; |
105 | |
106 | void setRelatedTarget(EventTarget& relatedTarget) final { m_relatedTarget = &relatedTarget; } |
107 | |
108 | unsigned short m_button { 0 }; |
109 | unsigned short m_buttons { 0 }; |
110 | unsigned short m_syntheticClickType { 0 }; |
111 | bool m_buttonDown { false }; |
112 | RefPtr<EventTarget> m_relatedTarget; |
113 | double m_force { 0 }; |
114 | RefPtr<DataTransfer> m_dataTransfer; |
115 | }; |
116 | |
117 | } // namespace WebCore |
118 | |
119 | SPECIALIZE_TYPE_TRAITS_EVENT(MouseEvent) |
120 | |