• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(QT)
36 QT_BEGIN_NAMESPACE
37 class QWheelEvent;
38 class QGraphicsSceneWheelEvent;
39 QT_END_NAMESPACE
40 #endif
41 
42 #if PLATFORM(WIN)
43 typedef struct HWND__* HWND;
44 typedef unsigned WPARAM;
45 typedef long LPARAM;
46 #endif
47 
48 #if PLATFORM(WX)
49 class wxMouseEvent;
50 class wxPoint;
51 #endif
52 
53 #if PLATFORM(HAIKU)
54 class BMessage;
55 #endif
56 
57 namespace WebCore {
58 
59     class FloatPoint;
60     class FloatSize;
61 
62     // Wheel events come in two flavors:
63     // 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,
64     // and synthesized in other cases where platforms generate line-by-line scrolling events.
65     // 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
66     // 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.
67     enum PlatformWheelEventGranularity { ScrollByPageWheelEvent, ScrollByPixelWheelEvent };
68 
69     class PlatformWheelEvent {
70     public:
PlatformWheelEvent()71         PlatformWheelEvent()
72             : m_deltaX(0)
73             , m_deltaY(0)
74             , m_wheelTicksX(0)
75             , m_wheelTicksY(0)
76             , m_granularity(ScrollByPixelWheelEvent)
77             , m_isAccepted(false)
78             , m_shiftKey(false)
79             , m_ctrlKey(false)
80             , m_altKey(false)
81             , m_metaKey(false)
82         {
83         }
84 
pos()85         const IntPoint& pos() const { return m_position; } // PlatformWindow coordinates.
globalPos()86         const IntPoint& globalPos() const { return m_globalPosition; } // Screen coordinates.
87 
deltaX()88         float deltaX() const { return m_deltaX; }
deltaY()89         float deltaY() const { return m_deltaY; }
90 
wheelTicksX()91         float wheelTicksX() const { return m_wheelTicksX; }
wheelTicksY()92         float wheelTicksY() const { return m_wheelTicksY; }
93 
granularity()94         PlatformWheelEventGranularity granularity() const { return m_granularity; }
95 
isAccepted()96         bool isAccepted() const { return m_isAccepted; }
shiftKey()97         bool shiftKey() const { return m_shiftKey; }
ctrlKey()98         bool ctrlKey() const { return m_ctrlKey; }
altKey()99         bool altKey() const { return m_altKey; }
metaKey()100         bool metaKey() const { return m_metaKey; }
101 
x()102         int x() const { return m_position.x(); } // PlatformWindow coordinates.
y()103         int y() const { return m_position.y(); }
globalX()104         int globalX() const { return m_globalPosition.x(); } // Screen coordinates.
globalY()105         int globalY() const { return m_globalPosition.y(); }
106 
accept()107         void accept() { m_isAccepted = true; }
ignore()108         void ignore() { m_isAccepted = false; }
109 
turnVerticalTicksIntoHorizontal()110         void turnVerticalTicksIntoHorizontal()
111         {
112             m_deltaX = m_deltaY;
113             m_deltaY = 0;
114 
115             m_wheelTicksX = m_wheelTicksY;
116             m_wheelTicksY = 0;
117         }
118 
119 #if PLATFORM(GTK)
120         PlatformWheelEvent(GdkEventScroll*);
121 #endif
122 
123 #if PLATFORM(MAC) && defined(__OBJC__)
124         PlatformWheelEvent(NSEvent *, NSView *windowView);
125 #endif
126 
127 #if PLATFORM(QT)
128         PlatformWheelEvent(QWheelEvent*);
129         PlatformWheelEvent(QGraphicsSceneWheelEvent*);
130         void applyDelta(int delta, Qt::Orientation);
131 #endif
132 
133 #if PLATFORM(WIN)
134         PlatformWheelEvent(HWND, WPARAM, LPARAM, bool isMouseHWheel);
135         PlatformWheelEvent(HWND, const FloatSize& delta, const FloatPoint& location);
136 #endif
137 
138 #if PLATFORM(WX)
139         PlatformWheelEvent(const wxMouseEvent&, const wxPoint&);
140 #endif
141 
142 #if PLATFORM(HAIKU)
143         PlatformWheelEvent(BMessage*);
144 #endif
145 
146     protected:
147         IntPoint m_position;
148         IntPoint m_globalPosition;
149         float m_deltaX;
150         float m_deltaY;
151         float m_wheelTicksX;
152         float m_wheelTicksY;
153         PlatformWheelEventGranularity m_granularity;
154         bool m_isAccepted;
155         bool m_shiftKey;
156         bool m_ctrlKey;
157         bool m_altKey;
158         bool m_metaKey;
159     };
160 
161 } // namespace WebCore
162 
163 #endif // PlatformWheelEvent_h
164