Add support for passive event listeners on touch events
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2016 01:18:37 +0000 (01:18 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2016 01:18:37 +0000 (01:18 +0000)
commit1ad546c4d46672bd22a7b6d519bfa4441d93a7c1
treee9830fa7502659943fdd38ca3dd4c9510e8eeb4e
parent87ea109de019509a09d18b62642d81914ddec973
Add support for passive event listeners on touch events
https://bugs.webkit.org/show_bug.cgi?id=158601

Patch by Benjamin Poulain <bpoulain@apple.com> on 2016-06-10
Reviewed by Simon Fraser.

Source/WebCore:

This patch wires "passive" state of EventTarget to the delivery of touch
events in WebKit2.

Instead of having a NonFastScrollableRegion, we have a pair of regions
in EventTrackingRegions.
The "asynchronousDispatchRegion" tracks the area for which all event
listeners are passive. For those, events should be dispatched asynchronously.
The "synchronousDispatchRegion" tracks the area for which there is at
least one active event listener. Events have to be dispatched synchronously
for correctness.

Tests: fast/events/touch/ios/tap-with-active-listener-on-elements.html
       fast/events/touch/ios/tap-with-active-listener-on-window.html
       fast/events/touch/ios/tap-with-passive-listener-on-elements.html
       fast/events/touch/ios/tap-with-passive-listener-on-window.html

* WebCore.xcodeproj/project.pbxproj:
* dom/Document.cpp:
(WebCore::Document::wheelEventHandlersChanged):
(WebCore::Document::Document): Deleted.
* dom/Document.h:

* dom/EventListenerMap.cpp:
(WebCore::EventListenerMap::containsActive):
If a Target has multiple listener for an event type, we want to know
if any of them is active.

* dom/EventListenerMap.h:
* dom/EventTarget.cpp:
(WebCore::EventTarget::hasActiveEventListeners):
(WebCore::EventTarget::hasActiveTouchEventListeners):
* dom/EventTarget.h:

* page/DebugPageOverlays.cpp:
(WebCore::NonFastScrollableRegionOverlay::updateRegion):
I did not change the debug overlays.
The NonFastScrollable area is the region for which events needs
synchronous dispatch. Everything else should scroll without delay.

* page/FrameView.cpp:
(WebCore::FrameView::scrollableAreaSetChanged):
* page/Page.cpp:
(WebCore::Page::nonFastScrollableRects):
* page/scrolling/AsyncScrollingCoordinator.cpp:
(WebCore::AsyncScrollingCoordinator::setEventTrackingRegionsDirty):
(WebCore::AsyncScrollingCoordinator::willCommitTree):
(WebCore::AsyncScrollingCoordinator::updateEventTrackingRegions):
(WebCore::AsyncScrollingCoordinator::frameViewLayoutUpdated):
(WebCore::AsyncScrollingCoordinator::frameViewEventTrackingRegionsChanged):
(WebCore::AsyncScrollingCoordinator::scrollingStateTreeAsText):
(WebCore::AsyncScrollingCoordinator::setNonFastScrollableRegionDirty): Deleted.
(WebCore::AsyncScrollingCoordinator::updateNonFastScrollableRegion): Deleted.
(WebCore::AsyncScrollingCoordinator::frameViewNonFastScrollableRegionChanged): Deleted.
* page/scrolling/AsyncScrollingCoordinator.h:
(WebCore::AsyncScrollingCoordinator::eventTrackingRegionsDirty):
(WebCore::AsyncScrollingCoordinator::nonFastScrollableRegionDirty): Deleted.

* page/scrolling/ScrollingCoordinator.cpp:
(WebCore::ScrollingCoordinator::absoluteEventTrackingRegionsForFrame):
(WebCore::ScrollingCoordinator::absoluteEventTrackingRegions):
(WebCore::ScrollingCoordinator::absoluteNonFastScrollableRegionForFrame): Deleted.
(WebCore::ScrollingCoordinator::absoluteNonFastScrollableRegion): Deleted.
I intentionally left the Wheel event with synchronous dispatch.
This use case will need its own set of tests.

* page/scrolling/ScrollingCoordinator.h:
(WebCore::ScrollingCoordinator::frameViewEventTrackingRegionsChanged):
(WebCore::ScrollingCoordinator::frameViewNonFastScrollableRegionChanged): Deleted.
* page/scrolling/ScrollingStateFrameScrollingNode.cpp:
(WebCore::ScrollingStateFrameScrollingNode::ScrollingStateFrameScrollingNode):
(WebCore::ScrollingStateFrameScrollingNode::setEventTrackingRegions):
(WebCore::ScrollingStateFrameScrollingNode::dumpProperties):
(WebCore::ScrollingStateFrameScrollingNode::setNonFastScrollableRegion): Deleted.
* page/scrolling/ScrollingStateFrameScrollingNode.h:
* page/scrolling/ScrollingTree.cpp:
(WebCore::ScrollingTree::shouldHandleWheelEventSynchronously):
(WebCore::ScrollingTree::commitNewTreeState):
(WebCore::ScrollingTree::eventTrackingTypeForPoint):
(WebCore::ScrollingTree::isPointInNonFastScrollableRegion): Deleted.
* page/scrolling/ScrollingTree.h:
* page/scrolling/mac/ScrollingCoordinatorMac.mm:
(WebCore::ScrollingCoordinatorMac::scheduleTreeStateCommit):
* platform/EventTrackingRegions.h: Added.
(WebCore::EventTrackingRegions::isEmpty):
(WebCore::EventTrackingRegions::trackingTypeForPoint):
(WebCore::operator==):

Source/WebKit2:

* Shared/Scrolling/RemoteScrollingCoordinatorTransaction.cpp:
(ArgumentCoder<ScrollingStateFrameScrollingNode>::encode):
(ArgumentCoder<ScrollingStateFrameScrollingNode>::decode):
(WebKit::dump):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<EventTrackingRegions>::encode):
(IPC::ArgumentCoder<EventTrackingRegions>::decode):
* Shared/WebCoreArgumentCoders.h:
* UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp:
(WebKit::RemoteScrollingCoordinatorProxy::eventTrackingTypeForPoint):
(WebKit::RemoteScrollingCoordinatorProxy::isPointInNonFastScrollableRegion): Deleted.
* UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::touchEventTrackingType):
The type is the most restrictive type of all the touch points.
If any touch point needs synchronous tracking, everything has to be synchronous.

