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/DataTransfer.h"
28 #include "platform/PlatformMouseEvent.h"
29 #include "platform/PlatformWheelEvent.h"
33 WheelEventInit::WheelEventInit()
39 , deltaMode(WheelEvent::DOM_DELTA_PIXEL)
43 WheelEvent::WheelEvent()
47 , m_deltaMode(DOM_DELTA_PIXEL)
51 WheelEvent::WheelEvent(const AtomicString& type, const WheelEventInit& initializer)
52 : MouseEvent(type, initializer)
53 , m_wheelDelta(initializer.wheelDeltaX ? initializer.wheelDeltaX : -initializer.deltaX, initializer.wheelDeltaY ? initializer.wheelDeltaY : -initializer.deltaY)
54 , m_deltaX(initializer.deltaX ? initializer.deltaX : -initializer.wheelDeltaX)
55 , m_deltaY(initializer.deltaY ? initializer.deltaY : -initializer.wheelDeltaY)
56 , m_deltaZ(initializer.deltaZ)
57 , m_deltaMode(initializer.deltaMode)
61 WheelEvent::WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta, unsigned deltaMode,
62 PassRefPtrWillBeRawPtr<AbstractView> view, const IntPoint& screenLocation, const IntPoint& pageLocation,
63 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
64 : MouseEvent(EventTypeNames::wheel, true, true, view, 0, screenLocation.x(), screenLocation.y(),
65 pageLocation.x(), pageLocation.y(), 0, 0, ctrlKey, altKey, shiftKey, metaKey, 0, nullptr,
66 nullptr, false, PlatformMouseEvent::RealOrIndistinguishable)
67 , m_wheelDelta(wheelTicks.x() * TickMultiplier, wheelTicks.y() * TickMultiplier)
68 , m_deltaX(-rawDelta.x())
69 , m_deltaY(-rawDelta.y())
71 , m_deltaMode(deltaMode)
75 const AtomicString& WheelEvent::interfaceName() const
77 return EventNames::WheelEvent;
80 bool WheelEvent::isMouseEvent() const
85 bool WheelEvent::isWheelEvent() const
90 void WheelEvent::trace(Visitor* visitor)
92 MouseEvent::trace(visitor);
95 inline static unsigned deltaMode(const PlatformWheelEvent& event)
97 return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA_PAGE : WheelEvent::DOM_DELTA_PIXEL;
100 PassRefPtrWillBeRawPtr<WheelEventDispatchMediator> WheelEventDispatchMediator::create(const PlatformWheelEvent& event, PassRefPtrWillBeRawPtr<AbstractView> view)
102 return adoptRefWillBeNoop(new WheelEventDispatchMediator(event, view));
105 WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtrWillBeRawPtr<AbstractView> view)
107 if (!(event.deltaX() || event.deltaY()))
110 setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()),
111 deltaMode(event), view, event.globalPosition(), event.position(),
112 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey()));
115 WheelEvent* WheelEventDispatchMediator::event() const
117 return toWheelEvent(EventDispatchMediator::event());
120 bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
123 return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled();