Home | History | Annotate | Download | only in Shared
      1 /*
      2  * Copyright (C) 2010, 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 WebEvent_h
     27 #define WebEvent_h
     28 
     29 // FIXME: We should probably move to makeing the WebCore/PlatformFooEvents trivial classes so that
     30 // we can use them as the event type.
     31 
     32 #include <WebCore/FloatSize.h>
     33 #include <WebCore/IntPoint.h>
     34 #include <wtf/text/WTFString.h>
     35 
     36 namespace CoreIPC {
     37     class ArgumentDecoder;
     38     class ArgumentEncoder;
     39 }
     40 
     41 namespace WebKit {
     42 
     43 class WebEvent {
     44 public:
     45     enum Type {
     46         NoType = -1,
     47 
     48         // WebMouseEvent
     49         MouseDown,
     50         MouseUp,
     51         MouseMove,
     52 
     53         // WebWheelEvent
     54         Wheel,
     55 
     56         // WebKeyboardEvent
     57         KeyDown,
     58         KeyUp,
     59         RawKeyDown,
     60         Char,
     61 
     62 #if ENABLE(GESTURE_EVENTS)
     63         // WebGestureEvent
     64         GestureScrollBegin,
     65         GestureScrollEnd,
     66 #endif
     67 
     68 #if ENABLE(TOUCH_EVENTS)
     69         // WebTouchEvent
     70         TouchStart,
     71         TouchMove,
     72         TouchEnd,
     73         TouchCancel,
     74 #endif
     75     };
     76 
     77     enum Modifiers {
     78         ShiftKey    = 1 << 0,
     79         ControlKey  = 1 << 1,
     80         AltKey      = 1 << 2,
     81         MetaKey     = 1 << 3,
     82         CapsLockKey = 1 << 4,
     83     };
     84 
     85     Type type() const { return static_cast<Type>(m_type); }
     86 
     87     bool shiftKey() const { return m_modifiers & ShiftKey; }
     88     bool controlKey() const { return m_modifiers & ControlKey; }
     89     bool altKey() const { return m_modifiers & AltKey; }
     90     bool metaKey() const { return m_modifiers & MetaKey; }
     91     bool capsLockKey() const { return m_modifiers & CapsLockKey; }
     92 
     93     Modifiers modifiers() const { return static_cast<Modifiers>(m_modifiers); }
     94 
     95     double timestamp() const { return m_timestamp; }
     96 
     97 protected:
     98     WebEvent();
     99 
    100     WebEvent(Type, Modifiers, double timestamp);
    101 
    102     void encode(CoreIPC::ArgumentEncoder*) const;
    103     static bool decode(CoreIPC::ArgumentDecoder*, WebEvent&);
    104 
    105 private:
    106     uint32_t m_type; // Type
    107     uint32_t m_modifiers; // Modifiers
    108     double m_timestamp;
    109 };
    110 
    111 // FIXME: Move this class to its own header file.
    112 class WebMouseEvent : public WebEvent {
    113 public:
    114     enum Button {
    115         NoButton = -1,
    116         LeftButton,
    117         MiddleButton,
    118         RightButton
    119     };
    120 
    121     WebMouseEvent();
    122 
    123     WebMouseEvent(Type, Button, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers, double timestamp);
    124 #if PLATFORM(WIN)
    125     WebMouseEvent(Type, Button, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers, double timestamp, bool didActivateWebView);
    126 #endif
    127 
    128     Button button() const { return static_cast<Button>(m_button); }
    129     const WebCore::IntPoint& position() const { return m_position; }
    130     const WebCore::IntPoint& globalPosition() const { return m_globalPosition; }
    131     float deltaX() const { return m_deltaX; }
    132     float deltaY() const { return m_deltaY; }
    133     float deltaZ() const { return m_deltaZ; }
    134     int32_t clickCount() const { return m_clickCount; }
    135 #if PLATFORM(WIN)
    136     bool didActivateWebView() const { return m_didActivateWebView; }
    137 #endif
    138 
    139     void encode(CoreIPC::ArgumentEncoder*) const;
    140     static bool decode(CoreIPC::ArgumentDecoder*, WebMouseEvent&);
    141 
    142 private:
    143     static bool isMouseEventType(Type);
    144 
    145     uint32_t m_button;
    146     WebCore::IntPoint m_position;
    147     WebCore::IntPoint m_globalPosition;
    148     float m_deltaX;
    149     float m_deltaY;
    150     float m_deltaZ;
    151     int32_t m_clickCount;
    152 #if PLATFORM(WIN)
    153     bool m_didActivateWebView;
    154 #endif
    155 };
    156 
    157 // FIXME: Move this class to its own header file.
    158 class WebWheelEvent : public WebEvent {
    159 public:
    160     enum Granularity {
    161         ScrollByPageWheelEvent,
    162         ScrollByPixelWheelEvent
    163     };
    164 
    165 #if PLATFORM(MAC)
    166     enum Phase {
    167         PhaseNone        = 0,
    168         PhaseBegan       = 1 << 1,
    169         PhaseStationary  = 1 << 2,
    170         PhaseChanged     = 1 << 3,
    171         PhaseEnded       = 1 << 4,
    172         PhaseCancelled   = 1 << 5,
    173     };
    174 #endif
    175 
    176     WebWheelEvent() { }
    177 
    178     WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, Modifiers, double timestamp);
    179 #if PLATFORM(MAC)
    180     WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, Phase phase, Phase momentumPhase,bool hasPreciseScrollingDeltas, Modifiers, double timestamp);
    181 #endif
    182 
    183     const WebCore::IntPoint position() const { return m_position; }
    184     const WebCore::IntPoint globalPosition() const { return m_globalPosition; }
    185     const WebCore::FloatSize delta() const { return m_delta; }
    186     const WebCore::FloatSize wheelTicks() const { return m_wheelTicks; }
    187     Granularity granularity() const { return static_cast<Granularity>(m_granularity); }
    188 #if PLATFORM(MAC)
    189     Phase phase() const { return static_cast<Phase>(m_phase); }
    190     Phase momentumPhase() const { return static_cast<Phase>(m_momentumPhase); }
    191     bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; }
    192 #endif
    193 
    194     void encode(CoreIPC::ArgumentEncoder*) const;
    195     static bool decode(CoreIPC::ArgumentDecoder*, WebWheelEvent&);
    196 
    197 private:
    198     static bool isWheelEventType(Type);
    199 
    200     WebCore::IntPoint m_position;
    201     WebCore::IntPoint m_globalPosition;
    202     WebCore::FloatSize m_delta;
    203     WebCore::FloatSize m_wheelTicks;
    204     uint32_t m_granularity; // Granularity
    205 #if PLATFORM(MAC)
    206     uint32_t m_phase; // Phase
    207     uint32_t m_momentumPhase; // Phase
    208     bool m_hasPreciseScrollingDeltas;
    209 #endif
    210 };
    211 
    212 // FIXME: Move this class to its own header file.
    213 class WebKeyboardEvent : public WebEvent {
    214 public:
    215     WebKeyboardEvent() { }
    216 
    217     WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
    218 
    219     const String& text() const { return m_text; }
    220     const String& unmodifiedText() const { return m_unmodifiedText; }
    221     const String& keyIdentifier() const { return m_keyIdentifier; }
    222     int32_t windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
    223     int32_t nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
    224     int32_t macCharCode() const { return m_macCharCode; }
    225     bool isAutoRepeat() const { return m_isAutoRepeat; }
    226     bool isKeypad() const { return m_isKeypad; }
    227     bool isSystemKey() const { return m_isSystemKey; }
    228 
    229     void encode(CoreIPC::ArgumentEncoder*) const;
    230     static bool decode(CoreIPC::ArgumentDecoder*, WebKeyboardEvent&);
    231 
    232     static bool isKeyboardEventType(Type);
    233 
    234 private:
    235     String m_text;
    236     String m_unmodifiedText;
    237     String m_keyIdentifier;
    238     int32_t m_windowsVirtualKeyCode;
    239     int32_t m_nativeVirtualKeyCode;
    240     int32_t m_macCharCode;
    241     bool m_isAutoRepeat;
    242     bool m_isKeypad;
    243     bool m_isSystemKey;
    244 };
    245 
    246 
    247 #if ENABLE(GESTURE_EVENTS)
    248 // FIXME: Move this class to its own header file.
    249 class WebGestureEvent : public WebEvent {
    250 public:
    251     WebGestureEvent() { }
    252     WebGestureEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, Modifiers, double timestamp);
    253 
    254     const WebCore::IntPoint position() const { return m_position; }
    255     const WebCore::IntPoint globalPosition() const { return m_globalPosition; }
    256 
    257     void encode(CoreIPC::ArgumentEncoder*) const;
    258     static bool decode(CoreIPC::ArgumentDecoder*, WebGestureEvent&);
    259 
    260 private:
    261     static bool isGestureEventType(Type);
    262 
    263     WebCore::IntPoint m_position;
    264     WebCore::IntPoint m_globalPosition;
    265 };
    266 #endif // ENABLE(GESTURE_EVENTS)
    267 
    268 
    269 #if ENABLE(TOUCH_EVENTS)
    270 // FIXME: Move this class to its own header file.
    271 // FIXME: Having "Platform" in the name makes it sound like this event is platform-specific or low-
    272 // level in some way. That doesn't seem to be the case.
    273 class WebPlatformTouchPoint {
    274 public:
    275     enum TouchPointState {
    276         TouchReleased,
    277         TouchPressed,
    278         TouchMoved,
    279         TouchStationary,
    280         TouchCancelled
    281     };
    282 
    283     WebPlatformTouchPoint() { }
    284 
    285     WebPlatformTouchPoint(uint32_t id, TouchPointState, const WebCore::IntPoint& screenPosition, const WebCore::IntPoint& position);
    286 
    287     uint32_t id() const { return m_id; }
    288     TouchPointState state() const { return static_cast<TouchPointState>(m_state); }
    289 
    290     const WebCore::IntPoint& screenPosition() const { return m_screenPosition; }
    291     const WebCore::IntPoint& position() const { return m_position; }
    292 
    293     void setState(TouchPointState state) { m_state = state; }
    294 
    295     void encode(CoreIPC::ArgumentEncoder*) const;
    296     static bool decode(CoreIPC::ArgumentDecoder*, WebPlatformTouchPoint&);
    297 
    298 private:
    299     uint32_t m_id;
    300     uint32_t m_state;
    301     WebCore::IntPoint m_screenPosition;
    302     WebCore::IntPoint m_position;
    303 
    304 };
    305 
    306 // FIXME: Move this class to its own header file.
    307 class WebTouchEvent : public WebEvent {
    308 public:
    309     WebTouchEvent() { }
    310 
    311     // FIXME: It would be nice not to have to copy the Vector here.
    312     WebTouchEvent(Type, Vector<WebPlatformTouchPoint>, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, Modifiers, double timestamp);
    313 
    314     const Vector<WebPlatformTouchPoint>& touchPoints() const { return m_touchPoints; }
    315 
    316     void encode(CoreIPC::ArgumentEncoder*) const;
    317     static bool decode(CoreIPC::ArgumentDecoder*, WebTouchEvent&);
    318 
    319 private:
    320     static bool isTouchEventType(Type);
    321 
    322     Vector<WebPlatformTouchPoint> m_touchPoints;
    323     bool m_ctrlKey;
    324     bool m_altKey;
    325     bool m_shiftKey;
    326     bool m_metaKey;
    327 };
    328 
    329 #endif // ENABLE(TOUCH_EVENTS)
    330 
    331 } // namespace WebKit
    332 
    333 #endif // WebEvent_h
    334