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, 2004, 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 25 #ifndef WheelEvent_h 26 #define WheelEvent_h 27 28 #include "core/events/EventDispatchMediator.h" 29 #include "core/events/MouseEvent.h" 30 #include "platform/geometry/FloatPoint.h" 31 32 namespace blink { 33 34 class PlatformWheelEvent; 35 36 struct WheelEventInit : public MouseEventInit { 37 WheelEventInit(); 38 39 double deltaX; 40 double deltaY; 41 double deltaZ; 42 int wheelDeltaX; // Deprecated. 43 int wheelDeltaY; // Deprecated. 44 unsigned deltaMode; 45 }; 46 47 class WheelEvent FINAL : public MouseEvent { 48 DEFINE_WRAPPERTYPEINFO(); 49 public: 50 enum { TickMultiplier = 120 }; 51 52 enum DeltaMode { 53 DOM_DELTA_PIXEL = 0, 54 DOM_DELTA_LINE, 55 DOM_DELTA_PAGE 56 }; 57 create()58 static PassRefPtrWillBeRawPtr<WheelEvent> create() 59 { 60 return adoptRefWillBeNoop(new WheelEvent); 61 } 62 create(const AtomicString & type,const WheelEventInit & initializer)63 static PassRefPtrWillBeRawPtr<WheelEvent> create(const AtomicString& type, const WheelEventInit& initializer) 64 { 65 return adoptRefWillBeNoop(new WheelEvent(type, initializer)); 66 } 67 create(const FloatPoint & wheelTicks,const FloatPoint & rawDelta,unsigned deltaMode,PassRefPtrWillBeRawPtr<AbstractView> view,const IntPoint & screenLocation,const IntPoint & pageLocation,bool ctrlKey,bool altKey,bool shiftKey,bool metaKey)68 static PassRefPtrWillBeRawPtr<WheelEvent> create(const FloatPoint& wheelTicks, 69 const FloatPoint& rawDelta, unsigned deltaMode, PassRefPtrWillBeRawPtr<AbstractView> view, 70 const IntPoint& screenLocation, const IntPoint& pageLocation, 71 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey) 72 { 73 return adoptRefWillBeNoop(new WheelEvent(wheelTicks, rawDelta, deltaMode, view, 74 screenLocation, pageLocation, ctrlKey, altKey, shiftKey, metaKey)); 75 } 76 deltaX()77 double deltaX() const { return m_deltaX; } // Positive when scrolling right. deltaY()78 double deltaY() const { return m_deltaY; } // Positive when scrolling down. deltaZ()79 double deltaZ() const { return m_deltaZ; } wheelDelta()80 int wheelDelta() const { return wheelDeltaY() ? wheelDeltaY() : wheelDeltaX(); } // Deprecated. wheelDeltaX()81 int wheelDeltaX() const { return m_wheelDelta.x(); } // Deprecated, negative when scrolling right. wheelDeltaY()82 int wheelDeltaY() const { return m_wheelDelta.y(); } // Deprecated, negative when scrolling down. deltaMode()83 unsigned deltaMode() const { return m_deltaMode; } ticksX()84 float ticksX() const { return static_cast<float>(m_wheelDelta.x()) / TickMultiplier; } ticksY()85 float ticksY() const { return static_cast<float>(m_wheelDelta.y()) / TickMultiplier; } 86 87 virtual const AtomicString& interfaceName() const OVERRIDE; 88 virtual bool isMouseEvent() const OVERRIDE; 89 virtual bool isWheelEvent() const OVERRIDE; 90 91 virtual void trace(Visitor*) OVERRIDE; 92 93 private: 94 WheelEvent(); 95 WheelEvent(const AtomicString&, const WheelEventInit&); 96 WheelEvent(const FloatPoint& wheelTicks, const FloatPoint& rawDelta, 97 unsigned, PassRefPtrWillBeRawPtr<AbstractView>, const IntPoint& screenLocation, const IntPoint& pageLocation, 98 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey); 99 100 IntPoint m_wheelDelta; 101 double m_deltaX; 102 double m_deltaY; 103 double m_deltaZ; 104 unsigned m_deltaMode; 105 }; 106 107 DEFINE_EVENT_TYPE_CASTS(WheelEvent); 108 109 class WheelEventDispatchMediator FINAL : public EventDispatchMediator { 110 public: 111 static PassRefPtrWillBeRawPtr<WheelEventDispatchMediator> create(const PlatformWheelEvent&, PassRefPtrWillBeRawPtr<AbstractView>); 112 private: 113 WheelEventDispatchMediator(const PlatformWheelEvent&, PassRefPtrWillBeRawPtr<AbstractView>); 114 WheelEvent* event() const; 115 virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE; 116 }; 117 118 } // namespace blink 119 120 #endif // WheelEvent_h 121