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/WheelEventDeltaFilter.h>
33#include <memory>
34#include <wtf/HashMap.h>
35#include <wtf/Lock.h>
36#include <wtf/Noncopyable.h>
37#include <wtf/RefPtr.h>
38#include <wtf/ThreadingPrimitives.h>
39
40#if ENABLE(MAC_GESTURE_EVENTS)
41#include "WebGestureEvent.h"
42#endif
43
44namespace WebCore {
45class ThreadedScrollingTree;
46}
47
48namespace WebKit {
49
50class WebEvent;
51class WebPage;
52class WebWheelEvent;
53
54class EventDispatcher : public IPC::Connection::WorkQueueMessageReceiver {
55public:
56 static Ref<EventDispatcher> create();
57 ~EventDispatcher();
58
59#if ENABLE(ASYNC_SCROLLING)
60 void addScrollingTreeForPage(WebPage*);
61 void removeScrollingTreeForPage(WebPage*);
62#endif
63
64#if ENABLE(IOS_TOUCH_EVENTS)
65 typedef Vector<WebTouchEvent, 1> TouchEventQueue;
66
67 void clearQueuedTouchEventsForPage(const WebPage&);
68 void getQueuedTouchEventsForPage(const WebPage&, TouchEventQueue&);
69#endif
70
71 void initializeConnection(IPC::Connection*);
72
73private:
74 EventDispatcher();
75
76 // IPC::Connection::WorkQueueMessageReceiver.
77 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
78
79 // Message handlers
80 void wheelEvent(uint64_t pageID, const WebWheelEvent&, bool canRubberBandAtLeft, bool canRubberBandAtRight, bool canRubberBandAtTop, bool canRubberBandAtBottom);
81#if ENABLE(IOS_TOUCH_EVENTS)
82 void touchEvent(uint64_t pageID, const WebTouchEvent&);
83#endif
84#if ENABLE(MAC_GESTURE_EVENTS)
85 void gestureEvent(uint64_t pageID, const WebGestureEvent&);
86#endif
87
88
89 // This is called on the main thread.
90 void dispatchWheelEvent(uint64_t pageID, const WebWheelEvent&);
91#if ENABLE(IOS_TOUCH_EVENTS)
92 void dispatchTouchEvents();
93#endif
94#if ENABLE(MAC_GESTURE_EVENTS)
95 void dispatchGestureEvent(uint64_t pageID, const WebGestureEvent&);
96#endif
97
98#if ENABLE(ASYNC_SCROLLING)
99 void sendDidReceiveEvent(uint64_t pageID, const WebEvent&, bool didHandleEvent);
100#endif
101
102 Ref<WorkQueue> m_queue;
103
104#if ENABLE(ASYNC_SCROLLING)
105 Lock m_scrollingTreesMutex;
106 HashMap<uint64_t, RefPtr<WebCore::ThreadedScrollingTree>> m_scrollingTrees;
107#endif
108 std::unique_ptr<WebCore::WheelEventDeltaFilter> m_recentWheelEventDeltaFilter;
109#if ENABLE(IOS_TOUCH_EVENTS)
110 Lock m_touchEventsLock;
111 HashMap<uint64_t, TouchEventQueue> m_touchEvents;
112#endif
113};
114
115} // namespace WebKit
116
117#endif // EventDispatcher_h
118