Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / PlatformGestureEvent.h
blob53453a186462f593f6548137716175d6aa9d50ae
1 /*
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
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.
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"
34 #include <string.h>
36 namespace blink {
38 class PlatformGestureEvent : public PlatformEvent {
39 public:
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)
52 , m_area(area)
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) {
64 ASSERT(deltaX == 0);
65 ASSERT(deltaY == 0);
66 ASSERT(velocityX == 0);
67 ASSERT(velocityY == 0);
68 ASSERT(!preventPropagation);
71 if (type() == PlatformEvent::GestureScrollBegin)
72 ASSERT(!inertial);
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; }
88 float deltaX() const
90 ASSERT(m_type == PlatformEvent::GestureScrollUpdate);
91 return m_data.m_scroll.m_deltaX;
94 float deltaY() const
96 ASSERT(m_type == PlatformEvent::GestureScrollUpdate);
97 return m_data.m_scroll.m_deltaY;
100 int tapCount() const
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.
133 return -1;
136 bool preventPropagation() const
138 ASSERT(m_type == PlatformEvent::GestureScrollUpdate);
139 return m_data.m_scroll.m_preventPropagation;
142 float scale() const
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
160 switch (m_type) {
161 case GestureScrollBegin:
162 case GestureScrollEnd:
163 case GestureScrollUpdate:
164 case GestureFlingStart:
165 case GesturePinchBegin:
166 case GesturePinchEnd:
167 case GesturePinchUpdate:
168 return true;
169 case GestureTap:
170 case GestureTapUnconfirmed:
171 case GestureTapDown:
172 case GestureShowPress:
173 case GestureTapDownCancel:
174 case GestureTwoFingerTap:
175 case GestureLongPress:
176 case GestureLongTap:
177 return false;
178 default:
179 ASSERT_NOT_REACHED();
180 return false;
184 protected:
185 IntPoint m_position;
186 IntPoint m_globalPosition;
187 IntSize m_area;
189 union {
190 struct {
191 int m_tapCount;
192 } m_tap;
194 struct {
195 float m_deltaX;
196 float m_deltaY;
197 float m_velocityX;
198 float m_velocityY;
199 int m_preventPropagation;
200 bool m_inertial;
201 int m_resendingPluginId;
202 } m_scroll;
204 struct {
205 float m_scale;
206 } m_pinchUpdate;
207 } m_data;
210 } // namespace blink
212 #endif // PlatformGestureEvent_h