Skip to content

Commit

Permalink
Bug 1162771 - Fall back to using the non-anonymous ancestor node of t…
Browse files Browse the repository at this point in the history
…he target if the anonymous target is disconnected from the document. r=smaug

MozReview-Commit-ID: 8FLXSWqQnk1
  • Loading branch information
staktrace committed Aug 18, 2016
1 parent 35fe4d8 commit 2fcc30f
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
99 changes: 99 additions & 0 deletions gfx/layers/apz/test/mochitest/helper_bug1162771.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>Test for touchend on media elements</title>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript">

function* test(testDriver) {
var v = document.getElementById('video');
var a = document.getElementById('audio');
var d = document.getElementById('div');

document.body.ontouchstart = function(e) {
if (e.target === v || e.target === a || e.target === d) {
e.target.style.display = 'none';
ok(true, 'Set display to none on #' + e.target.id);
} else {
ok(false, 'Got unexpected touchstart on ' + e.target);
}
waitForAllPaints(testDriver);
};

document.body.ontouchend = function(e) {
if (e.target === v || e.target === a || e.target === d) {
e.target._gotTouchend = true;
ok(true, 'Got touchend event on #' + e.target.id);
}
testDriver();
};

yield synthesizeNativeTouch(v, 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
yield synthesizeNativeTouch(v, 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
ok(v._gotTouchend, 'Touchend was received on video element');

yield synthesizeNativeTouch(a, 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
yield synthesizeNativeTouch(a, 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
ok(a._gotTouchend, 'Touchend was received on audio element');

yield synthesizeNativeTouch(d, 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT);
yield synthesizeNativeTouch(d, 5, 5, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE);
ok(d._gotTouchend, 'Touchend was received on div element');
}

waitUntilApzStable()
.then(runContinuation(test))
.then(subtestDone);

</script>
<style>
* {
font-size: 24px;
box-sizing: border-box;
}

#video {
display:block;
position:absolute;
top: 100px;
left:0;
width: 33%;
height: 100px;
border:solid black 1px;
background-color: #8a8;
}

#audio {
display:block;
position:absolute;
top: 100px;
left:33%;
width: 33%;
height: 100px;
border:solid black 1px;
background-color: #a88;
}

#div {
display:block;
position:absolute;
top: 100px;
left: 66%;
width: 34%;
height: 100px;
border:solid black 1px;
background-color: #88a;
}
</style>
</head>
<body>
<p>Tap on the colored boxes to hide them.</p>
<video id="video"></video>
<audio id="audio" controls></audio>
<div id="div"></div>
</body>
</html>
1 change: 1 addition & 0 deletions gfx/layers/apz/test/mochitest/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ support-files =
helper_drag_scroll.html
helper_touch_action_complex.html
helper_tap_fullzoom.html
helper_bug1162771.html
tags = apz
[test_bug982141.html]
[test_bug1151663.html]
Expand Down
5 changes: 5 additions & 0 deletions gfx/layers/apz/test/mochitest/test_group_touchevents.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
{'file': 'helper_scrollto_tap.html?true', 'prefs': [["apz.paint_skipping.enabled", true]], 'dp_suppression': false},
{'file': 'helper_scrollto_tap.html?false', 'prefs': [["apz.paint_skipping.enabled", false]], 'dp_suppression': false},

// Taps on media elements to make sure the touchend event is delivered
// properly. We increase the long-tap timeout to ensure it doesn't get trip
// during the tap.
{'file': 'helper_bug1162771.html', 'prefs': [["ui.click_hold_context_menus.delay", 10000]]},

// For the long-tap test, reduce the content response timeout because the touchstart
// event doesn't get processed (because of the event listener) until this expires.
// Once we support passive event listeners, we can use that instead and stop mucking
Expand Down
8 changes: 8 additions & 0 deletions layout/base/TouchManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
touches.RemoveElementAt(i);
continue;
}
nsCOMPtr<nsINode> targetNode(do_QueryInterface(targetPtr));
if (!targetNode->IsInComposedDoc()) {
targetPtr = do_QueryInterface(info.mNonAnonymousTarget);
}
touch->SetTarget(targetPtr);

info.mTouch = touch;
Expand Down Expand Up @@ -228,6 +232,10 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
continue;
}
nsCOMPtr<EventTarget> targetPtr = info.mTouch->mTarget;
nsCOMPtr<nsINode> targetNode(do_QueryInterface(targetPtr));
if (!targetNode->IsInComposedDoc()) {
targetPtr = do_QueryInterface(info.mNonAnonymousTarget);
}

aCurrentEventContent = do_QueryInterface(targetPtr);
touch->SetTarget(targetPtr);
Expand Down

0 comments on commit 2fcc30f

Please sign in to comment.