2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, 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 COMPUTER, 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.
26 #ifndef PlatformGestureEvent_h
27 #define PlatformGestureEvent_h
29 #include "platform/PlatformEvent.h"
30 #include "platform/geometry/FloatPoint.h"
31 #include "platform/geometry/IntPoint.h"
32 #include "platform/geometry/IntSize.h"
33 #include "wtf/Assertions.h"
38 class PlatformGestureEvent
: public PlatformEvent
{
40 PlatformGestureEvent()
41 : PlatformEvent(PlatformEvent::GestureScrollBegin
)
43 memset(&m_data
, 0, sizeof(m_data
));
46 PlatformGestureEvent(Type type
, const IntPoint
& position
,
47 const IntPoint
& globalPosition
, const IntSize
& area
, double timestamp
,
48 bool shiftKey
, bool ctrlKey
, bool altKey
, bool metaKey
)
49 : PlatformEvent(type
, shiftKey
, ctrlKey
, altKey
, metaKey
, timestamp
)
50 , m_position(position
)
51 , m_globalPosition(globalPosition
)
54 memset(&m_data
, 0, sizeof(m_data
));
57 void setScrollGestureData(float deltaX
, float deltaY
, float velocityX
, float velocityY
,
58 bool inertial
, bool preventPropagation
, int resendingPluginId
)
60 ASSERT(type() == PlatformEvent::GestureScrollBegin
61 || type() == PlatformEvent::GestureScrollUpdate
62 || type() == PlatformEvent::GestureScrollEnd
);
63 if (type() != GestureScrollUpdate
) {
66 ASSERT(velocityX
== 0);
67 ASSERT(velocityY
== 0);
68 ASSERT(!preventPropagation
);
71 if (type() == PlatformEvent::GestureScrollBegin
)
74 m_data
.m_scroll
.m_deltaX
= deltaX
;
75 m_data
.m_scroll
.m_deltaY
= deltaY
;
76 m_data
.m_scroll
.m_velocityX
= velocityX
;
77 m_data
.m_scroll
.m_velocityY
= velocityY
;
78 m_data
.m_scroll
.m_inertial
= inertial
;
79 m_data
.m_scroll
.m_resendingPluginId
= resendingPluginId
;
80 m_data
.m_scroll
.m_preventPropagation
= preventPropagation
;
83 const IntPoint
& position() const { return m_position
; } // PlatformWindow coordinates.
84 const IntPoint
& globalPosition() const { return m_globalPosition
; } // Screen coordinates.
86 const IntSize
& area() const { return m_area
; }
90 ASSERT(m_type
== PlatformEvent::GestureScrollUpdate
);
91 return m_data
.m_scroll
.m_deltaX
;
96 ASSERT(m_type
== PlatformEvent::GestureScrollUpdate
);
97 return m_data
.m_scroll
.m_deltaY
;
102 ASSERT(m_type
== PlatformEvent::GestureTap
);
103 return m_data
.m_tap
.m_tapCount
;
106 float velocityX() const
108 ASSERT(m_type
== PlatformEvent::GestureScrollUpdate
|| m_type
== PlatformEvent::GestureFlingStart
);
109 return m_data
.m_scroll
.m_velocityX
;
112 float velocityY() const
114 ASSERT(m_type
== PlatformEvent::GestureScrollUpdate
|| m_type
== PlatformEvent::GestureFlingStart
);
115 return m_data
.m_scroll
.m_velocityY
;
118 bool inertial() const
120 ASSERT(m_type
== PlatformEvent::GestureScrollUpdate
|| m_type
== PlatformEvent::GestureScrollEnd
);
121 return m_data
.m_scroll
.m_inertial
;
124 int resendingPluginId() const
126 if (m_type
== PlatformEvent::GestureScrollUpdate
127 || m_type
== PlatformEvent::GestureScrollBegin
128 || m_type
== PlatformEvent::GestureScrollEnd
)
129 return m_data
.m_scroll
.m_resendingPluginId
;
131 // This function is called by *all* gesture event types in
132 // GestureEvent::Create(), so we return -1 for all other types.
136 bool preventPropagation() const
138 ASSERT(m_type
== PlatformEvent::GestureScrollUpdate
);
139 return m_data
.m_scroll
.m_preventPropagation
;
144 ASSERT(m_type
== PlatformEvent::GesturePinchUpdate
);
145 return m_data
.m_pinchUpdate
.m_scale
;
148 void applyTouchAdjustment(const IntPoint
& adjustedPosition
)
150 // Update the window-relative position of the event so that the node that was
151 // ultimately hit is under this point (i.e. elementFromPoint for the client
152 // co-ordinates in a 'click' event should yield the target). The global
153 // position is intentionally left unmodified because it's intended to reflect
154 // raw co-ordinates unrelated to any content.
155 m_position
= adjustedPosition
;
158 bool isScrollEvent() const
161 case GestureScrollBegin
:
162 case GestureScrollEnd
:
163 case GestureScrollUpdate
:
164 case GestureFlingStart
:
165 case GesturePinchBegin
:
166 case GesturePinchEnd
:
167 case GesturePinchUpdate
:
170 case GestureTapUnconfirmed
:
172 case GestureShowPress
:
173 case GestureTapDownCancel
:
174 case GestureTwoFingerTap
:
175 case GestureLongPress
:
179 ASSERT_NOT_REACHED();
186 IntPoint m_globalPosition
;
199 int m_preventPropagation
;
201 int m_resendingPluginId
;
212 #endif // PlatformGestureEvent_h