Home | History | Annotate | Download | only in platform
      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 "wtf/Assertions.h"
     34 #include <string.h>
     35 
     36 namespace WebCore {
     37 
     38 class PlatformGestureEvent : public PlatformEvent {
     39 public:
     40     PlatformGestureEvent()
     41         : PlatformEvent(PlatformEvent::GestureScrollBegin)
     42     {
     43         memset(&m_data, 0, sizeof(m_data));
     44     }
     45 
     46     PlatformGestureEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const IntSize& area, double timestamp, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, float deltaX, float deltaY, float velocityX, float velocityY)
     47         : PlatformEvent(type, shiftKey, ctrlKey, altKey, metaKey, timestamp)
     48         , m_position(position)
     49         , m_globalPosition(globalPosition)
     50         , m_area(area)
     51     {
     52         ASSERT(type == PlatformEvent::GestureScrollBegin
     53             || type == PlatformEvent::GestureScrollEnd
     54             || type == PlatformEvent::GestureScrollUpdate
     55             || type == PlatformEvent::GestureScrollUpdateWithoutPropagation);
     56         memset(&m_data, 0, sizeof(m_data));
     57         m_data.m_scrollUpdate.m_deltaX = deltaX;
     58         m_data.m_scrollUpdate.m_deltaY = deltaY;
     59         m_data.m_scrollUpdate.m_velocityX = velocityX;
     60         m_data.m_scrollUpdate.m_velocityY = velocityY;
     61     }
     62 
     63     const IntPoint& position() const { return m_position; } // PlatformWindow coordinates.
     64     const IntPoint& globalPosition() const { return m_globalPosition; } // Screen coordinates.
     65 
     66     const IntSize& area() const { return m_area; }
     67 
     68     float deltaX() const
     69     {
     70         ASSERT(m_type == PlatformEvent::GestureScrollUpdate
     71             || m_type == PlatformEvent::GestureScrollUpdateWithoutPropagation);
     72         return m_data.m_scrollUpdate.m_deltaX;
     73     }
     74 
     75     float deltaY() const
     76     {
     77         ASSERT(m_type == PlatformEvent::GestureScrollUpdate
     78             || m_type == PlatformEvent::GestureScrollUpdateWithoutPropagation);
     79         return m_data.m_scrollUpdate.m_deltaY;
     80     }
     81 
     82     int tapCount() const
     83     {
     84         ASSERT(m_type == PlatformEvent::GestureTap);
     85         return m_data.m_tap.m_tapCount;
     86     }
     87 
     88     float velocityX() const
     89     {
     90         ASSERT(m_type == PlatformEvent::GestureScrollUpdate
     91             || m_type == PlatformEvent::GestureScrollUpdateWithoutPropagation);
     92         return m_data.m_scrollUpdate.m_velocityX;
     93     }
     94 
     95     float velocityY() const
     96     {
     97         ASSERT(m_type == PlatformEvent::GestureScrollUpdate
     98             || m_type == PlatformEvent::GestureScrollUpdateWithoutPropagation);
     99         return m_data.m_scrollUpdate.m_velocityY;
    100     }
    101 
    102     float scale() const
    103     {
    104         ASSERT(m_type == PlatformEvent::GesturePinchUpdate);
    105         return m_data.m_pinchUpdate.m_scale;
    106     }
    107 
    108 protected:
    109     IntPoint m_position;
    110     IntPoint m_globalPosition;
    111     IntSize m_area;
    112 
    113     union {
    114         struct {
    115             int m_tapCount;
    116         } m_tap;
    117 
    118         struct {
    119             float m_deltaX;
    120             float m_deltaY;
    121             float m_velocityX;
    122             float m_velocityY;
    123         } m_scrollUpdate;
    124 
    125         struct {
    126             float m_scale;
    127         } m_pinchUpdate;
    128     } m_data;
    129 };
    130 
    131 } // namespace WebCore
    132 
    133 #endif // PlatformGestureEvent_h
    134