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.
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.
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.
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.
25 #include "core/events/WheelEvent.h"
27 #include "core/clipboard/Clipboard.h"
28 #include "platform/PlatformWheelEvent.h"
32 WheelEventInit::WheelEventInit()
38 , deltaMode(WheelEvent::DOM_DELTA_PIXEL)
42 WheelEvent::WheelEvent()
46 , m_deltaMode(DOM_DELTA_PIXEL)
47 , m_directionInvertedFromDevice(false)
49 ScriptWrappable::init(this);
52 WheelEvent::WheelEvent(const AtomicString& type, const WheelEventInit& initializer)
53 : MouseEvent(type, initializer)
54 , m_wheelDelta(initializer.wheelDeltaX ? initializer.wheelDeltaX : -initializer.deltaX, initializer.wheelDeltaY ? initializer.wheelDeltaY : -initializer.deltaY)
55 , m_deltaX(initializer.deltaX ? initializer.deltaX : -initializer.wheelDeltaX)
56 , m_deltaY(initializer.deltaY ? initializer.deltaY : -initializer.wheelDeltaY)
57 , m_deltaZ(initializer.deltaZ)
58 , m_deltaMode(initializer.deltaMode)
60 ScriptWrappable::init(this);
63 WheelEvent::WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta, unsigned deltaMode,
64 PassRefPtrWillBeRawPtr<AbstractView> view, const IntPoint& screenLocation, const IntPoint& pageLocation,
65 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool directionInvertedFromDevice)
66 : MouseEvent(EventTypeNames::wheel,
67 true, true, view, 0, screenLocation.x(), screenLocation.y(),
68 pageLocation.x(), pageLocation.y(),
70 ctrlKey, altKey, shiftKey, metaKey, 0, nullptr, nullptr, false)
71 , m_wheelDelta(wheelTicks.x() * TickMultiplier, wheelTicks.y() * TickMultiplier)
72 , m_deltaX(-rawDelta.x())
73 , m_deltaY(-rawDelta.y())
75 , m_deltaMode(deltaMode)
76 , m_directionInvertedFromDevice(directionInvertedFromDevice)
78 ScriptWrappable::init(this);
81 void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtrWillBeRawPtr<AbstractView> view,
82 int screenX, int screenY, int pageX, int pageY,
83 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
88 initUIEvent(EventTypeNames::wheel, true, true, view, 0);
90 m_screenLocation = IntPoint(screenX, screenY);
93 m_shiftKey = shiftKey;
96 m_wheelDelta = IntPoint(rawDeltaX * TickMultiplier, rawDeltaY * TickMultiplier);
97 m_deltaX = -rawDeltaX;
98 m_deltaY = -rawDeltaY;
99 m_deltaMode = DOM_DELTA_PIXEL;
100 m_directionInvertedFromDevice = false;
102 initCoordinates(IntPoint(pageX, pageY));
105 void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtrWillBeRawPtr<AbstractView> view,
106 int screenX, int screenY, int pageX, int pageY,
107 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
109 initWheelEvent(rawDeltaX, rawDeltaY, view, screenX, screenY, pageX, pageY,
110 ctrlKey, altKey, shiftKey, metaKey);
113 const AtomicString& WheelEvent::interfaceName() const
115 return EventNames::WheelEvent;
118 bool WheelEvent::isMouseEvent() const
123 bool WheelEvent::isWheelEvent() const
128 void WheelEvent::trace(Visitor* visitor)
130 MouseEvent::trace(visitor);
133 inline static unsigned deltaMode(const PlatformWheelEvent& event)
135 return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA_PAGE : WheelEvent::DOM_DELTA_PIXEL;
138 PassRefPtrWillBeRawPtr<WheelEventDispatchMediator> WheelEventDispatchMediator::create(const PlatformWheelEvent& event, PassRefPtrWillBeRawPtr<AbstractView> view)
140 return adoptRefWillBeNoop(new WheelEventDispatchMediator(event, view));
143 WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtrWillBeRawPtr<AbstractView> view)
145 if (!(event.deltaX() || event.deltaY()))
148 setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()),
149 deltaMode(event), view, event.globalPosition(), event.position(),
150 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.directionInvertedFromDevice()));
153 WheelEvent* WheelEventDispatchMediator::event() const
155 return toWheelEvent(EventDispatchMediator::event());
158 bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
161 return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled();
164 } // namespace WebCore