1 | /* |
2 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
3 | * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
4 | * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 | * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2010, 2013 Apple Inc. All rights reserved. |
6 | * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
7 | * |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. |
12 | * |
13 | * This library is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Library General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Library General Public License |
19 | * along with this library; see the file COPYING.LIB. If not, write to |
20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | * Boston, MA 02110-1301, USA. |
22 | * |
23 | */ |
24 | |
25 | #pragma once |
26 | |
27 | #include "MouseEvent.h" |
28 | #include "PlatformWheelEvent.h" |
29 | |
30 | namespace WebCore { |
31 | |
32 | class WheelEvent final : public MouseEvent { |
33 | public: |
34 | enum { TickMultiplier = 120 }; |
35 | |
36 | enum { |
37 | DOM_DELTA_PIXEL = 0, |
38 | DOM_DELTA_LINE, |
39 | DOM_DELTA_PAGE |
40 | }; |
41 | |
42 | static Ref<WheelEvent> create(const PlatformWheelEvent&, RefPtr<WindowProxy>&&); |
43 | static Ref<WheelEvent> createForBindings(); |
44 | |
45 | struct Init : MouseEventInit { |
46 | double deltaX { 0 }; |
47 | double deltaY { 0 }; |
48 | double deltaZ { 0 }; |
49 | unsigned deltaMode { DOM_DELTA_PIXEL }; |
50 | int wheelDeltaX { 0 }; // Deprecated. |
51 | int wheelDeltaY { 0 }; // Deprecated. |
52 | }; |
53 | |
54 | static Ref<WheelEvent> create(const AtomicString& type, const Init&); |
55 | |
56 | WEBCORE_EXPORT void initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, RefPtr<WindowProxy>&&, int screenX, int screenY, int pageX, int pageY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey); |
57 | |
58 | const Optional<PlatformWheelEvent>& underlyingPlatformEvent() const { return m_underlyingPlatformEvent; } |
59 | |
60 | double deltaX() const { return m_deltaX; } // Positive when scrolling right. |
61 | double deltaY() const { return m_deltaY; } // Positive when scrolling down. |
62 | double deltaZ() const { return m_deltaZ; } |
63 | int wheelDelta() const { return wheelDeltaY() ? wheelDeltaY() : wheelDeltaX(); } // Deprecated. |
64 | int wheelDeltaX() const { return m_wheelDelta.x(); } // Deprecated, negative when scrolling right. |
65 | int wheelDeltaY() const { return m_wheelDelta.y(); } // Deprecated, negative when scrolling down. |
66 | unsigned deltaMode() const { return m_deltaMode; } |
67 | |
68 | bool webkitDirectionInvertedFromDevice() const { return m_underlyingPlatformEvent && m_underlyingPlatformEvent.value().directionInvertedFromDevice(); } |
69 | |
70 | #if PLATFORM(MAC) |
71 | PlatformWheelEventPhase phase() const { return m_underlyingPlatformEvent ? m_underlyingPlatformEvent.value().phase() : PlatformWheelEventPhaseNone; } |
72 | PlatformWheelEventPhase momentumPhase() const { return m_underlyingPlatformEvent ? m_underlyingPlatformEvent.value().momentumPhase() : PlatformWheelEventPhaseNone; } |
73 | #endif |
74 | |
75 | private: |
76 | WheelEvent(); |
77 | WheelEvent(const AtomicString&, const Init&); |
78 | WheelEvent(const PlatformWheelEvent&, RefPtr<WindowProxy>&&); |
79 | |
80 | EventInterface eventInterface() const final; |
81 | |
82 | bool isWheelEvent() const final; |
83 | |
84 | IntPoint m_wheelDelta; |
85 | double m_deltaX { 0 }; |
86 | double m_deltaY { 0 }; |
87 | double m_deltaZ { 0 }; |
88 | unsigned m_deltaMode { DOM_DELTA_PIXEL }; |
89 | Optional<PlatformWheelEvent> m_underlyingPlatformEvent; |
90 | }; |
91 | |
92 | } // namespace WebCore |
93 | |
94 | SPECIALIZE_TYPE_TRAITS_EVENT(WheelEvent) |
95 | |