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 PlatformWheelEvent_h
27 #define PlatformWheelEvent_h
28 
29 #include "IntPoint.h"
30 
31 #if PLATFORM(GTK)
32 typedef struct _GdkEventScroll GdkEventScroll;
33 #endif
34 
35 #if PLATFORM(EFL)
36 typedef struct _Evas_Event_Mouse_Wheel Evas_Event_Mouse_Wheel;
37 #endif
38 
39 #if PLATFORM(QT)
40 QT_BEGIN_NAMESPACE
41 class QWheelEvent;
42 class QGraphicsSceneWheelEvent;
43 QT_END_NAMESPACE
44 #endif
45 
46 #if PLATFORM(WIN)
47 typedef struct HWND__* HWND;
48 typedef unsigned WPARAM;
49 typedef long LPARAM;
50 #endif
51 
52 #if PLATFORM(WX)
53 class wxMouseEvent;
54 class wxPoint;
55 #endif
56 
57 #if PLATFORM(HAIKU)
58 class BMessage;
59 #endif
60 
61 namespace WebCore {
62 
63     class FloatPoint;
64     class FloatSize;
65 
66     // Wheel events come in two flavors:
67     // The ScrollByPixelWheelEvent is a fine-grained event that specifies the precise number of pixels to scroll.  It is sent directly by MacBook touchpads on OS X,
68     // and synthesized in other cases where platforms generate line-by-line scrolling events.
69     // The ScrollByPageWheelEvent indicates that the wheel event should scroll an entire page.  In this case WebCore's built in paging behavior is used to page
70     // up and down (you get the same behavior as if the user was clicking in a scrollbar track to page up or page down).  Page scrolling only works in the vertical direction.
71     enum PlatformWheelEventGranularity {
72         ScrollByPageWheelEvent,
73         ScrollByPixelWheelEvent
74     };
75 
76 #if PLATFORM(MAC)
77     enum PlatformWheelEventPhase {
78         PlatformWheelEventPhaseNone        = 0,
79         PlatformWheelEventPhaseBegan       = 1 << 1,
80         PlatformWheelEventPhaseStationary  = 1 << 2,
81         PlatformWheelEventPhaseChanged     = 1 << 3,
82         PlatformWheelEventPhaseEnded       = 1 << 4,
83         PlatformWheelEventPhaseCancelled   = 1 << 5,
84     };
85 #endif
86 
87     class PlatformWheelEvent {
88     public:
PlatformWheelEvent()89         PlatformWheelEvent()
90             : m_deltaX(0)
91             , m_deltaY(0)
92             , m_wheelTicksX(0)
93             , m_wheelTicksY(0)
94             , m_granularity(ScrollByPixelWheelEvent)
95             , m_isAccepted(false)
96             , m_shiftKey(false)
97             , m_ctrlKey(false)
98             , m_altKey(false)
99             , m_metaKey(false)
100 #if PLATFORM(MAC)
101             , m_hasPreciseScrollingDeltas(false)
102             , m_phase(PlatformWheelEventPhaseNone)
103             , m_momentumPhase(PlatformWheelEventPhaseNone)
104             , m_timestamp(0)
105 #endif
106         {
107         }
108 
pos()109         const IntPoint& pos() const { return m_position; } // PlatformWindow coordinates.
globalPos()110         const IntPoint& globalPos() const { return m_globalPosition; } // Screen coordinates.
111 
deltaX()112         float deltaX() const { return m_deltaX; }
deltaY()113         float deltaY() const { return m_deltaY; }
114 
wheelTicksX()115         float wheelTicksX() const { return m_wheelTicksX; }
wheelTicksY()116         float wheelTicksY() const { return m_wheelTicksY; }
117 
granularity()118         PlatformWheelEventGranularity granularity() const { return m_granularity; }
119 
isAccepted()120         bool isAccepted() const { return m_isAccepted; }
shiftKey()121         bool shiftKey() const { return m_shiftKey; }
ctrlKey()122         bool ctrlKey() const { return m_ctrlKey; }
altKey()123         bool altKey() const { return m_altKey; }
metaKey()124         bool metaKey() const { return m_metaKey; }
125 
x()126         int x() const { return m_position.x(); } // PlatformWindow coordinates.
y()127         int y() const { return m_position.y(); }
globalX()128         int globalX() const { return m_globalPosition.x(); } // Screen coordinates.
globalY()129         int globalY() const { return m_globalPosition.y(); }
130 
accept()131         void accept() { m_isAccepted = true; }
ignore()132         void ignore() { m_isAccepted = false; }
133 
turnVerticalTicksIntoHorizontal()134         void turnVerticalTicksIntoHorizontal()
135         {
136             m_deltaX = m_deltaY;
137             m_deltaY = 0;
138 
139             m_wheelTicksX = m_wheelTicksY;
140             m_wheelTicksY = 0;
141         }
142 
143 #if PLATFORM(GTK)
144         PlatformWheelEvent(GdkEventScroll*);
145 #endif
146 
147 #if PLATFORM(EFL)
148         PlatformWheelEvent(const Evas_Event_Mouse_Wheel*);
149 #endif
150 
151 #if PLATFORM(MAC)
152 #if defined(__OBJC__)
153         PlatformWheelEvent(NSEvent *, NSView *windowView);
154 #endif
155 
phase()156         PlatformWheelEventPhase phase() const { return m_phase; }
momentumPhase()157         PlatformWheelEventPhase momentumPhase() const { return m_momentumPhase; }
hasPreciseScrollingDeltas()158         bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; }
timestamp()159         double timestamp() const { return m_timestamp; }
160 #endif
161 
162 #if PLATFORM(QT)
163         PlatformWheelEvent(QWheelEvent*);
164         PlatformWheelEvent(QGraphicsSceneWheelEvent*);
165         void applyDelta(int delta, Qt::Orientation);
166 #endif
167 
168 #if PLATFORM(WIN)
169         PlatformWheelEvent(HWND, WPARAM, LPARAM, bool isMouseHWheel);
170         PlatformWheelEvent(HWND, const FloatSize& delta, const FloatPoint& location);
171 #endif
172 
173 #if PLATFORM(WX)
174         PlatformWheelEvent(const wxMouseEvent&, const wxPoint&);
175 #endif
176 
177 #if PLATFORM(HAIKU)
178         PlatformWheelEvent(BMessage*);
179 #endif
180 
181     protected:
182         IntPoint m_position;
183         IntPoint m_globalPosition;
184         float m_deltaX;
185         float m_deltaY;
186         float m_wheelTicksX;
187         float m_wheelTicksY;
188         PlatformWheelEventGranularity m_granularity;
189         bool m_isAccepted;
190         bool m_shiftKey;
191         bool m_ctrlKey;
192         bool m_altKey;
193         bool m_metaKey;
194 #if PLATFORM(MAC)
195         bool m_hasPreciseScrollingDeltas;
196         PlatformWheelEventPhase m_phase;
197         PlatformWheelEventPhase m_momentumPhase;
198         double m_timestamp;
199 #endif
200     };
201 
202 } // namespace WebCore
203 
204 #endif // PlatformWheelEvent_h
205