blob: 9d60b85152f378566118574663701c25b001df3d [file] [log] [blame]
dino@apple.comf6e7e052018-09-22 00:51:47 +00001/*
2 * Copyright (C) 2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
commit-queue@webkit.orge0296562019-06-05 19:21:38 +000028#include "EventNames.h"
dino@apple.comf6e7e052018-09-22 00:51:47 +000029#include "MouseEvent.h"
wenson_hsieh@apple.com39720622021-02-23 03:16:32 +000030#include "PointerEventTypeNames.h"
commit-queue@webkit.orgd7f25882019-02-04 16:22:49 +000031#include "PointerID.h"
dino@apple.comf6e7e052018-09-22 00:51:47 +000032#include <wtf/text/WTFString.h>
33
dino@apple.com0c550382018-11-05 18:37:43 +000034#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
35#include "PlatformTouchEventIOS.h"
36#endif
37
dino@apple.comf6e7e052018-09-22 00:51:47 +000038namespace WebCore {
39
wenson_hsieh@apple.com39720622021-02-23 03:16:32 +000040class Node;
41
dino@apple.comf6e7e052018-09-22 00:51:47 +000042class PointerEvent final : public MouseEvent {
ysuzuki@apple.come4070702019-09-18 22:10:00 +000043 WTF_MAKE_ISO_ALLOCATED(PointerEvent);
dino@apple.comf6e7e052018-09-22 00:51:47 +000044public:
45 struct Init : MouseEventInit {
graouts@webkit.org73e37b02019-05-22 19:58:15 +000046 PointerID pointerId { mousePointerID };
dino@apple.comf6e7e052018-09-22 00:51:47 +000047 double width { 1 };
48 double height { 1 };
49 float pressure { 0 };
50 float tangentialPressure { 0 };
51 long tiltX { 0 };
52 long tiltY { 0 };
53 long twist { 0 };
wenson_hsieh@apple.com39720622021-02-23 03:16:32 +000054 String pointerType { mousePointerEventType() };
dino@apple.comf6e7e052018-09-22 00:51:47 +000055 bool isPrimary { false };
56 };
57
commit-queue@webkit.orgdf631aa2019-05-07 18:43:27 +000058 enum class IsPrimary : uint8_t { No, Yes };
59
darin@apple.com0ce67df2019-06-17 01:48:13 +000060 static Ref<PointerEvent> create(const AtomString& type, Init&& initializer)
dino@apple.comf6e7e052018-09-22 00:51:47 +000061 {
62 return adoptRef(*new PointerEvent(type, WTFMove(initializer)));
63 }
64
graouts@webkit.orgf9d26f42019-07-05 10:25:06 +000065 static Ref<PointerEvent> createForPointerCapture(const AtomString& type, PointerID pointerId, bool isPrimary, String pointerType)
graouts@webkit.org9902bef2019-01-29 03:15:02 +000066 {
67 Init initializer;
68 initializer.bubbles = true;
graouts@webkit.orgf9d26f42019-07-05 10:25:06 +000069 initializer.pointerId = pointerId;
70 initializer.isPrimary = isPrimary;
71 initializer.pointerType = pointerType;
graouts@webkit.org9902bef2019-01-29 03:15:02 +000072 return adoptRef(*new PointerEvent(type, WTFMove(initializer)));
73 }
graouts@webkit.org9902bef2019-01-29 03:15:02 +000074
dino@apple.comf6e7e052018-09-22 00:51:47 +000075 static Ref<PointerEvent> createForBindings()
76 {
77 return adoptRef(*new PointerEvent);
78 }
79
commit-queue@webkit.org91e50bc2020-12-09 17:03:08 +000080 static RefPtr<PointerEvent> create(short button, const MouseEvent&, PointerID, const String& pointerType);
81 static Ref<PointerEvent> create(const String& type, short button, const MouseEvent&, PointerID, const String& pointerType);
commit-queue@webkit.orgdf631aa2019-05-07 18:43:27 +000082 static Ref<PointerEvent> create(const String& type, PointerID, const String& pointerType, IsPrimary = IsPrimary::No);
commit-queue@webkit.org19a4b722019-02-27 19:02:03 +000083
dino@apple.com0c550382018-11-05 18:37:43 +000084#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
graouts@webkit.orgb4552c92018-11-17 09:29:52 +000085 static Ref<PointerEvent> create(const PlatformTouchEvent&, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
graouts@webkit.org807fd002019-02-18 17:52:34 +000086 static Ref<PointerEvent> create(const String& type, const PlatformTouchEvent&, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
dino@apple.com0c550382018-11-05 18:37:43 +000087#endif
88
dino@apple.comf6e7e052018-09-22 00:51:47 +000089 virtual ~PointerEvent();
90
commit-queue@webkit.orgd7f25882019-02-04 16:22:49 +000091 PointerID pointerId() const { return m_pointerId; }
dino@apple.comf6e7e052018-09-22 00:51:47 +000092 double width() const { return m_width; }
93 double height() const { return m_height; }
94 float pressure() const { return m_pressure; }
95 float tangentialPressure() const { return m_tangentialPressure; }
96 long tiltX() const { return m_tiltX; }
97 long tiltY() const { return m_tiltY; }
98 long twist() const { return m_twist; }
99 String pointerType() const { return m_pointerType; }
100 bool isPrimary() const { return m_isPrimary; }
101
dino@apple.com0c550382018-11-05 18:37:43 +0000102 bool isPointerEvent() const final { return true; }
dino@apple.comf6e7e052018-09-22 00:51:47 +0000103
commit-queue@webkit.org7fa3a302019-05-29 21:04:55 +0000104 // https://w3c.github.io/pointerevents/#attributes-and-default-actions
105 // Many user agents expose non-standard attributes fromElement and toElement in MouseEvents to
106 // support legacy content. In those user agents, the values of those (inherited) attributes in
107 // PointerEvents must be null to encourage the use of the standardized alternates (i.e. target
108 // and relatedTarget).
109 RefPtr<Node> toElement() const final { return nullptr; }
110 RefPtr<Node> fromElement() const final { return nullptr; }
111
dino@apple.comf6e7e052018-09-22 00:51:47 +0000112 EventInterface eventInterface() const override;
113
114private:
darin@apple.com0ce67df2019-06-17 01:48:13 +0000115 static bool typeIsEnterOrLeave(const AtomString& type) { return type == eventNames().pointerenterEvent || type == eventNames().pointerleaveEvent; }
116 static CanBubble typeCanBubble(const AtomString& type) { return typeIsEnterOrLeave(type) ? CanBubble::No : CanBubble::Yes; }
117 static IsCancelable typeIsCancelable(const AtomString& type) { return typeIsEnterOrLeave(type) ? IsCancelable::No : IsCancelable::Yes; }
118 static IsComposed typeIsComposed(const AtomString& type) { return typeIsEnterOrLeave(type) ? IsComposed::No : IsComposed::Yes; }
commit-queue@webkit.orge0296562019-06-05 19:21:38 +0000119
dino@apple.comf6e7e052018-09-22 00:51:47 +0000120 PointerEvent();
darin@apple.com0ce67df2019-06-17 01:48:13 +0000121 PointerEvent(const AtomString&, Init&&);
commit-queue@webkit.org91e50bc2020-12-09 17:03:08 +0000122 PointerEvent(const AtomString& type, short button, const MouseEvent&, PointerID, const String& pointerType);
darin@apple.com0ce67df2019-06-17 01:48:13 +0000123 PointerEvent(const AtomString& type, PointerID, const String& pointerType, IsPrimary);
dino@apple.com0c550382018-11-05 18:37:43 +0000124#if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
darin@apple.com0ce67df2019-06-17 01:48:13 +0000125 PointerEvent(const AtomString& type, const PlatformTouchEvent&, IsCancelable isCancelable, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
dino@apple.com0c550382018-11-05 18:37:43 +0000126#endif
dino@apple.comf6e7e052018-09-22 00:51:47 +0000127
graouts@webkit.org73e37b02019-05-22 19:58:15 +0000128 PointerID m_pointerId { mousePointerID };
dino@apple.comf6e7e052018-09-22 00:51:47 +0000129 double m_width { 1 };
130 double m_height { 1 };
131 float m_pressure { 0 };
132 float m_tangentialPressure { 0 };
133 long m_tiltX { 0 };
134 long m_tiltY { 0 };
135 long m_twist { 0 };
wenson_hsieh@apple.com39720622021-02-23 03:16:32 +0000136 String m_pointerType { mousePointerEventType() };
dino@apple.comf6e7e052018-09-22 00:51:47 +0000137 bool m_isPrimary { false };
138};
139
140} // namespace WebCore
141
142SPECIALIZE_TYPE_TRAITS_EVENT(PointerEvent)