| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 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 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. | |
| 24 */ | |
| 25 | |
| 26 #ifndef PlatformGestureEvent_h | |
| 27 #define PlatformGestureEvent_h | |
| 28 | |
| 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 "platform/scroll/ScrollTypes.h" | |
| 34 #include "wtf/Assertions.h" | |
| 35 #include <string.h> | |
| 36 | |
| 37 namespace blink { | |
| 38 | |
| 39 enum PlatformGestureSource { | |
| 40 PlatformGestureSourceUninitialized, | |
| 41 PlatformGestureSourceTouchpad, | |
| 42 PlatformGestureSourceTouchscreen | |
| 43 }; | |
| 44 | |
| 45 class PlatformGestureEvent : public PlatformEvent { | |
| 46 public: | |
| 47 PlatformGestureEvent() | |
| 48 : PlatformEvent(PlatformEvent::GestureScrollBegin), | |
| 49 m_source(PlatformGestureSourceUninitialized) { | |
| 50 memset(&m_data, 0, sizeof(m_data)); | |
| 51 } | |
| 52 | |
| 53 PlatformGestureEvent(EventType type, | |
| 54 const IntPoint& position, | |
| 55 const IntPoint& globalPosition, | |
| 56 const IntSize& area, | |
| 57 TimeTicks timestamp, | |
| 58 PlatformEvent::Modifiers modifiers, | |
| 59 PlatformGestureSource source) | |
| 60 : PlatformEvent(type, modifiers, timestamp), | |
| 61 m_position(position), | |
| 62 m_globalPosition(globalPosition), | |
| 63 m_area(area), | |
| 64 m_source(source) { | |
| 65 memset(&m_data, 0, sizeof(m_data)); | |
| 66 } | |
| 67 | |
| 68 void setScrollGestureData(float deltaX, | |
| 69 float deltaY, | |
| 70 ScrollGranularity deltaUnits, | |
| 71 float velocityX, | |
| 72 float velocityY, | |
| 73 ScrollInertialPhase inertialPhase, | |
| 74 bool preventPropagation, | |
| 75 int resendingPluginId) { | |
| 76 ASSERT(type() == PlatformEvent::GestureScrollBegin || | |
| 77 type() == PlatformEvent::GestureScrollUpdate || | |
| 78 type() == PlatformEvent::GestureScrollEnd); | |
| 79 if (type() != GestureScrollUpdate) { | |
| 80 ASSERT(deltaX == 0); | |
| 81 ASSERT(deltaY == 0); | |
| 82 ASSERT(velocityX == 0); | |
| 83 ASSERT(velocityY == 0); | |
| 84 ASSERT(!preventPropagation); | |
| 85 } | |
| 86 | |
| 87 if (type() == PlatformEvent::GestureScrollBegin) | |
| 88 DCHECK_NE(ScrollInertialPhaseMomentum, inertialPhase); | |
| 89 | |
| 90 m_data.m_scroll.m_deltaX = deltaX; | |
| 91 m_data.m_scroll.m_deltaY = deltaY; | |
| 92 m_data.m_scroll.m_deltaUnits = deltaUnits; | |
| 93 m_data.m_scroll.m_velocityX = velocityX; | |
| 94 m_data.m_scroll.m_velocityY = velocityY; | |
| 95 m_data.m_scroll.m_inertialPhase = inertialPhase; | |
| 96 m_data.m_scroll.m_resendingPluginId = resendingPluginId; | |
| 97 m_data.m_scroll.m_preventPropagation = preventPropagation; | |
| 98 } | |
| 99 | |
| 100 const IntPoint& position() const { | |
| 101 return m_position; | |
| 102 } // PlatformWindow coordinates. | |
| 103 const IntPoint& globalPosition() const { | |
| 104 return m_globalPosition; | |
| 105 } // Screen coordinates. | |
| 106 | |
| 107 const IntSize& area() const { return m_area; } | |
| 108 | |
| 109 PlatformGestureSource source() const { return m_source; } | |
| 110 | |
| 111 float deltaX() const { | |
| 112 ASSERT(m_type == PlatformEvent::GestureScrollBegin || | |
| 113 m_type == PlatformEvent::GestureScrollUpdate); | |
| 114 return m_data.m_scroll.m_deltaX; | |
| 115 } | |
| 116 | |
| 117 float deltaY() const { | |
| 118 ASSERT(m_type == PlatformEvent::GestureScrollBegin || | |
| 119 m_type == PlatformEvent::GestureScrollUpdate); | |
| 120 return m_data.m_scroll.m_deltaY; | |
| 121 } | |
| 122 | |
| 123 ScrollGranularity deltaUnits() const { | |
| 124 ASSERT(m_type == PlatformEvent::GestureScrollBegin || | |
| 125 m_type == PlatformEvent::GestureScrollUpdate || | |
| 126 m_type == PlatformEvent::GestureScrollEnd); | |
| 127 return m_data.m_scroll.m_deltaUnits; | |
| 128 } | |
| 129 | |
| 130 int tapCount() const { | |
| 131 ASSERT(m_type == PlatformEvent::GestureTap); | |
| 132 return m_data.m_tap.m_tapCount; | |
| 133 } | |
| 134 | |
| 135 float velocityX() const { | |
| 136 ASSERT(m_type == PlatformEvent::GestureScrollUpdate || | |
| 137 m_type == PlatformEvent::GestureFlingStart); | |
| 138 return m_data.m_scroll.m_velocityX; | |
| 139 } | |
| 140 | |
| 141 float velocityY() const { | |
| 142 ASSERT(m_type == PlatformEvent::GestureScrollUpdate || | |
| 143 m_type == PlatformEvent::GestureFlingStart); | |
| 144 return m_data.m_scroll.m_velocityY; | |
| 145 } | |
| 146 | |
| 147 ScrollInertialPhase inertialPhase() const { | |
| 148 ASSERT(m_type == PlatformEvent::GestureScrollBegin || | |
| 149 m_type == PlatformEvent::GestureScrollUpdate || | |
| 150 m_type == PlatformEvent::GestureScrollEnd); | |
| 151 return m_data.m_scroll.m_inertialPhase; | |
| 152 } | |
| 153 | |
| 154 bool synthetic() const { | |
| 155 ASSERT(m_type == PlatformEvent::GestureScrollBegin || | |
| 156 m_type == PlatformEvent::GestureScrollEnd); | |
| 157 return m_data.m_scroll.m_synthetic; | |
| 158 } | |
| 159 | |
| 160 int resendingPluginId() const { | |
| 161 if (m_type == PlatformEvent::GestureScrollUpdate || | |
| 162 m_type == PlatformEvent::GestureScrollBegin || | |
| 163 m_type == PlatformEvent::GestureScrollEnd) | |
| 164 return m_data.m_scroll.m_resendingPluginId; | |
| 165 | |
| 166 // This function is called by *all* gesture event types in | |
| 167 // GestureEvent::Create(), so we return -1 for all other types. | |
| 168 return -1; | |
| 169 } | |
| 170 | |
| 171 bool preventPropagation() const { | |
| 172 // TODO(tdresser) Once we've decided if we're getting rid of scroll | |
| 173 // chaining, we should remove all scroll chaining related logic. See | |
| 174 // crbug.com/526462 for details. | |
| 175 ASSERT(m_type == PlatformEvent::GestureScrollUpdate); | |
| 176 return true; | |
| 177 } | |
| 178 | |
| 179 float scale() const { | |
| 180 ASSERT(m_type == PlatformEvent::GesturePinchUpdate); | |
| 181 return m_data.m_pinchUpdate.m_scale; | |
| 182 } | |
| 183 | |
| 184 void applyTouchAdjustment(const IntPoint& adjustedPosition) { | |
| 185 // Update the window-relative position of the event so that the node that | |
| 186 // was ultimately hit is under this point (i.e. elementFromPoint for the | |
| 187 // client co-ordinates in a 'click' event should yield the target). The | |
| 188 // global position is intentionally left unmodified because it's intended to | |
| 189 // reflect raw co-ordinates unrelated to any content. | |
| 190 m_position = adjustedPosition; | |
| 191 } | |
| 192 | |
| 193 bool isScrollEvent() const { | |
| 194 switch (m_type) { | |
| 195 case GestureScrollBegin: | |
| 196 case GestureScrollEnd: | |
| 197 case GestureScrollUpdate: | |
| 198 case GestureFlingStart: | |
| 199 case GesturePinchBegin: | |
| 200 case GesturePinchEnd: | |
| 201 case GesturePinchUpdate: | |
| 202 return true; | |
| 203 case GestureTap: | |
| 204 case GestureTapUnconfirmed: | |
| 205 case GestureTapDown: | |
| 206 case GestureShowPress: | |
| 207 case GestureTapDownCancel: | |
| 208 case GestureTwoFingerTap: | |
| 209 case GestureLongPress: | |
| 210 case GestureLongTap: | |
| 211 return false; | |
| 212 default: | |
| 213 ASSERT_NOT_REACHED(); | |
| 214 return false; | |
| 215 } | |
| 216 } | |
| 217 | |
| 218 uint32_t uniqueTouchEventId() const { return m_uniqueTouchEventId; } | |
| 219 | |
| 220 protected: | |
| 221 IntPoint m_position; | |
| 222 IntPoint m_globalPosition; | |
| 223 IntSize m_area; | |
| 224 PlatformGestureSource m_source; | |
| 225 | |
| 226 union { | |
| 227 struct { | |
| 228 int m_tapCount; | |
| 229 } m_tap; | |
| 230 | |
| 231 struct { | |
| 232 // |m_deltaX| and |m_deltaY| represent deltas in GSU but | |
| 233 // are only hints in GSB. | |
| 234 float m_deltaX; | |
| 235 float m_deltaY; | |
| 236 float m_velocityX; | |
| 237 float m_velocityY; | |
| 238 int m_preventPropagation; | |
| 239 ScrollInertialPhase m_inertialPhase; | |
| 240 ScrollGranularity m_deltaUnits; | |
| 241 int m_resendingPluginId; | |
| 242 bool m_synthetic; | |
| 243 } m_scroll; | |
| 244 | |
| 245 struct { | |
| 246 float m_scale; | |
| 247 } m_pinchUpdate; | |
| 248 } m_data; | |
| 249 | |
| 250 uint32_t m_uniqueTouchEventId; | |
| 251 }; | |
| 252 | |
| 253 } // namespace blink | |
| 254 | |
| 255 #endif // PlatformGestureEvent_h | |
| OLD | NEW |