<!DOCTYPEHTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>Dragging the mouse on a content-implemented scrollbar</title>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style> body {
background: linear-gradient(135deg, red, blue);
}
#scrollbar {
position:fixed;
top: 0;
right: 10px;
height: 100%;
width: 150px;
background-color: gray;
}
</style>
<script type="text/javascript"> var bar = null; var mouseDown = false; var mouseDownY = -1;
async function moveTo(mouseY) { var fraction = (mouseY - bar.getBoundingClientRect().top) / bar.getBoundingClientRect().height;
fraction = Math.max(0, fraction);
fraction = Math.min(1, fraction); var oldScrollPos = document.scrollingElement.scrollTop; var newScrollPos = fraction * window.scrollMaxY;
ok(newScrollPos > oldScrollPos, "Scroll position strictly increased");
// split the scroll in two with a paint in between, just to increase the
// complexity of the simulated web content, and to ensure this works as well.
document.scrollingElement.scrollTop = (oldScrollPos + newScrollPos) / 2;
await promiseAllPaintsDone();
document.scrollingElement.scrollTop = newScrollPos;
}
async function moveMouseAndHandleEvent(x, y) {
let mouseMoveHandledPromise = new Promise(resolve => {
async function mouseOnTarget(e) {
if (!mouseDown) {
return;
}
dump("Got mousemove clientY " + e.clientY + "\n");
e.stopPropagation();
if (e.clientY == mouseDownY) {
dump("Discarding spurious mousemove\n");
return;
}
await moveTo(e.clientY);
handled();
}
function mouseOffTarget(e) {
if (!mouseDown) {
return;
}
ok(false, "The mousemove at " + e.clientY + " was not stopped by the bar listener, and is a glitchy event!");
handled();
}
function handled() {
bar.removeEventListener("mousemove", mouseOnTarget, true);
window.removeEventListener("mousemove", mouseOffTarget);
resolve();
}
bar.addEventListener("mousemove", mouseOnTarget, true);
window.addEventListener("mousemove", mouseOffTarget);
});
await synthesizeNativeMouseEventWithAPZ({
target: bar,
offsetX: x,
offsetY: y,
type: "mousemove",
});
await mouseMoveHandledPromise;
}
async function test() {
bar = document.getElementById("scrollbar");
mouseDown = false;
mouseDownY = -1;
// Move the mouse to the "scrollbar" (the div upon which dragging changes scroll position)
await promiseNativeMouseEventWithAPZ({
target: bar,
offsetX: 10,
offsetY: 10,
type: "mousemove",
});
// mouse down
await downMouseAndHandleEvent(10, 10);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.