Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
body {
margin: 0;
}
.scroller {
position: absolute;
top: 0;
width: 150px;
height: 100px;
overflow-x: hidden;
overflow-y: scroll;
}
#dragged {
left: 0;
}
#flung {
left: 200px;
}
.content {
height: 5000px;
}
</style>
<div class="scroller" id="dragged"><div class="content"></div></div>
<div class="scroller" id="flung"><div class="content"></div></div>
<script>
promiseTest(async () => {
await animationFrame();
await animationFrame();
const dragged = document.getElementById("dragged");
const flung = document.getElementById("flung");
const scrollends = new Map([[dragged, 0], [flung, 0]]);
for (const scroller of scrollends.keys())
scroller.addEventListener("scrollend", () => scrollends.set(scroller, scrollends.get(scroller) + 1));
const report = when => println(`${when}: dragged box ${scrollends.get(dragged)}, flung box ${scrollends.get(flung)}`);
const settle = async () => {
for (let frame = 0; frame < 4; frame++)
await animationFrame();
await new Promise(resolve => setTimeout(resolve, 700));
};
const flick = async () => {
await internals.wheelThroughUIProcess(250, 50, 0, 0, true, "ongoing");
for (let step = 0; step < 3; step++)
await internals.wheelThroughUIProcess(250, 50, 0, 50, true, "ongoing");
};
// A pause of 500 milliseconds in a stream of momentum ends the gesture, and a slow runner can take that long
// between two events. Fingers on the touchpad hold a gesture for as long as they rest, so only one event is
// momentum.
const momentum = () => internals.wheelThroughUIProcess(250, 50, 0, 2, true, "momentum");
// The flung box comes to rest while the thumb of the other is held, and its scroll ends then.
await internals.mouseEventThroughUIProcess("mousemove", 147, 5);
await internals.mouseEventThroughUIProcess("mousedown", 147, 5);
await internals.mouseEventThroughUIProcess("mousemove", 147, 40, { buttons: 1 });
await flick();
await momentum();
await internals.wheelThroughUIProcess(250, 50, 0, 0, true, "ended");
await settle();
report("flung box at rest while the thumb is held");
await internals.mouseEventThroughUIProcess("mouseup", 147, 40);
await settle();
report("thumb released");
// The thumb of the other box is let go of while the fingers still hold the flung box, and its scroll ends then.
await flick();
await internals.mouseEventThroughUIProcess("mousemove", 147, 40);
await internals.mouseEventThroughUIProcess("mousedown", 147, 40);
await internals.mouseEventThroughUIProcess("mousemove", 147, 70, { buttons: 1 });
const draggedBoxScrollEnded = scrollendEvent(dragged);
await internals.mouseEventThroughUIProcess("mouseup", 147, 70);
await draggedBoxScrollEnded;
report("thumb released while the other box is being flung");
await momentum();
await internals.wheelThroughUIProcess(250, 50, 0, 0, true, "ended");
await settle();
report("momentum ended");
});
</script>