(WebKit::WebPageProxy::handleTouchEventSynchronously):
This is a very unfortunate design.

The upper layer dealing with UIKit knows about gesture and when something
can be dispatched asynchrnously because a gesture has started.
This layer knows about tracking and can use that extra inforamtion
to dispatch an event asynchrnously anyway.

In the future, we should refactor this to let WebPageProxy
always decide of the dispatch type. I am just concerned changing
the upper layer while we are stabilizing WebKit.

(WebKit::WebPageProxy::handleTouchEventAsynchronously):
(WebKit::WebPageProxy::handleTouchEvent):
(WebKit::WebPageProxy::resetState):
(WebKit::WebPageProxy::WebPageProxy): Deleted.
(WebKit::WebPageProxy::shouldStartTrackingTouchEvents): Deleted.
* UIProcess/WebPageProxy.h:

LayoutTests:

* fast/events/touch/ios/tap-with-active-listener-on-elements-expected.txt: Added.
* fast/events/touch/ios/tap-with-active-listener-on-elements.html: Added.
* fast/events/touch/ios/tap-with-active-listener-on-window-expected.txt: Added.
* fast/events/touch/ios/tap-with-active-listener-on-window.html: Added.
* fast/events/touch/ios/tap-with-passive-listener-inside-active-listener-expected.txt: Added.
* fast/events/touch/ios/tap-with-passive-listener-on-elements-expected.txt: Added.
* fast/events/touch/ios/tap-with-passive-listener-on-elements.html: Added.
* fast/events/touch/ios/tap-with-passive-listener-on-window-expected.txt: Added.
* fast/events/touch/ios/tap-with-passive-listener-on-window.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@201958 268f45cc-cd09-0410-ab3c-d52691b4dbfc
47 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/touch/ios/tap-with-active-listener-on-elements-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-active-listener-on-elements.html [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-active-listener-on-window-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-active-listener-on-window.html [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-passive-listener-inside-active-listener-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-passive-listener-on-elements-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-passive-listener-on-elements.html [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-passive-listener-on-window-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-passive-listener-on-window.html [new file with mode: 0644]
LayoutTests/tiled-drawing/scrolling/fixed/fixed-in-overflow-expected.txt
LayoutTests/tiled-drawing/scrolling/frames/coordinated-frame-expected.txt
LayoutTests/tiled-drawing/scrolling/frames/coordinated-frame-gain-scrolling-ancestor-expected.txt
LayoutTests/tiled-drawing/scrolling/frames/coordinated-frame-in-fixed-expected.txt
LayoutTests/tiled-drawing/scrolling/frames/coordinated-frame-lose-scrolling-ancestor-expected.txt
LayoutTests/tiled-drawing/scrolling/frames/frameset-frame-scrollability-expected.txt
LayoutTests/tiled-drawing/scrolling/frames/frameset-nested-frame-scrollability-expected.txt
LayoutTests/tiled-drawing/scrolling/frames/scroll-region-after-frame-layout-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/EventListenerMap.cpp
Source/WebCore/dom/EventListenerMap.h
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/EventTarget.h
Source/WebCore/page/DebugPageOverlays.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp
Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h
Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
Source/WebCore/page/scrolling/ScrollingCoordinator.h
Source/WebCore/page/scrolling/ScrollingStateFrameScrollingNode.cpp
Source/WebCore/page/scrolling/ScrollingStateFrameScrollingNode.h
Source/WebCore/page/scrolling/ScrollingTree.cpp
Source/WebCore/page/scrolling/ScrollingTree.h
Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm
Source/WebCore/platform/EventTrackingRegions.h [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/Scrolling/RemoteScrollingCoordinatorTransaction.cpp
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
Source/WebKit2/Shared/WebCoreArgumentCoders.h
Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp
Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h