darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 1 | /* |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 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) |
benjamin@webkit.org | ac28bde | 2013-06-19 22:41:17 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003, 2005, 2006, 2008, 2010, 2013 Apple Inc. All rights reserved. |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 6 | * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include "config.h" |
| 25 | #include "WheelEvent.h" |
| 26 | |
darin@apple.com | 569b13f | 2013-03-03 05:55:53 +0000 | [diff] [blame] | 27 | #include "Clipboard.h" |
dglazkov@chromium.org | 72e43ec | 2011-04-08 15:48:21 +0000 | [diff] [blame] | 28 | #include "EventDispatcher.h" |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 29 | #include "EventNames.h" |
dglazkov@chromium.org | 72e43ec | 2011-04-08 15:48:21 +0000 | [diff] [blame] | 30 | #include "PlatformWheelEvent.h" |
| 31 | |
hyatt | 4f172f9 | 2006-09-20 09:52:25 +0000 | [diff] [blame] | 32 | #include <wtf/MathExtras.h> |
| 33 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 34 | namespace WebCore { |
| 35 | |
haraken@chromium.org | 5dc16a7 | 2013-01-30 22:43:57 +0000 | [diff] [blame] | 36 | WheelEventInit::WheelEventInit() |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 37 | : deltaX(0) |
| 38 | , deltaY(0) |
| 39 | , deltaZ(0) |
haraken@chromium.org | b3a16d2 | 2013-02-04 23:55:06 +0000 | [diff] [blame] | 40 | , deltaMode(WheelEvent::DOM_DELTA_PIXEL) |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 41 | , wheelDeltaX(0) |
| 42 | , wheelDeltaY(0) |
haraken@chromium.org | 5dc16a7 | 2013-01-30 22:43:57 +0000 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 46 | WheelEvent::WheelEvent() |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 47 | : m_deltaX(0) |
| 48 | , m_deltaY(0) |
| 49 | , m_deltaZ(0) |
| 50 | , m_deltaMode(DOM_DELTA_PIXEL) |
commit-queue@webkit.org | bcc7ca5 | 2012-04-04 17:03:13 +0000 | [diff] [blame] | 51 | , m_directionInvertedFromDevice(false) |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
haraken@chromium.org | 5dc16a7 | 2013-01-30 22:43:57 +0000 | [diff] [blame] | 55 | WheelEvent::WheelEvent(const AtomicString& type, const WheelEventInit& initializer) |
| 56 | : MouseEvent(type, initializer) |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 57 | , m_wheelDelta(initializer.wheelDeltaX ? initializer.wheelDeltaX : -initializer.deltaX, initializer.wheelDeltaY ? initializer.wheelDeltaY : -initializer.deltaY) |
| 58 | , m_deltaX(initializer.deltaX ? initializer.deltaX : -initializer.wheelDeltaX) |
| 59 | , m_deltaY(initializer.deltaY ? initializer.deltaY : -initializer.wheelDeltaY) |
| 60 | , m_deltaZ(initializer.deltaZ) |
haraken@chromium.org | b3a16d2 | 2013-02-04 23:55:06 +0000 | [diff] [blame] | 61 | , m_deltaMode(initializer.deltaMode) |
haraken@chromium.org | 5dc16a7 | 2013-01-30 22:43:57 +0000 | [diff] [blame] | 62 | { |
| 63 | } |
| 64 | |
haraken@chromium.org | b3a16d2 | 2013-02-04 23:55:06 +0000 | [diff] [blame] | 65 | WheelEvent::WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta, unsigned deltaMode, |
haraken@chromium.org | 92472c5 | 2013-01-31 11:10:44 +0000 | [diff] [blame] | 66 | PassRefPtr<AbstractView> view, const IntPoint& screenLocation, const IntPoint& pageLocation, |
benjamin@webkit.org | ac28bde | 2013-06-19 22:41:17 +0000 | [diff] [blame] | 67 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool directionInvertedFromDevice, double timestamp) |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 68 | : MouseEvent(eventNames().wheelEvent, |
benjamin@webkit.org | ac28bde | 2013-06-19 22:41:17 +0000 | [diff] [blame] | 69 | true, true, timestamp, view, 0, screenLocation.x(), screenLocation.y(), |
dominicc@chromium.org | 0edeeac | 2012-06-26 07:41:32 +0000 | [diff] [blame] | 70 | pageLocation.x(), pageLocation.y(), |
scheib@chromium.org | e972c2e | 2011-11-24 00:25:38 +0000 | [diff] [blame] | 71 | #if ENABLE(POINTER_LOCK) |
dominicc@chromium.org | 0edeeac | 2012-06-26 07:41:32 +0000 | [diff] [blame] | 72 | 0, 0, |
scheib@chromium.org | e972c2e | 2011-11-24 00:25:38 +0000 | [diff] [blame] | 73 | #endif |
dominicc@chromium.org | 0edeeac | 2012-06-26 07:41:32 +0000 | [diff] [blame] | 74 | ctrlKey, altKey, shiftKey, metaKey, 0, 0, 0, false) |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 75 | , m_wheelDelta(wheelTicks.x() * TickMultiplier, wheelTicks.y() * TickMultiplier) |
| 76 | , m_deltaX(-rawDelta.x()) |
| 77 | , m_deltaY(-rawDelta.y()) |
| 78 | , m_deltaZ(0) |
haraken@chromium.org | 92472c5 | 2013-01-31 11:10:44 +0000 | [diff] [blame] | 79 | , m_deltaMode(deltaMode) |
jonlee@apple.com | 736fb65 | 2011-10-04 18:06:44 +0000 | [diff] [blame] | 80 | , m_directionInvertedFromDevice(directionInvertedFromDevice) |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 81 | { |
| 82 | } |
| 83 | |
mrowe@apple.com | 95c4eac | 2010-03-02 23:33:38 +0000 | [diff] [blame] | 84 | void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view, |
darin | c1f6b2b | 2006-08-16 04:22:22 +0000 | [diff] [blame] | 85 | int screenX, int screenY, int pageX, int pageY, |
| 86 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey) |
| 87 | { |
| 88 | if (dispatched()) |
| 89 | return; |
| 90 | |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 91 | initUIEvent(eventNames().wheelEvent, true, true, view, 0); |
darin | c1f6b2b | 2006-08-16 04:22:22 +0000 | [diff] [blame] | 92 | |
eae@chromium.org | 039e826 | 2011-06-01 23:19:02 +0000 | [diff] [blame] | 93 | m_screenLocation = IntPoint(screenX, screenY); |
darin | c1f6b2b | 2006-08-16 04:22:22 +0000 | [diff] [blame] | 94 | m_ctrlKey = ctrlKey; |
| 95 | m_altKey = altKey; |
| 96 | m_shiftKey = shiftKey; |
| 97 | m_metaKey = metaKey; |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 98 | |
| 99 | // Normalize to 120 multiple for compatibility with IE. |
haraken@chromium.org | 5dc16a7 | 2013-01-30 22:43:57 +0000 | [diff] [blame] | 100 | m_wheelDelta = IntPoint(rawDeltaX * TickMultiplier, rawDeltaY * TickMultiplier); |
ch.dumez@sisa.samsung.com | 181483e | 2013-08-27 10:09:06 +0000 | [diff] [blame] | 101 | m_deltaX = -rawDeltaX; |
| 102 | m_deltaY = -rawDeltaY; |
| 103 | |
haraken@chromium.org | b3a16d2 | 2013-02-04 23:55:06 +0000 | [diff] [blame] | 104 | m_deltaMode = DOM_DELTA_PIXEL; |
jonlee@apple.com | 736fb65 | 2011-10-04 18:06:44 +0000 | [diff] [blame] | 105 | m_directionInvertedFromDevice = false; |
| 106 | |
eae@chromium.org | 039e826 | 2011-06-01 23:19:02 +0000 | [diff] [blame] | 107 | initCoordinates(IntPoint(pageX, pageY)); |
darin | c1f6b2b | 2006-08-16 04:22:22 +0000 | [diff] [blame] | 108 | } |
| 109 | |
mrowe@apple.com | 95c4eac | 2010-03-02 23:33:38 +0000 | [diff] [blame] | 110 | void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view, |
| 111 | int screenX, int screenY, int pageX, int pageY, |
| 112 | bool ctrlKey, bool altKey, bool shiftKey, bool metaKey) |
| 113 | { |
| 114 | initWheelEvent(rawDeltaX, rawDeltaY, view, screenX, screenY, pageX, pageY, |
| 115 | ctrlKey, altKey, shiftKey, metaKey); |
| 116 | } |
darin | c1f6b2b | 2006-08-16 04:22:22 +0000 | [diff] [blame] | 117 | |
abarth@webkit.org | 090fa4b | 2011-10-21 00:00:37 +0000 | [diff] [blame] | 118 | const AtomicString& WheelEvent::interfaceName() const |
| 119 | { |
| 120 | return eventNames().interfaceForWheelEvent; |
| 121 | } |
| 122 | |
dominicc@chromium.org | 0edeeac | 2012-06-26 07:41:32 +0000 | [diff] [blame] | 123 | bool WheelEvent::isMouseEvent() const |
| 124 | { |
| 125 | return false; |
| 126 | } |
| 127 | |
haraken@chromium.org | b3a16d2 | 2013-02-04 23:55:06 +0000 | [diff] [blame] | 128 | inline static unsigned deltaMode(const PlatformWheelEvent& event) |
dglazkov@chromium.org | 72e43ec | 2011-04-08 15:48:21 +0000 | [diff] [blame] | 129 | { |
haraken@chromium.org | b3a16d2 | 2013-02-04 23:55:06 +0000 | [diff] [blame] | 130 | return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA_PAGE : WheelEvent::DOM_DELTA_PIXEL; |
dglazkov@chromium.org | 72e43ec | 2011-04-08 15:48:21 +0000 | [diff] [blame] | 131 | } |
| 132 | |
hayato@chromium.org | 1931df6 | 2011-08-03 10:17:31 +0000 | [diff] [blame] | 133 | PassRefPtr<WheelEventDispatchMediator> WheelEventDispatchMediator::create(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view) |
| 134 | { |
| 135 | return adoptRef(new WheelEventDispatchMediator(event, view)); |
| 136 | } |
| 137 | |
dglazkov@chromium.org | 72e43ec | 2011-04-08 15:48:21 +0000 | [diff] [blame] | 138 | WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view) |
| 139 | { |
| 140 | if (!(event.deltaX() || event.deltaY())) |
| 141 | return; |
| 142 | |
jonlee@apple.com | 736fb65 | 2011-10-04 18:06:44 +0000 | [diff] [blame] | 143 | setEvent(WheelEvent::create(FloatPoint(event.wheelTicksX(), event.wheelTicksY()), FloatPoint(event.deltaX(), event.deltaY()), |
haraken@chromium.org | 92472c5 | 2013-01-31 11:10:44 +0000 | [diff] [blame] | 144 | deltaMode(event), view, event.globalPosition(), event.position(), |
benjamin@webkit.org | ac28bde | 2013-06-19 22:41:17 +0000 | [diff] [blame] | 145 | event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.directionInvertedFromDevice(), event.timestamp())); |
dglazkov@chromium.org | 72e43ec | 2011-04-08 15:48:21 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | WheelEvent* WheelEventDispatchMediator::event() const |
| 149 | { |
| 150 | return static_cast<WheelEvent*>(EventDispatchMediator::event()); |
| 151 | } |
| 152 | |
| 153 | bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const |
| 154 | { |
hayato@chromium.org | 133ec0d | 2013-02-19 07:57:37 +0000 | [diff] [blame] | 155 | ASSERT(event()); |
dglazkov@chromium.org | 72e43ec | 2011-04-08 15:48:21 +0000 | [diff] [blame] | 156 | return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled(); |
| 157 | } |
| 158 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 159 | } // namespace WebCore |