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