Bug 1452751 - add a pref to control whether to default to passive touch listeners on window/document/documentElement/body , r=kats
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -681,33 +681,49 @@ EventListenerManager::ListenerCanHandle(
if (!aEvent->mFlags.mInSystemGroup && !aListener->mIsChrome) {
return false;
}
}
MOZ_ASSERT(mIsMainThreadELM);
return aListener->mEventMessage == aEventMessage;
}
+static bool
+DefaultToPassiveTouchListeners()
+{
+ static bool sDefaultToPassiveTouchListeners = false;
+ static bool sIsPrefCached = false;
+
+ if (!sIsPrefCached) {
+ sIsPrefCached = true;
+ Preferences::AddBoolVarCache(&sDefaultToPassiveTouchListeners,
+ "dom.event.default_to_passive_touch_listeners");
+ }
+
+ return sDefaultToPassiveTouchListeners;
+}
+
void
EventListenerManager::AddEventListenerByType(
EventListenerHolder aListenerHolder,
const nsAString& aType,
const EventListenerFlags& aFlags,
const Optional<bool>& aPassive)
{
RefPtr<nsAtom> atom;
EventMessage message = mIsMainThreadELM ?
nsContentUtils::GetEventMessageAndAtomForListener(aType,
getter_AddRefs(atom)) :
eUnidentifiedEvent;
EventListenerFlags flags = aFlags;
if (aPassive.WasPassed()) {
flags.mPassive = aPassive.Value();
- } else if (message == eTouchStart || message == eTouchMove) {
+ } else if ((message == eTouchStart || message == eTouchMove) &&
+ mIsMainThreadELM && DefaultToPassiveTouchListeners()) {
nsCOMPtr<nsINode> node;
nsCOMPtr<nsPIDOMWindowInner> win;
if ((win = GetTargetAsInnerWindow()) ||
((node = do_QueryInterface(mTarget)) &&
(node == node->OwnerDoc() ||
node == node->OwnerDoc()->GetRootElement() ||
node == node->OwnerDoc()->GetBody()))) {
flags.mPassive = true;
--- a/gfx/layers/apz/test/mochitest/test_group_touchevents.html
+++ b/gfx/layers/apz/test/mochitest/test_group_touchevents.html
@@ -71,17 +71,18 @@ var subtests = [
// For the following tests, we want to make sure APZ doesn't wait for a content
// response that is never going to arrive. To detect this we set the content response
// timeout to a day, so that the entire test times out and fails if APZ does
// end up waiting.
{'file': 'helper_tap_passive.html', 'prefs': [["apz.content_response_timeout", 24 * 60 * 60 * 1000],
["apz.test.fails_with_native_injection", isWindows]]},
{'file': 'helper_tap_default_passive.html', 'prefs': [["apz.content_response_timeout", 24 * 60 * 60 * 1000],
- ["apz.test.fails_with_native_injection", isWindows]]},
+ ["apz.test.fails_with_native_injection", isWindows],
+ ["dom.event.default_to_passive_touch_listeners", true]]},
// Simple test to exercise touch-action CSS property
{'file': 'helper_touch_action.html', 'prefs': touch_action_prefs},
// More complex touch-action tests, with overlapping regions and such
{'file': 'helper_touch_action_complex.html', 'prefs': touch_action_prefs},
// Tests that touch-action CSS properties are handled in APZ without waiting
// on the main-thread, when possible
{'file': 'helper_touch_action_regions.html', 'prefs': touch_action_prefs},
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5912,8 +5912,12 @@ pref("layers.omtp.paint-workers", 1);
#endif
pref("layers.omtp.release-capture-on-main-thread", false);
pref("layers.omtp.dump-capture", false);
// Limits the depth of recursive conversion of data when opening
// a content to view. This is mostly intended to prevent infinite
// loops with faulty converters involved.
pref("general.document_open_conversion_depth_limit", 20);
+
+// If true, touchstart and touchmove listeners on window, document,
+// documentElement and document.body are passive by default.
+pref("dom.event.default_to_passive_touch_listeners", false);