Skip to content

Truly independent web browser

2.5 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script src="../../work-test.js"></script>
<script src="structural-matrix.js"></script>
<style>
    #hidden { display: none }
    #plain.changed { background-color: blue }
    #inheriting.changed { margin-left: 27px }
    #inheriting > span { margin-left: inherit }
    #color-source.changed { color: blue }
</style>
<div id="hidden">
    <div id="plain"><span></span><span></span><span></span></div>
    <div id="inheriting"><span></span><span></span><span></span></div>
    <div id="color-source"><span></span><span></span><span></span></div>
</div>
<script>
    test(() => {
        internals.updateStyle();

        // A computed style read under a display:none subtree recomputes the element's inheritance
        // chain instead of running the document traversal, and what it leaves marked is what the
        // next flush has to recompute. The rule is the one the traversal applies: a change confined
        // to non-inherited properties has nothing a child can read, so it marks no child. `inherit`
        // on a non-inherited property is the one way a child reaches past that.
        //
        // FIXME: The read after a non-inherited change should style only the element. The style engine
        //        styles its three children with it, so they are named.
        const measure = (id, label, read) => {
            const element = document.getElementById(id);
            getComputedStyle(element).color;
            const work = styleWork(
                () => {
                    element.classList.add("changed");
                    getComputedStyle(element).color;
                },
                internals,
                { flush: false }
            );
            printPassWithStyleWork(label, work);
            println(`${read.name}: ${read.value(element)}`);
        };

        const firstChildStyle = element => getComputedStyle(element.firstElementChild);
        measure("plain", "a read after a non-inherited change marks no child",
            { name: "background-color", value: element => getComputedStyle(element).backgroundColor });
        measure("inheriting", "a read marks a child explicitly inheriting a non-inherited property",
            { name: "explicitly inherited margin-left", value: element => firstChildStyle(element).marginLeft });
        measure("color-source", "a read after an inherited change marks every child",
            { name: "inherited color", value: element => firstChildStyle(element).color });
    });
</script>