Skip to content

Truly independent web browser

2.7 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="frame-in-flight.js"></script>
<style>
    body { margin: 0; }
    #stage { position: relative; width: 400px; height: 150px; }
    #box { position: absolute; left: 100px; top: 20px; width: 100px; height: 60px; cursor: cell; transform: translateX(-300px); }
    #box:hover { height: 80px; }
    #stage.active #box { animation: slide 10s linear infinite; }
    @keyframes slide { from { transform: translateX(-300px); } to { transform: translateX(300px); } }
</style>
<div id="stage"><div id="box"></div></div>
<script>
    // The compositor moves a box across the pointer at rest with a transform animation, and tells the render clock that
    // the pointer rests on moving content. The clock lane hovers where the pointer rests again at its next tick, hit
    // testing the frame with the animation sampled at the tick's time, as the screen shows it: it hovers the box as it
    // covers the pointer, with its cursor, and hovers it no more once it has moved away.
    asyncTest(async done => {
        internals.mouseMove(150, 50);
        await twoFrames();
        const result = await whileLaneAnimates(() => {
            stage.classList.add("active");
            return box.getAnimations()[0];
        }, (frameTime, animation, startTime) => {
            const lines = [];
            // The lane hears of the pointer as the compositor tells it of a move: 1 s in, the box is away from it.
            internals.injectHoverPointer(150, 50, startTime + 1000);
            lines.push(`at 1 s, after a move beside the box: cursor ${internals.currentCursor()}, presented height ${internals.presentedBorderBox(box)?.height}`);
            // 5 s in, the box is translated by 0px: it spans 100..200 by 20..80, under the pointer.
            internals.injectPointerRestsOnMovingContent(startTime + 5000);
            lines.push(`at 5 s, the box under the pointer: cursor ${internals.currentCursor()}, presented height ${internals.presentedBorderBox(box)?.height}`);
            // 9 s in, the box is translated by 240px, away from the pointer.
            internals.injectPointerRestsOnMovingContent(startTime + 9000);
            lines.push(`at 9 s, the box away: cursor ${internals.currentCursor()}, presented height ${internals.presentedBorderBox(box)?.height}`);
            lines.push(`last frame presented by: ${internals.lastFramePresentedBy(document)}`);
            return lines;
        });
        for (const line of result)
            println(line);
        await nextFrame();
        println(`box matches :hover after the task: ${box.matches(":hover")}`);
        println(`cursor after the task: ${internals.currentCursor()}`);
        done();
    });
</script>