OLD | NEW |
| (Empty) |
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/EventNames.h" | |
29 #include "core/platform/PlatformWheelEvent.h" | |
30 | |
31 namespace WebCore { | |
32 | |
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 | |
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 | |
53 WheelEvent::WheelEvent(const AtomicString& type, const WheelEventInit& initializ
er) | |
54 : MouseEvent(type, initializer) | |
55 , m_wheelDelta(initializer.wheelDeltaX ? initializer.wheelDeltaX : -initiali
zer.deltaX, initializer.wheelDeltaY ? initializer.wheelDeltaY : -initializer.del
taY) | |
56 , m_deltaX(initializer.deltaX ? initializer.deltaX : -initializer.wheelDelta
X) | |
57 , m_deltaY(initializer.deltaY ? initializer.deltaY : -initializer.wheelDelta
Y) | |
58 , m_deltaZ(initializer.deltaZ) | |
59 , m_deltaMode(initializer.deltaMode) | |
60 { | |
61 ScriptWrappable::init(this); | |
62 } | |
63 | |
64 WheelEvent::WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta,
unsigned deltaMode, | |
65 PassRefPtr<AbstractView> view, const IntPoint& screenLocation, const IntPoin
t& pageLocation, | |
66 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool directionInvert
edFromDevice) | |
67 : MouseEvent(eventNames().wheelEvent, | |
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() * TickMultipl
ier) | |
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 | |
82 void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<Abstrac
tView> view, | |
83 int screenX, int screenY, int pageX, int pageY, | |
84 bool ctrlKey, bool altKey, bool shiftKey, bool m
etaKey) | |
85 { | |
86 if (dispatched()) | |
87 return; | |
88 | |
89 initUIEvent(eventNames().wheelEvent, 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 * TickMultipli
er); | |
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 | |
106 void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<A
bstractView> view, | |
107 int screenX, int screenY, int pageX, int p
ageY, | |
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 | |
114 const AtomicString& WheelEvent::interfaceName() const | |
115 { | |
116 return eventNames().interfaceForWheelEvent; | |
117 } | |
118 | |
119 bool WheelEvent::isMouseEvent() const | |
120 { | |
121 return false; | |
122 } | |
123 | |
124 inline static unsigned deltaMode(const PlatformWheelEvent& event) | |
125 { | |
126 return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA
_PAGE : WheelEvent::DOM_DELTA_PIXEL; | |
127 } | |
128 | |
129 PassRefPtr<WheelEventDispatchMediator> WheelEventDispatchMediator::create(const
PlatformWheelEvent& event, PassRefPtr<AbstractView> view) | |
130 { | |
131 return adoptRef(new WheelEventDispatchMediator(event, view)); | |
132 } | |
133 | |
134 WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent&
event, PassRefPtr<AbstractView> view) | |
135 { | |
136 if (!(event.deltaX() || event.deltaY())) | |
137 return; | |
138 | |
139 setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicks
Y()), FloatPoint(event.deltaX(), event.deltaY()), | |
140 deltaMode(event), view, event.globalPosition(), event.position(), | |
141 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), even
t.directionInvertedFromDevice())); | |
142 } | |
143 | |
144 WheelEvent* WheelEventDispatchMediator::event() const | |
145 { | |
146 return static_cast<WheelEvent*>(EventDispatchMediator::event()); | |
147 } | |
148 | |
149 bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) cons
t | |
150 { | |
151 ASSERT(event()); | |
152 return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->default
Handled(); | |
153 } | |
154 | |
155 } // namespace WebCore | |
OLD | NEW |