Default passive touch event listeners on the root
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Aug 2017 19:22:28 +0000 (19:22 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Aug 2017 19:22:28 +0000 (19:22 +0000)
commit58a6cde9a02b39bc2b8e9af945bfd1c3022ca11e
tree4c59ecdf45043dfa4cb5f61508be1e7d2c0dc49e
parentde1035a4dbcd3b6548da4072706b1ecbff126c22
Default passive touch event listeners on the root
https://bugs.webkit.org/show_bug.cgi?id=175346
<rdar://problem/33164597>

Reviewed by Sam Weinig.

Source/WebCore:

Make any touchstart or touchmove event listeners passive by default
if they are on the document, window, body or document element targets.
This follows the "intervention" first implemented by Chrome/Blink:

https://github.com/WICG/interventions/issues/35
https://docs.google.com/document/d/1II7oSIpd8pK91V5kEM3tDLKcIj398jOJn8Niqy6_loI/edit
https://github.com/whatwg/dom/issues/365

If the event listener explicitly defines "passive" to false in their
options dictionary, then they'll still get a non-passive listener.

NOTE: Any fallout from this bug should be collected in:
https://bugs.webkit.org/show_bug.cgi?id=175869
Please do not revert this change just because a site is broken. We'll
gather the issues and see if we can evangelise or detect via code.

Tests: fast/events/touch/ios/passive-by-default-on-document-and-window.html
       fast/events/touch/ios/passive-by-default-overridden-on-document-and-window.html

* dom/EventNames.h:
(WebCore::EventNames::isTouchScrollBlockingEventType const): Added this helper
to identify the types of touches we want to check for.
* dom/EventTarget.cpp:
(WebCore::EventTarget::addEventListener): Check for the event being one of the touch-types
that we care about, and the target being one of the Node/Window types we care about. If
so, tell the event listener to be passive.
* dom/EventTarget.h: Use an optional for the passive member.
(WebCore::EventTarget::AddEventListenerOptions::AddEventListenerOptions):
* dom/EventTarget.idl: Change "passive" to not have a default value, so we
can detect if it was explicitly set to false.

LayoutTests:

* fast/events/touch/ios/passive-by-default-on-document-and-window-expected.txt: Added.
* fast/events/touch/ios/passive-by-default-on-document-and-window.html: Added.
* fast/events/touch/ios/passive-by-default-overridden-on-document-and-window-expected.txt: Added.
* fast/events/touch/ios/passive-by-default-overridden-on-document-and-window.html: Added.
* fast/events/touch/ios/tap-with-active-listener-on-window.html: Explicitly set passive to false.
* fast/events/touch/ios/touch-event-regions/document.html: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221092 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/touch/ios/passive-by-default-on-document-and-window-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/passive-by-default-on-document-and-window.html [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/passive-by-default-overridden-on-document-and-window-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/passive-by-default-overridden-on-document-and-window.html [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/tap-with-active-listener-on-window.html
LayoutTests/fast/events/touch/ios/touch-event-regions/document.html
Source/WebCore/ChangeLog
Source/WebCore/dom/EventNames.h
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/EventTarget.h
Source/WebCore/dom/EventTarget.idl