Skip to content

Truly independent web browser

2.6 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
    #target {
        width: 100px;
        height: 10px;
    }
    #target.paint-only {
        background-color: red;
    }
    #target.paint-only-next {
        background-color: blue;
    }
    #target.layout {
        width: 200px;
        height: 20px;
    }
    #target.transformed {
        transform: translateX(10px);
    }
</style>
<div id="target"></div>
<script>
    function styleUpdates() {
        return `[${internals.takeRenderingTrace().split("\n").filter(line => line.startsWith("style stabilization epoch")).join(", ")}]`;
    }

    test(() => {
        target.getBoundingClientRect();

        target.style.outlineColor = "blue";
        getComputedStyle(target).outlineColor;

        internals.beginRenderingTrace();
        target.className = "paint-only";
        const paintOnlyRect = target.getBoundingClientRect();
        const paintOnlyOffsetWidth = target.offsetWidth;
        const paintOnlyClientHeight = target.clientHeight;
        const paintOnlyStyleUpdates = styleUpdates();
        println(`paint-only geometry: ${paintOnlyRect.width}`);
        println(`paint-only offset width: ${paintOnlyOffsetWidth}`);
        println(`paint-only client height: ${paintOnlyClientHeight}`);
        println(`paint-only style updates after inline style setup: ${paintOnlyStyleUpdates}`);
        println(`deferred style is observable: ${getComputedStyle(target).backgroundColor}`);

        target.className = "";
        target.getBoundingClientRect();
        internals.beginRenderingTrace();
        target.className = "layout";
        const layoutOffsetWidth = target.offsetWidth;
        const layoutOffsetHeight = target.offsetHeight;
        const layoutStyleUpdates = styleUpdates();
        println(`layout offset size: ${layoutOffsetWidth}x${layoutOffsetHeight}`);
        println(`layout style updates: ${layoutStyleUpdates}`);

        target.className = "";
        target.getBoundingClientRect();
        internals.beginRenderingTrace();
        target.className = "transformed";
        const transformedRect = target.getBoundingClientRect();
        const transformedStyleUpdates = styleUpdates();
        println(`transformed geometry: ${transformedRect.x}`);
        println(`visual geometry style updates: ${transformedStyleUpdates}`);

        target.className = "";
        target.getBoundingClientRect();
        target.className = "paint-only";
        target.getBoundingClientRect();
        target.className = "paint-only-next";
        internals.updateStyle();
        println(`merged deferred style is observable: ${getComputedStyle(target).backgroundColor}`);
    });
</script>