Skip to content

Truly independent web browser

3.3 KB
Raw Blame
<!doctype html>
<script src="../include.js"></script>
<style>
    :root {
        container-type: scroll-state;
    }

    body {
        margin: 0;
        height: 5000px;
    }

    #scroller {
        width: 200px;
        height: 200px;
        overflow-y: scroll;
        container-type: scroll-state;
    }

    #filler {
        height: 2000px;
    }

    #snap-scroller {
        width: 200px;
        height: 200px;
        overflow-y: scroll;
        container-type: scroll-state;
        scroll-snap-type: y mandatory;
    }

    .snap-area {
        height: 200px;
        scroll-snap-align: start;
    }

    .target {
        --scrolled: none;
        @container scroll-state(scrolled: top) {
            --scrolled: top;
        }
        @container scroll-state(scrolled: bottom) {
            --scrolled: bottom;
        }
    }
</style>
<div id="scroller" tabindex="0"><div id="filler"><div class="target" id="inner"></div></div></div>
<div id="snap-scroller" tabindex="0">
    <div class="snap-area"><div class="target" id="snap-inner"></div></div>
    <div class="snap-area"></div>
    <div class="snap-area"></div>
    <div class="snap-area"></div>
    <div class="snap-area"></div>
</div>
<div class="target" id="outer"></div>
<script>
    promiseTest(async () => {
        const frames = async () => {
            await animationFrame();
            await animationFrame();
        };
        const report = (label, scrollingBox, target) => {
            println(`${label}: offset=${scrollingBox.scrollTop}, scrolled=${getComputedStyle(target).getPropertyValue("--scrolled")}`);
        };

        await frames();

        // Home and End are absolute scrolls, so they keep the most recent relative scroll direction, even when they
        // scroll the other way.
        const step = async (label, target, scrollingBox, queryTarget, keys) => {
            const scrollendTarget = scrollingBox === document.documentElement ? document : scrollingBox;
            for (const key of keys)
                await scrollSettled(scrollendTarget, () => internals.sendKey(target, key));
            await frames();
            report(label, scrollingBox, queryTarget);
        };

        scroller.focus();
        await step("Scroller after End", scroller, scroller, inner, ["End"]);
        await step("Scroller after Up and End", scroller, scroller, inner, ["Up", "End"]);
        await step("Scroller after Home, Down and Home", scroller, scroller, inner, ["Home", "Down", "Home"]);

        const snapScroller = document.getElementById("snap-scroller");
        const snapInner = document.getElementById("snap-inner");
        snapScroller.focus();
        await step("Snap scroller after End", snapScroller, snapScroller, snapInner, ["End"]);
        await step("Snap scroller after Up and End", snapScroller, snapScroller, snapInner, ["Up", "End"]);
        await step("Snap scroller after Home, Down and Home", snapScroller, snapScroller, snapInner, ["Home", "Down", "Home"]);

        snapScroller.blur();
        const root = document.documentElement;
        await step("Viewport after End", document.body, root, outer, ["End"]);
        await step("Viewport after Up and End", document.body, root, outer, ["Up", "End"]);
        await step("Viewport after Home, Down and Home", document.body, root, outer, ["Home", "Down", "Home"]);
    });
</script>