1/*
2 * Copyright (C) 2004, 2005, 2006, 2009 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 PlatformMouseEvent_h
27#define PlatformMouseEvent_h
28
29#include "IntPoint.h"
30#include "PlatformEvent.h"
31#if OS(WINDOWS)
32#include "WindowsExtras.h"
33#endif
34
35#if PLATFORM(GTK)
36typedef struct _GdkEventButton GdkEventButton;
37typedef struct _GdkEventMotion GdkEventMotion;
38#endif
39
40#if PLATFORM(EFL)
41typedef struct _Evas_Event_Mouse_Down Evas_Event_Mouse_Down;
42typedef struct _Evas_Event_Mouse_Up Evas_Event_Mouse_Up;
43typedef struct _Evas_Event_Mouse_Move Evas_Event_Mouse_Move;
44#endif
45
46namespace WebCore {
47
48    // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified.
49    enum MouseButton { NoButton = -1, LeftButton, MiddleButton, RightButton };
50
51#if PLATFORM(BLACKBERRY)
52    enum MouseInputMethod { PointingDevice, TouchScreen };
53#endif
54
55    class PlatformMouseEvent : public PlatformEvent {
56    public:
57        PlatformMouseEvent()
58            : PlatformEvent(PlatformEvent::MouseMoved)
59            , m_button(NoButton)
60            , m_clickCount(0)
61            , m_modifierFlags(0)
62#if PLATFORM(MAC)
63            , m_eventNumber(0)
64#elif PLATFORM(WIN)
65            , m_didActivateWebView(false)
66#endif
67        {
68        }
69
70        PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, PlatformEvent::Type type,
71                           int clickCount, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, double timestamp)
72            : PlatformEvent(type, shiftKey, ctrlKey, altKey, metaKey, timestamp)
73            , m_position(position)
74            , m_globalPosition(globalPosition)
75            , m_button(button)
76            , m_clickCount(clickCount)
77            , m_modifierFlags(0)
78#if PLATFORM(MAC)
79            , m_eventNumber(0)
80#elif PLATFORM(WIN)
81            , m_didActivateWebView(false)
82#endif
83        {
84        }
85
86        const IntPoint& position() const { return m_position; }
87        const IntPoint& globalPosition() const { return m_globalPosition; }
88#if ENABLE(POINTER_LOCK)
89        const IntPoint& movementDelta() const { return m_movementDelta; }
90#endif
91
92        MouseButton button() const { return m_button; }
93        int clickCount() const { return m_clickCount; }
94        unsigned modifierFlags() const { return m_modifierFlags; }
95
96
97#if PLATFORM(GTK)
98        explicit PlatformMouseEvent(GdkEventButton*);
99        explicit PlatformMouseEvent(GdkEventMotion*);
100        void setClickCount(int count) { m_clickCount = count; }
101#endif
102
103#if PLATFORM(EFL)
104        void setClickCount(unsigned int);
105        PlatformMouseEvent(const Evas_Event_Mouse_Down*, IntPoint);
106        PlatformMouseEvent(const Evas_Event_Mouse_Up*, IntPoint);
107        PlatformMouseEvent(const Evas_Event_Mouse_Move*, IntPoint);
108#endif
109
110#if PLATFORM(MAC)
111        int eventNumber() const { return m_eventNumber; }
112#endif
113
114#if PLATFORM(WIN)
115        PlatformMouseEvent(HWND, UINT, WPARAM, LPARAM, bool didActivateWebView = false);
116        void setClickCount(int count) { m_clickCount = count; }
117        bool didActivateWebView() const { return m_didActivateWebView; }
118#endif
119
120#if PLATFORM(BLACKBERRY)
121        PlatformMouseEvent(const IntPoint& eventPosition, const IntPoint& globalPosition, const PlatformEvent::Type, int clickCount, MouseButton, bool shiftKey, bool ctrlKey, bool altKey, MouseInputMethod = PointingDevice);
122        MouseInputMethod inputMethod() const { return m_inputMethod; }
123#endif
124    protected:
125        IntPoint m_position;
126        IntPoint m_globalPosition;
127#if ENABLE(POINTER_LOCK)
128        IntPoint m_movementDelta;
129#endif
130        MouseButton m_button;
131        int m_clickCount;
132        unsigned m_modifierFlags;
133
134#if PLATFORM(MAC)
135        int m_eventNumber;
136#elif PLATFORM(WIN)
137        bool m_didActivateWebView;
138#elif PLATFORM(BLACKBERRY)
139        MouseInputMethod m_inputMethod;
140#endif
141    };
142
143} // namespace WebCore
144
145#endif // PlatformMouseEvent_h
146