Skip to content

Truly independent web browser

2.9 KB
Raw Blame
<!DOCTYPE html>
<meta charset="utf-8">
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<style>
    body {
        margin: 0;
    }

    #plain,
    #link {
        display: block;
        width: 100px;
        height: 20px;
    }

    a:hover {
        color: rgb(0, 128, 0);
    }

    #active-target {
        display: block;
        width: 80px;
        height: 40px;
        color: black;
    }

    #active-target:active {
        color: rgb(1, 2, 3);
    }

    #active-target:active + #active-sibling {
        color: rgb(4, 5, 6);
    }

    #active-container:active #active-ancestor-descendant {
        color: rgb(7, 8, 9);
    }
</style>
<div id="plain">plain text</div>
<a id="link" href="#">link text</a>
<div id="active-container">
    <button id="active-target">target</button>
    <div id="active-sibling">sibling</div>
    <div id="active-ancestor-descendant">ancestor descendant</div>
</div>
<script>
    function moveTo(element) {
        const rect = element.getBoundingClientRect();
        internals.mouseMove(rect.left + 5, rect.top + 5);
        internals.updateStyle();
    }

    function dumpWork(label, mutate) {
        const work = styleWork(mutate);
        const fullPass = work.passes().includes("FULL") ? " (full pass)" : "";
        println(`${label}: restyled [${work.restyled().map(shortStyleName).join(", ")}]${fullPass}`);
    }

    function appendUnaffectedSubtree(parent, count) {
        for (let i = 0; i < count; ++i) {
            let leaf = document.createElement("span");
            leaf.textContent = `leaf ${i}`;
            parent.appendChild(leaf);
        }
    }

    function clickAndHold(element) {
        const rect = element.getBoundingClientRect();
        internals.clickAndHold(Math.floor(rect.left + rect.width / 2), Math.floor(rect.top + rect.height / 2));
        internals.updateStyle();
    }

    test(() => {
        const plain = document.getElementById("plain");
        const link = document.getElementById("link");
        const activeContainer = document.getElementById("active-container");
        const activeTarget = document.getElementById("active-target");

        getComputedStyle(plain).color;
        dumpWork("plain text hover", () => moveTo(plain));

        dumpWork("link hover", () => moveTo(link));
        println(`link color: ${getComputedStyle(link).color}`);

        appendUnaffectedSubtree(activeContainer, 100);
        getComputedStyle(activeContainer).color;
        // The target, the two elements its :active rules reach and the link the pointer left, not the
        // 100 unaffected leaves.
        dumpWork("active state", () => clickAndHold(activeTarget));
        for (const id of ["active-target", "active-sibling", "active-ancestor-descendant"])
            println(`${id} color: ${getComputedStyle(document.getElementById(id)).color}`);
        internals.mouseUp(0, 0);
    });
</script>