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, 2005, 2006, 2008, 2010 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 #include "config.h"
25 #include "core/events/WheelEvent.h"
26
27 #include "core/dom/Clipboard.h"
28 #include "core/events/ThreadLocalEventNames.h"
29 #include "platform/PlatformWheelEvent.h"
30
31 namespace WebCore {
32
WheelEventInit()33 WheelEventInit::WheelEventInit()
34 : deltaX(0)
35 , deltaY(0)
36 , deltaZ(0)
37 , wheelDeltaX(0)
38 , wheelDeltaY(0)
39 , deltaMode(WheelEvent::DOM_DELTA_PIXEL)
40 {
41 }
42
WheelEvent()43 WheelEvent::WheelEvent()
44 : m_deltaX(0)
45 , m_deltaY(0)
46 , m_deltaZ(0)
47 , m_deltaMode(DOM_DELTA_PIXEL)
48 , m_directionInvertedFromDevice(false)
49 {
50 ScriptWrappable::init(this);
51 }
52
WheelEvent(const AtomicString & type,const WheelEventInit & initializer)53 WheelEvent::WheelEvent(const AtomicString& type, const WheelEventInit& initializer)
54 : MouseEvent(type, initializer)
55 , m_wheelDelta(initializer.wheelDeltaX ? initializer.wheelDeltaX : -initializer.deltaX, initializer.wheelDeltaY ? initializer.wheelDeltaY : -initializer.deltaY)
56 , m_deltaX(initializer.deltaX ? initializer.deltaX : -initializer.wheelDeltaX)
57 , m_deltaY(initializer.deltaY ? initializer.deltaY : -initializer.wheelDeltaY)
58 , m_deltaZ(initializer.deltaZ)
59 , m_deltaMode(initializer.deltaMode)
60 {
61 ScriptWrappable::init(this);
62 }
63
WheelEvent(const FloatPoint & wheelTicks,const FloatPoint & rawDelta,unsigned deltaMode,PassRefPtr<AbstractView> view,const IntPoint & screenLocation,const IntPoint & pageLocation,bool ctrlKey,bool altKey,bool shiftKey,bool metaKey,bool directionInvertedFromDevice)64 WheelEvent::WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta, unsigned deltaMode,
65 PassRefPtr<AbstractView> view, const IntPoint& screenLocation, const IntPoint& pageLocation,
66 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool directionInvertedFromDevice)
67 : MouseEvent(EventTypeNames::wheel,
68 true, true, view, 0, screenLocation.x(), screenLocation.y(),
69 pageLocation.x(), pageLocation.y(),
70 0, 0,
71 ctrlKey, altKey, shiftKey, metaKey, 0, 0, 0, false)
72 , m_wheelDelta(wheelTicks.x() * TickMultiplier, wheelTicks.y() * TickMultiplier)
73 , m_deltaX(-rawDelta.x())
74 , m_deltaY(-rawDelta.y())
75 , m_deltaZ(0)
76 , m_deltaMode(deltaMode)
77 , m_directionInvertedFromDevice(directionInvertedFromDevice)
78 {
79 ScriptWrappable::init(this);
80 }
81
initWheelEvent(int rawDeltaX,int rawDeltaY,PassRefPtr<AbstractView> view,int screenX,int screenY,int pageX,int pageY,bool ctrlKey,bool altKey,bool shiftKey,bool metaKey)82 void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
83 int screenX, int screenY, int pageX, int pageY,
84 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
85 {
86 if (dispatched())
87 return;
88
89 initUIEvent(EventTypeNames::wheel, true, true, view, 0);
90
91 m_screenLocation = IntPoint(screenX, screenY);
92 m_ctrlKey = ctrlKey;
93 m_altKey = altKey;
94 m_shiftKey = shiftKey;
95 m_metaKey = metaKey;
96
97 m_wheelDelta = IntPoint(rawDeltaX * TickMultiplier, rawDeltaY * TickMultiplier);
98 m_deltaX = -rawDeltaX;
99 m_deltaY = -rawDeltaY;
100 m_deltaMode = DOM_DELTA_PIXEL;
101 m_directionInvertedFromDevice = false;
102
103 initCoordinates(IntPoint(pageX, pageY));
104 }
105
initWebKitWheelEvent(int rawDeltaX,int rawDeltaY,PassRefPtr<AbstractView> view,int screenX,int screenY,int pageX,int pageY,bool ctrlKey,bool altKey,bool shiftKey,bool metaKey)106 void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
107 int screenX, int screenY, int pageX, int pageY,
108 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
109 {
110 initWheelEvent(rawDeltaX, rawDeltaY, view, screenX, screenY, pageX, pageY,
111 ctrlKey, altKey, shiftKey, metaKey);
112 }
113
interfaceName() const114 const AtomicString& WheelEvent::interfaceName() const
115 {
116 return EventNames::WheelEvent;
117 }
118
isMouseEvent() const119 bool WheelEvent::isMouseEvent() const
120 {
121 return false;
122 }
123
isWheelEvent() const124 bool WheelEvent::isWheelEvent() const
125 {
126 return true;
127 }
128
deltaMode(const PlatformWheelEvent & event)129 inline static unsigned deltaMode(const PlatformWheelEvent& event)
130 {
131 return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA_PAGE : WheelEvent::DOM_DELTA_PIXEL;
132 }
133
create(const PlatformWheelEvent & event,PassRefPtr<AbstractView> view)134 PassRefPtr<WheelEventDispatchMediator> WheelEventDispatchMediator::create(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view)
135 {
136 return adoptRef(new WheelEventDispatchMediator(event, view));
137 }
138
WheelEventDispatchMediator(const PlatformWheelEvent & event,PassRefPtr<AbstractView> view)139 WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view)
140 {
141 if (!(event.deltaX() || event.deltaY()))
142 return;
143
144 setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()),
145 deltaMode(event), view, event.globalPosition(), event.position(),
146 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.directionInvertedFromDevice()));
147 }
148
event() const149 WheelEvent* WheelEventDispatchMediator::event() const
150 {
151 return toWheelEvent(EventDispatchMediator::event());
152 }
153
dispatchEvent(EventDispatcher * dispatcher) const154 bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
155 {
156 ASSERT(event());
157 return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled();
158 }
159
160 } // namespace WebCore
161