Skip to content

Truly independent web browser

2.8 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<style>
    body {
        margin: 0;
    }

    #scroller {
        width: 200px;
        height: 200px;
        overflow: scroll;
    }

    #target {
        width: 100px;
        height: 100px;
    }

    #spacer {
        width: 1000px;
        height: 1000px;
    }

    #not-scrollable {
        position: absolute;
        left: 250px;
        top: 0;
        width: 100px;
        height: 100px;
    }
</style>
<div id="scroller">
    <div id="target"></div>
    <div id="spacer"></div>
</div>
<div id="not-scrollable"></div>
<script>
    function printOutputAndDisplayList(output, displayList, label = "display list:") {
        for (const line of output)
            println(line);
        println(label);
        println(displayList);
    }

    function wheelTarget(output, label, x, y) {
        output.push(`${label}: ${wheelTargetToString(internals.compositorWheelTargetAt(x, y, 0, 100))}`);
    }

    async function frames() {
        await animationFrame();
        await animationFrame();
    }

    promiseTest(async () => {
        await frames();
        const output = [];
        output.push(`initial routing admission: ${internals.compositorScrollState().wheelRoutingAdmission}`);
        wheelTarget(output, "no listener over scroller", 150, 150);
        wheelTarget(output, "no scrollable target", 275, 50);

        target.addEventListener("wheel", event => {}, { passive: true });
        await frames();
        wheelTarget(output, "passive listener over target", 50, 50);

        // A blocking listener holds every step back until a frame shows where the listener is.
        const blockingElementListener = event => {};
        target.addEventListener("wheel", blockingElementListener, { passive: false });
        wheelTarget(output, "blocking element listener before the next frame", 150, 150);
        await frames();
        output.push(`blocking element routing admission: ${internals.compositorScrollState().wheelRoutingAdmission}`);
        wheelTarget(output, "blocking element listener inside", 50, 50);
        wheelTarget(output, "blocking element listener outside", 150, 150);
        const displayList = internals.dumpDisplayList();

        target.removeEventListener("wheel", blockingElementListener);
        const blockingWindowListener = event => {};
        window.addEventListener("wheel", blockingWindowListener, { passive: false });
        wheelTarget(output, "blocking window listener before the next frame", 150, 150);
        await frames();
        output.push(`blocking window routing admission: ${internals.compositorScrollState().wheelRoutingAdmission}`);
        wheelTarget(output, "blocking window listener", 150, 150);
        printOutputAndDisplayList(output, displayList, "display list after blocking element listener:");
    });
</script>