1 /* 2 * Copyright (C) 2001 Peter Kelly (pmk (at) post.com) 3 * Copyright (C) 2001 Tobias Anton (anton (at) stud.fbi.fh-darmstadt.de) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig (at) gmail.com) 5 * Copyright (C) 2003, 2005, 2006, 2008, 2010 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 "core/events/WheelEvent.h" 26 27 #include "core/clipboard/Clipboard.h" 28 #include "platform/PlatformWheelEvent.h" 29 30 namespace WebCore { 31 32 WheelEventInit::WheelEventInit() 33 : deltaX(0) 34 , deltaY(0) 35 , deltaZ(0) 36 , wheelDeltaX(0) 37 , wheelDeltaY(0) 38 , deltaMode(WheelEvent::DOM_DELTA_PIXEL) 39 { 40 } 41 42 WheelEvent::WheelEvent() 43 : m_deltaX(0) 44 , m_deltaY(0) 45 , m_deltaZ(0) 46 , m_deltaMode(DOM_DELTA_PIXEL) 47 , m_directionInvertedFromDevice(false) 48 { 49 ScriptWrappable::init(this); 50 } 51 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) 59 { 60 ScriptWrappable::init(this); 61 } 62 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(), 69 0, 0, 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()) 74 , m_deltaZ(0) 75 , m_deltaMode(deltaMode) 76 , m_directionInvertedFromDevice(directionInvertedFromDevice) 77 { 78 ScriptWrappable::init(this); 79 } 80 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) 84 { 85 if (dispatched()) 86 return; 87 88 initUIEvent(EventTypeNames::wheel, true, true, view, 0); 89 90 m_screenLocation = IntPoint(screenX, screenY); 91 m_ctrlKey = ctrlKey; 92 m_altKey = altKey; 93 m_shiftKey = shiftKey; 94 m_metaKey = metaKey; 95 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; 101 102 initCoordinates(IntPoint(pageX, pageY)); 103 } 104 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) 108 { 109 initWheelEvent(rawDeltaX, rawDeltaY, view, screenX, screenY, pageX, pageY, 110 ctrlKey, altKey, shiftKey, metaKey); 111 } 112 113 const AtomicString& WheelEvent::interfaceName() const 114 { 115 return EventNames::WheelEvent; 116 } 117 118 bool WheelEvent::isMouseEvent() const 119 { 120 return false; 121 } 122 123 bool WheelEvent::isWheelEvent() const 124 { 125 return true; 126 } 127 128 void WheelEvent::trace(Visitor* visitor) 129 { 130 MouseEvent::trace(visitor); 131 } 132 133 inline static unsigned deltaMode(const PlatformWheelEvent& event) 134 { 135 return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::DOM_DELTA_PAGE : WheelEvent::DOM_DELTA_PIXEL; 136 } 137 138 PassRefPtrWillBeRawPtr<WheelEventDispatchMediator> WheelEventDispatchMediator::create(const PlatformWheelEvent& event, PassRefPtrWillBeRawPtr<AbstractView> view) 139 { 140 return adoptRefWillBeNoop(new WheelEventDispatchMediator(event, view)); 141 } 142 143 WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtrWillBeRawPtr<AbstractView> view) 144 { 145 if (!(event.deltaX() || event.deltaY())) 146 return; 147 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())); 151 } 152 153 WheelEvent* WheelEventDispatchMediator::event() const 154 { 155 return toWheelEvent(EventDispatchMediator::event()); 156 } 157 158 bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const 159 { 160 ASSERT(event()); 161 return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled(); 162 } 163 164 } // namespace WebCore 165