| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 
 | <!doctype html>
<meta charset="utf-8">
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<link rel='stylesheet' href='support/base.css' />
<link rel="author" title="Joy Yu" href="mailto:joysyu@mit.edu">
<link rel="help" href="https://drafts.csswg.org/css-tables-3/#visibility-collapse-cell-rendering">
<style>
table {
    border-spacing: 0;
    border-collapse: collapse;
}
table td {
    border: 1px solid blue;
    padding: 5px;
}
</style>
<main>
    <h1>Visibility collapse</h1>
    <a href="https://drafts.csswg.org/css-tables-3/#visibility-collapse-cell-rendering">Spec</a>
    <p>
    Setting a row to visibility:collapse changes table height but not width.
    </p>
    <table id="one">
        <tr id="firstRowRef">
            <td rowspan="5" id="spanningCellRef">B<br>B<br>B<br>B<br>B</td>
            <td>first row</td>
        </tr>
        <tr id="secondRowRef">
            <td>aaaa</td>
        </tr>
        <tr>
            <td>bbbb</td>
        </tr>
        <tr id="fourthRowRef">
            <td>cccc</td>
        </tr>
        <tr id="fifthRowRef">
            <td>dddd</td>
        </tr>
    </table>
    In the bottom table, a row is dynamically collapsed, made visible, and collapsed again.
    <table id="two">
        <tr id="firstRow">
            <td rowspan="5" id="spanningCell">B<br>B<br>B<br>B<br>B</td>
            <td>first row</td>
        </tr>
        <tr id="secondRow">
            <td>aaaa</td>
        </tr>
        <tr id="thirdRow">
            <td>bbbb</td>
        </tr>
        <tr id="fourthRow">
            <td>cccc</td>
        </tr>
        <tr id="fifthRow">
            <td>dddd</td>
        </tr>
    </table>
</main>
<script>
    function runTests() {
        for (i = 0; i< tests.length; i++) {
            test(function()
                {
                    assert_equals.apply(this, tests[i]);
                },
                tests[i][2]);
        };
    }
    function width(element) {
        return element.getBoundingClientRect().width;
    }
    function height(element) {
        return element.getBoundingClientRect().height;
    }
    document.getElementById("thirdRow").style.visibility = "collapse";
    tests = [
        [
            width(document.getElementById('two')),
            width(document.getElementById('one')),
            "spanning row visibility:collapse doesn't change table width"
        ],
        [
            height(document.getElementById('firstRow')),
            height(document.getElementById('firstRowRef')),
            "when third row is collapsed, first row stays the same height"
        ],
        [
            height(document.getElementById('secondRow')),
            height(document.getElementById('secondRowRef')),
            "when third row is collapsed, second row stays the same height"
        ],
        [
            height(document.getElementById('thirdRow')),
            0,
            "third row visibility:collapse makes row height 0"
        ],
        [
            height(document.getElementById('fourthRow')),
            height(document.getElementById('fourthRowRef')),
            "when third row is collapsed, fourth row stays the same height"
        ],
        [
            height(document.getElementById('spanningCell')),
            height(document.getElementById('firstRow')) +
            height(document.getElementById('secondRow')) +
            height(document.getElementById('fourthRow')) +
            height(document.getElementById('fifthRow')),
            "spanning cell shrinks to sum of remaining three rows' height"
        ]];
    runTests();
    document.getElementById("thirdRow").style.visibility = "visible";
    tests = [
        [
            height(document.getElementById('firstRow')),
            height(document.getElementById('firstRowRef')),
            "when third row is visible, first row stays the same height"
        ],
        [
            height(document.getElementById('secondRow')),
            height(document.getElementById('secondRowRef')),
            "when third row is visible, second row stays the same height"
        ],
        [
            height(document.getElementById('thirdRow')),
            height(document.getElementById('secondRowRef')),
            "when third row is visible, third row stays the same height"
        ],
        [
            height(document.getElementById('fourthRow')),
            height(document.getElementById('fourthRowRef')),
            "when third row is visible, fourth row stays the same height"
        ],
        [
            height(document.getElementById('fifthRow')),
            height(document.getElementById('fifthRowRef')),
            "when third row is visible, fifth row stays the same height"
        ],
        [
            height(document.getElementById('spanningCell')),
            height(document.getElementById('spanningCellRef')),
            "when third row is visible, spanning cell stays the same height"
        ]];
    runTests();
    document.getElementById("thirdRow").style.visibility = "collapse";
    tests = [
        [
            width(document.getElementById('two')),
            width(document.getElementById('one')),
            "(2nd collapse) spanning row visibility:collapse doesn't change table width"
        ],
        [
            height(document.getElementById('firstRow')),
            height(document.getElementById('firstRowRef')),
            "when third row is collapsed again, first row stays the same height"
        ],
        [
            height(document.getElementById('secondRow')),
            height(document.getElementById('secondRowRef')),
            "when third row is collapsed again, second row stays the same height"
        ],
        [
            height(document.getElementById('thirdRow')),
            0,
            "(2nd collapse) third row visibility:collapse makes row height 0"
        ],
        [
            height(document.getElementById('fourthRow')),
            height(document.getElementById('fourthRowRef')),
            "when third row is collapsed again, fourth row stays the same height"
        ],
        [
            height(document.getElementById('spanningCell')),
            height(document.getElementById('firstRow')) +
            height(document.getElementById('secondRow')) +
            height(document.getElementById('fourthRow')) +
            height(document.getElementById('fifthRow')),
            "(2nd collapse) spanning cell shrinks to sum of remaining three rows' height"
        ]];
    runTests();
</script>
</html>
 |