Skip to content

Truly independent web browser

2.3 KB
Raw Blame
<!DOCTYPE html>
<script src="include.js"></script>
<script src="work-test.js"></script>
<style>
    body { margin: 0; }
    table { border-collapse: collapse; width: 400px; }
    td { padding: 0 4px; font: 12px monospace; vertical-align: middle; }
    td.num { width: 1%; position: relative; }
    .marker { position: absolute; left: 0; top: 0; width: 8px; height: 8px; background: green; }
</style>
<table id="table"><tbody id="rows"></tbody></table>
<script>
    test(() => {
        const ROWS = 40;
        const parts = [];
        for (let i = 0; i < ROWS; ++i)
            parts.push(`<tr><td class="num" id="r${i}c0">${i}</td><td class="num" id="r${i}c1">${i}</td><td id="r${i}c2">line ${i} with <span>some</span> <b>markup</b></td></tr>`);
        const missedCells = work => {
            const tableRun = work.events.find(event => event.event === "run" && event.box === "Box<TABLE>#table");
            return work.events.filter(event => tableRun && event.depth === tableRun.depth + 1 && event.event === "run" && event.action === "RUN");
        };

        const lines = [];
        let work = layoutWork(() => document.getElementById("rows").innerHTML = parts.join(""));
        const cells = document.querySelectorAll("td");
        const table = document.getElementById("table");
        lines.push(`cells: ${cells.length}`);
        lines.push(`misses during the initial layout: ${missedCells(work).length}`);

        work = layoutWork(() => table.style.marginTop = "10px");
        lines.push(`misses after restyling the table: ${missedCells(work).length}`);

        const heightBefore = table.getBoundingClientRect().height;
        const marker = document.createElement("span");
        marker.className = "marker";
        work = layoutWork(() => cells[3].appendChild(marker));
        lines.push(`misses after inserting an abspos marker into one cell: ${missedCells(work).length}`);
        lines.push(`table height unchanged by the marker: ${table.getBoundingClientRect().height === heightBefore}`);

        // The cell that took the marker is measured again too, with this next layout of the table.
        work = layoutWork(() => cells[8].firstChild.data = "changed");
        lines.push(`misses after changing the text of another cell: ${missedCells(work).map(event => event.box).join(", ")}`);

        for (const line of lines)
            println(line);
    });
</script>