2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "EventDispatcher.h"
30 #include "WebEventConversion.h"
32 #include "WebPageProxyMessages.h"
33 #include "WebProcess.h"
34 #include <WebCore/Page.h>
35 #include <WebCore/RunLoop.h>
36 #include <wtf/MainThread.h>
38 #if ENABLE(THREADED_SCROLLING)
39 #include <WebCore/ScrollingCoordinator.h>
40 #include <WebCore/ScrollingThread.h>
41 #include <WebCore/ScrollingTree.h>
44 using namespace WebCore;
48 EventDispatcher::EventDispatcher()
52 EventDispatcher::~EventDispatcher()
56 #if ENABLE(THREADED_SCROLLING)
57 void EventDispatcher::addScrollingTreeForPage(WebPage* webPage)
59 MutexLocker locker(m_scrollingTreesMutex);
61 ASSERT(webPage->corePage()->scrollingCoordinator());
62 ASSERT(!m_scrollingTrees.contains(webPage->pageID()));
63 m_scrollingTrees.set(webPage->pageID(), webPage->corePage()->scrollingCoordinator()->scrollingTree());
66 void EventDispatcher::removeScrollingTreeForPage(WebPage* webPage)
68 MutexLocker locker(m_scrollingTreesMutex);
69 ASSERT(m_scrollingTrees.contains(webPage->pageID()));
71 m_scrollingTrees.remove(webPage->pageID());
75 void EventDispatcher::didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, bool& didHandleMessage)
77 if (messageID.is<CoreIPC::MessageClassEventDispatcher>()) {
78 didReceiveEventDispatcherMessageOnConnectionWorkQueue(connection, messageID, arguments, didHandleMessage);
83 void EventDispatcher::wheelEvent(CoreIPC::Connection*, uint64_t pageID, const WebWheelEvent& wheelEvent, bool canGoBack, bool canGoForward)
85 #if ENABLE(THREADED_SCROLLING)
86 MutexLocker locker(m_scrollingTreesMutex);
87 if (ScrollingTree* scrollingTree = m_scrollingTrees.get(pageID).get()) {
88 PlatformWheelEvent platformWheelEvent = platform(wheelEvent);
90 // FIXME: It's pretty horrible that we're updating the back/forward state here.
91 // WebCore should always know the current state and know when it changes so the
92 // scrolling tree can be notified.
93 // We only need to do this at the beginning of the gesture.
94 if (platformWheelEvent.phase() == PlatformWheelEventPhaseBegan)
95 ScrollingThread::dispatch(bind(&ScrollingTree::updateBackForwardState, scrollingTree, canGoBack, canGoForward));
97 ScrollingTree::EventResult result = scrollingTree->tryToHandleWheelEvent(platformWheelEvent);
98 if (result == ScrollingTree::DidHandleEvent || result == ScrollingTree::DidNotHandleEvent) {
99 sendDidReceiveEvent(pageID, wheelEvent, result == ScrollingTree::DidHandleEvent);
104 UNUSED_PARAM(canGoBack);
105 UNUSED_PARAM(canGoForward);
108 RunLoop::main()->dispatch(bind(&EventDispatcher::dispatchWheelEvent, this, pageID, wheelEvent));
111 #if ENABLE(GESTURE_EVENTS)
112 void EventDispatcher::gestureEvent(CoreIPC::Connection*, uint64_t pageID, const WebGestureEvent& gestureEvent)
114 RunLoop::main()->dispatch(bind(&EventDispatcher::dispatchGestureEvent, this, pageID, gestureEvent));
118 void EventDispatcher::dispatchWheelEvent(uint64_t pageID, const WebWheelEvent& wheelEvent)
120 ASSERT(isMainThread());
122 WebPage* webPage = WebProcess::shared().webPage(pageID);
126 webPage->wheelEvent(wheelEvent);
129 #if ENABLE(GESTURE_EVENTS)
130 void EventDispatcher::dispatchGestureEvent(uint64_t pageID, const WebGestureEvent& gestureEvent)
132 ASSERT(isMainThread());
134 WebPage* webPage = WebProcess::shared().webPage(pageID);
138 webPage->gestureEvent(gestureEvent);
142 #if ENABLE(THREADED_SCROLLING)
143 void EventDispatcher::sendDidReceiveEvent(uint64_t pageID, const WebEvent& event, bool didHandleEvent)
145 WebProcess::shared().connection()->send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(event.type()), didHandleEvent), pageID);
149 } // namespace WebKit