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 INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef PlatformEvent_h 27 #define PlatformEvent_h 28 29 namespace WebCore { 30 31 class PlatformEvent { 32 public: 33 enum Type { 34 NoType = 0, 35 36 // PlatformKeyboardEvent 37 KeyDown, 38 KeyUp, 39 RawKeyDown, 40 Char, 41 42 // PlatformMouseEvent 43 MouseMoved, 44 MousePressed, 45 MouseReleased, 46 MouseScroll, 47 48 // PlatformWheelEvent 49 Wheel, 50 51 // PlatformGestureEvent 52 GestureScrollBegin, 53 GestureScrollEnd, 54 GestureScrollUpdate, 55 GestureScrollUpdateWithoutPropagation, 56 GestureTap, 57 GestureTapUnconfirmed, 58 GestureTapDown, 59 GestureShowPress, 60 GestureTapDownCancel, 61 GestureTwoFingerTap, 62 GestureLongPress, 63 GestureLongTap, 64 GesturePinchBegin, 65 GesturePinchEnd, 66 GesturePinchUpdate, 67 GestureFlingStart, 68 69 // PlatformTouchEvent 70 TouchStart, 71 TouchMove, 72 TouchEnd, 73 TouchCancel, 74 }; 75 76 enum Modifiers { 77 AltKey = 1 << 0, 78 CtrlKey = 1 << 1, 79 MetaKey = 1 << 2, 80 ShiftKey = 1 << 3, 81 }; 82 83 Type type() const { return static_cast<Type>(m_type); } 84 85 bool shiftKey() const { return m_modifiers & ShiftKey; } 86 bool ctrlKey() const { return m_modifiers & CtrlKey; } 87 bool altKey() const { return m_modifiers & AltKey; } 88 bool metaKey() const { return m_modifiers & MetaKey; } 89 90 unsigned modifiers() const { return m_modifiers; } 91 92 double timestamp() const { return m_timestamp; } 93 94 protected: 95 PlatformEvent() 96 : m_type(NoType) 97 , m_modifiers(0) 98 , m_timestamp(0) 99 { 100 } 101 102 explicit PlatformEvent(Type type) 103 : m_type(type) 104 , m_modifiers(0) 105 , m_timestamp(0) 106 { 107 } 108 109 PlatformEvent(Type type, Modifiers modifiers, double timestamp) 110 : m_type(type) 111 , m_modifiers(modifiers) 112 , m_timestamp(timestamp) 113 { 114 } 115 116 PlatformEvent(Type type, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, double timestamp) 117 : m_type(type) 118 , m_modifiers(0) 119 , m_timestamp(timestamp) 120 { 121 if (shiftKey) 122 m_modifiers |= ShiftKey; 123 if (ctrlKey) 124 m_modifiers |= CtrlKey; 125 if (altKey) 126 m_modifiers |= AltKey; 127 if (metaKey) 128 m_modifiers |= MetaKey; 129 } 130 131 // Explicit protected destructor so that people don't accidentally 132 // delete a PlatformEvent. 133 ~PlatformEvent() 134 { 135 } 136 137 unsigned m_type; 138 unsigned m_modifiers; 139 double m_timestamp; 140 }; 141 142 } // namespace WebCore 143 144 #endif // PlatformEvent_h 145