| 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 | #pragma once |
| 27 | |
| 28 | #include <wtf/OptionSet.h> |
| 29 | #include <wtf/WallTime.h> |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | class PlatformEvent { |
| 34 | public: |
| 35 | enum Type : uint8_t { |
| 36 | NoType = 0, |
| 37 | |
| 38 | // PlatformKeyboardEvent |
| 39 | KeyDown, |
| 40 | KeyUp, |
| 41 | RawKeyDown, |
| 42 | Char, |
| 43 | |
| 44 | // PlatformMouseEvent |
| 45 | MouseMoved, |
| 46 | MousePressed, |
| 47 | MouseReleased, |
| 48 | MouseForceChanged, |
| 49 | MouseForceDown, |
| 50 | MouseForceUp, |
| 51 | MouseScroll, |
| 52 | |
| 53 | // PlatformWheelEvent |
| 54 | Wheel, |
| 55 | |
| 56 | #if ENABLE(TOUCH_EVENTS) |
| 57 | // PlatformTouchEvent |
| 58 | TouchStart, |
| 59 | TouchMove, |
| 60 | TouchEnd, |
| 61 | TouchCancel, |
| 62 | TouchForceChange, |
| 63 | #endif |
| 64 | |
| 65 | #if ENABLE(MAC_GESTURE_EVENTS) |
| 66 | // PlatformGestureEvent |
| 67 | GestureStart, |
| 68 | GestureChange, |
| 69 | GestureEnd, |
| 70 | #endif |
| 71 | }; |
| 72 | |
| 73 | enum class Modifier : uint8_t { |
| 74 | AltKey = 1 << 0, |
| 75 | ControlKey = 1 << 1, |
| 76 | MetaKey = 1 << 2, |
| 77 | ShiftKey = 1 << 3, |
| 78 | CapsLockKey = 1 << 4, |
| 79 | |
| 80 | // Never used in native platforms but added for initEvent |
| 81 | AltGraphKey = 1 << 5, |
| 82 | }; |
| 83 | |
| 84 | Type type() const { return static_cast<Type>(m_type); } |
| 85 | |
| 86 | bool shiftKey() const { return m_modifiers.contains(Modifier::ShiftKey); } |
| 87 | bool controlKey() const { return m_modifiers.contains(Modifier::ControlKey); } |
| 88 | bool altKey() const { return m_modifiers.contains(Modifier::AltKey); } |
| 89 | bool metaKey() const { return m_modifiers.contains(Modifier::MetaKey); } |
| 90 | |
| 91 | OptionSet<Modifier> modifiers() const { return m_modifiers; } |
| 92 | |
| 93 | WallTime timestamp() const { return m_timestamp; } |
| 94 | |
| 95 | protected: |
| 96 | PlatformEvent() |
| 97 | : m_type(NoType) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | explicit PlatformEvent(Type type) |
| 102 | : m_type(type) |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | PlatformEvent(Type type, OptionSet<Modifier> modifiers, WallTime timestamp) |
| 107 | : m_type(type) |
| 108 | , m_modifiers(modifiers) |
| 109 | , m_timestamp(timestamp) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | PlatformEvent(Type type, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, WallTime timestamp) |
| 114 | : m_type(type) |
| 115 | , m_timestamp(timestamp) |
| 116 | { |
| 117 | if (shiftKey) |
| 118 | m_modifiers.add(Modifier::ShiftKey); |
| 119 | if (ctrlKey) |
| 120 | m_modifiers.add(Modifier::ControlKey); |
| 121 | if (altKey) |
| 122 | m_modifiers.add(Modifier::AltKey); |
| 123 | if (metaKey) |
| 124 | m_modifiers.add(Modifier::MetaKey); |
| 125 | } |
| 126 | |
| 127 | // Explicit protected destructor so that people don't accidentally |
| 128 | // delete a PlatformEvent. |
| 129 | ~PlatformEvent() = default; |
| 130 | |
| 131 | unsigned m_type; |
| 132 | OptionSet<Modifier> m_modifiers; |
| 133 | WallTime m_timestamp; |
| 134 | }; |
| 135 | |
| 136 | } // namespace WebCore |
| 137 | |