• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Apple Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include "config.h"
24 #include "WheelEvent.h"
25 
26 #include "EventDispatcher.h"
27 #include "EventNames.h"
28 #include "PlatformWheelEvent.h"
29 
30 #include <wtf/MathExtras.h>
31 
32 namespace WebCore {
33 
WheelEvent()34 WheelEvent::WheelEvent()
35     : m_wheelDeltaX(0)
36     , m_wheelDeltaY(0)
37     , m_rawDeltaX(0)
38     , m_rawDeltaY(0)
39     , m_granularity(Pixel)
40 {
41 }
42 
WheelEvent(float wheelTicksX,float wheelTicksY,float rawDeltaX,float rawDeltaY,Granularity granularity,PassRefPtr<AbstractView> view,int screenX,int screenY,int pageX,int pageY,bool ctrlKey,bool altKey,bool shiftKey,bool metaKey)43 WheelEvent::WheelEvent(float wheelTicksX, float wheelTicksY, float rawDeltaX, float rawDeltaY,
44                        Granularity granularity, PassRefPtr<AbstractView> view,
45                        int screenX, int screenY, int pageX, int pageY,
46                        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
47     : MouseRelatedEvent(eventNames().mousewheelEvent,
48                         true, true, view, 0, screenX, screenY, pageX, pageY,
49                         ctrlKey, altKey, shiftKey, metaKey)
50     , m_wheelDeltaX(lroundf(wheelTicksX * 120))
51     , m_wheelDeltaY(lroundf(wheelTicksY * 120)) // Normalize to the Windows 120 multiple
52     , m_rawDeltaX(rawDeltaX)
53     , m_rawDeltaY(rawDeltaY)
54     , m_granularity(granularity)
55 {
56 }
57 
initWheelEvent(int rawDeltaX,int rawDeltaY,PassRefPtr<AbstractView> view,int screenX,int screenY,int pageX,int pageY,bool ctrlKey,bool altKey,bool shiftKey,bool metaKey)58 void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
59                                 int screenX, int screenY, int pageX, int pageY,
60                                 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
61 {
62     if (dispatched())
63         return;
64 
65     initUIEvent(eventNames().mousewheelEvent, true, true, view, 0);
66 
67     m_screenX = screenX;
68     m_screenY = screenY;
69     m_ctrlKey = ctrlKey;
70     m_altKey = altKey;
71     m_shiftKey = shiftKey;
72     m_metaKey = metaKey;
73 
74     // Normalize to the Windows 120 multiple
75     m_wheelDeltaX = rawDeltaX * 120;
76     m_wheelDeltaY = rawDeltaY * 120;
77 
78     m_rawDeltaX = rawDeltaX;
79     m_rawDeltaY = rawDeltaY;
80     m_granularity = Pixel;
81 
82     initCoordinates(pageX, pageY);
83 }
84 
initWebKitWheelEvent(int rawDeltaX,int rawDeltaY,PassRefPtr<AbstractView> view,int screenX,int screenY,int pageX,int pageY,bool ctrlKey,bool altKey,bool shiftKey,bool metaKey)85 void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
86                                       int screenX, int screenY, int pageX, int pageY,
87                                       bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
88 {
89     initWheelEvent(rawDeltaX, rawDeltaY, view, screenX, screenY, pageX, pageY,
90                    ctrlKey, altKey, shiftKey, metaKey);
91 }
92 
isWheelEvent() const93 bool WheelEvent::isWheelEvent() const
94 {
95     return true;
96 }
97 
granularity(const PlatformWheelEvent & event)98 inline static WheelEvent::Granularity granularity(const PlatformWheelEvent& event)
99 {
100     return event.granularity() == ScrollByPageWheelEvent ? WheelEvent::Page : WheelEvent::Pixel;
101 }
102 
WheelEventDispatchMediator(const PlatformWheelEvent & event,PassRefPtr<AbstractView> view)103 WheelEventDispatchMediator::WheelEventDispatchMediator(const PlatformWheelEvent& event, PassRefPtr<AbstractView> view)
104 {
105     if (!(event.deltaX() || event.deltaY()))
106         return;
107 
108     setEvent(WheelEvent::create(event.wheelTicksX(), event.wheelTicksY(), event.deltaX(), event.deltaY(), granularity(event),
109         view, event.globalX(), event.globalY(), event.x(), event.y(), event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey()));
110 
111 }
112 
event() const113 WheelEvent* WheelEventDispatchMediator::event() const
114 {
115     return static_cast<WheelEvent*>(EventDispatchMediator::event());
116 }
117 
dispatchEvent(EventDispatcher * dispatcher) const118 bool WheelEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
119 {
120     if (!event())
121         return true;
122 
123     return EventDispatchMediator::dispatchEvent(dispatcher) && !event()->defaultHandled();
124 }
125 
126 } // namespace WebCore
127