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 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB.  If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef WheelEvent_h
25#define WheelEvent_h
26
27#include "EventDispatchMediator.h"
28#include "FloatPoint.h"
29#include "MouseEvent.h"
30
31namespace WebCore {
32
33class PlatformWheelEvent;
34
35struct WheelEventInit : public MouseEventInit {
36    WheelEventInit();
37
38    int wheelDeltaX;
39    int wheelDeltaY;
40    unsigned deltaMode;
41};
42
43class WheelEvent : public MouseEvent {
44public:
45    enum { TickMultiplier = 120 };
46
47    enum DeltaMode {
48        DOM_DELTA_PIXEL = 0,
49        DOM_DELTA_LINE,
50        DOM_DELTA_PAGE
51    };
52
53    static PassRefPtr<WheelEvent> create()
54    {
55        return adoptRef(new WheelEvent);
56    }
57
58    static PassRefPtr<WheelEvent> create(const AtomicString& type, const WheelEventInit& initializer)
59    {
60        return adoptRef(new WheelEvent(type, initializer));
61    }
62
63    static PassRefPtr<WheelEvent> create(const FloatPoint& wheelTicks,
64        const FloatPoint& rawDelta, unsigned deltaMode, PassRefPtr<AbstractView> view,
65        const IntPoint& screenLocation, const IntPoint& pageLocation,
66        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool directionInvertedFromDevice)
67    {
68        return adoptRef(new WheelEvent(wheelTicks, rawDelta, deltaMode, view,
69        screenLocation, pageLocation, ctrlKey, altKey, shiftKey, metaKey, directionInvertedFromDevice));
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    int wheelDelta() const { return m_wheelDelta.y() ? m_wheelDelta.y() : m_wheelDelta.x(); }
81    int wheelDeltaX() const { return m_wheelDelta.x(); }
82    int wheelDeltaY() const { return m_wheelDelta.y(); }
83    int rawDeltaX() const { return m_rawDelta.x(); }
84    int rawDeltaY() const { return m_rawDelta.y(); }
85    unsigned deltaMode() const { return m_deltaMode; }
86
87    bool webkitDirectionInvertedFromDevice() const { return m_directionInvertedFromDevice; }
88    // Needed for Objective-C legacy support
89    bool isHorizontal() const { return m_wheelDelta.x(); }
90
91    virtual const AtomicString& interfaceName() const;
92    virtual bool isMouseEvent() const;
93
94private:
95    WheelEvent();
96    WheelEvent(const AtomicString&, const WheelEventInit&);
97    WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta,
98        unsigned, PassRefPtr<AbstractView>, const IntPoint& screenLocation, const IntPoint& pageLocation,
99        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool directionInvertedFromDevice);
100
101    IntPoint m_wheelDelta;
102    IntPoint m_rawDelta;
103    unsigned m_deltaMode;
104    bool m_directionInvertedFromDevice;
105};
106
107class WheelEventDispatchMediator : public EventDispatchMediator {
108public:
109    static PassRefPtr<WheelEventDispatchMediator> create(const PlatformWheelEvent&, PassRefPtr<AbstractView>);
110private:
111    WheelEventDispatchMediator(const PlatformWheelEvent&, PassRefPtr<AbstractView>);
112    WheelEvent* event() const;
113    virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
114};
115
116} // namespace WebCore
117
118#endif // WheelEvent_h
119