2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef PlatformWheelEvent_h
27 #define PlatformWheelEvent_h
40 typedef struct HWND__* HWND;
41 typedef unsigned WPARAM;
46 typedef struct _GdkEventScroll GdkEventScroll;
62 // Wheel events come in three flavors:
63 // The ScrollByPixelWheelEvent is a fine-grained event that specifies the precise number of pixels to scroll. It is sent by MacBook touchpads on OS X.
64 // For ScrollByPixelWheelEvents, the delta values contain the precise number of pixels to scroll.
65 // The ScrollByLineWheelEvent (the normal wheel event) sends a delta that can be corrected by a line multiplier to determine how many lines to scroll.
66 // If the platform has configurable line sensitivity (Windows), then the number of lines to scroll is used in order to behave like the platform.
67 // If the platform does not have configurable line sensitivity, then WebCore's default behavior is used (which scrolls 3 * the wheel line delta).
68 // For ScrollByLineWheelEvents, the delta values represent the number of lines to scroll.
69 // The ScrollByPageWheelEvent indicates that the wheel event should scroll an entire page instead. 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 { ScrollByLineWheelEvent, ScrollByPageWheelEvent, ScrollByPixelWheelEvent };
73 // WebCore uses a line multiple of ~3 (40px per line step) when doing arrowing with a scrollbar or line stepping via the arrow keys. The delta for wheeling is expressed
74 // as a # of actual lines (40 / 3 = 1 wheel line). We use the horizontalLineMultiplier and verticalLineMultiplier methods to incorporate the line multiplier into the deltas. On
75 // platforms that do not support wheel sensitivity, we use this hardcoded constant value of 3 to ensure that wheeling by default matches the WebCore multiplier you
76 // get when doing other kinds of line stepping.
77 const int cLineMultiplier = 3;
79 class PlatformWheelEvent {
81 const IntPoint& pos() const { return m_position; } // PlatformWindow coordinates.
82 const IntPoint& globalPos() const { return m_globalPosition; } // Screen coordinates.
84 float deltaX() const { return m_deltaX; }
85 float deltaY() const { return m_deltaY; }
87 PlatformWheelEventGranularity granularity() const { return m_granularity; }
89 bool isAccepted() const { return m_isAccepted; }
90 bool shiftKey() const { return m_shiftKey; }
91 bool ctrlKey() const { return m_ctrlKey; }
92 bool altKey() const { return m_altKey; }
93 bool metaKey() const { return m_metaKey; }
95 int x() const { return m_position.x(); } // PlatformWindow coordinates.
96 int y() const { return m_position.y(); }
97 int globalX() const { return m_globalPosition.x(); } // Screen coordinates.
98 int globalY() const { return m_globalPosition.y(); }
100 void accept() { m_isAccepted = true; }
101 void ignore() { m_isAccepted = false; }
104 PlatformWheelEvent(NSEvent*);
107 PlatformWheelEvent(HWND, WPARAM, LPARAM, bool isHorizontal);
110 PlatformWheelEvent(GdkEventScroll*);
113 PlatformWheelEvent(QWheelEvent*);
116 PlatformWheelEvent(const wxMouseEvent&, const wxPoint&);
121 int horizontalLineMultiplier() const { return cLineMultiplier; }
122 int verticalLineMultiplier() const { return cLineMultiplier; }
124 int horizontalLineMultiplier() const;
125 int verticalLineMultiplier() const;
129 IntPoint m_globalPosition;
132 PlatformWheelEventGranularity m_granularity;
140 } // namespace WebCore
142 #endif // PlatformWheelEvent_h