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.
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.
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.
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.
24 #include "WheelEvent.h"
26 #include "EventDispatcher.h"
27 #include "EventNames.h"
28 #include "PlatformWheelEvent.h"
30 #include <wtf/MathExtras.h>
34 WheelEvent::WheelEvent()
35 : m_granularity(Pixel)
39 WheelEvent::WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta,
40 Granularity granularity, PassRefPtr<AbstractView> view,
41 const IntPoint& screenLocation, const IntPoint& pageLocation,
42 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
43 : MouseRelatedEvent(eventNames().mousewheelEvent,
44 true, true, view, 0, screenLocation, pageLocation,
45 ctrlKey, altKey, shiftKey, metaKey)
46 , m_wheelDelta(IntPoint(static_cast<int>(wheelTicks.x() * tickMultiplier), static_cast<int>(wheelTicks.y() * tickMultiplier)))
47 , m_rawDelta(roundedIntPoint(rawDelta))
48 , m_granularity(granularity)
52 void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
53 int screenX, int screenY, int pageX, int pageY,
54 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
59 initUIEvent(eventNames().mousewheelEvent, true, true, view, 0);
61 m_screenLocation = IntPoint(screenX, screenY);
64 m_shiftKey = shiftKey;
67 // Normalize to the Windows 120 multiple
68 m_wheelDelta = IntPoint(rawDeltaX * tickMultiplier, rawDeltaY * tickMultiplier);
70 m_rawDelta = IntPoint(rawDeltaX, rawDeltaY);
71 m_granularity = Pixel;
73 initCoordinates(IntPoint(pageX, pageY));
76 void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
77 int screenX, int screenY, int pageX, int pageY,
78 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
80 initWheelEvent(rawDeltaX, rawDeltaY, view, screenX, screenY, pageX, pageY,
81 ctrlKey, altKey, shiftKey, metaKey);
84 bool WheelEvent::isWheelEvent() const
89 inline static WheelEvent::Granularity granularity(const PlatformWheelEvent& event)
91 return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::Page : WheelEvent::Pixel;
94 PassRefPtr<WheelEventDispatchMediator> WheelEventDispatchMediator::create(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view)
96 return adoptRef(new WheelEventDispatchMediator(event, view));
99 WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view)
101 if (!(event.deltaX() || event.deltaY()))
104 setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()), granularity(event),
105 view, IntPoint(event.globalX(), event.globalY()), IntPoint(event.x(), event.y()), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey()));
109 WheelEvent* WheelEventDispatchMediator::event() const
111 return static_cast<WheelEvent*>(EventDispatchMediator::event());
114 bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
119 return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled();
122 } // namespace WebCore