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#ifndef WheelEvent_h
26#define WheelEvent_h
27
28#include "FloatPoint.h"
29#include "MouseEvent.h"
30#include "PlatformWheelEvent.h"
31
32namespace WebCore {
33
34class PlatformWheelEvent;
35
36struct WheelEventInit : public MouseEventInit {
37    WheelEventInit();
38
39    double deltaX;
40    double deltaY;
41    double deltaZ;
42    unsigned deltaMode;
43    int wheelDeltaX; // Deprecated.
44    int wheelDeltaY; // Deprecated.
45};
46
47class WheelEvent : public MouseEvent {
48public:
49    enum { TickMultiplier = 120 };
50
51    enum DeltaMode {
52        DOM_DELTA_PIXEL = 0,
53        DOM_DELTA_LINE,
54        DOM_DELTA_PAGE
55    };
56
57    static PassRefPtr<WheelEvent> create()
58    {
59        return adoptRef(new WheelEvent);
60    }
61
62    static PassRefPtr<WheelEvent> create(const AtomicString& type, const WheelEventInit& initializer)
63    {
64        return adoptRef(new WheelEvent(type, initializer));
65    }
66
67    static PassRefPtr<WheelEvent> create(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view)
68    {
69        return adoptRef(new WheelEvent(event, view));
70    }
71
72    void initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView>,
73        int screenX, int screenY, int pageX, int pageY,
74        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
75
76    void initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView>,
77        int screenX, int screenY, int pageX, int pageY,
78        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
79
80    double deltaX() const { return m_deltaX; } // Positive when scrolling right.
81    double deltaY() const { return m_deltaY; } // Positive when scrolling down.
82    double deltaZ() const { return m_deltaZ; }
83    int wheelDelta() const { return wheelDeltaY() ? wheelDeltaY() : wheelDeltaX(); } // Deprecated.
84    int wheelDeltaX() const { return m_wheelDelta.x(); } // Deprecated, negative when scrolling right.
85    int wheelDeltaY() const { return m_wheelDelta.y(); } // Deprecated, negative when scrolling down.
86    unsigned deltaMode() const { return m_deltaMode; }
87
88    bool webkitDirectionInvertedFromDevice() const { return m_directionInvertedFromDevice; }
89    // Needed for Objective-C legacy support
90    bool isHorizontal() const { return m_wheelDelta.x(); }
91
92    virtual EventInterface eventInterface() const override;
93    virtual bool isMouseEvent() const override;
94
95#if PLATFORM(MAC)
96    PlatformWheelEventPhase phase() const { return m_phase; }
97    PlatformWheelEventPhase momentumPhase() const { return m_momentumPhase; }
98#endif
99
100private:
101    WheelEvent();
102    WheelEvent(const AtomicString&, const WheelEventInit&);
103    WheelEvent(const PlatformWheelEvent&, PassRefPtr<AbstractView>);
104
105    virtual bool isWheelEvent() const override;
106
107    IntPoint m_wheelDelta;
108    double m_deltaX;
109    double m_deltaY;
110    double m_deltaZ;
111    unsigned m_deltaMode;
112    bool m_directionInvertedFromDevice;
113
114#if PLATFORM(MAC)
115    PlatformWheelEventPhase m_phase;
116    PlatformWheelEventPhase m_momentumPhase;
117#endif
118};
119
120EVENT_TYPE_CASTS(WheelEvent)
121
122} // namespace WebCore
123
124#endif // WheelEvent_h
125