1 | /* |
2 | * Copyright (C) 2011, 2014 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #ifndef EventDispatcher_h |
27 | #define EventDispatcher_h |
28 | |
29 | #include "Connection.h" |
30 | |
31 | #include "WebEvent.h" |
32 | #include <WebCore/PageIdentifier.h> |
33 | #include <WebCore/WheelEventDeltaFilter.h> |
34 | #include <memory> |
35 | #include <wtf/HashMap.h> |
36 | #include <wtf/Lock.h> |
37 | #include <wtf/Noncopyable.h> |
38 | #include <wtf/RefPtr.h> |
39 | #include <wtf/ThreadingPrimitives.h> |
40 | |
41 | #if ENABLE(MAC_GESTURE_EVENTS) |
42 | #include "WebGestureEvent.h" |
43 | #endif |
44 | |
45 | namespace WebCore { |
46 | class ThreadedScrollingTree; |
47 | } |
48 | |
49 | namespace WebKit { |
50 | |
51 | class WebEvent; |
52 | class WebPage; |
53 | class WebWheelEvent; |
54 | |
55 | class EventDispatcher : public IPC::Connection::WorkQueueMessageReceiver { |
56 | public: |
57 | static Ref<EventDispatcher> create(); |
58 | ~EventDispatcher(); |
59 | |
60 | #if ENABLE(ASYNC_SCROLLING) |
61 | void addScrollingTreeForPage(WebPage*); |
62 | void removeScrollingTreeForPage(WebPage*); |
63 | #endif |
64 | |
65 | #if ENABLE(IOS_TOUCH_EVENTS) |
66 | typedef Vector<WebTouchEvent, 1> TouchEventQueue; |
67 | |
68 | void clearQueuedTouchEventsForPage(const WebPage&); |
69 | void getQueuedTouchEventsForPage(const WebPage&, TouchEventQueue&); |
70 | #endif |
71 | |
72 | void initializeConnection(IPC::Connection*); |
73 | |
74 | private: |
75 | EventDispatcher(); |
76 | |
77 | // IPC::Connection::WorkQueueMessageReceiver. |
78 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
79 | |
80 | // Message handlers |
81 | void wheelEvent(WebCore::PageIdentifier, const WebWheelEvent&, bool canRubberBandAtLeft, bool canRubberBandAtRight, bool canRubberBandAtTop, bool canRubberBandAtBottom); |
82 | #if ENABLE(IOS_TOUCH_EVENTS) |
83 | void touchEvent(WebCore::PageIdentifier, const WebTouchEvent&); |
84 | #endif |
85 | #if ENABLE(MAC_GESTURE_EVENTS) |
86 | void gestureEvent(WebCore::PageIdentifier, const WebGestureEvent&); |
87 | #endif |
88 | |
89 | |
90 | // This is called on the main thread. |
91 | void dispatchWheelEvent(WebCore::PageIdentifier, const WebWheelEvent&); |
92 | #if ENABLE(IOS_TOUCH_EVENTS) |
93 | void dispatchTouchEvents(); |
94 | #endif |
95 | #if ENABLE(MAC_GESTURE_EVENTS) |
96 | void dispatchGestureEvent(WebCore::PageIdentifier, const WebGestureEvent&); |
97 | #endif |
98 | |
99 | #if ENABLE(ASYNC_SCROLLING) |
100 | void sendDidReceiveEvent(WebCore::PageIdentifier, const WebEvent&, bool didHandleEvent); |
101 | #endif |
102 | |
103 | Ref<WorkQueue> m_queue; |
104 | |
105 | #if ENABLE(ASYNC_SCROLLING) |
106 | Lock m_scrollingTreesMutex; |
107 | HashMap<WebCore::PageIdentifier, RefPtr<WebCore::ThreadedScrollingTree>> m_scrollingTrees; |
108 | #endif |
109 | std::unique_ptr<WebCore::WheelEventDeltaFilter> m_recentWheelEventDeltaFilter; |
110 | #if ENABLE(IOS_TOUCH_EVENTS) |
111 | Lock m_touchEventsLock; |
112 | HashMap<WebCore::PageIdentifier, TouchEventQueue> m_touchEvents; |
113 | #endif |
114 | }; |
115 | |
116 | } // namespace WebKit |
117 | |
118 | #endif // EventDispatcher_h |
119 | |