| 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, 2013 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 "WheelEvent.h" |
| 26 | |
| 27 | #include "DataTransfer.h" |
| 28 | #include "EventNames.h" |
| 29 | #include <wtf/MathExtras.h> |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | inline static unsigned determineDeltaMode(const PlatformWheelEvent& event) |
| 34 | { |
| 35 | return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA_PAGE : WheelEvent::DOM_DELTA_PIXEL; |
| 36 | } |
| 37 | |
| 38 | inline WheelEvent::WheelEvent() = default; |
| 39 | |
| 40 | inline WheelEvent::WheelEvent(const AtomicString& type, const Init& initializer) |
| 41 | : MouseEvent(type, initializer) |
| 42 | , m_wheelDelta(initializer.wheelDeltaX ? initializer.wheelDeltaX : -initializer.deltaX, initializer.wheelDeltaY ? initializer.wheelDeltaY : -initializer.deltaY) |
| 43 | , m_deltaX(initializer.deltaX ? initializer.deltaX : -initializer.wheelDeltaX) |
| 44 | , m_deltaY(initializer.deltaY ? initializer.deltaY : -initializer.wheelDeltaY) |
| 45 | , m_deltaZ(initializer.deltaZ) |
| 46 | , m_deltaMode(initializer.deltaMode) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | inline WheelEvent::WheelEvent(const PlatformWheelEvent& event, RefPtr<WindowProxy>&& view) |
| 51 | : MouseEvent(eventNames().wheelEvent, CanBubble::Yes, IsCancelable::Yes, IsComposed::Yes, event.timestamp().approximateMonotonicTime(), WTFMove(view), 0, |
| 52 | event.globalPosition(), event.position() , { }, event.modifiers(), 0, 0, nullptr, 0, 0, nullptr, IsSimulated::No, IsTrusted::Yes) |
| 53 | , m_wheelDelta(event.wheelTicksX() * TickMultiplier, event.wheelTicksY() * TickMultiplier) |
| 54 | , m_deltaX(-event.deltaX()) |
| 55 | , m_deltaY(-event.deltaY()) |
| 56 | , m_deltaMode(determineDeltaMode(event)) |
| 57 | , m_underlyingPlatformEvent(event) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | Ref<WheelEvent> WheelEvent::create(const PlatformWheelEvent& event, RefPtr<WindowProxy>&& view) |
| 62 | { |
| 63 | return adoptRef(*new WheelEvent(event, WTFMove(view))); |
| 64 | } |
| 65 | |
| 66 | Ref<WheelEvent> WheelEvent::createForBindings() |
| 67 | { |
| 68 | return adoptRef(*new WheelEvent); |
| 69 | } |
| 70 | |
| 71 | Ref<WheelEvent> WheelEvent::create(const AtomicString& type, const Init& initializer) |
| 72 | { |
| 73 | return adoptRef(*new WheelEvent(type, initializer)); |
| 74 | } |
| 75 | |
| 76 | void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, RefPtr<WindowProxy>&& view, int screenX, int screenY, int pageX, int pageY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey) |
| 77 | { |
| 78 | if (isBeingDispatched()) |
| 79 | return; |
| 80 | |
| 81 | initMouseEvent(eventNames().wheelEvent, true, true, WTFMove(view), 0, screenX, screenY, pageX, pageY, ctrlKey, altKey, shiftKey, metaKey, 0, nullptr); |
| 82 | |
| 83 | // Normalize to 120 multiple for compatibility with IE. |
| 84 | m_wheelDelta = { rawDeltaX * TickMultiplier, rawDeltaY * TickMultiplier }; |
| 85 | m_deltaX = -rawDeltaX; |
| 86 | m_deltaY = -rawDeltaY; |
| 87 | |
| 88 | m_deltaMode = DOM_DELTA_PIXEL; |
| 89 | |
| 90 | m_underlyingPlatformEvent = WTF::nullopt; |
| 91 | } |
| 92 | |
| 93 | EventInterface WheelEvent::eventInterface() const |
| 94 | { |
| 95 | return WheelEventInterfaceType; |
| 96 | } |
| 97 | |
| 98 | bool WheelEvent::isWheelEvent() const |
| 99 | { |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | } // namespace WebCore |
| 104 | |