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 29namespace WebCore { 30 31class PlatformEvent { 32public: 33 enum Type : uint8_t { 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#if ENABLE(TOUCH_EVENTS) 52 // PlatformTouchEvent 53 TouchStart, 54 TouchMove, 55 TouchEnd, 56 TouchCancel, 57#endif 58 }; 59 60 enum Modifiers : uint8_t { 61 AltKey = 1 << 0, 62 CtrlKey = 1 << 1, 63 MetaKey = 1 << 2, 64 ShiftKey = 1 << 3, 65 }; 66 67 Type type() const { return static_cast<Type>(m_type); } 68 69 bool shiftKey() const { return m_modifiers & ShiftKey; } 70 bool ctrlKey() const { return m_modifiers & CtrlKey; } 71 bool altKey() const { return m_modifiers & AltKey; } 72 bool metaKey() const { return m_modifiers & MetaKey; } 73 74 unsigned modifiers() const { return m_modifiers; } 75 76 double timestamp() const { return m_timestamp; } 77 78protected: 79 PlatformEvent() 80 : m_type(NoType) 81 , m_modifiers(0) 82 , m_timestamp(0) 83 { 84 } 85 86 explicit PlatformEvent(Type type) 87 : m_type(type) 88 , m_modifiers(0) 89 , m_timestamp(0) 90 { 91 } 92 93 PlatformEvent(Type type, Modifiers modifiers, double timestamp) 94 : m_type(type) 95 , m_modifiers(modifiers) 96 , m_timestamp(timestamp) 97 { 98 } 99 100 PlatformEvent(Type type, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, double timestamp) 101 : m_type(type) 102 , m_modifiers(0) 103 , m_timestamp(timestamp) 104 { 105 if (shiftKey) 106 m_modifiers |= ShiftKey; 107 if (ctrlKey) 108 m_modifiers |= CtrlKey; 109 if (altKey) 110 m_modifiers |= AltKey; 111 if (metaKey) 112 m_modifiers |= MetaKey; 113 } 114 115 // Explicit protected destructor so that people don't accidentally 116 // delete a PlatformEvent. 117 ~PlatformEvent() 118 { 119 } 120 121 unsigned m_type; 122 unsigned m_modifiers; 123 double m_timestamp; 124}; 125 126} // namespace WebCore 127 128#endif // PlatformEvent_h 129