dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 1 | /* |
| 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.org | e029656 | 2019-06-05 19:21:38 +0000 | [diff] [blame] | 28 | #include "EventNames.h" |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 29 | #include "MouseEvent.h" |
wenson_hsieh@apple.com | 3972062 | 2021-02-23 03:16:32 +0000 | [diff] [blame] | 30 | #include "PointerEventTypeNames.h" |
commit-queue@webkit.org | d7f2588 | 2019-02-04 16:22:49 +0000 | [diff] [blame] | 31 | #include "PointerID.h" |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 32 | #include <wtf/text/WTFString.h> |
| 33 | |
dino@apple.com | 0c55038 | 2018-11-05 18:37:43 +0000 | [diff] [blame] | 34 | #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY) |
| 35 | #include "PlatformTouchEventIOS.h" |
| 36 | #endif |
| 37 | |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 38 | namespace WebCore { |
| 39 | |
wenson_hsieh@apple.com | 3972062 | 2021-02-23 03:16:32 +0000 | [diff] [blame] | 40 | class Node; |
| 41 | |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 42 | class PointerEvent final : public MouseEvent { |
ysuzuki@apple.com | e407070 | 2019-09-18 22:10:00 +0000 | [diff] [blame] | 43 | WTF_MAKE_ISO_ALLOCATED(PointerEvent); |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 44 | public: |
| 45 | struct Init : MouseEventInit { |
graouts@webkit.org | 73e37b0 | 2019-05-22 19:58:15 +0000 | [diff] [blame] | 46 | PointerID pointerId { mousePointerID }; |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 47 | 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.com | 3972062 | 2021-02-23 03:16:32 +0000 | [diff] [blame] | 54 | String pointerType { mousePointerEventType() }; |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 55 | bool isPrimary { false }; |
| 56 | }; |
| 57 | |
commit-queue@webkit.org | df631aa | 2019-05-07 18:43:27 +0000 | [diff] [blame] | 58 | enum class IsPrimary : uint8_t { No, Yes }; |
| 59 | |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 60 | static Ref<PointerEvent> create(const AtomString& type, Init&& initializer) |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 61 | { |
| 62 | return adoptRef(*new PointerEvent(type, WTFMove(initializer))); |
| 63 | } |
| 64 | |
graouts@webkit.org | f9d26f4 | 2019-07-05 10:25:06 +0000 | [diff] [blame] | 65 | static Ref<PointerEvent> createForPointerCapture(const AtomString& type, PointerID pointerId, bool isPrimary, String pointerType) |
graouts@webkit.org | 9902bef | 2019-01-29 03:15:02 +0000 | [diff] [blame] | 66 | { |
| 67 | Init initializer; |
| 68 | initializer.bubbles = true; |
graouts@webkit.org | f9d26f4 | 2019-07-05 10:25:06 +0000 | [diff] [blame] | 69 | initializer.pointerId = pointerId; |
| 70 | initializer.isPrimary = isPrimary; |
| 71 | initializer.pointerType = pointerType; |
graouts@webkit.org | 9902bef | 2019-01-29 03:15:02 +0000 | [diff] [blame] | 72 | return adoptRef(*new PointerEvent(type, WTFMove(initializer))); |
| 73 | } |
graouts@webkit.org | 9902bef | 2019-01-29 03:15:02 +0000 | [diff] [blame] | 74 | |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 75 | static Ref<PointerEvent> createForBindings() |
| 76 | { |
| 77 | return adoptRef(*new PointerEvent); |
| 78 | } |
| 79 | |
commit-queue@webkit.org | 91e50bc | 2020-12-09 17:03:08 +0000 | [diff] [blame] | 80 | 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.org | df631aa | 2019-05-07 18:43:27 +0000 | [diff] [blame] | 82 | static Ref<PointerEvent> create(const String& type, PointerID, const String& pointerType, IsPrimary = IsPrimary::No); |
commit-queue@webkit.org | 19a4b72 | 2019-02-27 19:02:03 +0000 | [diff] [blame] | 83 | |
dino@apple.com | 0c55038 | 2018-11-05 18:37:43 +0000 | [diff] [blame] | 84 | #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY) |
graouts@webkit.org | b4552c9 | 2018-11-17 09:29:52 +0000 | [diff] [blame] | 85 | static Ref<PointerEvent> create(const PlatformTouchEvent&, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&); |
graouts@webkit.org | 807fd00 | 2019-02-18 17:52:34 +0000 | [diff] [blame] | 86 | static Ref<PointerEvent> create(const String& type, const PlatformTouchEvent&, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&); |
dino@apple.com | 0c55038 | 2018-11-05 18:37:43 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 89 | virtual ~PointerEvent(); |
| 90 | |
commit-queue@webkit.org | d7f2588 | 2019-02-04 16:22:49 +0000 | [diff] [blame] | 91 | PointerID pointerId() const { return m_pointerId; } |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 92 | 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.com | 0c55038 | 2018-11-05 18:37:43 +0000 | [diff] [blame] | 102 | bool isPointerEvent() const final { return true; } |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 103 | |
commit-queue@webkit.org | 7fa3a30 | 2019-05-29 21:04:55 +0000 | [diff] [blame] | 104 | // 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.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 112 | EventInterface eventInterface() const override; |
| 113 | |
| 114 | private: |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 115 | 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.org | e029656 | 2019-06-05 19:21:38 +0000 | [diff] [blame] | 119 | |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 120 | PointerEvent(); |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 121 | PointerEvent(const AtomString&, Init&&); |
commit-queue@webkit.org | 91e50bc | 2020-12-09 17:03:08 +0000 | [diff] [blame] | 122 | PointerEvent(const AtomString& type, short button, const MouseEvent&, PointerID, const String& pointerType); |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 123 | PointerEvent(const AtomString& type, PointerID, const String& pointerType, IsPrimary); |
dino@apple.com | 0c55038 | 2018-11-05 18:37:43 +0000 | [diff] [blame] | 124 | #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY) |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 125 | PointerEvent(const AtomString& type, const PlatformTouchEvent&, IsCancelable isCancelable, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&); |
dino@apple.com | 0c55038 | 2018-11-05 18:37:43 +0000 | [diff] [blame] | 126 | #endif |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 127 | |
graouts@webkit.org | 73e37b0 | 2019-05-22 19:58:15 +0000 | [diff] [blame] | 128 | PointerID m_pointerId { mousePointerID }; |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 129 | 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.com | 3972062 | 2021-02-23 03:16:32 +0000 | [diff] [blame] | 136 | String m_pointerType { mousePointerEventType() }; |
dino@apple.com | f6e7e05 | 2018-09-22 00:51:47 +0000 | [diff] [blame] | 137 | bool m_isPrimary { false }; |
| 138 | }; |
| 139 | |
| 140 | } // namespace WebCore |
| 141 | |
| 142 | SPECIALIZE_TYPE_TRAITS_EVENT(PointerEvent) |