Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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 "core/dom/EventDispatchMediator.h" |
| 28 | #include "core/dom/MouseEvent.h" |
| 29 | #include "core/platform/graphics/FloatPoint.h" |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | class PlatformWheelEvent; |
| 34 | |
| 35 | struct WheelEventInit : public MouseEventInit { |
| 36 | WheelEventInit(); |
| 37 | |
| 38 | int wheelDeltaX; |
| 39 | int wheelDeltaY; |
| 40 | unsigned deltaMode; |
| 41 | }; |
| 42 | |
| 43 | class WheelEvent : public MouseEvent { |
| 44 | public: |
| 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 | |
| 89 | virtual const AtomicString& interfaceName() const; |
| 90 | virtual bool isMouseEvent() const; |
| 91 | |
| 92 | private: |
| 93 | WheelEvent(); |
| 94 | WheelEvent(const AtomicString&, const WheelEventInit&); |
| 95 | WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta, |
| 96 | unsigned, PassRefPtr<AbstractView>, const IntPoint& screenLocation, const IntPoint& pageLocation, |
| 97 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool directionInvertedFromDevice); |
| 98 | |
| 99 | IntPoint m_wheelDelta; |
| 100 | IntPoint m_rawDelta; |
| 101 | unsigned m_deltaMode; |
| 102 | bool m_directionInvertedFromDevice; |
| 103 | }; |
| 104 | |
| 105 | class WheelEventDispatchMediator : public EventDispatchMediator { |
| 106 | public: |
| 107 | static PassRefPtr<WheelEventDispatchMediator> create(const PlatformWheelEvent&, PassRefPtr<AbstractView>); |
| 108 | private: |
| 109 | WheelEventDispatchMediator(const PlatformWheelEvent&, PassRefPtr<AbstractView>); |
| 110 | WheelEvent* event() const; |
| 111 | virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE; |
| 112 | }; |
| 113 | |
| 114 | } // namespace WebCore |
| 115 | |
| 116 | #endif // WheelEvent_h |