Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Table row ordering 330 (#435)
Browse files Browse the repository at this point in the history
* whitespace tweaks

* Fix algorithm

Process the first `thead` and first `foot` elements, moving them to the
start and end of the table respectively. Process others as row groups
in the order they appear.
  • Loading branch information
chaals authored and Alex Danilo committed May 30, 2016
1 parent f60d126 commit 5c4635e
Showing 1 changed file with 93 additions and 40 deletions.
133 changes: 93 additions & 40 deletions sections/semantics-tabular-data.include
Original file line number Diff line number Diff line change
Expand Up @@ -1523,17 +1523,24 @@ the cell that corresponds to the values of the two dice.
model</dfn>.

A <dfn lt="table|tables">table</dfn> consists of cells aligned on a two-dimensional grid of
<dfn>slots</dfn> with coordinates (<var>x</var>, <var>y</var>). The grid is finite, and is either empty or has one or more slots. If the grid
has one or more slots, then the <var>x</var> coordinates are always in the range 0&nbsp;≤&nbsp;<var>x</var>&nbsp;&lt;&nbsp;<var>x<sub>width</sub></var>, and the <var>y</var> coordinates are always in the
range 0&nbsp;≤&nbsp;<var>y</var>&nbsp;&lt;&nbsp;<var>y<sub>height</sub></var>. If one or both of <var>x<sub>width</sub></var> and <var>y<sub>height</sub></var> are zero, then the
table is empty (has no slots). Tables correspond to <{table}> elements.

A <dfn lt="cell|cells">cell</dfn> is a set of slots anchored at a slot (<var>cell<sub>x</sub></var>, <var>cell<sub>y</sub></var>), and with
<dfn>slots</dfn> with coordinates (<var>x</var>, <var>y</var>). The grid is finite, and
is either empty or has one or more slots. If the grid has one or more slots, then
the <var>x</var> coordinates are always in the range
0&nbsp;≤&nbsp;<var>x</var>&nbsp;&lt;&nbsp;<var>x<sub>width</sub></var>,
and the <var>y</var> coordinates are always in the range
0&nbsp;≤&nbsp;<var>y</var>&nbsp;&lt;&nbsp;<var>y<sub>height</sub></var>.
If one or both of <var>x<sub>width</sub></var> and <var>y<sub>height</sub></var> are zero,
then the table is empty (has no slots). Tables correspond to <{table}> elements.

A <dfn lt="cell|cells">cell</dfn> is a set of slots anchored at a slot
(<var>cell<sub>x</sub></var>, <var>cell<sub>y</sub></var>), and with
a particular <var>width</var> and <var>height</var> such that the cell covers
all the slots with coordinates (<var>x</var>, <var>y</var>) where <var>cell<sub>x</sub></var>&nbsp;≤&nbsp;<var>x</var>&nbsp;&lt;&nbsp;<var>cell<sub>x</sub></var>+<var>width</var> and <var>cell<sub>y</sub></var>&nbsp;≤&nbsp;<var>y</var>&nbsp;&lt;&nbsp;<var>cell<sub>y</sub></var>+<var>height</var>. Cells can either be <em>data cells</em>
or <em>header cells</em>. Data cells correspond to <{td}> elements, and header cells
correspond to <{th}> elements. Cells of both types can have zero or more associated
header cells.
all the slots with coordinates (<var>x</var>, <var>y</var>) where
<var>cell<sub>x</sub></var>&nbsp;≤&nbsp;<var>x</var>&nbsp;&lt;&nbsp;<var>cell<sub>x</sub></var>+<var>width</var>
and <var>cell<sub>y</sub></var>&nbsp;≤&nbsp;<var>y</var>&nbsp;&lt;&nbsp;<var>cell<sub>y</sub></var>+<var>height</var>.
Cells can either be <em>data cells</em> or <em>header cells</em>. Data cells correspond
to <{td}> elements, and header cells correspond to <{th}> elements. Cells of both types
can have zero or more associated header cells.

It is possible, in certain error cases, for two cells to occupy the same slot.

Expand Down Expand Up @@ -1571,30 +1578,47 @@ the cell that corresponds to the values of the two dice.

<h5 id="forming-a-table">Forming a table</h5>

To determine which elements correspond to which slots in a <a>table</a> associated with a <{table}> element, to determine the
dimensions of the table (<var>x<sub>width</sub></var> and <var>y<sub>height</sub></var>), and to determine if there are any <a>table model errors</a>, user agents must use the following algorithm:
User agents must use the following algorithm to determine
<ul>
<li>which elements correspond to which slots in a <a>table</a> associated with a <{table}> element,</li>
<li>the dimensions of the table (<var>x<sub>width</sub></var> and <var>y<sub>height</sub></var>), and</li>
<li>if there are any <a>table model errors</a></li>.

<p class="note">The algorithm selects the first <{caption}> encountered and assigns it as
the <code>caption</code> for the table, and selects the first <{thead}> and processes it.
Until there is a <{thead}>, <{tfoot}>, <{tbody}> or <{tr}> element, it processes any
<{colgroup}> elements encountered, and any <{col}> children, to create column groups.
Finally, from the first <{thead}>, <{tfoot}>, <{tbody}> or <{tr}> element encountered
as a child of the <{table}> it processes those elements, moving the first <{tfoot}>
encountered to the end of the table respectively.</p>

<ol>

<li>

Let <var>x<sub>width</sub></var> be zero.
</li>

<li>

Let <var>y<sub>height</sub></var> be zero.
</li>

<li>

Let <var>pending <{tfoot}> elements</var> be a list of <code>tfoot</code>
elements, initially empty.
Let <var>table footer</var> be null.
</li>

<li>

Let <var>table header</var> be null.
</li>

<li>

Let <var>the table</var> be the <a>table</a> represented
by the <{table}> element. The <var>x<sub>width</sub></var> and <var>y<sub>height</sub></var> variables give <var>the table</var>'s
by the <{table}> element. The <var>x<sub>width</sub></var> and
<var>y<sub>height</sub></var> variables give <var>the table</var>'s
dimensions. <var>The table</var> is initially empty.

</li>
Expand Down Expand Up @@ -1627,7 +1651,8 @@ the cell that corresponds to the values of the two dice.

<li>

While the <var>current element</var> is not one of the following elements, <a>advance</a> the <var>current element</var> to the next
While the <var>current element</var> is not one of the following elements,
<a>advance</a> the <var>current element</var> to the next
child of the <code>table</code>:

<ul class="brief">
Expand Down Expand Up @@ -1655,7 +1680,6 @@ the cell that corresponds to the values of the two dice.
<dl class="switch">

<dt>If the <var>current element</var> has any <{col}> element children</dt>

<dd>

Follow these steps:
Expand Down Expand Up @@ -1823,31 +1847,61 @@ the cell that corresponds to the values of the two dice.

</li>

Run the <a>algorithm for processing row groups</a> for the first <{thead}> child of the <{table}>.

<li>

If the <var>current element</var> is a <{tfoot}> and the value of
<var>table footer</var> is null, then run the following substeps:

<ol>
<li>

let <var>table footer</var> be the current element;</li>
<li>

<a>advance</a> the <var>current element</var> to the next child of the <{table}>, and </li>
<li>

return to the step labeled <i>rows</i>.</li></ol>

</li>

<li>

If the <var>current element</var> is a <{tr}>, then run the <a>algorithm
for processing rows</a>, <a>advance</a> the <var>current element</var> to the next child of the <{table}>, and return to the
step labeled <i>rows</i>.
If the <var>current element</var> is a <{thead}> and the value of
<var>table header</var> is null, then run the following substeps:

<ol>
<li>

let <var>table header</var> be the current element;</li>
<li>

<a>advance</a> the <var>current element</var> to the next child of the <{table}>, and </li>
<li>

return to the step labeled <i>rows</i>.</li></ol>

</li>

<li>

Run the <a>algorithm for ending a row group</a>.
If the <var>current element</var> is a <{tr}> then run the <a>algorithm
for processing rows</a>, <a>advance</a> the <var>current element</var> to the next child
of the <{table}>, and return to the step labeled <i>rows</i>.

</li>

<li>

If the <var>current element</var> is a <{tfoot}>, then add that element to
the list of <var>pending <{tfoot}> elements</var>, <a>advance</a> the <var>current element</var> to the next
child of the <{table}>, and return to the step labeled <i>rows</i>.
Run the <a>algorithm for ending a row group</a>.

</li>

<li>

The <var>current element</var> is either a <code>thead</code> or a
The <var>current element</var> is either a <code>thead</code>, <{tfoot}>, or a
<{tbody}>.

Run the <a>algorithm for processing row groups</a>.
Expand All @@ -1869,16 +1923,14 @@ the cell that corresponds to the values of the two dice.

<li>

<i>End</i>: For each <{tfoot}> element in the list of <var>pending
<{tfoot}> elements</var>, in <a>tree order</a>, run the <a>algorithm for processing row
groups</a>.
<i>End</i>: run the <a>algorithm for processing row groups</a> to process <var>table footer</var>.

</li>

<li>

If there exists a <a>row</a> or <a>column</a> in <var>the table</var> containing only <a>slots</a> that do not have a <a>cell</a>
anchored to them, then this is a <a>table model error</a>.
If there exists a <a>row</a> or <a>column</a> in <var>the table</var> containing only <a>slots</a>
that do not have a <a>cell</a> anchored to them, then this is a <a>table model error</a>.

</li>

Expand Down Expand Up @@ -2224,8 +2276,7 @@ the cell that corresponds to the values of the two dice.

<li>

Remove all the <a>empty cells</a> from the <var>header
list</var>.
Remove all the <a>empty cells</a> from the <var>header list</var>.

</li>

Expand All @@ -2244,8 +2295,7 @@ the cell that corresponds to the values of the two dice.

<li>

Assign the headers in the <var>header list</var> to the <var>principal
cell</var>.
Assign the headers in the <var>header list</var> to the <var>principal cell</var>.

</li>

Expand Down Expand Up @@ -2337,8 +2387,7 @@ the cell that corresponds to the values of the two dice.

<li>Set <var>in header block</var> to true.</li>

<li>Add <var>current cell</var> to <var>headers from current header
block</var>.</li>
<li>Add <var>current cell</var> to <var>headers from current header block</var>.</li>

<li>Let <var>blocked</var> be false.</li>

Expand Down Expand Up @@ -2401,26 +2450,30 @@ the cell that corresponds to the values of the two dice.

</ol>

A header cell anchored at the slot with coordinate (<var>x</var>, <var>y</var>) with width <var>width</var> and height <var>height</var> is
A header cell anchored at the slot with coordinate (<var>x</var>, <var>y</var>)
with width <var>width</var> and height <var>height</var> is
said to be a <dfn>column header</dfn> if any of the following conditions are true:

<ul>

<li>The cell's <{td/scope}> attribute is in the <a state for="scope">column</a> state, or</li>

<li>The cell's <{td/scope}> attribute is in the <a state for="scope">auto</a> state, and there are no data cells in any of the cells
<li>The cell's <{td/scope}> attribute is in the <a state for="scope">auto</a> state,
and there are no data cells in any of the cells
covering slots with <var>y</var>-coordinates <var>y</var> .. <var>y</var>+<var>height</var>-1.</li>

</ul>

A header cell anchored at the slot with coordinate (<var>x</var>, <var>y</var>) with width <var>width</var> and height <var>height</var> is
A header cell anchored at the slot with coordinate (<var>x</var>, <var>y</var>)
with width <var>width</var> and height <var>height</var> is
said to be a <dfn>row header</dfn> if any of the following conditions are true:

<ul>

<li>The cell's <{td/scope}> attribute is in the <a state for="scope">row</a> state, or</li>

<li>The cell's <{td/scope}> attribute is in the <a state for="scope">auto</a> state, the cell is not a <a>column header</a>, and
<li>The cell's <{td/scope}> attribute is in the <a state for="scope">auto</a> state,
the cell is not a <a>column header</a>, and
there are no data cells in any of the cells covering slots with <var>x</var>-coordinates
<var>x</var> .. <var>x</var>+<var>width</var>-1.</li>

Expand Down

0 comments on commit 5c4635e

Please sign in to comment.