Annotation of html5/spec/interactive-elements.html, revision 1.1004

1.866     mike        1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
1.885     mike        2: <!DOCTYPE html>
1.987     mike        3: <!-- when publishing, change bits marked ZZZ --><html lang="en-US-x-Hixie" class="split chapter"><head><title>4.11 Interactive elements &#8212; HTML5 </title><style type="text/css">
1.1       mike        4:    pre { margin-left: 2em; white-space: pre-wrap; }
                      5:    h2 { margin: 3em 0 1em 0; }
                      6:    h3 { margin: 2.5em 0 1em 0; }
                      7:    h4 { margin: 2.5em 0 0.75em 0; }
                      8:    h5, h6 { margin: 2.5em 0 1em; }
                      9:    h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
                     10:    h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
                     11:    p { margin: 1em 0; }
                     12:    hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
                     13:    dl, dd { margin-top: 0; margin-bottom: 0; }
                     14:    dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
                     15:    dt + dt { margin-top: 0; }
                     16:    dd dt { margin-top: 0.25em; margin-bottom: 0; }
                     17:    dd p { margin-top: 0; }
                     18:    dd dl + p { margin-top: 1em; }
                     19:    dd table + p { margin-top: 1em; }
                     20:    p + * > li, dd li { margin: 1em 0; }
                     21:    dt, dfn { font-weight: bold; font-style: normal; }
                     22:    dt dfn { font-style: italic; }
                     23:    pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
                     24:    pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
                     25:    pre em { font-weight: bolder; font-style: normal; }
                     26:    @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
                     27:    var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
                     28:    table { border-collapse: collapse; border-style: hidden hidden none hidden; }
1.974     mike       29:    table thead, table tbody { border-bottom: solid; }
1.1       mike       30:    table tbody th:first-child { border-left: solid; }
1.469     mike       31:    table tbody th { text-align: left; }
1.1       mike       32:    table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
                     33:    blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
                     34: 
                     35:    .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
                     36:    .matrix, .matrix td { border: none; text-align: right; }
                     37:    .matrix { margin-left: 2em; }
                     38:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                     39:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                     40:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                     41: 
                     42:    .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
                     43:    img.extra { float: right; }
                     44:    pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
                     45:    pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
                     46:    pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
                     47:    pre.css:first-line { color: #AAAA50; }
1.834     mike       48:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
1.1       mike       49:    hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
                     50:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     51:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     52:    dl.domintro dd p { margin: 0.5em 0; }
                     53:    dl.switch { padding-left: 2em; }
                     54:    dl.switch > dt { text-indent: -1.5em; }
                     55:    dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
                     56:    dl.triple { padding: 0 0 0 1em; }
                     57:    dl.triple dt, dl.triple dd { margin: 0; display: inline }
                     58:    dl.triple dt:after { content: ':'; }
                     59:    dl.triple dd:after { content: '\A'; white-space: pre; }
                     60:    .diff-old { text-decoration: line-through; color: silver; background: transparent; }
                     61:    .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
                     62:    a .diff-new { border-bottom: 1px blue solid; }
                     63: 
                     64:    h2 { page-break-before: always; }
                     65:    h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
                     66:    h1 + h2, hr + h2.no-toc { page-break-before: auto; }
                     67: 
                     68:    p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }
                     69: 
                     70:    div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
                     71:    div.head p { margin: 0; }
                     72:    div.head h1 { margin: 0; }
                     73:    div.head .logo { float: right; margin: 0 1em; }
                     74:    div.head .logo img { border: none } /* remove border from top image */
                     75:    div.head dl { margin: 1em 0; }
1.665     mike       76:    div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
1.1       mike       77: 
                     78:    body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
                     79:    body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
                     80:    body > .toc > li > * { margin-bottom: 0.5em; }
                     81:    body > .toc > li > * > li > * { margin-bottom: 0.25em; }
                     82:    .toc, .toc li { list-style: none; }
                     83: 
                     84:    .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
                     85:    .brief li { margin: 0; padding: 0; }
                     86:    .brief li p { margin: 0; padding: 0; }
                     87: 
                     88:    .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
                     89:    .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
                     90:    .category-list li { display: inline; }
                     91:    .category-list li:not(:last-child)::after { content: ', '; }
                     92:    .category-list li > span, .category-list li > a { text-transform: lowercase; }
                     93:    .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
                     94: 
                     95:    .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
                     96:    .XXX > :first-child { margin-top: 0; }
                     97:    p .XXX { line-height: 3em; }
1.153     mike       98:    .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
                     99:    .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
                    100:    .annotation :link, .annotation :visited { color: inherit; }
                    101:    .annotation :link:hover, .annotation :visited:hover { background: transparent; }
                    102:    .annotation span { border: none ! important; }
1.1       mike      103:    .note { color: green; background: transparent; font-family: sans-serif; }
                    104:    .warning { color: red; background: transparent; }
                    105:    .note, .warning { font-weight: bolder; font-style: italic; }
                    106:    p.note, div.note { padding: 0.5em 2em; }
                    107:    span.note { padding: 0 2em; }
                    108:    .note p:first-child, .warning p:first-child { margin-top: 0; }
                    109:    .note p:last-child, .warning p:last-child { margin-bottom: 0; }
                    110:    .warning:before { font-style: normal; }
                    111:    p.note:before { content: 'Note: '; }
                    112:    p.warning:before { content: '\26A0 Warning! '; }
                    113: 
                    114:    .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
                    115:    .bookkeeping { font-size: 0.8em; margin: 2em 0; }
                    116:    .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
1.996     mike      117:    .bookkeeping dt { margin: 0.5em 2em 0; }
                    118:    .bookkeeping dd { margin: 0 3em 0.5em; }
1.1       mike      119: 
                    120:    h4 { position: relative; z-index: 3; }
                    121:    h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
                    122:    .element {
                    123:      background: #EEEEFF;
                    124:      color: black;
                    125:      margin: 0 0 1em 0.15em;
                    126:      padding: 0 1em 0.25em 0.75em;
                    127:      border-left: solid #9999FF 0.25em;
                    128:      position: relative;
                    129:      z-index: 1;
                    130:    }
                    131:    .element:before {
                    132:      position: absolute;
                    133:      z-index: 2;
                    134:      top: 0;
                    135:      left: -1.15em;
                    136:      height: 2em;
                    137:      width: 0.9em;
                    138:      background: #EEEEFF;
                    139:      content: ' ';
                    140:      border-style: none none solid solid;
                    141:      border-color: #9999FF;
                    142:      border-width: 0.25em;
                    143:    }
                    144: 
1.143     mike      145:    .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
                    146:    td > .example:only-child { margin: 0 0 0 0.1em; }
1.1       mike      147: 
                    148:    ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
                    149:    ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
                    150:    ul.domTree li li { list-style: none; }
                    151:    ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    152:    ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
                    153:    ul.domTree span { font-style: italic; font-family: serif; }
                    154:    ul.domTree .t1 code { color: purple; font-weight: bold; }
                    155:    ul.domTree .t2 { font-style: normal; font-family: monospace; }
                    156:    ul.domTree .t2 .name { color: black; font-weight: bold; }
                    157:    ul.domTree .t2 .value { color: blue; font-weight: normal; }
                    158:    ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
                    159:    ul.domTree .t7 code, .domTree .t8 code { color: green; }
                    160:    ul.domTree .t10 code { color: teal; }
                    161: 
1.730     mike      162:    body.dfnEnabled dfn { cursor: pointer; }
                    163:    .dfnPanel {
                    164:      display: inline;
                    165:      position: absolute;
                    166:      z-index: 10;
                    167:      height: auto;
                    168:      width: auto;
                    169:      padding: 0.5em 0.75em;
                    170:      font: small sans-serif, Droid Sans Fallback;
                    171:      background: #DDDDDD;
                    172:      color: black;
                    173:      border: outset 0.2em;
                    174:    }
                    175:    .dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
                    176:    .dfnPanel :link, .dfnPanel :visited { color: black; }
                    177:    .dfnPanel p { font-weight: bolder; }
                    178:    .dfnPanel * + p { margin-top: 0.25em; }
                    179:    .dfnPanel li { list-style-position: inside; }
                    180: 
1.665     mike      181:    #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
                    182:    #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
                    183:    #configUI p label { display: block; }
                    184:    #configUI #updateUI, #configUI .loginUI { text-align: center; }
                    185:    #configUI input[type=button] { display: block; margin: auto; }
1.995     mike      186: 
1.261     mike      187:   </style><style type="text/css">
                    188: 
1.286     mike      189:    .applies thead th > * { display: block; }
                    190:    .applies thead code { display: block; }
                    191:    .applies tbody th { whitespace: nowrap; }
                    192:    .applies td { text-align: center; }
                    193:    .applies .yes { background: yellow; }
                    194: 
1.997     mike      195:    .matrix, .matrix td { border: hidden; text-align: right; }
1.261     mike      196:    .matrix { margin-left: 2em; }
                    197: 
                    198:    .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
                    199:    .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
                    200:    .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
                    201: 
1.1003    mike      202:    td.eg { border-width: thin; text-align: center; }
                    203: 
1.261     mike      204:    #table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
                    205:    #table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
                    206:    #table-example-1 caption { padding-bottom: 0.5em; }
                    207:    #table-example-1 thead, #table-example-1 tbody { border: none; }
                    208:    #table-example-1 th, #table-example-1 td { border: solid thin; }
                    209:    #table-example-1 th { font-weight: normal; }
                    210:    #table-example-1 td { border-style: none solid; vertical-align: top; }
                    211:    #table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
                    212:    #table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
                    213:    #table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
                    214:    #table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
                    215:    #table-example-1 tbody td:first-child::after { content: leader(". "); }
                    216:    #table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
                    217:    #table-example-1 tbody td:first-child + td { width: 10em; }
                    218:    #table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
                    219:    #table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
                    220: 
                    221:    .apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
                    222:    .apple-table-examples * { font-family: "Times", serif; }
                    223:    .apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
                    224:    .apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
                    225:    .apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
                    226:    .apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
                    227:    .apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
                    228:    .apple-table-examples td { text-align: right; vertical-align: top; }
                    229:    .apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
                    230:    .apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
                    231:    .apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
                    232:    .apple-table-examples sup { line-height: 0; }
                    233: 
1.718     mike      234:    .details-example img { vertical-align: top; }
                    235: 
1.875     mike      236:    #named-character-references-table {
                    237:      font-size: 0.6em;
                    238:      column-width: 28em;
                    239:      column-gap: 1em;
                    240:      -moz-column-width: 28em;
                    241:      -moz-column-gap: 1em;
                    242:      -webkit-column-width: 28em;
                    243:      -webkit-column-gap: 1em;
                    244:    }
                    245:    #named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
                    246:    #named-character-references-table > table > tbody > tr > td:last-child:hover > span { position: absolute; top: auto; left: auto; margin-left: 0.5em; line-height: 1.2; font-size: 5em; border: outset; padding: 0.25em 0.5em; background: white; width: 1.25em; height: auto; text-align: center; }
                    247: 
1.988     mike      248:    .glyph.control { color: red; }
                    249: 
1.990     mike      250:    @font-face {
                    251:      font-family: 'Essays1743';
                    252:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
                    253:    }
                    254:    @font-face {
                    255:      font-family: 'Essays1743';
                    256:      font-weight: bold;
                    257:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
                    258:    }
                    259:    @font-face {
                    260:      font-family: 'Essays1743';
                    261:      font-style: italic;
                    262:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
                    263:    }
                    264:    @font-face {
                    265:      font-family: 'Essays1743';
                    266:      font-style: italic;
                    267:      font-weight: bold;
                    268:      src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
                    269:    }
                    270: 
1.866     mike      271:   </style><style type="text/css">
1.874     mike      272:    .domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
                    273:   </style><link href="data:text/css," id="complete" rel="stylesheet" title="Complete specification"><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D%0Ahtml%20%7B%20border:%20solid%20yellow;%20%7D%20.domintro:before%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D%20.domintro:before%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation requirements"><script type="text/javascript">
1.665     mike      274:    function getCookie(name) {
                    275:      var params = location.search.substr(1).split("&");
                    276:      for (var index = 0; index < params.length; index++) {
                    277:        if (params[index] == name)
                    278:          return "1";
                    279:        var data = params[index].split("=");
                    280:        if (data[0] == name)
                    281:          return unescape(data[1]);
                    282:      }
                    283:      var cookies = document.cookie.split("; ");
                    284:      for (var index = 0; index < cookies.length; index++) {
                    285:        var data = cookies[index].split("=");
                    286:        if (data[0] == name)
                    287:          return unescape(data[1]);
                    288:      }
                    289:      return null;
                    290:    }
                    291:    function load(script) {
                    292:      var e = document.createElement('script');
                    293:      e.setAttribute('src', 'http://www.whatwg.org/specs/web-apps/current-work/' + script + '?' + encodeURIComponent(location) + '&' + encodeURIComponent(document.referrer));
                    294:      document.body.appendChild(e);
                    295:    }
                    296:    function init() {
                    297:      if (location.search == '?slow-browser')
                    298:        return;
                    299:      var configUI = document.createElement('div');
                    300:      configUI.id = 'configUI';
                    301:      document.body.appendChild(configUI);
                    302:      // load('reviewer.js'); // would need cross-site XHR
                    303:      if (document.getElementById('head'))
                    304:        load('toc.js');
                    305:      load('styler.js');
                    306:      // load('updater.js'); // would need cross-site XHR
1.718     mike      307:      load('dfn.js'); // doesn't support split-out specs, but, oh well.
1.665     mike      308:      // load('status.js'); // would need cross-site XHR
                    309:      if (getCookie('profile') == '1')
                    310:        document.getElementsByTagName('h2')[0].textContent += '; load: ' + (new Date() - loadTimer) + 'ms';
                    311:      fixBrokenLink();
                    312:    }
1.993     mike      313:   </script><link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet" type="text/css">
1.987     mike      314:   <script src="link-fixup.js"></script>
                    315:   <link href="association-of-controls-and-forms.html" title="4.10.18 Association of controls and forms" rel="prev">
1.2       mike      316:   <link href="spec.html#contents" title="Table of contents" rel="index">
1.987     mike      317:   <link href="commands.html" title="4.11.5 Commands" rel="next">
1.665     mike      318:   </head><body onload="fixBrokenLink(); init()"><div class="head" id="head">
1.1       mike      319:    <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
1.989     mike      320: 
1.177     mike      321:    <h1>HTML5</h1>
1.868     mike      322:    </div><div>
1.987     mike      323:    <a href="association-of-controls-and-forms.html">&#8592; 4.10.18 Association of controls and forms</a> &#8211;
1.2       mike      324:    <a href="spec.html#contents">Table of contents</a> &#8211;
1.987     mike      325:    <a href="commands.html">4.11.5 Commands &#8594;</a>
                    326:   <ol class="toc"><li><ol><li><a href="interactive-elements.html#interactive-elements"><span class="secno">4.11 </span>Interactive elements</a>
                    327:     <ol><li><a href="interactive-elements.html#the-details-element"><span class="secno">4.11.1 </span>The <code>details</code> element</a></li><li><a href="interactive-elements.html#the-summary-element"><span class="secno">4.11.2 </span>The <code>summary</code> element</a></li><li><a href="interactive-elements.html#the-command"><span class="secno">4.11.3 </span>The <code>command</code> element</a></li><li><a href="interactive-elements.html#menus"><span class="secno">4.11.4 </span>The <code>menu</code> element</a>
                    328:       <ol><li><a href="interactive-elements.html#menus-intro"><span class="secno">4.11.4.1 </span>Introduction</a></li><li><a href="interactive-elements.html#building-menus-and-toolbars"><span class="secno">4.11.4.2 </span>Building menus and toolbars</a></li><li><a href="interactive-elements.html#context-menus"><span class="secno">4.11.4.3 </span>Context menus</a></li><li><a href="interactive-elements.html#toolbars"><span class="secno">4.11.4.4 </span>Toolbars</a></li></ol></li></ol></li></ol></li></ol></div>
1.1       mike      329: 
1.1001    mike      330:   <h3 id="interactive-elements"><span class="secno">4.11 </span>Interactive elements</h3><h4 id="the-details-element"><span class="secno">4.11.1 </span>The <dfn><code>details</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
1.987     mike      331:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                    332:    <dd><a href="sections.html#sectioning-root">Sectioning root</a>.</dd>
                    333:    <dd><a href="content-models.html#interactive-content">Interactive content</a>.</dd>
1.1002    mike      334:    <dt>Contexts in which this element can be used:</dt>
1.987     mike      335:    <dd>Where <a href="content-models.html#flow-content">flow content</a> is expected.</dd>
1.1       mike      336:    <dt>Content model:</dt>
1.987     mike      337:    <dd>One <code><a href="#the-summary-element">summary</a></code> element followed by <a href="content-models.html#flow-content">flow content</a>.</dd>
1.1       mike      338:    <dt>Content attributes:</dt>
1.987     mike      339:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
1.1       mike      340:    <dd><code title="attr-details-open"><a href="#attr-details-open">open</a></code></dd>
                    341:    <dt>DOM interface:</dt>
                    342:    <dd>
1.987     mike      343: <pre class="idl">interface <dfn id="htmldetailselement">HTMLDetailsElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
1.1       mike      344:            attribute boolean <a href="#dom-details-open" title="dom-details-open">open</a>;
                    345: };</pre>
                    346:    </dd>
1.987     mike      347:   </dl><p>The <code><a href="#the-details-element">details</a></code> element <a href="rendering.html#represents">represents</a> a
1.307     mike      348:   disclosure widget from which the user can obtain additional
                    349:   information or controls.</p><p class="note">The <code><a href="#the-details-element">details</a></code> element is not appropriate
1.987     mike      350:   for footnotes. Please see <a href="links.html#footnotes">the section on
1.729     mike      351:   footnotes</a> for details on how to mark up footnotes.</p><p>The <span class="impl">first</span> <code><a href="#the-summary-element">summary</a></code> element
1.987     mike      352:   child of the element, if any, <a href="rendering.html#represents">represents</a> the summary or
1.729     mike      353:   legend of the details. <span class="impl">If there is no child
                    354:   <code><a href="#the-summary-element">summary</a></code> element, the user agent should provide its own
                    355:   legend (e.g. "Details").</span></p><p>The <dfn id="attr-details-open" title="attr-details-open"><code>open</code></dfn>
1.987     mike      356:   content attribute is a <a href="common-microsyntaxes.html#boolean-attribute">boolean attribute</a>. If present,
1.1       mike      357:   it indicates that the details are to be shown to the user. If the
1.117     mike      358:   attribute is absent, the details are not to be shown.</p><div class="impl">
1.1       mike      359: 
                    360:   <p>If the attribute is removed, then the details should be
                    361:   hidden. If the attribute is added, the details should be shown.</p>
                    362: 
                    363:   <p>The user agent should allow the user to request that the details
                    364:   be shown or hidden. To honor a request for the details to be shown,
                    365:   the user agent must set the <code title="attr-details-open"><a href="#attr-details-open">open</a></code> attribute on the element to
                    366:   the value <code title="">open</code>. To honor a request for the
                    367:   details to be hidden, the user agent must remove the <code title="attr-details-open"><a href="#attr-details-open">open</a></code> attribute from the
                    368:   element.</p>
                    369: 
                    370:   <p>The <dfn id="dom-details-open" title="dom-details-open"><code>open</code></dfn>
1.987     mike      371:   attribute must <a href="common-dom-interfaces.html#reflect">reflect</a> the <code title="attr-details-open"><a href="#attr-details-open">open</a></code> content attribute.</p>
1.1       mike      372: 
1.271     mike      373:   </div><div class="example">
                    374: 
                    375:    <p>The following example shows the <code><a href="#the-details-element">details</a></code> element
                    376:    being used to hide technical details in a progress report.</p>
                    377: 
                    378:    <pre>&lt;section class="progress window"&gt;
                    379:  &lt;h1&gt;Copying "Really Achieving Your Childhood Dreams"&lt;/h1&gt;
                    380:  &lt;details&gt;
1.876     mike      381:   &lt;summary&gt;Copying... &lt;progress max="375505392" value="97543282"&gt;&lt;/progress&gt; 25%&lt;/summary&gt;
1.729     mike      382:   &lt;dl&gt;
                    383:    &lt;dt&gt;Transfer rate:&lt;/dt&gt; &lt;dd&gt;452KB/s&lt;/dd&gt;
                    384:    &lt;dt&gt;Local filename:&lt;/dt&gt; &lt;dd&gt;/home/rpausch/raycd.m4v&lt;/dd&gt;
                    385:    &lt;dt&gt;Remote filename:&lt;/dt&gt; &lt;dd&gt;/var/www/lectures/raycd.m4v&lt;/dd&gt;
                    386:    &lt;dt&gt;Duration:&lt;/dt&gt; &lt;dd&gt;01:16:27&lt;/dd&gt;
                    387:    &lt;dt&gt;Color profile:&lt;/dt&gt; &lt;dd&gt;SD (6-1-6)&lt;/dd&gt;
                    388:    &lt;dt&gt;Dimensions:&lt;/dt&gt; &lt;dd&gt;320&#215;240&lt;/dd&gt;
                    389:   &lt;/dl&gt;
1.271     mike      390:  &lt;/details&gt;
                    391: &lt;/section&gt;</pre>
                    392: 
1.718     mike      393:   </div><div class="example">
                    394: 
                    395:    <p>The following shows how a <code><a href="#the-details-element">details</a></code> element can be
                    396:    used to hide some controls by default:</p>
                    397: 
                    398:    <pre>&lt;details&gt;
1.1004  ! mike      399:  &lt;summary&gt;&lt;label for=fn&gt;Name &amp; Extension:&lt;/label&gt;&lt;/summary&gt;
        !           400:  &lt;p&gt;&lt;input type=text id=fn name=fn value="Pillar Magazine.pdf"&gt;
1.729     mike      401:  &lt;p&gt;&lt;label&gt;&lt;input type=checkbox name=ext checked&gt; Hide extension&lt;/label&gt;
1.718     mike      402: &lt;/details&gt;</pre>
                    403: 
                    404:    <p>One could use this in conjuction with other <code><a href="#the-details-element">details</a></code>
                    405:    in a list to allow the user to collapse a set of fields down to a
                    406:    small set of headings, with the ability to open each one.</p>
                    407: 
1.1002    mike      408:    <p class="details-example"><img alt="" height="611" src="http://dev.w3.org/html5/spec/images/sample-details-1.png" width="345"><img alt="" height="666" src="http://dev.w3.org/html5/spec/images/sample-details-2.png" width="345"></p>
1.718     mike      409: 
1.729     mike      410:    <p>In these examples, the summary really just summarises what the
                    411:    controls can change, and not the actual values, which is less than
                    412:    ideal.</p>
                    413: 
                    414:   </div><h4 id="the-summary-element"><span class="secno">4.11.2 </span>The <dfn><code>summary</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
                    415:    <dd>None.</dd>
1.1002    mike      416:    <dt>Contexts in which this element can be used:</dt>
1.729     mike      417:    <dd>As the first child of a <code><a href="#the-details-element">details</a></code> element.</dd>
                    418:    <dt>Content model:</dt>
1.987     mike      419:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
1.729     mike      420:    <dt>Content attributes:</dt>
1.987     mike      421:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
1.729     mike      422:    <dt>DOM interface:</dt>
1.987     mike      423:    <dd>Uses <code><a href="elements.html#htmlelement">HTMLElement</a></code>.</dd>
                    424:   </dl><p>The <code><a href="#the-summary-element">summary</a></code> element <a href="rendering.html#represents">represents</a> a
1.729     mike      425:   summary, caption, or legend for the rest of the contents of the
                    426:   <code><a href="#the-summary-element">summary</a></code> element's parent <code><a href="#the-details-element">details</a></code>
                    427:   element<span class="impl">, if any</span>.</p><!-- v2DATAGRID
1.80      mike      428:   <h4 id="datagrid">The <dfn><code>datagrid</code></dfn> element</h4>
                    429: 
                    430:   <dl class="element">
                    431:    <dt>Categories</dt>
                    432:    <dd><span>Flow content</span>.</dd>
                    433:    <dd><span>Interactive content</span>.</dd>
                    434:    <dd><span>Sectioning root</span>.</dd>
1.1002    mike      435:    <dt>Contexts in which this element can be used:</dt>
1.80      mike      436:    <dd>Where <span>flow content</span> is expected.</dd>
1.1       mike      437:    <dt>Content model:</dt>
1.80      mike      438:    <dd><span>Flow content</span>.</dd>
1.1       mike      439:    <dt>Content attributes:</dt>
1.80      mike      440:    <dd><span>Global attributes</span></dd>
                    441: <!- -v2DGS:
1.1       mike      442:    <dd><code title="attr-datagrid-multiple">multiple</code></dd>
1.80      mike      443: - ->
                    444:    <dd><code title="attr-datagrid-disabled">disabled</code></dd>
1.1       mike      445:    <dt>DOM interface:</dt>
                    446:    <dd>
1.80      mike      447: <pre class="idl">interface <dfn>HTMLDataGridElement</dfn> : <span>HTMLElement</span> {
                    448: <!- -v2DGS:
1.1       mike      449:            attribute boolean <span title="dom-datagrid-multiple">multiple</span>;
1.80      mike      450: - ->           attribute boolean <span title="dom-datagrid-disabled">disabled</span>;
                    451:            attribute <span>DataGridListener</span> <span title="dom-datagrid-listener">listener</span>;
                    452: <!- - v2DGS:
1.1       mike      453:   readonly attribute <span>DataGridSelection</span> <span title="dom-datagrid-selection">selection</span>;
1.80      mike      454: - ->
1.1       mike      455:   // columns
1.395     mike      456:   void <span title="dom-datagrid-addColumn">addColumn</span>(in <span>Column</span> id, in DOMString label, in DOMString type, in optional HTMLImageElement icon, in optional boolean sortable, in optional boolean hidden);
1.80      mike      457:            attribute DOMString <span title="dom-datagrid-sortColumn">sortColumn</span>;
                    458:            attribute boolean <span title="dom-datagrid-sortAscending">sortAscending</span>;
                    459:   void <span title="dom-datagrid-clearColumns">clearColumns</span>();
1.1       mike      460: 
                    461:   // rows
1.80      mike      462:   void <span title="dom-datagrid-renotify">renotify</span>();
                    463:   void <span title="dom-datagrid-setRowCount">setRowCount</span>(in long childCount, in long rowCount);
                    464:   void <span title="dom-datagrid-setRows">setRows</span>(in <span>RowList</span> rows);
                    465:   void <span title="dom-datagrid-insertRows">insertRows</span>(in <span>RowList</span> rows);
                    466:   void <span title="dom-datagrid-deleteRows">deleteRows</span>(in <span>RowIDList</span> rows);
                    467:   void <span title="dom-datagrid-repaint">repaint</span>(in <span>RowID</span> row, in DOMString column);
                    468:   void <span title="dom-datagrid-clearRows">clearRows</span>();
                    469: <!- -
1.1       mike      470:  v2: opening and closing a row
                    471:      moving a row's actual ID
                    472:       - imagine new mail moving a thread up; you just want to add the new mail to the thread and move the thread's first mail to the top
                    473:       - though actually that should probably just be done using display sorting
1.80      mike      474: - ->
1.1       mike      475: };
                    476: 
1.80      mike      477: typedef DOMString <dfn>Column</dfn>;
                    478: typedef sequence&lt;<span>Column</span>> <dfn>ColumnList</dfn>;
1.81      mike      479: typedef sequence&lt;any> <dfn>Cell</dfn>; // <span>Column</span>, any... (exact types expected depend on the column type)
1.80      mike      480: typedef sequence&lt;<span>Cell</span>> <dfn>CellList</dfn>;
1.81      mike      481: typedef sequence&lt;any> <dfn>Row</dfn>; // <span>RowID</span>, long, long, <span>CellList</span>, optional boolean, optional long
1.80      mike      482: typedef sequence&lt;<span>Row</span>> <dfn>RowList</dfn>;
                    483: typedef sequence&lt;unsigned long> <dfn>RowID</dfn>;
                    484: typedef sequence&lt;<span>RowID</span>> <dfn>RowIDList</dfn>;
1.1       mike      485: 
                    486: [Callback=FunctionOnly, NoInterfaceObject]
1.80      mike      487: interface <dfn>RenderingContext2DCallback</dfn> {
                    488:   DOMString <span title="dom-Rendering2DContextCallback-handleEvent">handleEvent</span>(in <span>CanvasRenderingContext2D</span> context, in unsigned long width, in unsigned long height);
1.1       mike      489: };</pre>
                    490:    </dd>
1.80      mike      491:   </dl>
                    492: 
                    493:  <!- - v2:
                    494:    * datagrid: cells that are links (<a href=""></a>)
                    495:   - ->
                    496: 
                    497:   <p>The <code>datagrid</code> element <span>represents</span> an
                    498:   interactive representation of tree, list, or tabular data.</p>
                    499: 
                    500:   <p>The data being presented is provided by script using the methods
                    501:   described in the following sections.</p>
                    502: 
                    503: <!- -v2DGS:
1.1       mike      504:   <p>The <dfn
                    505:   title="attr-datagrid-multiple"><code>multiple</code></dfn> attribute
                    506:   is a <span>boolean attribute</span>. When set, it indicates that the
                    507:   user can select more than one row at a time.</p>
1.80      mike      508: - ->
                    509: 
                    510:   <p>The <dfn
                    511:   title="attr-datagrid-disabled"><code>disabled</code></dfn> attribute
                    512:   is a <span>boolean attribute</span> used to disable the
1.1       mike      513:   control. <span class="impl">When the attribute is set, the user
1.80      mike      514:   agent must disable the <code>datagrid</code>, preventing the user
                    515:   from interacting with it. The <code>datagrid</code> element should
1.1       mike      516:   still continue to update itself when the underlying data changes,
                    517:   though, as described in the next few sections. However, conformance
1.80      mike      518:   requirements stating that <code>datagrid</code> elements must react
1.1       mike      519:   to users in particular ways do not apply when the
1.80      mike      520:   <code>datagrid</code> is disabled.</span></p>
                    521: 
                    522:   <div class="impl">
1.1       mike      523: 
1.80      mike      524:   <!- -vsDGS: multiple - ->
1.1       mike      525: 
1.80      mike      526:   <p>The <dfn
1.186     mike      527:   title="dom-datagrid-disabled"><code>disabled</code></dfn> IDL
1.80      mike      528:   attribute must <span>reflect</span> the content attribute of the
1.1       mike      529:   same name.</p>
                    530: 
1.80      mike      531:   </div>
                    532: 
                    533:   <!- - v2DGPA: One possible thing to be added is a way to detect when a
1.1       mike      534:   row/selection has been deleted, activated, etc, by the user (delete
1.80      mike      535:   key, enter key, etc). (v2DGPA = <datagrid> Perform Action) - ->
                    536: 
                    537: 
                    538:   <h5>Introduction</h5>
                    539: 
                    540:   <p><i>This section is non-normative.</i></p>
                    541: 
                    542:   <p>In the <code>datagrid</code> data model, data is structured as a
1.1       mike      543:   set of rows representing a tree, each row being split into a number
                    544:   of columns. The columns are always present in the data model,
1.80      mike      545:   although individual columns might be hidden in the presentation.</p>
                    546: 
                    547:   <hr>
                    548: 
                    549:   <p>Each row can have child rows. Child rows may be hidden or
                    550:   shown, by closing or opening (respectively) the parent row.</p>
                    551: 
                    552:   <p>Rows are referred to by the path along the tree that one would
1.1       mike      553:   take to reach the row, using zero-based indices. Thus, the first row
                    554:   of a list is row "0", the second row is row "1"; the first child row
                    555:   of the first row is row "0,0", the second child row of the first row
                    556:   is row "0,1"; the fourth child of the seventh child of the third
1.80      mike      557:   child of the tenth row is "9,2,6,3", etc.</p>
                    558: 
                    559:   <p>The chains of numbers that give a row's path, or identifier, are
1.1       mike      560:   represented by arrays of positions, represented in IDL by the
1.80      mike      561:   <span>RowID</span> interface.</p>
                    562: 
                    563:   <p>The root of the tree is represented by an empty array.</p>
                    564: 
                    565:   <hr>
                    566: 
                    567:   <p>Each column has a string that is used to identify it in the API,
1.1       mike      568:   a label that is shown to users interacting with the column, a type,
1.80      mike      569:   and optionally an icon.</p>
                    570: 
                    571:   <p>The possible types are as follows:</p>
                    572: 
                    573:   <table>
                    574:    <thead>
                    575:     <tr>
                    576:      <td>Keyword
                    577:      <td>Description
                    578:    <tbody>
                    579:     <tr>
                    580:      <td><code title="datagrid-type-text">text</code>
                    581:      <td>Simple text.
                    582:     <tr>
                    583:      <td><code title="datagrid-type-editable">editable</code>
                    584:      <td>Editable text.
                    585:     <tr>
                    586:      <td><code title="datagrid-type-checkable">checkable</code>
                    587:      <td>Text with a check box.
                    588:     <tr>
                    589:      <td><code title="datagrid-type-list">list</code>
                    590:      <td>A list of values that the user can switch between.
                    591:     <tr>
                    592:      <td><code title="datagrid-type-progress">progress</code>
                    593:      <td>A progress bar.
                    594:     <tr>
                    595:      <td><code title="datagrid-type-meter">meter</code>
                    596:      <td>A gauge.
                    597:     <tr>
                    598:      <td><code title="datagrid-type-custom">custom</code>
                    599:      <td>A canvas onto which arbitrary content can be drawn.
                    600:   </table>
                    601: 
                    602:   <p>Each column can be flagged as sortable, in which case the user
                    603:   will be able to sort the view using that column.</p>
                    604: 
                    605:   <p>Columns are not necessarily visible. A column can be created
1.1       mike      606:   invisible by default. The user can select which columns are to be
1.80      mike      607:   shown.</p>
                    608: 
                    609:   <p>When no columns have been added to the <code>datagrid</code>, a
1.1       mike      610:   column with no name, whose identifier is the empty string, whose
1.80      mike      611:   type is <code title="datagrid-type-text">text</code>, and which is
1.1       mike      612:   not sortable, is implied. This column is removed if any explicit
1.80      mike      613:   columns are declared.</p>
                    614: 
                    615:   <p>Each cell uses the type given for its column, so all cells in a
                    616:   column present the same type of information.</p>
                    617: 
                    618: <!- -v2DGS:
1.1       mike      619:   <p>Selection of data in a <code>datagrid</code> operates at the row
                    620:   level. If the <code title="attr-datagrid-multiple">multiple</code>
                    621:   attribute is present, multiple rows can be selected at once,
                    622:   otherwise the user can only select one row at a time.</p>
1.80      mike      623: - ->
                    624: 
                    625:   <!- - v2DGDND: selection should draggable to and from datagrids - ->
                    626: 
                    627: 
                    628:   <h6>Example: a <code>datagrid</code> backed by a static <code>table</code> element</h6>
                    629: 
                    630:   ...
                    631: 
                    632: 
                    633:   <h6>Example: a <code>datagrid</code> backed by nested <code>ol</code> elements</h6>
                    634: 
                    635:   ...
                    636: 
                    637: 
                    638:   <h6>Example: a <code>datagrid</code> backed by a server</h6>
                    639: 
                    640:   ...
                    641: 
                    642: 
                    643:   <h5>Populating the <code>datagrid</code></h5>
                    644: 
                    645:   <dl class="domintro">
                    646: 
                    647:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-listener">listener</code> [ = <var title="">value</var> ]</dt>
1.1       mike      648:    <dd>
                    649: 
                    650:     <p>Return the current object that is configured as the
1.80      mike      651:     <code>datagrid</code> listener, if any. Returns null if there is
1.1       mike      652:     none.</p>
                    653: 
                    654:     <p>The listener is an object provided by the script author that
1.80      mike      655:     receives notifications when the <code>datagrid</code> needs row
1.1       mike      656:     data to render itself, when the user opens and closes rows with
                    657:     children, when the user edits a cell, and when the user invokes a
1.80      mike      658:     row's context menu. (The <code>DataGridListener</code> interface
1.1       mike      659:     used for this purpose is described in the next section.)</p>
                    660: 
                    661:     <p>Can be set, to change the current listener.</p>
                    662: 
                    663:    </dd>
                    664: 
                    665: 
1.80      mike      666:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-renotify">renotify</code>()</dt>
1.1       mike      667:    <dd>
                    668: 
1.80      mike      669:     <p>Causes the <code>datagrid</code> to resend notifications to the
1.1       mike      670:     listener (if any) for any rows or cells that the
1.80      mike      671:     <code>datagrid</code> does not yet have information for.</p>
1.1       mike      672: 
1.80      mike      673:     <!- - useful, e.g., if there is a server error and the script loses
                    674:     track of what rows it's supposed to be reporting. - ->
1.1       mike      675: 
                    676:    </dd>
                    677: 
                    678: 
1.80      mike      679:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-addColumn">addColumn</code>(<var title="">id</var>, <var title="">label</var>, <var title="">type</var> [, <var title="">icon</var> [, <var title="">sortable</var> [, <var title="">hidden</var> ] ] ] )</dt>
1.1       mike      680:    <dd>
                    681: 
1.80      mike      682:     <p>Adds a column to the <code>datagrid</code>.</p>
1.1       mike      683: 
                    684:     <p>If a column with the given identifier has already been added,
                    685:     it just replaces the information for that column.</p>
                    686: 
                    687:     <p>The possible types are enumerated in the previous section.</p>
                    688: 
                    689:    </dd>
                    690: 
                    691: 
1.80      mike      692:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-sortColumn">sortColumn</code> [ = <var title="">value</var> ]</dt>
1.1       mike      693:    <dd>
                    694: 
                    695:     <p>Returns the identifier of the column by which the data is to be
                    696:     sorted.</p>
                    697: 
                    698:     <p>Can be set, to indicate that the sort order has changed. This
1.80      mike      699:     will cause the <code>datagrid</code> to clear its position
                    700:     information for rows, so <code
                    701:     title="dom-datagrid-setRows">setRows()</code> will have to be
1.1       mike      702:     called again with the new sort order.</p>
                    703: 
                    704:     <p>The columns are not actually sorted by the
1.80      mike      705:     <code>datagrid</code>; the data has to be sorted by the script
                    706:     that adds the rows to the <code>datagrid</code>.</p>
1.1       mike      707: 
                    708:    </dd>
                    709: 
                    710: 
1.80      mike      711:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-sortAscending">sortAscending</code> [ = <var title="">value</var> ]</dt>
1.1       mike      712:    <dd>
                    713: 
                    714:     <p>Returns true if the data is to be sorted with smaller values
                    715:     first; otherwise, returns false, indicating that bigger values are
                    716:     to be put first.</p>
                    717: 
                    718:     <p>Can be set, to indicate that the order is about to change.</p>
                    719: 
                    720:    </dd>
                    721: 
                    722: 
1.80      mike      723:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-clearColumns">clearColumns</code>()</dt>
1.1       mike      724:    <dd>
                    725: 
1.80      mike      726:     <p>Removes all the columns in the <code>datagrid</code>,
1.1       mike      727:     reinstating the implied column.</p>
                    728: 
                    729:    </dd>
                    730: 
                    731: 
1.80      mike      732:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-setRowCount">setRowCount</code>(<var title="">childCount</var>, <var title="">rowCount</var>)</dt>
1.1       mike      733:    <dd>
                    734: 
1.80      mike      735:     <p>Sets the numbers of rows in the <code>datagrid</code>,
1.1       mike      736:     excluding rows that are descendants of rows that are closed.</p>
                    737: 
1.80      mike      738:     <p>Throws a <code>DATAGRID_MODEL_ERR</code> exception if the
1.1       mike      739:     arguments contradict each other or previously declared information
1.80      mike      740:     (e.g. declaring that the <code>datagrid</code> has three rows when
1.1       mike      741:     the 12th row has been declared).</p>
                    742: 
                    743:    </dd>
                    744: 
                    745: 
1.80      mike      746:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-setRows">setRows</code>(<var title="">rows</var>)</dt>
1.1       mike      747:    <dd>
                    748: 
1.80      mike      749:     <p>Updates data for rows in the <code>datagrid</code>, or fills in
                    750:     data for rows previously implied by a call to <code
                    751:     title="dom-datagrid-setRowCount">setRowCount()</code> but not
1.1       mike      752:     previously declared.</p>
                    753: 
                    754:     <p>The <var title="">rows</var> argument is an array of rows, each
                    755:     represented by a further array consisting of:</p>
                    756: 
1.80      mike      757:     <ol class="brief">
                    758: 
                    759:      <li>A <code>RowID</code> object identifying the row.</li>
1.1       mike      760: 
                    761:      <li>An integer giving the position of the row in its parent,
1.80      mike      762:      given the current sort order, or &#x2212;1 to set other row data
1.1       mike      763:      without setting a position or changing a previously declared
                    764:      position.</li>
                    765: 
                    766:      <li>An integer giving the number of children of the row, or 0 if
1.80      mike      767:      the row has no children, or &#x2212;1 if the row has children but
1.1       mike      768:      the count is currently unknown. If the number of children has
                    769:      already been set to 0 or a positive integer, then passing
1.80      mike      770:      &#x2212;1 leaves the previous count unchanged.</li>
1.1       mike      771: 
                    772:      <li>An array giving the data for zero or more cells in the row,
                    773:      as described below.</li>
                    774: 
                    775:      <li>A boolean declaring whether the row is open or not. This
                    776:      entry, if omitted, is assumed to be false (closed), unless the
                    777:      row has already been declared as open.</li>
                    778: 
                    779:      <li>An integer giving the number of rows that are descendants of
                    780:      this row, excluding those that are descendants of descendants of
                    781:      this row that are closed. This entry can be omitted if the row is
                    782:      closed or if it has already been declared.</li>
                    783: 
1.80      mike      784:     </ol>
                    785: 
                    786:     <p>The array giving the data for the cells in the row consists of
1.1       mike      787:     a further set of arrays, one per cell. The first item of each of
                    788:     these arrays is the column's identifier; the subsequent values
                    789:     vary based on the type of the column, as follows:</p>
                    790: 
1.80      mike      791:     <dl>
                    792: 
                    793:      <dt><code title="datagrid-type-text">text</code></dt>
1.1       mike      794:      <dd>
1.80      mike      795:       <ol class="brief">
                    796:        <li>A string giving the cell's value.
                    797:        <li>Optionally, an <code>img</code> element giving an icon for the cell.
                    798:       </ol>
                    799:      </dd>
1.1       mike      800: 
1.80      mike      801:      <dt><code title="datagrid-type-editable">editable</code></dt>
1.1       mike      802:      <dd>
1.80      mike      803:       <ol class="brief">
                    804:        <li>A string giving the cell's value.
                    805:        <li>Optionally, a <code>datalist</code> element giving a set of predefined options.
                    806:        <li>Optionally, an <code>img</code> element giving an icon for the cell.
                    807:       </ol>
                    808:      </dd>
1.1       mike      809: 
1.80      mike      810:      <dt><code title="datagrid-type-checkable">checkable</code></dt>
1.1       mike      811:      <dd>
1.80      mike      812:       <ol class="brief">
                    813:        <li>A string giving the cell's value.
                    814:        <li>A boolean, indicating whether the cell is checked (true) or not (false).
                    815:        <li>Optionally, a boolean indicating whether the value of the cell is obscured as indeterminate (true), or not (false).
                    816:        <li>Optionally, an <code>img</code> element giving an icon for the cell.
                    817:       </ol>
                    818:      </dd>
1.1       mike      819: 
1.80      mike      820:      <dt><code title="datagrid-type-list">list</code></dt>
1.1       mike      821:      <dd>
1.80      mike      822:       <ol class="brief">
                    823:        <li>A string giving the cell's current value.
                    824:        <li>A <code>select</code> element giving the <span title="concept-select-option-list">list of options</span>.
                    825:        <li>Optionally, an <code>img</code> element giving an icon for the cell.
                    826:       </ol>
                    827:      </dd>
1.1       mike      828: 
1.80      mike      829:      <dt><code title="datagrid-type-progress">progress</code></dt>
1.1       mike      830:      <dd>
1.80      mike      831:       <ol class="brief">
                    832:        <li>A value in the range 0.0 (no progress) to 1.0 (task complete).
                    833:       </ol>
                    834:      </dd>
1.1       mike      835: 
1.80      mike      836:      <dt><code title="datagrid-type-meter">meter</code></dt>
1.1       mike      837:      <dd>
1.80      mike      838:       <ol class="brief">
                    839:        <li>A number giving the cell's value.
                    840:        <li>Optionally, a number giving the maximum value, if it's not 1.
                    841:        <li>Optionally, a number giving the minimum value, if it's not 0.
                    842:        <li>Optionally, a number giving the highest value that is considered "low".
                    843:        <li>Optionally, a number giving the lowest value that is considered "high".
                    844:        <li>Optionally, a number giving the value that is considered optimal.
                    845:       </ol>
                    846:      </dd>
1.1       mike      847: 
1.80      mike      848:      <dt><code title="datagrid-type-custom">custom</code></dt>
1.1       mike      849:      <dd>
1.80      mike      850:       <ol class="brief">
                    851:        <li>A number giving the minimum width of the cell, in CSS pixels, that is desired.
                    852:        <li>A number giving the minimum height of the cell, in CSS pixels, that is desired.
                    853:        <li>A function that is passed a <code>CanvasRenderingContext2D</code> object, along with the width and height (in CSS pixels) of the cell that the context will draw on.
                    854:       </ol>
                    855:      </dd>
                    856: 
                    857:     </dl>
1.1       mike      858: 
1.80      mike      859:     <p>While the rows in a single call to the <code
                    860:     title="dom-datagrid-setRows">setRows()</code> method can be in any
1.1       mike      861:     order, for each row, it is important that all its ancestor rows
                    862:     and all its open previous siblings are also declared, either in
                    863:     the same call or in an earlier one.</p>
                    864: 
1.80      mike      865:     <p>Throws a <code>DATAGRID_MODEL_ERR</code> exception if the
1.1       mike      866:     arguments contradict each other or previously declared information
                    867:     (e.g. saying that a row's position is 5 when the parent row only
                    868:     has 3 children, or naming a column that doesn't exist, or
                    869:     declaring a row without declaring its parent, or changing the
                    870:     number of children that a row has while that row and its ancestors
                    871:     are all open).</p>
                    872: 
                    873:    </dd>
                    874: 
                    875: 
1.80      mike      876:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-insertRows">insertRows</code>(<var title="">rows</var>)</dt>
1.1       mike      877:    <dd>
                    878: 
1.80      mike      879:     <p>Inserts the given rows into the <code>datagrid</code>,
                    880:     increasing the numbers of rows that the <code>datagrid</code>
1.1       mike      881:     assumes are present.</p>
                    882: 
                    883:     <p>The <var title="">rows</var> argument is an array of rows in
1.80      mike      884:     the same structure as the argument to the <code
                    885:     title="dom-datagrid-setRows">setRows()</code> method described
1.1       mike      886:     above, with the same expectations of consistency (a given row's
                    887:     ancestors and earlier open siblings being listed either earlier or
1.80      mike      888:     in the same call as a given row). However, unlike with the <code
                    889:     title="dom-datagrid-setRows">setRows()</code> method, if a row is
1.1       mike      890:     inserted along with its child, the child is not included in the
1.80      mike      891:     child and row counts of the parent row; every row in the <var
                    892:     title="">rows</var> argument will increase its parent's counts
1.1       mike      893:     automatically.</p>
                    894: 
1.80      mike      895:     <p>Throws a <code>DATAGRID_MODEL_ERR</code> exception if the
1.1       mike      896:     arguments contradict each other or previously declared
                    897:     information.</p>
                    898: 
                    899:    </dd>
                    900: 
                    901: 
1.80      mike      902:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-deleteRows">deleteRows</code>(<var title="">rows</var>)</dt>
1.1       mike      903:    <dd>
                    904: 
1.80      mike      905:     <p>Removes the given rows from the <code>datagrid</code>, and
1.1       mike      906:     updates the number of rows known to be in the
1.80      mike      907:     <code>datagrid</code> accordingly. The argument is an array of
                    908:     <code>RowID</code> objects identifying the rows to remove.</p>
1.1       mike      909: 
1.80      mike      910:     <p>Throws a <code>DATAGRID_MODEL_ERR</code> exception if the argument
                    911:     includes a row the <code>datagrid</code> doesn't know about.</p>
                    912:     <!- - since otherwise behaviour might depend on where the user
                    913:     scrolled! - ->
1.1       mike      914: 
                    915:    </dd>
                    916: 
                    917: 
1.80      mike      918:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-repaint">repaint</code>(<var title="">row</var>, <var title="">column</var>)</dt>
1.1       mike      919:    <dd>
                    920: 
1.80      mike      921:     <p>If the given column's type is <code
                    922:     title="datagrid-type-custom">custom</code>, then causes the
                    923:     <code>datagrid</code> to reinvoke the function that obtains the
1.1       mike      924:     desired rendering.</p>
                    925: 
                    926:    </dd>
                    927: 
                    928: 
1.80      mike      929:    <dt><var title="">datagrid</var> . <code title="dom-datagrid-clearRows">clearRows</code>()</dt>
1.1       mike      930:    <dd>
                    931: 
1.80      mike      932:     <p>Clears the <code>datagrid</code> of all row data, resetting it
                    933:     to empty<!- - v2DGS:, and clears the selection- ->.</p>
1.1       mike      934: 
                    935:    </dd>
                    936: 
1.80      mike      937:   </dl>
                    938: 
                    939: 
                    940:   <div class="impl">
1.1       mike      941: 
1.80      mike      942:   <h6>The listener</h6>
1.1       mike      943: 
1.80      mike      944:   <p>The <dfn
1.186     mike      945:   title="dom-datagrid-listener"><code>listener</code></dfn> IDL
1.1       mike      946:   attribute allows authors to specify an object that will receive all
1.80      mike      947:   the notifications from the <code>datagrid</code>. Initially, its
1.1       mike      948:   value must be null. On getting, it must return its value. On
                    949:   setting, its value must be set to the new value, and then the user
1.80      mike      950:   agent must <span>queue a task</span> to call the <code
                    951:   title="dom-listener-initialize">initialize()</code> method with the
                    952:   <code>datagrid</code> element as its only argument.</p>
1.1       mike      953: 
                    954: 
1.80      mike      955:   <h6>The columns</h6>
1.1       mike      956: 
1.80      mike      957:   <p>The columns are represented by the <dfn>column list</dfn>, an
1.1       mike      958:   ordered list of entries for columns, each of which consists of:</p>
                    959: 
1.80      mike      960:   <dl>
                    961: 
                    962:    <dt>An identifier</dt>
1.1       mike      963: 
                    964:    <dd>A string used to identify the column in the API.</dd>
                    965: 
                    966:    <dt>A label</dt>
                    967: 
                    968:    <dd>A string used in the user interface.</dd>
                    969: 
                    970:    <dt>A type</dt>
                    971: 
                    972:    <dd>One of the types described below.</dd>
                    973: 
                    974:    <dt>An icon</dt>
                    975: 
1.80      mike      976:    <dd>An image, copied from an <code>img</code> element when the
1.1       mike      977:    column was declared.</dd>
                    978: 
                    979:    <dt>Whether the column is sortable</dt>
                    980: 
                    981:    <dd>A boolean indicating whether the user can request that the data
                    982:    be sorted by this column (true), or not (false).</dd>
                    983: 
                    984:    <dt>Whether the column is visible</dt>
                    985: 
                    986:    <dd>A boolean indicating whether the column is part of the
1.80      mike      987:    <code>datagrid</code>'s rendering.</dd>
1.1       mike      988: 
1.80      mike      989:   </dl>
                    990: 
                    991:   <p>Initially, the <span>column list</span> must have a single
                    992:   column, the <dfn>default column</dfn>, whose identifier is the empty
                    993:   string, whose label is the empty string, whose type is <code
                    994:   title="datagrid-type-text">text</code>, with no icon, which is not
1.1       mike      995:   sortable, and which <em>is</em> visible.</p>
                    996: 
1.80      mike      997:   <hr>
                    998: 
                    999:   <p>The <dfn title="dom-datagrid-addColumn"><code>addColumn(<var
                   1000:   title="">id</var>, <var title="">label</var>, <var
                   1001:   title="">type</var>, <var title="">icon</var>, <var
                   1002:   title="">sortable</var>, <var title="">hidden</var>)</code></dfn>
1.1       mike     1003:   method must run the following steps:</p>
                   1004: 
1.80      mike     1005:   <ol>
                   1006: 
                   1007:    <li><p>If there is already an entry in <span>column list</span>,
                   1008:    other than the <span>default column</span>, whose identifier is
                   1009:    <var title="">id</var>, throw a <code>DATAGRID_MODEL_ERR</code>
1.1       mike     1010:    exception and abort these steps.</p></li>
                   1011: 
                   1012:    <li>
                   1013: 
                   1014:     <p>If <var title="">type</var> is not a string equal to one of the
1.80      mike     1015:     <span>allowed <code>datagrid</code> column types</span>, then
                   1016:     throw a <code>DATAGRID_MODEL_ERR</code> exception and abort these
1.1       mike     1017:     steps.</p>
                   1018: 
                   1019:    </li>
                   1020: 
                   1021:    <li><p>If the <var title="">icon</var> argument is present and not
1.80      mike     1022:    null, but the given <code>img</code> element's <code
1.998     mike     1023:    title="dom-img-complete">complete</code> attribute is false or its
                   1024:    <code title="attr-img-src">src</code> attribute is omitted or
                   1025:    empty, then let <var title="">icon</var> be null.</p></li>
1.1       mike     1026: 
                   1027:    <li><p>If the <var title="">icon</var> argument is present and not
1.80      mike     1028:    null, then copy the image data from that <code>img</code> element,
1.1       mike     1029:    and let <var title="">image</var> be the copy of that image
                   1030:    data. Otherwise, let <var title="">image</var> be nothing.</p></li>
                   1031: 
1.80      mike     1032:    <li><p>Append a new entry to the <span>column list</span>, with
1.1       mike     1033:    <var title="">id</var> as its identifier, <var title="">label</var>
1.80      mike     1034:    as its label, <var title="">type</var> as its type, and <var
                   1035:    title="">image</var> as its icon. Let the column be sortable if the
1.1       mike     1036:    <var title="">sortable</var> argument is present and true, and make
                   1037:    it visible unless the <var title="">hidden</var> argument is
                   1038:    present and true.</p></li>
                   1039: 
1.80      mike     1040:    <li><p>If the <span>column list</span> contains the <span>default
                   1041:    column</span>, then remove the <span>default column</span> from the
                   1042:    <span>column list</span>, discard any data for cells in that column
                   1043:    in any rows in the <code>datagrid</code>, set <code
                   1044:    title="dom-datagrid-sortColumn">sortColumn</code> to <var
                   1045:    title="">id</var>, set <code
                   1046:    title="dom-datagrid-sortAscending">sortAscending</code> to true,
                   1047:    and run the <span><code>datagrid</code> resort
                   1048:    steps</span>.</p></li>
                   1049: 
                   1050:   </ol>
                   1051: 
                   1052:   <hr>
1.1       mike     1053: 
1.80      mike     1054:   <p>The <dfn
1.186     mike     1055:   title="dom-datagrid-sortColumn"><code>sortColumn</code></dfn> IDL
1.1       mike     1056:   attribute gives the current column used for sorting. Initially, its
                   1057:   value must be the empty string. On getting, it must return its
                   1058:   current value. On setting, if the new value doesn't match the
1.80      mike     1059:   identifier of one of the columns in the <span>column list</span>,
                   1060:   then the user agent must throw a <code>DATAGRID_MODEL_ERR</code>
1.1       mike     1061:   exception. Otherwise, if the new value is not the same as its
                   1062:   current value, then the user agent must set the attribute to the new
1.80      mike     1063:   value, and then run the <span><code>datagrid</code> resort
                   1064:   steps</span>.</p>
1.1       mike     1065: 
1.80      mike     1066:   <p>The <dfn
                   1067:   title="dom-datagrid-sortAscending"><code>sortAscending</code></dfn>
1.186     mike     1068:   IDL attribute specifies the direction that the tree is sorted in,
1.1       mike     1069:   ascending (true) or descending (false). Initially, its value must be
                   1070:   true (ascending). On getting, it must return its current value. On
                   1071:   setting, if the new value is not the same as its current value, then
                   1072:   the user agent must set the attribute to the new value, and then run
1.80      mike     1073:   the <span><code>datagrid</code> resort steps</span>.</p>
1.1       mike     1074: 
                   1075:   <p>When a column is marked as being sortable, the user agent should
                   1076:   allow the user to select that column to be the column used for
                   1077:   sorting, and should allow the user to chose whether the sort order
                   1078:   is ascending or descending.</p>
                   1079: 
                   1080:   <p>When the user changes the sort order in this manner, the user
1.80      mike     1081:   agent must update the <code
                   1082:   title="dom-datagrid-sortColumn">sortColumn</code> and <code
                   1083:   title="dom-datagrid-sortAscending">sortAscending</code> attributes
                   1084:   appropriately, and then run the <span><code>datagrid</code> resort
                   1085:   steps</span>.</p>
1.1       mike     1086: 
1.80      mike     1087:   <p class="note">The <span><code>datagrid</code> resort steps</span>
1.1       mike     1088:   are described in the next section.</p>
                   1089: 
1.80      mike     1090:   <hr>
1.1       mike     1091: 
1.80      mike     1092:   <p>The <dfn
                   1093:   title="dom-datagrid-clearColumns"><code>clearColumns()</code></dfn>
                   1094:   method, if the <span>column list</span> doesn't contain the
                   1095:   <span>default column</span>, must empty the <span>column
                   1096:   list</span>, append the <span>default column</span> to the now empty
                   1097:   <span>column list</span>, discard any data for cells in all rows in
                   1098:   the <code>datagrid</code>, set <code
                   1099:   title="dom-datagrid-sortColumn">sortColumn</code> to the empty
                   1100:   string, set <code
                   1101:   title="dom-datagrid-sortAscending">sortAscending</code> to true, and
                   1102:   run the <span><code>datagrid</code> resort steps</span>. (If the
                   1103:   <span>column list</span> is already just the <span>default
                   1104:   column</span>, then the method does nothing.)</p>
1.1       mike     1105: 
                   1106: 
1.80      mike     1107:   <h6>The rows</h6>
                   1108: 
                   1109:   <p>A <code>datagrid</code> element is intended to show a
1.1       mike     1110:   representation of a tree, where typically the user only sees a
                   1111:   small part of the tree at a time.</p>
                   1112: 
1.80      mike     1113:   <p>To make this efficient, the <code>datagrid</code> element
1.1       mike     1114:   <em>actually</em> shows a small part of a <em>sparse</em> tree, so
                   1115:   that only relevant parts of the data structure need be loaded at any
                   1116:   time. Specifically, the model requires only that all the ancestor
                   1117:   rows of the displayed rows be loaded, as well as any open earlier
                   1118:   siblings (in the displayed sort order) of the displayed rows.</p>
                   1119: 
1.80      mike     1120:   <p>Conceptually, therefore, a <code>datagrid</code> has a number of
1.1       mike     1121:   related sparse data structures backing it.</p>
                   1122: 
1.80      mike     1123:   <p>The first is the <dfn>natural order sparse data tree</dfn>. This
1.1       mike     1124:   is the structure in which rows are entered as they are declared, in
                   1125:   their natural order. This can differ from the order actually
                   1126:   displayed to the user. It consists of nested sparse lists of
1.80      mike     1127:   rows. In the <span>natural order sparse data tree</span>, a row will
1.1       mike     1128:   always have all its parents already declared. Once a row is added to
1.80      mike     1129:   this structure, it can only be removed by the <code
                   1130:   title="dom-datagrid-deleteRows">deleteRows()</code> and <code
                   1131:   title="dom-datagrid-clearRows">clearRows()</code> methods. The order of
1.1       mike     1132:   nodes in this tree never changes; to move a node in this tree, it
                   1133:   has to be removed and then another row (with the same data)
                   1134:   reinserted elsewhere.</p>
                   1135: 
1.80      mike     1136:   <p>The second structure is the <dfn>display order sparse data
1.1       mike     1137:   tree</dfn>. This is a similar structure that contains a subset of
1.80      mike     1138:   the rows in the <span>natural order sparse data tree</span>, ordered
                   1139:   in the order given by the <code
                   1140:   title="dom-datagrid-sortAscending">sortAscending</code> and <code
                   1141:   title="dom-datagrid-sortColumn">sortColumn</code> attributes, and
1.1       mike     1142:   excluding rows with one or more ancestors that are closed. This tree
1.80      mike     1143:   is cleared whenever the <code
                   1144:   title="dom-datagrid-sortAscending">sortAscending</code> and <code
                   1145:   title="dom-datagrid-sortColumn">sortColumn</code> attributes
1.1       mike     1146:   change.</p>
                   1147: 
1.80      mike     1148:   <p>The third structure is the <dfn>display order sparse data
1.1       mike     1149:   list</dfn>. This structure is a flattened representation of the
1.80      mike     1150:   <span>display order sparse data tree</span>.</p>
1.1       mike     1151: 
1.80      mike     1152:   <p>At any time, a number of consecutive rows in the <span>display
                   1153:   order sparse data list</span> are physically visible to the
                   1154:   user. The <code>datagrid</code> fires notifications to a <span
                   1155:   title="dom-datagrid-listener">listener</span> (provided by script),
1.1       mike     1156:   and the listener, or other some script, is expected to feed the
1.80      mike     1157:   <code>datagrid</code> with the information needed to render the
1.1       mike     1158:   control.</p>
                   1159: 
1.80      mike     1160:   <p>A <code>datagrid</code> has a <dfn>pending <code>datagrid</code>
                   1161:   rows list</dfn>, which is a list of rows in the <span>display order
                   1162:   sparse data list</span> for which the <code>datagrid</code> has sent
1.1       mike     1163:   notifications requesting information but not yet received
                   1164:   information about.</p>
                   1165: 
1.80      mike     1166:   <p>A <code>datagrid</code> also has a <dfn>pending
1.1       mike     1167:   <code>datagrid</code> <em>cells</em> list</dfn>, which is a list of
1.80      mike     1168:   row/column pairs (cells) for which the <code>datagrid</code> has
1.1       mike     1169:   sent notifications requesting information but not yet received
                   1170:   information about.</p>
                   1171: 
                   1172:   <p>User agents may discard information about rows that are not
                   1173:   displayed and that are not ancestors or open earlier siblings of
                   1174:   rows or ancestors of rows that are displayed.</p>
                   1175: 
1.80      mike     1176:   <hr>
                   1177: 
                   1178:   <p>These structures are different views of the collection of rows
                   1179:   that form the <code>datagrid</code>. Each row has the following
1.1       mike     1180:   information associated with it:</p>
                   1181: 
1.80      mike     1182:   <dl>
                   1183: 
                   1184:    <dt>A parent</dt>
1.1       mike     1185: 
1.80      mike     1186:    <dd><p>Either another row, or the <code>datagrid</code> itself. This
                   1187:    is the parent of the row in the <span>natural order sparse data
                   1188:    tree</span> and the <span>display order sparse data tree</span>
                   1189:    for the <code>datagrid</code>.</p></dd>
1.1       mike     1190: 
                   1191:    <dt>A natural order position relative to the other rows with the
                   1192:    same parent</dt>
                   1193: 
                   1194:    <dd>
                   1195: 
                   1196:     <p>This is the number of rows that precede this row under the same
1.80      mike     1197:     parent in the <span>natural order sparse data tree</span>. This
1.1       mike     1198:     number can't be changed relative to other rows in the same parent;
                   1199:     to change the relative natural order of data in the
1.80      mike     1200:     <code>datagrid</code>, the original rows have to be removed and
1.1       mike     1201:     new rows (with the same data but different natural positions)
                   1202:     inserted in their place. (The exact number of a row can change, as
                   1203:     new rows can be inserted above it.)</p>
                   1204: 
1.80      mike     1205:     <p>A row can be identified by a <code>RowID</code> object. This is
1.1       mike     1206:     an array of numbers, consisting of the natural order positions of
                   1207:     each ancestor row and the row itself, starting from the furthest
                   1208:     ancestor. Thus, for instance, the fourth child row of the first
1.80      mike     1209:     child row of the second row in a <code>datagrid</code> would be
                   1210:     identified by a <code>RowID</code> object whose value is <code
                   1211:     title="">[1, 0, 3]</code>. A row's identifier changes if rows are
                   1212:     <span title="dom-datagrid-insertRows">inserted before it</span> in
                   1213:     the <code>datagrid</code>.</p>
1.1       mike     1214: 
                   1215:    </dd>
                   1216: 
                   1217:    <dt>A display order position relative to the other rows with
                   1218:    the same parent</dt>
                   1219: 
                   1220:    <dd><p>This is the number of rows that precede this row under the
1.80      mike     1221:    same parent in the <span>display order sparse data
                   1222:    tree</span>. This number can be unknown. If the sort order
                   1223:    changes, then this information is lost (as the <span>display order
                   1224:    sparse data tree</span> is cleared).</p></dd>
1.1       mike     1225: 
                   1226:    <dt>A child count</dt>
                   1227: 
                   1228:    <dd><p>The number of rows that have this row as a parent. If this is
1.80      mike     1229:    zero, the row cannot be opened. If this is &#x2212;1, then the
1.1       mike     1230:    child count is unknown but the row can be opened. This value can be
1.80      mike     1231:    changed by the <code title="dom-datagrid-setRows">setRows()</code>
                   1232:    method only if the current value is &#x2212;1 or if the row or one
1.1       mike     1233:    of its ancestors is closed. Otherwise, it can only be changed
1.80      mike     1234:    indirectly using the <code
                   1235:    title="dom-datagrid-insertRows">insertRows()</code> and <code
                   1236:    title="dom-datagrid-deleteRows">deleteRows()</code> methods.</p></dd>
1.1       mike     1237: 
                   1238:    <dt>An open flag</dt>
                   1239: 
                   1240:    <dd><p>A boolean indicating whether the row is open (true) or
                   1241:    closed (false). Once set, the flag can only be changed by the user
                   1242:    or while one of the row's ancestors is itself closed. A row can
                   1243:    also be in a third state, "opening", which is treated as closed for
                   1244:    all purposes except that the user agent may indicate that the row
                   1245:    is in this special state, and except that when the row is updated
                   1246:    to have a row count, the row will switch to being open.</p></dd>
                   1247: 
                   1248:    <dt>A row count</dt>
                   1249: 
                   1250:    <dd><p>The number of rows that have this row as a parent or
                   1251:    ancestor, and that do not have an ancestor that is a descendant of
1.80      mike     1252:    this row that is itself closed. If this is &#x2212;1, then the row
                   1253:    count is unknown. This value can be changed by the <code
                   1254:    title="dom-datagrid-setRows">setRows()</code> method only if the
1.1       mike     1255:    row or one of its ancestors is closed (or opening, but not
1.80      mike     1256:    open). Otherwise, it can only be changed indirectly using the <code
                   1257:    title="dom-datagrid-insertRows">insertRows()</code> and <code
                   1258:    title="dom-datagrid-deleteRows">deleteRows()</code>
1.1       mike     1259:    methods.</p></dd>
                   1260: 
                   1261:    <dt>Cells</dt>
                   1262: 
                   1263:    <dd><p>The data that applies to this row. Cell data is discussed in
                   1264:    more detail below.</p></dd>
                   1265: 
1.80      mike     1266:   </dl>
                   1267: 
                   1268:   <p>The <code>datagrid</code> itself also has a <dfn title="datagrid
                   1269:   child count">child count</dfn> and a <dfn title="datagrid row
1.1       mike     1270:   count">row count</dfn>, which are analogous to the child counts and
                   1271:   row counts for rows. Initially, these must be zero.</p>
                   1272: 
1.80      mike     1273:   <hr>
                   1274: 
                   1275:   <p>The <dfn><code>datagrid</code> resort steps</dfn>, which are
1.1       mike     1276:   invoked when the sort order changes as described in the previous
                   1277:   section, are as follows:</p>
                   1278: 
1.80      mike     1279:   <ol>
1.1       mike     1280: 
1.80      mike     1281:    <li>
                   1282: 
                   1283:     <p>Clear the <span>display order sparse data tree</span>
1.1       mike     1284:     (i.e. mark the display order position of all the rows in the
1.80      mike     1285:     <code>datagrid</code> as unknown).</p>
1.1       mike     1286: 
                   1287:     <p>User agents may cache the position information of rows for
1.80      mike     1288:     various values of <code
                   1289:     title="dom-datagrid-sortColumn">sortColumn</code> and <code
                   1290:     title="dom-datagrid-sortAscending">sortAscending</code>, instead
1.1       mike     1291:     of discarding the information altogether. If the user agent caches
                   1292:     this information, and has information that applies to the current
1.80      mike     1293:     values of <code title="dom-datagrid-sortColumn">sortColumn</code>
                   1294:     and <code title="dom-datagrid-sortAscending">sortAscending</code>,
                   1295:     then the user agent may repopulate the <span>display order sparse
                   1296:     data tree</span> from this information.</p>
1.1       mike     1297: 
                   1298:    </li>
                   1299: 
                   1300:    <li>
                   1301: 
1.80      mike     1302:     <p>Clear the <span>pending <code>datagrid</code> rows list</span>
                   1303:     and the <span>pending <code>datagrid</code> cells list</span>.</p>
1.1       mike     1304: 
                   1305:    </li>
                   1306: 
                   1307:    <li>
                   1308: 
1.80      mike     1309:     <p>Invoke the <span><code>datagrid</code> update display
                   1310:     algorithm</span>.</p>
1.1       mike     1311: 
                   1312:    </li>
                   1313: 
1.80      mike     1314:    <!- - v2: queue a task to fire an event, or tell the listener the
                   1315:    sort order changed, or something - ->
                   1316: 
                   1317:   </ol>
1.1       mike     1318: 
1.80      mike     1319:   <hr>
1.1       mike     1320: 
1.80      mike     1321:   <p>The <dfn
                   1322:   title="dom-datagrid-renotify"><code>renotify()</code></dfn> method
                   1323:   must empty the <span>pending <code>datagrid</code> rows list</span>
                   1324:   and the <span>pending <code>datagrid</code> cells list</span>, and
                   1325:   invoke the <span><code>datagrid</code> update display
                   1326:   algorithm</span>.</p>
                   1327: 
                   1328:   <hr>
                   1329: 
                   1330:   <p>The <dfn title="dom-datagrid-setRowCount"><code>setRowCount(<var
                   1331:   title="">childCount</var>, <var
                   1332:   title="">rowCount</var>)</code></dfn> method must run the following
1.1       mike     1333:   steps:</p>
                   1334: 
1.80      mike     1335:   <ol>
1.1       mike     1336: 
1.80      mike     1337:    <li>
                   1338: 
                   1339:     <p>Set the <span><code>datagrid</code> child count</span> to <var
                   1340:     title="">childCount</var>, the <span><code>datagrid</code> row
                   1341:     count</span> to <var title="">rowCount</var>.</p>
1.1       mike     1342: 
                   1343:    </li>
                   1344: 
                   1345:    <li>
                   1346: 
1.80      mike     1347:     <p><span>Audit the <code>datagrid</code></span>. If this fails,
1.1       mike     1348:     then revert the changes made in the previous step, throw a
1.80      mike     1349:     <code>DATAGRID_MODEL_ERR</code> exception, and abort these
1.1       mike     1350:     steps.</p>
                   1351: 
                   1352:    </li>
                   1353: 
                   1354:    <li>
                   1355: 
1.80      mike     1356:     <p>Invoke the <span><code>datagrid</code> update display
                   1357:     algorithm</span>.</p>
1.1       mike     1358: 
                   1359:    </li>
                   1360: 
1.80      mike     1361:   </ol>
                   1362: 
                   1363:   <hr>
                   1364: 
                   1365:   <p>The <dfn title="dom-datagrid-setRows"><code>setRows(<var
                   1366:   title="">rows</var>)</code></dfn> method must run the following
1.1       mike     1367:   steps:</p>
                   1368: 
1.80      mike     1369:   <ol>
1.1       mike     1370: 
1.80      mike     1371:    <li>
                   1372: 
                   1373:     <p><span title="type-check a RowList object">Type-check the <var
                   1374:     title="">rows</var> argument</span>. If this fails, throw a
1.1       mike     1375:     <code>TypeError</code> exception, and abort these steps.</p>
                   1376: 
                   1377:    </li>
                   1378: 
                   1379:    <li>
                   1380: 
1.80      mike     1381:     <p><span title="partially sort a RowList object">Partially sort
                   1382:     the <var title="">rows</var> argument</span>.</p>
1.1       mike     1383: 
                   1384:    </li>
                   1385: 
                   1386:    <li>
                   1387: 
1.80      mike     1388:     <p>For each <code>Row</code> object in the <var
                   1389:     title="">rows</var> argument, in order, perform the appropriate
1.1       mike     1390:     steps from the list below.</p>
                   1391: 
1.80      mike     1392:     <p class="note">The changes made to the <code>datagrid</code>'s
1.1       mike     1393:     data structures in this step get reverted (as required below) if
                   1394:     any consistency errors are detected either in this step or the
                   1395:     next.</p>
                   1396: 
1.80      mike     1397:     <dl>
                   1398: 
                   1399:      <dt>If there already exists a row in the <code>datagrid</code>'s
                   1400:      <span>natural order sparse data tree</span> with the same
                   1401:      identifier as given by the <code>Row</code> object's
                   1402:      <code>RowID</code> object, and that row and all its ancestors are
1.1       mike     1403:      open</dt>
                   1404: 
                   1405:      <dd>
                   1406: 
                   1407:       <p>If one of the following conditions is true, then revert all
                   1408:       the changes done in this step, throw a
1.80      mike     1409:       <code>DATAGRID_MODEL_ERR</code> exception, and abort these
1.1       mike     1410:       steps:</p>
                   1411: 
1.80      mike     1412:       <ul>
                   1413: 
                   1414:        <li>The value of the <code>Row</code> object's second entry is
                   1415:        neither &#x2212;1 nor equal to the child count of the
1.1       mike     1416:        preexisting row.</li>
                   1417: 
1.80      mike     1418:        <li>The <code>Row</code> object has fewer than four
1.1       mike     1419:        entries or more than six entries.</li>
                   1420: 
1.80      mike     1421:        <li>The <code>Row</code> object has five or more entries, and
1.1       mike     1422:        its fifth entry is false.</li>
                   1423: 
1.80      mike     1424:        <li>The <code>Row</code> object has six entries, and its sixth
1.1       mike     1425:        entry is not equal to the row count of the preexisting
                   1426:        row.</li>
                   1427: 
1.80      mike     1428:       </ul>
                   1429: 
                   1430:      </dd>
1.1       mike     1431: 
1.80      mike     1432:      <dt>If there already exists a row in the <code>datagrid</code>'s
                   1433:      <span>natural order sparse data tree</span> with the same
                   1434:      identifier as given by the <code>Row</code> object's
                   1435:      <code>RowID</code> object, but either that row or one of its
1.1       mike     1436:      ancestors is closed</dt>
                   1437: 
                   1438:      <dd>
                   1439: 
                   1440:       <p>Set the preexisting row's child count to the value of the
1.80      mike     1441:       <code>Row</code> object's second entry.</p>
1.1       mike     1442: 
1.80      mike     1443:       <p>If the <code>Row</code> object has five or more entries, and
1.1       mike     1444:       either its fifth entry is true and the preexisting row is closed
                   1445:       but not opening, or its fifth entry is false and the preexisting
                   1446:       row is open, then: if the preexisting row has no ancestor row
                   1447:       that is closed, then revert all the changes done in this step,
1.80      mike     1448:       throw a <code>DATAGRID_MODEL_ERR</code> exception, and abort
1.1       mike     1449:       these steps; otherwise, if the fifth entry is false, then close
                   1450:       the row; otherwise, open the row.</p>
                   1451: 
1.80      mike     1452:       <p>If the <code>Row</code> object has six entries, set the
                   1453:       preexisting row's row count to the value of the <code>Row</code>
1.1       mike     1454:       object's sixth entry.</p>
                   1455: 
                   1456:       <p>If the preexisting row is opening, then: increase the
1.80      mike     1457:       <span><code>datagrid</code> row count</span> and the row counts
1.1       mike     1458:       of any ancestor rows by the number of rows that the preexisting
1.80      mike     1459:       row now has in its row count, then open the row.</p> <!- - we
1.1       mike     1460:       should also "update the <span>pending <code>datagrid</code> rows
                   1461:       list</span> and the <span>pending <code>datagrid</code> cells
1.80      mike     1462:       list</span> accordingly" - ->
1.1       mike     1463: 
                   1464: 
                   1465:      </dd>
                   1466: 
1.80      mike     1467:      <dt>There does not exist a row in the <code>datagrid</code>'s
                   1468:      <span>natural order sparse data tree</span> with the same
                   1469:      identifier as given by the <code>Row</code> object's
                   1470:      <code>RowID</code> object</dt>
1.1       mike     1471: 
                   1472:      <dd>
                   1473: 
1.80      mike     1474:       <p>If the <code>RowID</code> object has a length greater than 1,
1.1       mike     1475:       then verify that there is a row identified by the
1.80      mike     1476:       <code>RowID</code> consisting of all but the last number in the
                   1477:       <code>Row</code> object's <code>RowID</code>. If there is no
                   1478:       such row present in the <span>natural order sparse data
                   1479:       tree</span>, then revert all the changes done in this step,
                   1480:       throw a <code>DATAGRID_MODEL_ERR</code> exception, and abort
1.1       mike     1481:       these steps.</p>
                   1482: 
1.80      mike     1483:       <p>Create a row and insert it into the <span>natural order
                   1484:       sparse data tree</span>, such that its parent is the row
                   1485:       identified by the <code>RowID</code> consisting of all but the
                   1486:       last number in the <code>Row</code> object's <code>RowID</code>,
                   1487:       or the <code>datagrid</code> if the length of the
                   1488:       <code>Row</code> object's <code>RowID</code> is 1; with its
1.1       mike     1489:       natural order position being the last number of the
1.80      mike     1490:       <code>Row</code> object's <code>RowID</code>; with the child
                   1491:       count being the value of the third entry of the <code>Row</code>
1.1       mike     1492:       object; with the row being marked closed unless the
1.80      mike     1493:       <code>Row</code> object has five or more entries and its fifth
1.1       mike     1494:       entry is true, in which case the row is open; and with its row
1.80      mike     1495:       count being &#x2212;1 unless the <code>Row</code> object has six
1.1       mike     1496:       entries, in which case the row count is equal to the value of
1.80      mike     1497:       the <code>Row</code> object's sixth entry.</p>
1.1       mike     1498: 
                   1499:      </dd>
                   1500: 
1.80      mike     1501:     </dl>
                   1502: 
                   1503:    </li>
1.1       mike     1504: 
                   1505:    <li>
                   1506: 
1.80      mike     1507:     <p><span>Audit the <code>datagrid</code></span>. If this fails,
1.1       mike     1508:     then revert the changes made in the previous step, throw a
1.80      mike     1509:     <code>DATAGRID_MODEL_ERR</code> exception, and abort these
1.1       mike     1510:     steps.</p>
                   1511: 
                   1512:    </li>
                   1513: 
                   1514:    <li>
                   1515: 
1.80      mike     1516:     <p>For each <code>Row</code> object in the <var
                   1517:     title="">rows</var> argument, in order, <span title="apply a Row
                   1518:     object">apply the <code>Row</code> object</span>.</p>
1.1       mike     1519: 
                   1520:    </li>
                   1521: 
                   1522:    <li>
                   1523: 
1.80      mike     1524:     <p>Invoke the <span><code>datagrid</code> update display
                   1525:     algorithm</span>.</p>
1.1       mike     1526: 
                   1527:    </li>
                   1528: 
1.80      mike     1529:   </ol>
                   1530: 
                   1531:   <hr>
                   1532: 
                   1533:   <p>The <dfn title="dom-datagrid-insertRows"><code>insertRows(<var
                   1534:   title="">rows</var>)</code></dfn> method must run the following
1.1       mike     1535:   steps:</p>
                   1536: 
1.80      mike     1537:   <ol>
                   1538: 
                   1539:    <li>
1.1       mike     1540: 
1.80      mike     1541:     <p><span title="type-check a RowList object">Type-check the <var
                   1542:     title="">rows</var> argument</span>. If this fails, throw a
1.1       mike     1543:     <code>TypeError</code> exception, and abort these steps.</p>
                   1544: 
                   1545:    </li>
                   1546: 
                   1547:    <li>
                   1548: 
1.80      mike     1549:     <p><span title="partially sort a RowList object">Partially sort
                   1550:     the <var title="">rows</var> argument</span>.</p>
1.1       mike     1551: 
                   1552:    </li>
                   1553: 
                   1554:    <li>
                   1555: 
1.80      mike     1556:     <p>For each <code>Row</code> object in the <var
                   1557:     title="">rows</var> argument, in order, run the following
1.1       mike     1558:     steps:</p>
                   1559: 
1.80      mike     1560:     <p class="note">The changes made to the <code>datagrid</code>'s
1.1       mike     1561:     data structures in this step get reverted (as required below) if
                   1562:     any consistency errors are detected either in this step or the
                   1563:     next.</p>
                   1564: 
1.80      mike     1565:     <ol>
                   1566: 
                   1567:      <li>
1.1       mike     1568: 
                   1569:       <p>Let <var title="">parent</var> be the row identified by the
1.80      mike     1570:       <code>RowID</code> consisting of all but the last number in the
                   1571:       <code>Row</code> object's <code>RowID</code>, or the
                   1572:       <code>datagrid</code> itself if the <code>Row</code> object's
                   1573:       <code>RowID</code> has length 0.</p>
                   1574: 
                   1575:       <p>If there is no such row present in the <span>natural order
                   1576:       sparse data tree</span>, then revert all the changes done in
                   1577:       this algorithm, throw a <code>DATAGRID_MODEL_ERR</code>
1.1       mike     1578:       exception, and abort these steps.</p>
                   1579: 
                   1580:      </li>
                   1581: 
                   1582:      <li>
                   1583: 
                   1584:       <p>Increment by one the natural order position of all rows whose
                   1585:       parent is <var title="">parent</var> and whose natural order
                   1586:       position is equal to or greater than the last number of the
1.80      mike     1587:       <code>Row</code> object's <code>RowID</code>.</p>
1.1       mike     1588: 
                   1589:      </li>
                   1590: 
                   1591:      <li>
                   1592: 
1.80      mike     1593:       <p>If the value of the <code>Row</code> object's second entry is
                   1594:       not &#x2212;1, then increment by one the display order position
1.1       mike     1595:       of all rows whose parent is <var title="">parent</var> and whose
                   1596:       display order position is equal to or greater than the value of
1.80      mike     1597:       the <code>Row</code> object's second entry.</p>
1.1       mike     1598: 
1.80      mike     1599:      <!- -(Not sure how to really say this.)
1.1       mike     1600:       <p>Update the <span>pending <code>datagrid</code> rows
                   1601:       list</span> and the <span>pending <code>datagrid</code> cells
                   1602:       list</span> accordingly.</p>
1.80      mike     1603:      - ->
1.1       mike     1604: 
                   1605:      </li>
                   1606: 
                   1607:      <li>
                   1608: 
1.80      mike     1609:       <p>Create a row and insert it into the <span>natural order
                   1610:       sparse data tree</span>, such that its parent is <var
                   1611:       title="">parent</var>; with its natural order position being the
                   1612:       last number of the <code>Row</code> object's <code>RowID</code>;
1.1       mike     1613:       with the child count being the value of the third entry of the
1.80      mike     1614:       <code>Row</code> object; with the row being marked closed unless
                   1615:       the <code>Row</code> object has five or more entries and its
1.1       mike     1616:       fifth entry is true, in which case the row is open; and with its
1.80      mike     1617:       row count being &#x2212;1 unless the <code>Row</code> object has
1.1       mike     1618:       six entries, in which case the row count is equal to the value
1.80      mike     1619:       of the <code>Row</code> object's sixth entry.</p>
1.1       mike     1620: 
                   1621:      </li>
                   1622: 
1.80      mike     1623:     </ol>
                   1624: 
                   1625:    </li>
1.1       mike     1626: 
                   1627:    <li>
                   1628: 
1.80      mike     1629:     <p>For each <code>Row</code> object in the <var
                   1630:     title="">rows</var> argument, in order, <span title="apply a Row
                   1631:     object">apply the <code>Row</code> object</span>.</p>
1.1       mike     1632: 
                   1633:    </li>
                   1634: 
                   1635:    <li>
                   1636: 
1.80      mike     1637:     <p>Invoke the <span><code>datagrid</code> update display
                   1638:     algorithm</span>.</p>
1.1       mike     1639: 
                   1640:    </li>
                   1641: 
1.80      mike     1642:   </ol>
                   1643: 
                   1644:   <hr>
                   1645: 
                   1646:   <p>When an algorithm requires the user agent to <dfn>type-check a
1.1       mike     1647:   <code>RowList</code> object</dfn> (an array), each entry in the
                   1648:   object must be checked against the following requirements. If any
                   1649:   are false, then the type-check fails, otherwise it passes.</p>
                   1650: 
1.80      mike     1651:   <ul>
                   1652: 
                   1653:    <li><p>The entry is a <code>Row</code> object (an
1.1       mike     1654:    array).</p></li>
                   1655: 
1.80      mike     1656:    <li><p>The first value in the <code>Row</code> is a
                   1657:    <code>RowID</code> object (also an array), whose length is at least
1.1       mike     1658:    1, and whose values are all integers greater than or equal to
                   1659:    zero.</p></li>
                   1660: 
1.80      mike     1661:    <li><p>The numbers in the <code>RowID</code> object do not exactly
                   1662:    match any of the other entries in the <code>RowList</code> object
                   1663:    (i.e. no two <code>Row</code> objects have the same
1.1       mike     1664:    identifier).</p></li>
                   1665: 
1.80      mike     1666:    <li><p>The second value in the <code>Row</code> is an integer that
                   1667:    is either &#x2212;1, zero, or a positive integer.</p></li>
1.1       mike     1668: 
1.80      mike     1669:    <li><p>The third value in the <code>Row</code> is an integer that
                   1670:    is either &#x2212;1, zero, or a positive integer.</p></li>
1.1       mike     1671: 
1.80      mike     1672:    <li><p>The fourth value in the <code>Row</code> is a
                   1673:    <code>CellList</code> object (yet another array).</p></li>
1.1       mike     1674: 
1.80      mike     1675:    <li><p>Each entry in the <span>CellList</span> object is a
                   1676:    <code>Cell</code> object (again, an array).</p></li>
1.1       mike     1677: 
1.80      mike     1678:    <li><p>Each <code>Cell</code> object in the <span>CellList</span>
                   1679:    object has as its first value a <code>Column</code> object (a
1.1       mike     1680:    string), and its value is the identifier of one of the columns in
1.80      mike     1681:    the <span>column list</span>.</p></li>
1.1       mike     1682: 
                   1683:    <li>
                   1684: 
1.80      mike     1685:     <p>Each <code>Cell</code> object in the <span>CellList</span>
1.1       mike     1686:     object has as its second and subsequent entries values that match
                   1687:     the following requirements, as determined by the type of the
                   1688:     column identified by the first entry:</p>
                   1689: 
1.80      mike     1690:     <dl>
                   1691: 
                   1692:      <dt>If the column's type is <code title="datagrid-type-text">text</code></dt>
1.1       mike     1693:      <dd>
                   1694: 
                   1695:       <p>The second entry's value is a string, and either there are
                   1696:       only two entries, or there are three, and the third entry is
1.80      mike     1697:       an <code>img</code> element.</p>
1.1       mike     1698: 
1.80      mike     1699:       <p>If there is an <code>img</code> element specified, its <code
1.998     mike     1700:       title="dom-img-complete">complete</code> attribute is true and
                   1701:       its <code title="attr-img-src">src</code> attribute is neither
                   1702:       omitted nor empty.</p>
1.1       mike     1703: 
                   1704:      </dd>
                   1705: 
1.80      mike     1706:      <dt>If the column's type is <code title="datagrid-type-editable">editable</code></dt>
1.1       mike     1707:      <dd>
                   1708: 
                   1709:       <p>The second entry's value is a string, and either there are
                   1710:       only two entries, or the third entry is a
1.80      mike     1711:       <code>datalist</code> element, and either there are only three
1.1       mike     1712:       entries, or there are four, and the fourth entry is an
1.80      mike     1713:       <code>img</code> element.</p>
1.1       mike     1714: 
1.80      mike     1715:       <p>If there is an <code>img</code> element specified, its <code
1.998     mike     1716:       title="dom-img-complete">complete</code> attribute is true and
                   1717:       its <code title="attr-img-src">src</code> attribute is neither
                   1718:       omitted nor empty.</p>
1.1       mike     1719: 
                   1720:      </dd>
                   1721: 
1.80      mike     1722:      <dt>If the column's type is <code title="datagrid-type-checkable">checkable</code></dt>
1.1       mike     1723:      <dd>
                   1724: 
                   1725:       <p>The second entry's value is a string, the third entry is a
                   1726:       boolean, and either there are only three entries, or the
                   1727:       fourth entry is also a boolean, and either there are only four
                   1728:       entries, or there are five, and the fifth entry is an
1.80      mike     1729:       <code>img</code> element.</p>
1.1       mike     1730: 
1.80      mike     1731:       <p>If there is an <code>img</code> element specified, its <code
1.998     mike     1732:       title="dom-img-complete">complete</code> attribute is true and
                   1733:       its <code title="attr-img-src">src</code> attribute is neither
                   1734:       omitted nor empty.</p>
1.1       mike     1735: 
                   1736:      </dd>
                   1737: 
1.80      mike     1738:      <dt>If the column's type is <code title="datagrid-type-list">list</code></dt>
1.1       mike     1739:      <dd>
                   1740: 
                   1741:       <p>The second entry's value is a string, the third entry is a
1.80      mike     1742:       <code>select</code> element, and either there are only three
1.1       mike     1743:       entries, or there are four, and the fourth entry is an
1.80      mike     1744:       <code>img</code> element.</p>
1.1       mike     1745: 
1.80      mike     1746:       <p>If there is an <code>img</code> element specified, its <code
1.998     mike     1747:       title="dom-img-complete">complete</code> attribute is true and
                   1748:       its <code title="attr-img-src">src</code> attribute is neither
                   1749:       omitted nor empty.</p>
1.1       mike     1750: 
                   1751:      </dd>
                   1752: 
1.80      mike     1753:      <dt>If the column's type is <code title="datagrid-type-progress">progress</code></dt>
1.1       mike     1754:      <dd>
                   1755: 
                   1756:       <p>There are only two entries, the second entry's value is a
                   1757:       number, and the number's value is between 0.0 and 1.0
                   1758:       inclusive.</p>
                   1759: 
                   1760:      </dd>
                   1761: 
1.80      mike     1762:      <dt>If the column's type is <code title="datagrid-type-meter">meter</code></dt>
1.1       mike     1763:      <dd>
                   1764: 
                   1765:       <p>There are at least two, but possibly up to seven, entries,
                   1766:       all entries but the first one are numbers, and the following
                   1767:       relationships hold:</p>
                   1768: 
1.80      mike     1769:       <ul class="brief">
                   1770: 
                   1771:        <li>The second entry is less than the third, or less than 1.0
1.1       mike     1772:        if the third is absent.</li>
                   1773: 
                   1774:        <li>The second entry is greater than the fourth, or greater
                   1775:        than 0.0 if the fourth is absent.</li>
                   1776: 
                   1777:        <li>If there are at least three entries, the third entry is
                   1778:        greater than the fourth, or greater than zero if the fourth
                   1779:        is absent.</li>
                   1780: 
                   1781:        <li>If there are at least five entries, the fifth is not
                   1782:        greater than the third and not less than the fourth.</li>
                   1783: 
                   1784:        <li>If there are at least six entries, the sixth is not
                   1785:        greater than the third and not less than the fifth.</li>
                   1786: 
                   1787:        <li>If there are at least seven entries, the fifth is not
                   1788:        greater than the third and not less than the fourth.</li>
                   1789: 
1.80      mike     1790:       </ul>
1.1       mike     1791: 
1.80      mike     1792:      </dd>
                   1793: 
                   1794:      <dt>If the column's type is <code title="datagrid-type-custom">custom</code></dt>
1.1       mike     1795:      <dd>
                   1796: 
                   1797:       <p>There are four entries, the second and third are numbers
                   1798:       that are integers greater than zero, and the fourth is a
                   1799:       <code>Rendering2DContextCallback</code> object (a
                   1800:       function).</p>
                   1801: 
                   1802:      </dd>
                   1803: 
1.80      mike     1804:     </dl>
                   1805: 
                   1806:    </li>
1.1       mike     1807: 
1.80      mike     1808:    <li><p>Either there are only four values in the <code>Row</code>,
                   1809:    or the fifth value in the <code>Row</code> is a boolean.</p></li>
1.1       mike     1810: 
                   1811:    <li><p>Either there are only four or five values in the
1.80      mike     1812:    <code>Row</code>, or there are six, and the sixth value in the
                   1813:    <code>Row</code> an integer that is greater than or equal to
1.1       mike     1814:    zero.</p></li>
                   1815: 
1.80      mike     1816:   </ul>
                   1817: 
                   1818:   <p>Where the above requirements say that a value is to be a string,
1.718     mike     1819:   the user agent must apply the ToString() abstract operation to the
1.1       mike     1820:   value, assume that the value was indeed a string, and use the result
                   1821:   in the rest of the algorithm as if it had that had been the value
1.98      mike     1822:   passed to the method. <a href="#refsECMA262">[ECMA262]</a></p>
1.1       mike     1823: 
                   1824:   <p>Where the above requirements say that a value is to be a number,
1.718     mike     1825:   the user agent must first apply the ToNumber() abstract operation
1.60      mike     1826:   to the value, and then verify that the result is neither an Infinity
                   1827:   value nor a Not-a-Number (NaN) value. If this result is indeed
                   1828:   acceptable (i.e. finite), the user agent must use the result in the
                   1829:   rest of the algorithm as if it had that had been the value passed to
1.98      mike     1830:   the method. <a href="#refsECMA262">[ECMA262]</a></p>
1.1       mike     1831: 
                   1832:   <p>Where the above requirements say that a value is to be an
1.718     mike     1833:   integer, the user agent must first apply the ToNumber() abstract
                   1834:   operation to the value, and then verify that the result is a finite
1.1       mike     1835:   integer. If so, the user agent must use the result in the rest of
                   1836:   the algorithm as if it had that had been the value passed to the
1.98      mike     1837:   method. <a href="#refsECMA262">[ECMA262]</a></p>
1.1       mike     1838: 
                   1839:   <p>Where the above requirements say that a value is to be a boolean,
1.718     mike     1840:   the user agent must apply the ToBoolean() abstract operation to the
1.1       mike     1841:   value, assume that the value was indeed a boolean, and use the
                   1842:   result in the rest of the algorithm as if it had that had been the
1.98      mike     1843:   value passed to the method. <a href="#refsECMA262">[ECMA262]</a></p>
1.80      mike     1844: 
                   1845:   <hr>
1.1       mike     1846: 
1.80      mike     1847:   <p>When an algorithm requires the user agent to <dfn>audit the
                   1848:   <code>datagrid</code></dfn>, the <code>datagrid</code> must be
1.1       mike     1849:   checked against the following requirements. If any are false, then
                   1850:   the audit fails, otherwise it passes.</p>
                   1851: 
1.80      mike     1852:   <ul>
                   1853: 
                   1854:    <li>There is no row whose natural order position is greater than or
                   1855:    equal to the child count of its parent row in the <span>natural
                   1856:    order sparse data tree</span>.</li>
1.1       mike     1857: 
                   1858:    <li>There is no row whose display order position is greater than or
1.80      mike     1859:    equal to the child count of its parent row in the <span>display
                   1860:    order sparse data tree</span>.</li>
1.1       mike     1861: 
                   1862:    <li>There is no row such that the sum of that row's child count and
                   1863:    the row counts all the open rows that are direct children of that
1.80      mike     1864:    row in the <span>natural order sparse data tree</span> is less than
1.1       mike     1865:    that row's row count.</li>
                   1866: 
                   1867:    <li>Of the rows whose child count is equal to the number of rows
1.80      mike     1868:    that are direct children of that row in the <span>natural order
                   1869:    sparse data tree</span>, there is none such that the sum of that
1.1       mike     1870:    row's child count and the row counts of all the open rows that are
1.80      mike     1871:    direct children of that row in the <span>natural order sparse data
                   1872:    tree</span> is greater than that row's row count.</li>
                   1873: 
                   1874:   </ul>
1.1       mike     1875: 
1.80      mike     1876:   <p>For the purposes of this audit, the <code>datagrid</code> must be
1.1       mike     1877:   treated as the parent row of all the rows that are direct children
1.80      mike     1878:   of the <code>datagrid</code> in the <span>natural order sparse data
                   1879:   tree</span> and the <span>display order sparse data tree</span>. The
                   1880:   child count of this implied row is the <span><code>datagrid</code>
                   1881:   child count</span>, and the row count of this implied row is the
                   1882:   <span><code>datagrid</code> row count</span>.</p>
                   1883: 
                   1884:   <hr>
1.1       mike     1885: 
1.80      mike     1886:   <p>When an algorithm requires the user agent to <dfn>partially sort
1.1       mike     1887:   a <code>RowList</code> object</dfn> (an array), the entries in the
1.80      mike     1888:   object must be resorted such that <code>Row</code> objects are
1.1       mike     1889:   listed after any of their ancestors and after any of their earlier
1.80      mike     1890:   siblings. In other words, for any two <code>Row</code> objects <var
                   1891:   title="">a</var> and <var title="">b</var> in the
                   1892:   <code>RowList</code>, where <var title="">a</var> is before <var
                   1893:   title="">b</var> after the sort, the following conditions must
1.1       mike     1894:   hold:</p>
                   1895: 
1.80      mike     1896:   <ul>
                   1897: 
                   1898:    <li><p>If their <code>RowID</code> objects are the same length and
1.1       mike     1899:    have values that are equal except for the last value, then the last
1.80      mike     1900:    value of <var title="">a</var>'s <code>RowID</code>'s last value
                   1901:    must be less than <var title="">b</var>'s <code>RowID</code>'s last
1.1       mike     1902:    value (i.e. earlier siblings must come before their later
                   1903:    siblings).</p></li>
                   1904: 
1.80      mike     1905:    <li><p>If their <code>RowID</code> objects are not the same length,
1.1       mike     1906:    but the values in the shorter of the two are the same as the first
                   1907:    few values in the longer one, then <var title="">a</var>'s
1.80      mike     1908:    <code>RowID</code> must be the shorter one (i.e. ancestors must
1.1       mike     1909:    come before their descendants).</p></li>
                   1910: 
1.80      mike     1911:   </ul>
                   1912: 
                   1913:   <hr>
                   1914: 
                   1915:   <p>The <dfn title="dom-datagrid-deleteRows"><code>deleteRows(<var
                   1916:   title="">rows</var>)</code></dfn> method must run the following
1.1       mike     1917:   steps:</p>
                   1918: 
1.80      mike     1919:   <ol>
                   1920: 
                   1921:    <li>
1.1       mike     1922: 
                   1923:     <p>If any of the entries in <var title="">rows</var> are not
1.80      mike     1924:     <code>RowID</code> objects consisting of one or more entries whose
1.1       mike     1925:     values are all integers that are greater than or equal to zero,
                   1926:     then throw a <code>TypeError</code> exception and abort these
                   1927:     steps.</p>
                   1928: 
                   1929:     <p>To check if a value is an integer, the user agent must first
1.718     mike     1930:     apply the ToNumber() abstract operation to the value, and then
1.1       mike     1931:     verify that the result is a finite integer. If so, the user agent
                   1932:     must use the result in the rest of the algorithm as if it had that
1.80      mike     1933:     had been the value passed to the method. <a
1.98      mike     1934:     href="#refsECMA262">[ECMA262]</a></p>
1.1       mike     1935: 
                   1936:    </li>
                   1937: 
                   1938:    <li>
                   1939: 
1.80      mike     1940:     <p>If any of the <code>RowID</code> objects in the <var
                   1941:     title="">rows</var> argument identify a row that isn't present in
                   1942:     the <span>natural order sparse data tree</span>, then throw a
                   1943:     <code>DATAGRID_MODEL_ERR</code> exception and abort these
1.1       mike     1944:     steps.</p>
                   1945: 
                   1946:    </li>
                   1947: 
                   1948:    <li>
                   1949: 
                   1950:     <p>If any row is listed twice in the <var title="">rows</var>
1.80      mike     1951:     argument, then throw a <code>DATAGRID_MODEL_ERR</code> exception
1.1       mike     1952:     and abort these steps.</p>
                   1953: 
                   1954:    </li>
                   1955: 
                   1956:    <li>
                   1957: 
                   1958:     <p>Sort the <var title="">rows</var> argument such that the
                   1959:     entries are given in the same order as the rows they identify
                   1960:     would be visited in a pre-order, depth first traversal of the
1.80      mike     1961:     <span>natural order sparse data tree</span>.</p>
1.1       mike     1962: 
                   1963:    </li>
                   1964: 
                   1965:    <li>
                   1966: 
                   1967:     <p>For each row identified by entries in <var title="">rows</var>,
                   1968:     <em>in reverse order</em>, run the following steps:</p>
                   1969: 
1.80      mike     1970:     <ol>
                   1971: 
                   1972:      <li>
1.1       mike     1973: 
                   1974:       <p>Decrement the child count of the row's parent row, if that
                   1975:       child count is greater than zero. If the row has no parent,
1.80      mike     1976:       decrement the <span><code>datagrid</code> child
                   1977:       count</span>.</p>
1.1       mike     1978: 
                   1979:       <p>If the row has a parent row, and its child count is now zero,
                   1980:       then close that row.</p>
                   1981: 
                   1982:      </li>
                   1983: 
                   1984:      <li>
                   1985: 
                   1986:       <p>Let <var title="">delta</var> be one more than the row's row
                   1987:       count if the row is open and its row count is greater than zero;
                   1988:       otherwise, let <var title="">delta</var> be one.</p>
                   1989: 
                   1990:      </li>
                   1991: 
                   1992:      <li>
                   1993: 
                   1994:       <p>Let <var title="">ancestor</var> be the row.</p>
                   1995: 
                   1996:      </li>
                   1997: 
                   1998:      <li>
                   1999: 
                   2000:       <p><i>Row count loop</i>: Let <var title="">ancestor</var> be
                   2001:       <var title="">ancestor</var>'s parent row, if any, or null if it
                   2002:       has none.</p>
                   2003: 
                   2004:      </li>
                   2005: 
                   2006:      <li>
                   2007: 
                   2008:       <p>If <var title="">ancestor</var> is null, then decrement the
1.80      mike     2009:       <span><code>datagrid</code> row count</span> by <var
                   2010:       title="">delta</var>. Otherwise, if <var title="">ancestor</var>
                   2011:       is open, then decrement its row count by <var
                   2012:       title="">delta</var>.</p>
1.1       mike     2013: 
                   2014:      </li>
                   2015: 
                   2016:      <li>
                   2017: 
                   2018:       <p>If <var title="">ancestor</var> is not null, then jump back
                   2019:       to the step labeled <i>row count loop</i> above.</p>
                   2020: 
                   2021:      </li>
                   2022: 
                   2023:      <li>
                   2024: 
                   2025:       <p>Let <var title="">parent</var> be the row's parent, or the
1.80      mike     2026:       <code>datagrid</code> if the row has no parent.</p>
1.1       mike     2027: 
                   2028:      </li>
                   2029: 
                   2030:      <li>
                   2031: 
                   2032:       <p>Decrement by one the natural order position of all rows whose
                   2033:       parent is <var title="">parent</var> and whose natural order
                   2034:       position is equal to or greater than the row's own natural order
                   2035:       position.</p>
                   2036: 
                   2037:      </li>
                   2038: 
                   2039:      <li>
                   2040: 
1.80      mike     2041:       <p>If the row is in the <span>display order sparse data
                   2042:       tree</span>, then decrement by one the display order position of
1.1       mike     2043:       all rows whose parent is <var title="">parent</var> and whose
                   2044:       display order position is equal to or greater than the row's own
                   2045:       display order position.</p>
                   2046: 
                   2047:      </li>
                   2048: 
                   2049:      <li>
                   2050: 
                   2051:       <p>Clear the row and its descendants from the
1.80      mike     2052:       <code>Datagrid</code>.</p>
1.1       mike     2053: 
                   2054:      </li>
                   2055: 
1.80      mike     2056:     </ol>
                   2057: 
                   2058:    </li>
1.1       mike     2059: 
                   2060:    <li>
                   2061: 
1.80      mike     2062:     <p>Invoke the <span><code>datagrid</code> update display
                   2063:     algorithm</span>.</p>
1.1       mike     2064: 
                   2065:    </li>
                   2066: 
1.80      mike     2067:   </ol>
1.1       mike     2068: 
1.80      mike     2069:   <hr>
                   2070: 
                   2071:   <p>The <dfn
                   2072:   title="dom-datagrid-clearRows"><code>clearRows()</code></dfn> method
                   2073:   must empty the <span>natural order sparse data tree</span>, reset
                   2074:   both the <span><code>datagrid</code> child count</span> and the
                   2075:   <span><code>datagrid</code> row count</span> to zero, and invoke the
                   2076:   <span><code>datagrid</code> update display algorithm</span>.</p>
                   2077: 
                   2078:   <hr>
                   2079: 
                   2080:   <p>The <dfn title="dom-datagrid-repaint"><code>repaint(<var
                   2081:   title="">row</var>, <var title="">column</var>)</code></dfn> method
1.1       mike     2082:   must cause the user agent to clear its cache for the cell specified
1.80      mike     2083:   by the identifier <var title="">row</var> and the column <var
                   2084:   title="">column</var>, if that column's type is <code
                   2085:   title="datagrid-type-custom">custom</code>. If the given column has
                   2086:   not been declared, or its type is not <code
                   2087:   title="datagrid-type-custom">custom</code>, then the user agent must
                   2088:   throw a <code>DATAGRID_MODEL_ERR</code> exception. If the given row
1.1       mike     2089:   is not known, then the method must do nothing. If the cell is indeed
                   2090:   cleared, the user agent must reinvoke the previously registered
1.80      mike     2091:   <code>RenderingContext2DCallback</code> callback when it needs to
1.1       mike     2092:   repaint that row.</p>
                   2093: 
1.80      mike     2094:   <hr>
                   2095: 
                   2096:   <p>If a row has a child count that isn't zero, then the user agent
1.1       mike     2097:   should offer to the user the option of opening and closing the
                   2098:   row.</p>
                   2099: 
                   2100:   <p>When a row is opened, if the row's row count is greater than
                   2101:   zero, then the user agent must increase the
1.80      mike     2102:   <span><code>datagrid</code> row count</span> and the row counts of
1.1       mike     2103:   any ancestor rows by the number of rows that the newly opened row
1.80      mike     2104:   has in its row count<!- - we should also "update the <span>pending
1.1       mike     2105:   <code>datagrid</code> rows list</span> and the <span>pending
1.80      mike     2106:   <code>datagrid</code> cells list</span> accordingly" - ->, then must
                   2107:   mark the row as open, then may fill in the <span>display order
                   2108:   sparse data tree</span> with any information that the user agent has
1.1       mike     2109:   cached about the display order positions of descendants of the newly
1.80      mike     2110:   opened row, and then must invoke the <code
                   2111:   title="dom-listener-rowOpened">rowOpened()</code> method on the
                   2112:   current <code title="dom-datagrid-listener">listener</code> with as
                   2113:   its first argument a <code>RowID</code> object identifying the row
1.1       mike     2114:   that was opened and as its second argument the boolean false, and
1.80      mike     2115:   then must invoke the <span><code>datagrid</code> update display
                   2116:   algorithm</span>.</p>
1.1       mike     2117: 
                   2118:   <p>On the other hand, when a row is opened and the row's row count
1.80      mike     2119:   is &#x2212;1, then the user agent must mark the row as opening, and
                   2120:   then must invoke the <code
                   2121:   title="dom-listener-rowOpened">rowOpened()</code> method on the
                   2122:   current <code title="dom-datagrid-listener">listener</code> with as
                   2123:   its first argument a <code>RowID</code> object identifying the row
1.1       mike     2124:   that was opened and as its second argument the boolean true.</p>
                   2125: 
                   2126:   <p>When a row is closed, the user agent must decrease the
1.80      mike     2127:   <span><code>datagrid</code> row count</span> and the row counts of
1.1       mike     2128:   any ancestor rows by the number of rows that the newly closed row
1.80      mike     2129:   has in its row count, and then must invoke the <code
                   2130:   title="dom-listener-rowOpened">rowOpened()</code> method on the
                   2131:   current <code title="dom-datagrid-listener">listener</code> with as
                   2132:   its first and only argument a <code>RowID</code> object identifying
1.1       mike     2133:   the row that was opened.</p>
                   2134: 
                   2135: 
                   2136: 
1.80      mike     2137:   <h6>The cells</h6>
1.1       mike     2138: 
                   2139:   <p>Each row has one cell per column. Each cell has the same type as
1.80      mike     2140:   its column. The <dfn>allowed <code>datagrid</code> column
1.1       mike     2141:   types</dfn>, what they represent, and the requirements for when the
                   2142:   user interacts with them, are as follows:</p>
                   2143: 
1.80      mike     2144:   <dl>
                   2145: 
                   2146:    <dt><dfn title="datagrid-type-text"><code>text</code></dfn></dt>
1.1       mike     2147:    <dd>
                   2148: 
                   2149:     <p>The cell represents some text and an optional image.</p>
                   2150: 
                   2151:    </dd>
                   2152: 
1.80      mike     2153:    <dt><dfn title="datagrid-type-editable"><code>editable</code></dfn></dt>
1.1       mike     2154:    <dd>
                   2155: 
                   2156:     <p>The cells represents some editable text, an optional
1.80      mike     2157:     <code>datalist</code> giving autocompletion hints, and an
1.1       mike     2158:     optional image.</p>
                   2159: 
1.80      mike     2160:     <p>If there is a <code>datalist</code> element, the user agent
1.1       mike     2161:     should offer the suggestions represented by that element to the
1.80      mike     2162:     user. The user agent may use the suggestion's <span
                   2163:     title="concept-option-label">label</span> to identify the
1.1       mike     2164:     suggestion. If the user selects a suggestion, then the editable
1.80      mike     2165:     text must be set to the selected suggestion's <span
                   2166:     title="concept-option-value">value</span>, as if the user had
1.1       mike     2167:     written that value himself.</p>
                   2168: 
                   2169:     <p>When the user edits the value, either directly or using the
1.80      mike     2170:     <code>datalist</code>, the user agent must invoke the <code
                   2171:     title="dom-listener-cellChanged">cellChanged()</code> method on
                   2172:     the current <code title="dom-datagrid-listener">listener</code>
                   2173:     with as its first argument a <code>RowID</code> identifying the
1.1       mike     2174:     cell's row, as its second argument the identifier of the cell's
                   2175:     column, as its third argument the new value, and as its fourth
                   2176:     argument the previous value.</p>
                   2177: 
                   2178:    </dd>
                   2179: 
1.80      mike     2180:    <dt><dfn title="datagrid-type-checkable"><code>checkable</code></dfn></dt>
1.1       mike     2181:    <dd>
                   2182: 
                   2183:     <p>The cell represents some text, a check box that optionally has
                   2184:     its value obscured as indeterminate, and an optional image.</p>
                   2185: 
                   2186:     <p>When the user checks or unchecks the check box, the user agent
                   2187:     must change the check box's state appropriately and stop obscuring
                   2188:     the check box as indeterminate (if it is obscuring it), and then
1.80      mike     2189:     must invoke the <code
                   2190:     title="dom-listener-cellChanged">cellChanged()</code> method on
                   2191:     the current <code title="dom-datagrid-listener">listener</code>
                   2192:     with as its first argument a <code>RowID</code> identifying the
1.1       mike     2193:     cell's row, as its second argument the identifier of the cell's
                   2194:     column, as its third argument true if the check box is now checked
                   2195:     and false otherwise, and as its fourth argument true if the check
                   2196:     box was previously checked and false otherwise.</p>
                   2197: 
                   2198:    </dd>
                   2199: 
1.80      mike     2200:    <dt><dfn title="datagrid-type-list"><code>list</code></dfn></dt>
1.1       mike     2201:    <dd>
                   2202: 
                   2203:     <p>The cell represents some text giving the current value selected
1.80      mike     2204:     from a dropdown list of options, a <code>select</code> element
1.1       mike     2205:     giving the list of options, and an optional image.</p>
                   2206: 
                   2207:     <p>The user agent should allow the user to change the value of the
1.80      mike     2208:     cell from its current value to one of the <span
                   2209:     title="concept-option-value">values</span> given by
                   2210:     <code>option</code> elements in the <span
                   2211:     title="concept-select-option-list">list of options</span> (if
                   2212:     any). The user agent may use the <code>option</code> elements'
                   2213:     <span title="concept-option-label">labels</span> to annotate each
1.1       mike     2214:     option.</p>
                   2215: 
1.80      mike     2216:     <p>When the user selects a new value from the <code>select</code>
                   2217:     element's <span title="concept-select-option-list">list of
                   2218:     options</span>, the user agent must invoke the <code
                   2219:     title="dom-listener-cellChanged">cellChanged()</code> method on
                   2220:     the current <code title="dom-datagrid-listener">listener</code>
                   2221:     with as its first argument a <code>RowID</code> identifying the
1.1       mike     2222:     cell's row, as its second argument the identifier of the cell's
                   2223:     column, as its third argument the new value, and as its fourth
                   2224:     argument the previous value.</p>
                   2225: 
                   2226:    </dd>
                   2227: 
1.80      mike     2228:    <dt><dfn title="datagrid-type-progress"><code>progress</code></dfn></dt>
1.1       mike     2229:    <dd>
                   2230: 
                   2231:     <p>The cell represents a (determinate) progress bar whose value is
                   2232:     between 0.0, indicating no progress, and 1.0, indicating the task
                   2233:     is complete.</p>
                   2234: 
                   2235:    </dd>
                   2236: 
1.80      mike     2237:    <dt><dfn title="datagrid-type-meter"><code>meter</code></dfn></dt>
1.1       mike     2238:    <dd>
                   2239: 
                   2240:     <p>The cell represents a gauge, described by one to six
                   2241:     numbers.</p>
                   2242: 
                   2243:     <p>The gauge's actual value is given by the first number.</p>
                   2244: 
                   2245:     <p>If there is a second number, then that number is the maximum
                   2246:     value. Otherwise, the maximum value is 1.0.</p>
                   2247: 
                   2248:     <p>If there is a third number, then that number is the minimum
                   2249:     value. Otherwise, the minimum value is 1.0.</p>
                   2250: 
                   2251:     <p>If there is a fourth number, then that number is the low
                   2252:     boundary. Otherwise, the low boundary is the minimum value.</p>
                   2253: 
                   2254:     <p>If there is a fifth number, then that number is the high
                   2255:     boundary. Otherwise, the high boundary is the maximum value.</p>
                   2256: 
                   2257:     <p>If there is a sixth number, then the optimal point is the sixth
                   2258:     number. Otherwise, the optimum point is the midpoint between the
                   2259:     minimum value and the maximum value.</p>
                   2260: 
1.80      mike     2261:     <!- - next two paragraphs copied from <meter>: - ->
1.1       mike     2262: 
                   2263:     <p>If the optimum point is equal to the low boundary or the high
                   2264:     boundary, or anywhere in between them, then the region between the
                   2265:     low and high boundaries of the gauge must be treated as the
                   2266:     optimum region, and the low and high parts, if any, must be
                   2267:     treated as suboptimal. Otherwise, if the optimum point is less
                   2268:     than the low boundary, then the region between the minimum value
                   2269:     and the low boundary must be treated as the optimum region, the
                   2270:     region between the low boundary and the high boundary must be
                   2271:     treated as a suboptimal region, and the region between the high
                   2272:     boundary and the maximum value must be treated as an even less
                   2273:     good region. Finally, if the optimum point is higher than the high
                   2274:     boundary, then the situation is reversed; the region between the
                   2275:     high boundary and the maximum value must be treated as the optimum
                   2276:     region, the region between the high boundary and the low boundary
                   2277:     must be treated as a suboptimal region, and the remaining region
                   2278:     between the low boundary and the minimum value must be treated as
                   2279:     an even less good region.</p>
                   2280: 
                   2281:     <p>User agents should indicate the relative position of the actual
                   2282:     value to the minimum and maximum values, and the relationship
                   2283:     between the actual value and the three regions of the gauge.</p>
                   2284: 
                   2285:    </dd>
                   2286: 
1.80      mike     2287:    <dt><dfn title="datagrid-type-custom"><code>custom</code></dfn></dt>
1.1       mike     2288:    <dd>
                   2289: 
                   2290:     <p>The cell represents a dynamically generated graphical image.</p>
                   2291: 
                   2292:     <p>The cell will have minimum dimensions (specified in CSS
                   2293:     pixels), and a callback (in the form of a
1.80      mike     2294:     <code>RenderingContext2DCallback</code> object) to get a rendering
1.1       mike     2295:     for the cell.</p>
                   2296: 
                   2297:     <p>The user agent should not allow the cell to be rendered with
                   2298:     dimensions less than the given minimum width and height.</p>
                   2299: 
                   2300:     <p>When the user agent needs to render the cell, the user agent
1.80      mike     2301:     must <span>queue a task</span> to invoke the
                   2302:     <span>RenderingContext2DCallback</span> callback, passing it a
                   2303:     newly created <code>CanvasRenderingContext2D</code> object whose
1.186     mike     2304:     <code title="dom-context-2d-canvas">canvas</code> IDL attribute is
1.1       mike     2305:     null as the first argument, the actual cell width in CSS pixels as
                   2306:     the second argument, and the actual cell height in CSS pixels as
                   2307:     the third argument.</p>
                   2308: 
                   2309:     <p>If the user agent is able to render graphics, then it must
                   2310:     render the graphics commands that the callback executed on the
1.80      mike     2311:     provided <code>CanvasRenderingContext2D</code> object onto the
1.1       mike     2312:     cell once the callback returns. The image must be clipped to the
                   2313:     dimensions of the cell. The coordinate space of the cell must be
                   2314:     aligned with that used by the 2D context such that the top left
                   2315:     corner of the cell is the 0,0 origin, with the coordinate space
                   2316:     increasing its <var title="">x</var> dimension towards the right
                   2317:     of the cell and its <var title="">y</var> axis towards the bottom
                   2318:     of the cell, and with the image not scaled (so that one CSS pixel
                   2319:     on the final rendering matches one CSS pixel in the coordinate
                   2320:     space used by the 2D context).</p>
                   2321: 
                   2322:     <p>The user agent must then decouple the
1.80      mike     2323:     <code>CanvasRenderingContext2D</code> object and any objects that
                   2324:     it created (such as <code>CanvasPattern</code> objects or
                   2325:     <code>ImageData</code> objects) from any real drawing surface.</p>
1.1       mike     2326: 
                   2327:     <p>If the user agent is unable to render graphics, then it must
                   2328:     render the text string returned by the callback instead.</p>
                   2329: 
                   2330:    </dd>
                   2331: 
1.80      mike     2332:   </dl>
                   2333: 
                   2334:   <hr>
                   2335: 
                   2336:   <p>When an algorithm requires the user agent to <dfn>apply a
1.1       mike     2337:   <code>Row</code> object</dfn>, the user agent must run the following
                   2338:   steps:</p>
                   2339: 
1.80      mike     2340:   <ol>
                   2341: 
                   2342:    <li>
                   2343: 
                   2344:     <p>If the value of the <code>Row</code> object's second entry is
                   2345:     not &#x2212;1, then run these substeps:</p>
1.1       mike     2346: 
1.80      mike     2347:     <ol>
1.1       mike     2348: 
1.80      mike     2349:      <li><p>If there is a row with the same parent as the row
                   2350:      specified by the <code>Row</code> object's <code>RowID</code>
1.1       mike     2351:      object, whose display order position is currently the same as the
1.80      mike     2352:      value of the <code>Row</code> object's second entry, then remove
                   2353:      that row from the <span>display order sparse data
                   2354:      tree</span>.</p></li>
1.1       mike     2355: 
                   2356:      <li><p>Set the display order position of the row specified by the
1.80      mike     2357:      <code>Row</code> object's <code>RowID</code> to the value of the
                   2358:      <code>Row</code> object's second entry, updating its position in
                   2359:      the <span>display order sparse data tree</span>
1.1       mike     2360:      accordingly.</p></li>
                   2361: 
1.80      mike     2362:      <li><p>If the row is in the <span>pending
                   2363:      <code>datagrid</code> rows list</span>, remove it.</p></li>
                   2364: 
                   2365:     </ol>
1.1       mike     2366: 
1.80      mike     2367:    </li>
1.1       mike     2368: 
                   2369:    <li>
                   2370: 
1.80      mike     2371:     <p>If the fourth entry in the <code>Row</code> object (a
                   2372:     <code>CellList</code> object, an array) is not empty, then for
                   2373:     each <code>Cell</code> object in that array update the cell that
1.1       mike     2374:     corresponds to the column identified by the value of the first
1.80      mike     2375:     entry of the <code>Cell</code> object, by using the appropriate
1.1       mike     2376:     set of steps given below as determined by the type of the
1.80      mike     2377:     column. Then, if the cell is in the <span>pending
                   2378:     <code>datagrid</code> cells list</span>, remove it.</p>
1.1       mike     2379: 
1.80      mike     2380:     <dl>
                   2381: 
                   2382:      <dt>If the column's type is <code title="datagrid-type-text">text</code></dt>
1.1       mike     2383:      <dd>
                   2384: 
                   2385:       <p>Update the cell's text to the value given in the
1.80      mike     2386:       <code>Cell</code> object's second entry.</p>
1.1       mike     2387: 
1.80      mike     2388:       <p>If the <code>Cell</code> object has three entries, then copy
                   2389:       the image data from the <code>img</code> element given in the
1.1       mike     2390:       third entry, and let the cell's image be given by that image
                   2391:       data. Otherwise, update the cell to have no image.</p>
                   2392: 
                   2393:      </dd>
                   2394: 
1.80      mike     2395:      <dt>If the column's type is <code title="datagrid-type-editable">editable</code></dt>
1.1       mike     2396:      <dd>
                   2397: 
                   2398:       <p>Update the cell's text to the value given in the
1.80      mike     2399:       <code>Cell</code> object's second entry.</p>
1.1       mike     2400: 
1.80      mike     2401:       <p>If the <code>Cell</code> object has three entries, then let
                   2402:       the <code>datalist</code> element given in the third entry be
                   2403:       the <code>datalist</code> element giving autocompletion
1.1       mike     2404:       hints. Otherwise, update the cell to have no
1.80      mike     2405:       <code>datalist</code> element.</p>
1.1       mike     2406: 
1.80      mike     2407:       <p>If the <code>Cell</code> object has four entries, then copy
                   2408:       the image data from the <code>img</code> element given in the
1.1       mike     2409:       fourth entry, and let the cell's image be given by that image
                   2410:       data. Otherwise, update the cell to have no image.</p>
                   2411: 
                   2412:      </dd>
                   2413: 
1.80      mike     2414:      <dt>If the column's type is <code title="datagrid-type-checkable">checkable</code></dt>
1.1       mike     2415:      <dd>
                   2416: 
                   2417:       <p>Update the cell's text to the value given in the
1.80      mike     2418:       <code>Cell</code> object's second entry.</p>
1.1       mike     2419: 
                   2420:       <p>Update the cell's checked state to match the value of the
                   2421:       third entry: checked if true, unchecked otherwise.</p>
                   2422: 
1.80      mike     2423:       <p>If the <code>Cell</code> object has four entries and the
1.1       mike     2424:       fourth entry is true, then update the cell to be obscured as
                   2425:       indeterminate. Otherwise, the cell's state is not obscured.</p>
                   2426: 
1.80      mike     2427:       <p>If the <code>Cell</code> object has five entries, then copy
                   2428:       the image data from the <code>img</code> element given in the
1.1       mike     2429:       fifth entry, and let the cell's image be given by that image
                   2430:       data. Otherwise, update the cell to have no image.</p>
                   2431: 
                   2432:      </dd>
                   2433: 
1.80      mike     2434:      <dt>If the column's type is <code title="datagrid-type-list">list</code></dt>
1.1       mike     2435:      <dd>
                   2436: 
                   2437:       <p>Update the cell's text to the value given in the
1.80      mike     2438:       <code>Cell</code> object's second entry, and the
                   2439:       <code>select</code> element to be the one given in the
                   2440:       <code>Cell</code> object's third entry</p>
1.1       mike     2441: 
1.80      mike     2442:       <p>If the <code>Cell</code> object has four entries, then copy
                   2443:       the image data from the <code>img</code> element given in the
1.1       mike     2444:       fourth entry, and let the cell's image be given by that image
                   2445:       data. Otherwise, update the cell to have no image.</p>
                   2446: 
                   2447:      </dd>
                   2448: 
1.80      mike     2449:      <dt>If the column's type is <code title="datagrid-type-progress">progress</code></dt>
1.1       mike     2450:      <dd>
                   2451: 
                   2452:       <p>Update the cell to be a progress bar whose progress, on the
                   2453:       scale of 0.0 (no progress) to 1.0 (task complete) is given by
1.80      mike     2454:       the value in the <code>Cell</code> object's second entry.</p>
1.1       mike     2455: 
                   2456:      </dd>
                   2457: 
1.80      mike     2458:      <dt>If the column's type is <code title="datagrid-type-meter">meter</code></dt>
1.1       mike     2459:      <dd>
                   2460: 
                   2461:       <p>Update the cell to be a gauge configured with the numbers
                   2462:       given by the second and subsequent entries of the
1.80      mike     2463:       <code>Cell</code> object.</p>
1.1       mike     2464: 
                   2465:      </dd>
                   2466: 
1.80      mike     2467:      <dt>If the column's type is <code title="datagrid-type-custom">custom</code></dt>
1.1       mike     2468:      <dd>
                   2469: 
                   2470:       <p>Update the cell's minimum width to be the length in CSS
1.80      mike     2471:       pixels given by the <code>Cell</code> object's second entry.</p>
1.1       mike     2472: 
                   2473:       <p>Update the cell's minimum height to be the length in CSS
1.80      mike     2474:       pixels given by the <code>Cell</code> object's third entry.</p>
1.1       mike     2475: 
                   2476:       <p>Update the cell's callback to be the
1.80      mike     2477:       <code>RenderingContext2DCallback</code> object given by the
                   2478:       <code>Cell</code> object's fourth entry.</p>
1.1       mike     2479: 
                   2480:      </dd>
                   2481: 
1.80      mike     2482:     </dl>
                   2483: 
                   2484:    </li>
1.1       mike     2485: 
1.80      mike     2486:   </ol>
                   2487: 
                   2488:   <hr>
                   2489: 
                   2490:   <p>When the user agent is to run the <dfn><code>datagrid</code>
                   2491:   update display algorithm</dfn>, the user agent must invoke the <code
                   2492:   title="dom-listener-getRows">getRows()</code> and <code
                   2493:   title="dom-listener-getCells">getCells()</code> methods on the
                   2494:   current <code title="dom-datagrid-listener">listener</code> such
                   2495:   that all the current visible rows in the <span>display order sparse
                   2496:   data list</span>, and all the cells in the currently visible columns
1.1       mike     2497:   on all the currently visible rows, have been covered.</p>
                   2498: 
1.80      mike     2499:   <p>A row is considered covered if it is present in the <span>pending
                   2500:   <code>datagrid</code> rows list</span>, or if the <code
                   2501:   title="dom-listener-getRows">getRows()</code> method is invoked with
1.1       mike     2502:   a range that includes the row in question.</p>
                   2503: 
                   2504:   <p>A cell is considered covered if it is present in the
1.80      mike     2505:   <span>pending <code>datagrid</code> cells list</span>, or if the
                   2506:   <code title="dom-listener-getRows">getRows()</code> method is
1.1       mike     2507:   invoked with a range that includes the row in question and a list of
1.80      mike     2508:   columns that includes the cell's column, or if the <code
                   2509:   title="dom-listener-getCells">getCells()</code> method is invoked
1.1       mike     2510:   with a list of rows and columns that intersects the cell in
1.80      mike     2511:   question. However, the <code
                   2512:   title="dom-listener-getCells">getCells()</code> method can only be
                   2513:   used if the row is already present in the <span>display order sparse
                   2514:   data list</span>.</p>
1.1       mike     2515: 
1.80      mike     2516:   <p>The <code title="dom-listener-getRows">getRows()</code> method,
1.1       mike     2517:   if used, must be invoked with five arguments. The first argument
1.80      mike     2518:   must be the index in the <span>display order sparse data list</span>
1.1       mike     2519:   to the first row that the user agent is requesting, known as the
                   2520:   <i>anchor row</i>. The second argument must be the number of
                   2521:   consecutive cells for which the user agent is requesting
1.80      mike     2522:   information. The third argument must be the <code>RowID</code> of
                   2523:   the row that is the nearest ancestor in the <span>display order
                   2524:   sparse data <em>tree</em></span> of the anchor row. If this is the
                   2525:   <code>datagrid</code>, then the <code>RowID</code> object must be an
1.1       mike     2526:   empty array. The fourth argument must be the display order position
1.80      mike     2527:   of the anchor row in the <span>display order sparse data
                   2528:   tree</span>, assuming that the row identified in the third argument
1.1       mike     2529:   is indeed the anchor row's parent row. The fifth and final argument
                   2530:   must be an array of the identifiers of the columns for which the
                   2531:   user agent is requesting information, in the order they were added
1.80      mike     2532:   to the <code>datagrid</code>.</p>
1.1       mike     2533: 
1.80      mike     2534:   <p>As the <code title="dom-listener-getRows">getRows()</code> method
                   2535:   is invoked, the <span>pending <code>datagrid</code> rows list</span>
1.1       mike     2536:   must be updated to include the rows for which information has been
                   2537:   requested, excluding rows for which information is already
1.80      mike     2538:   available; and the <span>pending <code>datagrid</code> cells
                   2539:   list</span> must be updated to include the cells for which
1.1       mike     2540:   information has been requested on those rows.</p>
                   2541: 
1.80      mike     2542:   <p>The <code title="dom-listener-getCells">getCells()</code> method,
1.1       mike     2543:   if used, must be invoked with two arguments. The first argument must
1.80      mike     2544:   be an array of <code>RowID</code> objects identifying the rows for
1.1       mike     2545:   which information is being requested. The second argument must be an
                   2546:   array of the identifiers of the columns for which the user agent is
                   2547:   requesting information, in the order they were added to the
1.80      mike     2548:   <code>datagrid</code>.</p>
1.1       mike     2549: 
1.80      mike     2550:   <p>As the <code title="dom-listener-getCells">getCells()</code>
                   2551:   method is invoked, the <span>pending <code>datagrid</code> cells
                   2552:   list</span> must be updated to include the cells for which
1.1       mike     2553:   information has been requested.</p>
                   2554: 
                   2555:   <p>Calls to these methods should be batched so that the rows and
                   2556:   cells to be covered are handled by the fewest number of calls to
                   2557:   these methods as possible. To this end, user agents may invoke the
1.80      mike     2558:   <code title="dom-listener-getRows">getRows()</code> method for a set
1.1       mike     2559:   of rows that includes some rows that are already in the
1.80      mike     2560:   <span>display order sparse data list</span>, and similarly may
                   2561:   invoke the <code title="dom-listener-getCells">getCells()</code>
1.1       mike     2562:   method with row/column combinations that cover some cells for which
                   2563:   data is already known. Generally, however, user agents should avoid
                   2564:   invoking these methods with arguments that cause information to be
                   2565:   requested when it has already been requested or is already
                   2566:   known.</p>
                   2567: 
                   2568:   <div class="example">
                   2569: 
                   2570:    <p>For example, consider a case represented by the following table,
                   2571:    where the cells marked "Yes" indicate that the data has already
                   2572:    been obtained, the cells marked "Pending" indicate that the data
                   2573:    has been previously requested but not yet obtained, and the cells
                   2574:    with just a dash indicate that no information has ever been
                   2575:    obtained, or any information that had been obtained has now been
                   2576:    discarded.</p>
                   2577: 
1.80      mike     2578:    <table>
                   2579:     <tr> <td>        <th> Row   <th> Column A  <th> Column B
                   2580:     <tr> <th> Row 1  <td> -     <td> -         <td> -
                   2581:     <tr> <th> Row 2  <td> Yes   <td> Yes       <td> Yes
                   2582:     <tr> <th> Row 3  <td> Yes   <td> Yes       <td> Yes
                   2583:     <tr> <th> Row 4  <td> Yes   <td> Yes       <td> Yes
                   2584:     <tr> <th> Row 5  <td> -     <td> -         <td> -
                   2585:     <tr> <th> Row 6  <td> -     <td> -         <td> -
                   2586:     <tr> <th> Row 7  <td> Yes   <td> Pending   <td> -
                   2587:     <tr> <th> Row 8  <td> Yes   <td> Pending   <td> Pending
                   2588:    </table>
                   2589: 
                   2590:    <p>Thus, rows 2, 3, 4, 7, and 8 are already covered, as are the
1.1       mike     2591:    cells from those rows except for the cell in column B of row 7.</p>
                   2592: 
                   2593:    <p>Now consider what happens if all of these rows become visible at
                   2594:    once. The user agent has several choices, including (but not
                   2595:    limited to) the following:</p>
                   2596: 
1.80      mike     2597:    <ul>
                   2598: 
                   2599:     <li>Fire the <code title="dom-listener-getRows">getRows()</code>
1.1       mike     2600:     method for rows 1 through 8 and columns A and B all at once.</li>
                   2601: 
1.80      mike     2602:     <li>Fire the <code title="dom-listener-getRows">getRows()</code>
1.1       mike     2603:     method for row 1, then fire it again for rows 5 through 7.</li>
                   2604: 
1.80      mike     2605:     <li>Fire the <code title="dom-listener-getRows">getRows()</code>
1.1       mike     2606:     method for row 1, then fire it again for rows 5 and 6, and then
1.80      mike     2607:     fire the <code title="dom-listener-getCells">getCells()</code>
1.1       mike     2608:     method for row 7 column B.</li>
                   2609: 
1.80      mike     2610:    </ul>
                   2611: 
                   2612:    <p>All three options are allowed, but the latter two are preferable
1.1       mike     2613:    to the former, as they minimise the amount of redundant information
                   2614:    requested.</p>
                   2615: 
                   2616:    <p>In any case, the data model now looks like this:</p>
                   2617: 
1.80      mike     2618:    <table>
                   2619:     <tr> <td>        <th> Row     <th> Column A  <th> Column B  <th> Column C
                   2620:     <tr> <th> Row 1  <td> Pending <td> Pending   <td> Pending   <td> -
                   2621:     <tr> <th> Row 2  <td> Yes     <td> Yes       <td> Yes       <td> -
                   2622:     <tr> <th> Row 3  <td> Yes     <td> Yes       <td> Yes       <td> -
                   2623:     <tr> <th> Row 4  <td> Yes     <td> Yes       <td> Yes       <td> -
                   2624:     <tr> <th> Row 5  <td> Pending <td> Pending   <td> Pending   <td> -
                   2625:     <tr> <th> Row 6  <td> Pending <td> Pending   <td> Pending   <td> -
                   2626:     <tr> <th> Row 7  <td> Yes     <td> Pending   <td> Pending   <td> -
                   2627:     <tr> <th> Row 8  <td> Yes     <td> Pending   <td> Pending   <td> -
                   2628:    </table>
                   2629: 
                   2630:    <p>Now consider the case where a third column, column C, is added
1.1       mike     2631:    to the data model. The user agent once again has several choices,
                   2632:    including (but not limited to) the following:</p>
                   2633: 
1.80      mike     2634:    <ul>
                   2635: 
                   2636:     <li>Fire the <code title="dom-listener-getRows">getRows()</code>
1.1       mike     2637:     method for rows 1 through 8 again, this time listing just column
                   2638:     C.</li>
                   2639: 
1.80      mike     2640:     <li>Fire the <code title="dom-listener-getRows">getRows()</code>
1.1       mike     2641:     method for row 1, then fire it again for rows 5 and 6, and then
1.80      mike     2642:     fire the <code title="dom-listener-getCells">getCells()</code>
1.1       mike     2643:     method for the other rows (in all three cases, listing just column
                   2644:     C).</li>
                   2645: 
1.80      mike     2646:    </ul>
                   2647: 
                   2648:    <p>The two options here are as bad as each other; the former
1.1       mike     2649:    involves a lot of overlap, but the latter involves a lot of method
                   2650:    calls. Unfortunately the user agent can't do the obvious thing,
1.80      mike     2651:    namely just to invoke the <code
                   2652:    title="dom-listener-getCells">getCells()</code> method for all the
1.1       mike     2653:    rows listing just column C, because it doesn't have the row
                   2654:    information for all the rows yet (rows 1, 5 and 6 are still
                   2655:    pending).</p>
                   2656: 
                   2657:    <p>In any case, the data model now looks like this:</p>
                   2658: 
1.80      mike     2659:    <table>
                   2660:     <tr> <td>        <th> Row     <th> Column A  <th> Column B  <th> Column C
                   2661:     <tr> <th> Row 1  <td> Pending <td> Pending   <td> Pending   <td> Pending
                   2662:     <tr> <th> Row 2  <td> Yes     <td> Yes       <td> Yes       <td> Pending
                   2663:     <tr> <th> Row 3  <td> Yes     <td> Yes       <td> Yes       <td> Pending
                   2664:     <tr> <th> Row 4  <td> Yes     <td> Yes       <td> Yes       <td> Pending
                   2665:     <tr> <th> Row 5  <td> Pending <td> Pending   <td> Pending   <td> Pending
                   2666:     <tr> <th> Row 6  <td> Pending <td> Pending   <td> Pending   <td> Pending
                   2667:     <tr> <th> Row 7  <td> Yes     <td> Pending   <td> Pending   <td> Pending
                   2668:     <tr> <th> Row 8  <td> Yes     <td> Pending   <td> Pending   <td> Pending
                   2669:    </table>
                   2670: 
                   2671:    <p>If at this point the user scrolls around anywhere within this
                   2672:    <code>datagrid</code>, the user agent won't fire the <code
                   2673:    title="dom-listener-getRows">getRows()</code> and <code
                   2674:    title="dom-listener-getCells">getCells()</code> methods, because
1.1       mike     2675:    all of the rows and cells are covered.</p>
                   2676: 
                   2677:    <p>Now consider the case where the user agent receives row
                   2678:    information, but no cell information, for rows 1, 5, and 6:</p>
                   2679: 
1.80      mike     2680:    <table>
                   2681:     <tr> <td>        <th> Row     <th> Column A  <th> Column B  <th> Column C
                   2682:     <tr> <th> Row 1  <td> Yes     <td> Pending   <td> Pending   <td> Pending
                   2683:     <tr> <th> Row 2  <td> Yes     <td> Yes       <td> Yes       <td> Pending
                   2684:     <tr> <th> Row 3  <td> Yes     <td> Yes       <td> Yes       <td> Pending
                   2685:     <tr> <th> Row 4  <td> Yes     <td> Yes       <td> Yes       <td> Pending
                   2686:     <tr> <th> Row 5  <td> Yes     <td> Pending   <td> Pending   <td> Pending
                   2687:     <tr> <th> Row 6  <td> Yes     <td> Pending   <td> Pending   <td> Pending
                   2688:     <tr> <th> Row 7  <td> Yes     <td> Pending   <td> Pending   <td> Pending
                   2689:     <tr> <th> Row 8  <td> Yes     <td> Pending   <td> Pending   <td> Pending
                   2690:    </table>
                   2691: 
                   2692:    <p>The user agent still won't fire any methods when the user
1.1       mike     2693:    scrolls, because the data is still covered. But if the script then
1.80      mike     2694:    calls the <code title="dom-datagrid-renotify">renotify()</code>
1.1       mike     2695:    method, the "Pending" flags would get reset, and the model would
                   2696:    now look like this:</p>
                   2697: 
1.80      mike     2698:    <table>
                   2699:     <tr> <td>        <th> Row     <th> Column A  <th> Column B  <th> Column C
                   2700:     <tr> <th> Row 1  <td> Yes     <td> -         <td> -         <td> -
                   2701:     <tr> <th> Row 2  <td> Yes     <td> Yes       <td> Yes       <td> -
                   2702:     <tr> <th> Row 3  <td> Yes     <td> Yes       <td> Yes       <td> -
                   2703:     <tr> <th> Row 4  <td> Yes     <td> Yes       <td> Yes       <td> -
                   2704:     <tr> <th> Row 5  <td> Yes     <td> -         <td> -         <td> -
                   2705:     <tr> <th> Row 6  <td> Yes     <td> -         <td> -         <td> -
                   2706:     <tr> <th> Row 7  <td> Yes     <td> -         <td> -         <td> -
                   2707:     <tr> <th> Row 8  <td> Yes     <td> -         <td> -         <td> -
                   2708:    </table>
                   2709: 
                   2710:    <p>Now, assuming that all eight rows and all three columns are
1.1       mike     2711:    still visible, the user agent has the following choices (amongst
                   2712:    others):</p>
                   2713: 
1.80      mike     2714:    <ul>
                   2715: 
                   2716:     <li>Fire the <code title="dom-listener-getRows">getCells()</code>
1.1       mike     2717:     method for rows 1 through 8, listing all three columns.</li>
                   2718: 
1.80      mike     2719:     <li>Fire the <code title="dom-listener-getRows">getCells()</code>
1.1       mike     2720:     method for rows 1 and 5 through 8, listing all three columns, and
                   2721:     then fire the method for rows 2 through 4, listing just column
                   2722:     C.</li>
                   2723: 
1.80      mike     2724:     <li>Fire the <code title="dom-listener-getRows">getCells()</code>
1.1       mike     2725:     method for rows 1 and 5 through 8, listing just columns A abd B,
                   2726:     and then fire the method for rows 1 through 8, listing just column
                   2727:     C.</li>
                   2728: 
1.80      mike     2729:    </ul>
                   2730: 
                   2731:    <p>Here the latter two are preferable because they result in less
1.1       mike     2732:    overlap than the first.</p>
                   2733: 
                   2734:   </div>
                   2735: 
1.80      mike     2736:   <hr>
                   2737: 
                   2738:   <p>The <span>task source</span> for tasks queued on behalf of a
                   2739:   <code>datagrid</code> is the <span>DOM manipulation task
                   2740:   source</span>.</p>
                   2741: 
                   2742:   </div>
                   2743: 
                   2744: 
                   2745:   <h5>Listening to notifications from the <code>datagrid</code></h5>
1.1       mike     2746: 
1.80      mike     2747:   <p><i>The conformance criteria in this section apply to any
                   2748:   implementation of the <code>DataGridListener</code> interface,
1.1       mike     2749:   including (and most commonly) the content author's
1.80      mike     2750:   implementation(s).</i></p>
                   2751: 
                   2752:   <pre class="idl">// To be implemented by Web authors as a JS object
1.81      mike     2753: [NoInterfaceObject]
                   2754: interface <dfn>DataGridListener</dfn> {
1.80      mike     2755:   void <span title="dom-listener-initialize">initialize</span>(in <span>HTMLDataGridElement</span> datagrid);
                   2756: 
                   2757:   void <span title="dom-listener-getRows">getRows</span>(in unsigned long rowIndex, in unsigned long rowCount, in <span>RowID</span> parentRow, in unsigned long position, in <span>ColumnList</span> columns);
                   2758:   void <span title="dom-listener-getCells">getCells</span>(in <span>RowIDList</span> rows, in <span>ColumnList</span> columns);
                   2759:   void <span title="dom-listener-rowOpened">rowOpened</span>(in <span>RowID</span> row, in boolean rowCountNeeded);
                   2760:   void <span title="dom-listener-rowClosed">rowClosed</span>(in <span>RowID</span> row);
                   2761: 
                   2762:   void <span title="dom-listener-cellChanged">cellChanged</span>(in <span>RowID</span> row, in <span>Column</span> column, in any newValue, in any prevValue);
                   2763:   <span>HTMLMenuElement</span> <span title="dom-listener-getRowMenu">getRowMenu</span>(in <span>RowID</span> row);
                   2764: <!- -vsDGDND
1.1       mike     2765:   boolean <span title="dom-listener-canDrop">canDrop</span>(in <span>RowID</span> row, in <span>RowID</span> position, data);
                   2766:   boolean <span title="dom-listener-dropped">dropped</span>(in <span>RowID</span> row, in <span>RowID</span> position, data);
1.80      mike     2767: - -><!- -v2DGPA
1.1       mike     2768:   void <span title="dom-listener-performAction">performAction</span>(in <span>RowID</span> row, in DOMString action);
1.80      mike     2769: - ->};</pre>
                   2770: 
                   2771:   <p>The <code>DataGridListener</code> interface, once implemented by
                   2772:   an object in a script and hooked up to a <code>datagrid</code> using
1.186     mike     2773:   the <code title="dom-datagrid-listener">listener</code> IDL
1.80      mike     2774:   attribute, receives notifications when the <code>datagrid</code>
                   2775:   needs information (such as which rows exist) for display.</p>
                   2776: 
                   2777:   <p>The following methods may be usefully implemented:</p>
                   2778: 
                   2779:   <dl>
                   2780: 
                   2781:    <dt><dfn title="dom-listener-initialize"><code>initialize(<var title="">datagrid</var>)</code></dfn></dt>
1.1       mike     2782: 
                   2783:    <dd>
                   2784: 
1.80      mike     2785:     <p>Called by the <code>datagrid</code> element (the one given by
                   2786:     the <var title="">datagrid</var> argument) when the <code
                   2787:     title="dom-datagrid-listener">listener</code> attribute is
1.1       mike     2788:     set.</p>
                   2789: 
                   2790:    </dd>
                   2791: 
1.80      mike     2792:    <dt><dfn title="dom-listener-getRows"><code>getRows(<var title="">rowIndex</var>, <var title="">rowCount</var>, <var title="">parentRow</var>, <var title="">position</var>, <var title="">columns</var>)</code></dfn></dt>
1.1       mike     2793: 
                   2794:    <dd>
                   2795: 
1.80      mike     2796:     <p>Called by the <code>datagrid</code> element when the user agent
1.1       mike     2797:     finds itself needing to render rows for which it is lacking
                   2798:     information.</p>
                   2799: 
                   2800:     <p>The <var title="">rowIndex</var> argument gives the flattened
                   2801:     index of the first row for which it needs information, ignoring
1.80      mike     2802:     the tree structure of the <code>datagrid</code> model, where zero
1.1       mike     2803:     is the first row of the entire tree.</p>
                   2804: 
                   2805:     <p>The <var title="">rowCount</var> argument gives the number of
                   2806:     rows for which the user agent would like information.</p>
                   2807: 
                   2808:     <p>The <var title="">parentRow</var> argument gives the
1.80      mike     2809:     <code>RowID</code> object identifying the nearest ancestor of the
1.1       mike     2810:     first row that the user agent is aware of. After the sort order
                   2811:     has changed, this will typically be the root of the tree
1.80      mike     2812:     (identified by a <code>RowID</code> object consisting of an empty
1.1       mike     2813:     array).
                   2814: 
1.80      mike     2815:     <p>The <var title="">columns</var> argument gives the columns for
1.1       mike     2816:     which the user agent is lacking information, as an array of column
1.80      mike     2817:     identifiers (as passed to <code
                   2818:     title="dom-datagrid-addColumn">addColumn()</code>).</p>
1.1       mike     2819: 
                   2820:    </dd>
                   2821: 
1.80      mike     2822:    <dt><dfn title="dom-listener-getCells"><code>getCells(<var title="">rows</var>, <var title="">columns</var>)</code></dfn></dt>
1.1       mike     2823: 
                   2824:    <dd>
                   2825: 
1.80      mike     2826:     <p>Called by the <code>datagrid</code> element when the user agent
1.1       mike     2827:     finds itself needing to render cells for which it is lacking
                   2828:     information in rows that it does know about.</p>
                   2829: 
                   2830:     <p>The <var title="">rows</var> argument gives an array of
1.80      mike     2831:     <code>RowID</code> objects identifying the various rows for which
1.1       mike     2832:     the user agent is lacking information.</p>
                   2833: 
                   2834:     <p>The <var title="">columns</var> argument gives the columns for
                   2835:     which the user agent is lacking information, as an array of column
1.80      mike     2836:     identifiers (as passed to <code
                   2837:     title="dom-datagrid-addColumn">addColumn()</code>).</p>
1.1       mike     2838: 
                   2839:    </dd>
                   2840: 
1.80      mike     2841:    <dt><dfn title="dom-listener-rowOpened"><code>rowOpened(<var title="">row</var>, <var title="">rowCountNeeded</var>)</code></dfn></dt>
1.1       mike     2842: 
                   2843:    <dd>
                   2844: 
1.80      mike     2845:     <p>Called by the <code>datagrid</code> element when the user has
1.1       mike     2846:     opened a row.</p>
                   2847: 
                   2848:     <p>The <var title="">row</var> argument gives an
1.80      mike     2849:     <code>RowID</code> object identifying the row that was opened.</p>
1.1       mike     2850: 
                   2851:     <p>If the user agent also knows how many children that row has,
                   2852:     then the <var title="">rowCountNeeded</var> argument will be
                   2853:     false. Otherwise, the argument will be true, and the row will
1.80      mike     2854:     remain closed until the <code
                   2855:     title="dom-datagrid-setRows">setRows()</code> method is called
1.1       mike     2856:     with an accurate row count.</p>
                   2857: 
                   2858:    </dd>
                   2859: 
1.80      mike     2860:    <dt><dfn title="dom-listener-rowClosed"><code>rowClosed(<var title="">row</var>)</code></dfn></dt>
1.1       mike     2861: 
                   2862:    <dd>
                   2863: 
1.80      mike     2864:     <p>Called by the <code>datagrid</code> element when the user has
1.1       mike     2865:     opened a row.</p>
                   2866: 
                   2867:     <p>The <var title="">row</var> argument gives an
1.80      mike     2868:     <code>RowID</code> object identifying the row that was closed.</p>
1.1       mike     2869: 
                   2870:    </dd>
                   2871: 
1.80      mike     2872:    <dt><dfn title="dom-listener-cellChanged"><code>cellChanged(<var title="">row</var>, <var title="">column</var>, <var title="">newValue</var>, <var title="">prevValue</var>)</code></dfn></dt>
1.1       mike     2873: 
                   2874:    <dd>
                   2875: 
1.80      mike     2876:     <p>Called by the <code>datagrid</code> element when the user has
1.1       mike     2877:     edited a cell or checked a check box in a cell.</p>
                   2878: 
                   2879:     <p>The <var title="">row</var> argument gives an
1.80      mike     2880:     <code>RowID</code> object identifying the row of the cell, and the
1.1       mike     2881:     <var title="">column</var> argument gives the identifier of the
                   2882:     cell's column.</p>
                   2883: 
                   2884:     <p>The <var title="">newValue</var> argument gives the new value,
                   2885:     and the <var title="">prevValue</var> argument gives the previous
                   2886:     value.</p>
                   2887: 
                   2888:    </dd>
                   2889: 
1.80      mike     2890:    <dt><dfn title="dom-listener-getRowMenu"><code>getRowMenu(<var title="">row</var>)</code></dfn></dt>
1.1       mike     2891: 
1.80      mike     2892:    <dd>Must return an <code>HTMLMenuElement</code> object that is to
1.1       mike     2893:    be used as a context menu for row <var title="">row</var>, or null
                   2894:    if there is no particular context menu. May be omitted if none of
                   2895:    the rows have a special context menu. As this method is called
                   2896:    immediately before showing the menu in question, no precautions
                   2897:    need to be taken if the return value of this method changes.</dd>
                   2898: 
1.80      mike     2899:    <!- -v2DGDND, v2DFPA- ->
1.1       mike     2900: 
1.80      mike     2901:   </dl>
                   2902: 
                   2903:   <div class="impl">
1.1       mike     2904: 
1.80      mike     2905:   <p>Objects that implement the <code>DataGridListener</code>
1.1       mike     2906:   interface may omit any or all of the methods. When a method is
                   2907:   omitted, a user agent intending to call that method must instead
                   2908:   skip the method call, and must assume that the method's return value
                   2909:   is null.</p>
                   2910: 
1.80      mike     2911:   </div>
                   2912: 
                   2913: 
                   2914: 
                   2915: <!- - v2DGS: <datagrid> selection (search for the bits marked "..." to see what needs filling in, at a minimum)
1.1       mike     2916: 
                   2917:   <h5>The selection</h5>
                   2918: 
                   2919:   <pre class="idl">interface <dfn>DataGridSelection</dfn> {
                   2920:   readonly attribute unsigned long <span title="dom-DataGridSelection-length">length</span>;
1.81      mike     2921:   getter <span>RowID</span> <span title="dom-DataGridSelection-item">item</span>(in unsigned long index);
1.1       mike     2922:   boolean <span title="dom-DataGridSelection-isSelected">isSelected</span>(in <span>RowID</span> row);
                   2923:   void <span title="dom-DataGridSelection-setSelected">setSelected</span>(in <span>RowID</span> row, in boolean selected);
                   2924:   void <span title="dom-DataGridSelection-selectAll">selectAll</span>();
                   2925:   void <span title="dom-DataGridSelection-clear">clear</span>();
                   2926: };</pre>
                   2927: 
                   2928:   <dl class="domintro">
                   2929: 
                   2930:    ...
                   2931: 
                   2932:   </dl>
                   2933: 
                   2934:   <div class="impl">
                   2935: 
                   2936:   <p>Each <code>datagrid</code> element must keep track of which rows
                   2937:   are currently selected. Initially, no rows are selected. This can be
                   2938:   changed using the methods described in this section.</p>
                   2939: 
                   2940:   <p>The selection of a <code>datagrid</code> is represented by its
1.186     mike     2941:   <dfn title="dom-datagrid-selection"><code>selection</code></dfn> IDL
1.1       mike     2942:   attribute, which must be a <code>DataGridSelection</code> object.</p>
                   2943: 
                   2944:   <p><code>DataGridSelection</code> objects represent the rows in the
                   2945:   selection. In the selection the rows must be ordered in their
                   2946:   natural order (and not, e.g., the display order). A row with an
                   2947:   ancestor that is closed cannot be selected.</p>
                   2948: 
                   2949:   <p>The <dfn
                   2950:   title="dom-DataGridSelection-length"><code>length</code></dfn>
                   2951:   attribute must return the number of rows currently present in the
                   2952:   selection. This is the <var
                   2953:   title="dom-DataGridSelection-length">length</var>.</p>
                   2954: 
                   2955:   <p>The object's <span>indices of the supported indexed
                   2956:   properties</span> are the numbers in the range zero to <span title=""><var
                   2957:   title="dom-DataGridSelection-length">length</var>-1</span>, unless
                   2958:   the <var title="dom-DataGridSelection-length">length</var> is zero,
                   2959:   in which case there are no <span>supported indexed
                   2960:   properties</span>.</p>
                   2961: 
                   2962:   <p>The <dfn title="dom-DataGridSelection-item"><code>item(<var
                   2963:   title="">index</var>)</code></dfn> method must return a
                   2964:   <code>RowID</code> object identifying the <var
                   2965:   title="">index</var>th row in the selection. If the argument is out
                   2966:   of range (less than zero or greater than the number of selected rows
                   2967:   minus one), then it must raise an <code>INDEX_SIZE_ERR</code>
1.98      mike     2968:   exception. <a href="#refsDOMCORE">[DOMCORE]</a></p>
1.1       mike     2969: 
                   2970:   <p>The <dfn
                   2971:   title="dom-DataGridSelection-isSelected"><code>isSelected()</code></dfn>
                   2972:   method must return the selected state of the row specified by its
                   2973:   argument. If the specified row is in the <span>natural order sparse
                   2974:   data tree</span> and is selected, the method must return true,
                   2975:   otherwise it must return false.</p>
                   2976: 
                   2977:   <p>The <dfn
                   2978:   title="dom-DataGridSelection-setSelected"><code>setSelected()</code></dfn>
                   2979:   method takes two arguments, <var title="">row</var> and <var
                   2980:   title="">selected</var>. When invoked, it must set the selection
                   2981:   state of row <var title="">row</var> to selected if <var
                   2982:   title="">selected</var> is true, and unselected if it is false. If
                   2983:   <var title="">row</var> does not specify a row in the <span>natural
                   2984:   order sparse data tree</span> ...
                   2985: 
                   2986:   <p>The <dfn
                   2987:   title="dom-DataGridSelection-selectAll"><code>selectAll()</code></dfn>
                   2988:   method must ...
                   2989: 
                   2990:   <p>The <dfn
                   2991:   title="dom-DataGridSelection-clear"><code>clear()</code></dfn>
                   2992:   method must mark all the rows in the <code>datagrid</code> as not
                   2993:   selected. After a call to <code
                   2994:   title="dom-DataGridSelection-clear">clear()</code>, the <code
                   2995:   title="dom-DataGridSelection-length">length</code> attribute will
                   2996:   return zero.</p>
                   2997: 
                   2998:   <p>If the <code>datagrid</code> element has a <code
                   2999:   title="attr-datagrid-multiple">multiple</code> attribute, then the
                   3000:   user agent should allow the user to select any number of rows (zero
                   3001:   or more). If the attribute is not present, then the user agent
                   3002:   should allow the user to select a row, and must not allow the user
                   3003:   to select more than a single row at a time; selecting another one
                   3004:   must unselect all the other rows.</p>
                   3005: 
                   3006:   <p class="note">This only applies to the user. Scripts can select
                   3007:   multiple rows even when the <code
                   3008:   title="attr-datagrid-multiple">multiple</code> attribute is
                   3009:   absent.</p>
                   3010: 
                   3011:   ...event on selection change?...
                   3012: 
                   3013:   </div>
                   3014: 
                   3015:   <p class="note">The <code>DataGridSelection</code> interface has no
                   3016:   relation to the <code>Selection</code> interface.</p>
                   3017: 
1.80      mike     3018: - ->
                   3019: 
                   3020: 
                   3021: <!- -vsDGDND
1.1       mike     3022:   <h5>Drag and drop in <code>datagrid</code>s</h5>
                   3023: 
                   3024:   <p><i>This section only applies to interactive user agents.</i></p>
                   3025: 
                   3026:   ...define drag and drop in datagrids; selectiondraggable...
1.80      mike     3027: - ->
                   3028: 
1.1001    mike     3029: --><h4 id="the-command"><span class="secno">4.11.3 </span>The <dfn><code>command</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
1.987     mike     3030:    <dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
                   3031:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                   3032:    <dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
1.1002    mike     3033:    <dt>Contexts in which this element can be used:</dt>
1.987     mike     3034:    <dd>Where <a href="content-models.html#metadata-content">metadata content</a> is expected.</dd>
                   3035:    <dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected.</dd>
1.1       mike     3036:    <dt>Content model:</dt>
                   3037:    <dd>Empty.</dd>
                   3038:    <dt>Content attributes:</dt>
1.987     mike     3039:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
1.1       mike     3040:    <dd><code title="attr-command-type"><a href="#attr-command-type">type</a></code></dd>
                   3041:    <dd><code title="attr-command-label"><a href="#attr-command-label">label</a></code></dd>
                   3042:    <dd><code title="attr-command-icon"><a href="#attr-command-icon">icon</a></code></dd>
                   3043:    <dd><code title="attr-command-disabled"><a href="#attr-command-disabled">disabled</a></code></dd>
                   3044:    <dd><code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code></dd>
                   3045:    <dd><code title="attr-command-radiogroup"><a href="#attr-command-radiogroup">radiogroup</a></code></dd>
                   3046:    <!--<dd><code title="attr-command-default">default</code></dd>-->
                   3047:    <dd>Also, the <code title="attr-command-title"><a href="#attr-command-title">title</a></code> attribute has special semantics on this element.</dd>
                   3048:    <dt>DOM interface:</dt>
                   3049:    <dd>
1.987     mike     3050: <pre class="idl">interface <dfn id="htmlcommandelement">HTMLCommandElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
1.1       mike     3051:            attribute DOMString <a href="#dom-command-type" title="dom-command-type">type</a>;
                   3052:            attribute DOMString <a href="#dom-command-label" title="dom-command-label">label</a>;
                   3053:            attribute DOMString <a href="#dom-command-icon" title="dom-command-icon">icon</a>;
                   3054:            attribute boolean <a href="#dom-command-disabled" title="dom-command-disabled">disabled</a>;
                   3055:            attribute boolean <a href="#dom-command-checked" title="dom-command-checked">checked</a>;
                   3056:            attribute DOMString <a href="#dom-command-radiogroup" title="dom-command-radiogroup">radiogroup</a>;<!--
                   3057:            attribute boolean <span title="dom-command-default">default</span>;-->
                   3058: };</pre>
                   3059:    </dd>
                   3060:   </dl><p>The <code><a href="#the-command">command</a></code> element represents a command that the user
1.117     mike     3061:   can invoke.</p><p>The <dfn id="attr-command-type" title="attr-command-type"><code>type</code></dfn>
1.1       mike     3062:   attribute indicates the kind of command: either a normal command
                   3063:   with an associated action, or a state or option that can be toggled,
1.987     mike     3064:   or a selection of one item from a list of items.</p><p>The attribute is an <a href="common-microsyntaxes.html#enumerated-attribute">enumerated attribute</a> with three
1.289     mike     3065:   keywords and states. The "<dfn id="attr-command-type-keyword-command" title="attr-command-type-keyword-command"><code>command</code></dfn>"
                   3066:   keyword maps to the <a href="#attr-command-type-state-command" title="attr-command-type-state-command">Command</a> state, the
1.520     mike     3067:   "<dfn id="attr-command-type-keyword-checkbox" title="attr-command-type-keyword-checkbox"><code>checkbox</code></dfn>"
1.289     mike     3068:   keyword maps to the <a href="#attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</a> state, and
                   3069:   the "<dfn id="attr-command-type-keyword-radio" title="attr-command-type-keyword-radio"><code>radio</code></dfn>"
1.1       mike     3070:   keyword maps to the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a> state. The
1.117     mike     3071:   <i>missing value default</i> is the <a href="#attr-command-type-state-command" title="attr-command-type-state-command">Command</a> state.</p><dl><dt>The <dfn id="attr-command-type-state-command" title="attr-command-type-state-command">Command</dfn> state</dt>
1.1       mike     3072: 
1.987     mike     3073:    <dd><p>The element <a href="rendering.html#represents">represents</a> a normal command with an associated action.</p></dd>
1.1       mike     3074: 
                   3075:    <dt>The <dfn id="attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</dfn> state</dt>
                   3076: 
1.987     mike     3077:    <dd><p>The element <a href="rendering.html#represents">represents</a> a state or option that can be toggled.</p></dd>
1.1       mike     3078: 
                   3079:    <dt>The <dfn id="attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</dfn> state</dt>
                   3080: 
1.987     mike     3081:    <dd><p>The element <a href="rendering.html#represents">represents</a> a selection of one item from a list of items.</p></dd>
1.1       mike     3082: 
                   3083:   </dl><p>The <dfn id="attr-command-label" title="attr-command-label"><code>label</code></dfn>
1.718     mike     3084:   attribute gives the name of the command, as shown to the user. The
                   3085:   <code title="attr-command-label"><a href="#attr-command-label">label</a></code> attribute must be
                   3086:   specified and must have a value that is not the empty string.</p><p>The <dfn id="attr-command-title" title="attr-command-title"><code>title</code></dfn>
1.1       mike     3087:   attribute gives a hint describing the command, which might be shown
1.117     mike     3088:   to the user to help him.</p><p>The <dfn id="attr-command-icon" title="attr-command-icon"><code>icon</code></dfn>
1.1       mike     3089:   attribute gives a picture that represents the command. If the
                   3090:   attribute is specified, the attribute's value must contain a
1.987     mike     3091:   <a href="urls.html#valid-non-empty-url-potentially-surrounded-by-spaces">valid non-empty URL potentially surrounded by
                   3092:   spaces</a>. <span class="impl">To obtain the <a href="urls.html#absolute-url">absolute
1.913     mike     3093:   URL</a> of the icon when the attribute's value is not the empty
1.987     mike     3094:   string, the attribute's value must be <a href="urls.html#resolve-a-url" title="resolve a
1.913     mike     3095:   url">resolved</a> relative to the element. When the attribute is
1.987     mike     3096:   absent, or its value is the empty string, or <a href="urls.html#resolve-a-url" title="resolve a
1.913     mike     3097:   url">resolving</a> its value fails, there is no icon.</span></p><!-- this is affected by the base URL being changed, so users of
                   3098:   this should cache the image once they've fetched it once, at least
                   3099:   until the relative url changes again --><p>The <dfn id="attr-command-disabled" title="attr-command-disabled"><code>disabled</code></dfn> attribute
1.987     mike     3100:   is a <a href="common-microsyntaxes.html#boolean-attribute">boolean attribute</a> that, if present, indicates that
1.117     mike     3101:   the command is not available in the current state.</p><p class="note">The distinction between <code title="attr-command-disabled"><a href="#attr-command-disabled">disabled</a></code> and <code title="attr-hidden"><a href="editing.html#the-hidden-attribute">hidden</a></code> is subtle. A command would be
1.1       mike     3102:   disabled if, in the same context, it could be enabled if only
                   3103:   certain aspects of the situation were changed. A command would be
                   3104:   marked as hidden if, in that situation, the command will never be
                   3105:   enabled. For example, in the context menu for a water faucet, the
                   3106:   command "open" might be disabled if the faucet is already open, but
                   3107:   the command "eat" would be marked hidden since the faucet could
1.117     mike     3108:   never be eaten.</p><p>The <dfn id="attr-command-checked" title="attr-command-checked"><code>checked</code></dfn>
1.987     mike     3109:   attribute is a <a href="common-microsyntaxes.html#boolean-attribute">boolean attribute</a> that, if present,
1.1       mike     3110:   indicates that the command is selected. The attribute must be
                   3111:   omitted unless the <code title="attr-command-type"><a href="#attr-command-type">type</a></code>
                   3112:   attribute is in either the <a href="#attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</a> state or
                   3113:   the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a>
1.117     mike     3114:   state.</p><p>The <dfn id="attr-command-radiogroup" title="attr-command-radiogroup"><code>radiogroup</code></dfn>
1.1       mike     3115:   attribute gives the name of the group of commands that will be
                   3116:   toggled when the command itself is toggled, for commands whose <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute has the value "<code title="">radio</code>". The scope of the name is the child list of
1.117     mike     3117:   the parent element. The attribute must be omitted unless the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute is in the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a> state.</p><!--
1.1       mike     3118:   <p>If the <code>command</code> element is used when <span
                   3119:   title="menu generation">generating</span> a <span>context
                   3120:   menu</span>, then the <dfn
                   3121:   title="attr-command-default"><code>default</code></dfn> attribute
                   3122:   indicates, if present, that the command is the one that would have
                   3123:   been invoked if the user had directly activated the menu's subject
                   3124:   instead of using its context menu. The <code
                   3125:   title="attr-command-default">default</code> attribute is a
                   3126:   <span>boolean attribute</span>. The attribute must be omitted unless
                   3127:   the <code title="attr-command-type">type</code> attribute is in the
                   3128:   <span title="attr-command-type-state-command">Command</span>
                   3129:   state.</p>
                   3130: 
                   3131:   <div class="example">
                   3132: 
                   3133:    ...an example that shows an element that, if double-clicked,
                   3134:    invokes an action, but that also has a context menu, showing the
                   3135:    various <code>command</code> attributes off, and that has a default
                   3136:    command...
                   3137: 
                   3138:   </div>
1.117     mike     3139: --><div class="impl">
1.1       mike     3140: 
1.999     mike     3141:   <p>The <dfn id="dom-command-type" title="dom-command-type"><code>type</code></dfn> IDL
                   3142:   attribute must <a href="common-dom-interfaces.html#reflect">reflect</a> the content attribute of the
                   3143:   same name, <a href="common-dom-interfaces.html#limited-to-only-known-values">limited to only known values</a>.</p>
                   3144: 
                   3145:   <p>The <dfn id="dom-command-label" title="dom-command-label"><code>label</code></dfn>, <dfn id="dom-command-icon" title="dom-command-icon"><code>icon</code></dfn>, <dfn id="dom-command-disabled" title="dom-command-disabled"><code>disabled</code></dfn>, <dfn id="dom-command-checked" title="dom-command-checked"><code>checked</code></dfn>, and <dfn id="dom-command-radiogroup" title="dom-command-radiogroup"><code>radiogroup</code></dfn><!--,
1.1       mike     3146:   and <dfn title="dom-command-default"><code>default</code></dfn>-->
1.987     mike     3147:   IDL attributes must <a href="common-dom-interfaces.html#reflect">reflect</a> the respective content
1.1       mike     3148:   attributes of the same name.</p>
                   3149: 
1.987     mike     3150:   <p>The element's <a href="content-models.html#activation-behavior">activation behavior</a> depends on the
1.1       mike     3151:   value of the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute
                   3152:   of the element, as follows:</p>
                   3153: 
                   3154:   <dl class="switch"><dt>If the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute is
                   3155:    in the <a href="#attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</a> state</dt>
                   3156: 
                   3157:    <dd><p>If the element has a <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute, the UA must
                   3158:    remove that attribute. Otherwise, the UA must add a <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute, with the
                   3159:    literal value <code title="">checked</code>. The UA must then
1.788     mike     3160:    <a href="webappapis.html#fire-a-click-event">fire a <code title="event-click">click</code> event</a> at the
1.1       mike     3161:    element.</p></dd>
                   3162: 
                   3163: 
                   3164:    <dt>If the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute is
                   3165:    in the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a> state</dt>
                   3166: 
                   3167:    <dd><p>If the element has a parent, then the UA must walk the list
                   3168:    of child nodes of that parent element, and for each node that is a
                   3169:    <code><a href="#the-command">command</a></code> element, if that element has a <code title="attr-command-radiogroup"><a href="#attr-command-radiogroup">radiogroup</a></code> attribute whose
                   3170:    value exactly matches the current element's (treating missing <code title="attr-command-radiogroup"><a href="#attr-command-radiogroup">radiogroup</a></code> attributes as if
                   3171:    they were the empty string), and has a <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute, must remove
                   3172:    that attribute.</p>
                   3173: 
                   3174:    <p>Then, the element's <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute attribute
                   3175:    must be set to the literal value <code title="">checked</code> and
1.788     mike     3176:    the user agent must <a href="webappapis.html#fire-a-click-event">fire a <code title="event-click">click</code>
1.1       mike     3177:    event</a> at the element.</p></dd>
                   3178: 
                   3179: 
                   3180:    <dt>Otherwise</dt>
                   3181: 
1.987     mike     3182:    <dd><p>The element has no <a href="content-models.html#activation-behavior">activation behavior</a>.</p></dd>
1.1       mike     3183: 
1.875     mike     3184:   </dl><p class="note">Firing a synthetic <code title="event-click"><a href="infrastructure.html#event-click">click</a></code> event at the element does not cause
1.1       mike     3185:   any of the actions described above to happen.</p>
                   3186: 
                   3187:   <!-- v2COMMAND: the command="" attribute to make a <command> element
                   3188:   reflect the state of another command, so that the script can update
                   3189:   one place in the page and have context menus, toolbars, shortcuts,
                   3190:   etc, automatically update. Once we add this, expose the Triggers
                   3191:   facet again. -->
                   3192: 
1.117     mike     3193:   </div><p class="note"><code><a href="#the-command">command</a></code> elements are not rendered
1.520     mike     3194:   unless they <a href="#menus" title="menu">form part of a menu</a>.</p><div class="example">
                   3195: 
                   3196:    <p>Here is an example of a toolbar with three buttons that let the
                   3197:    user toggle between left, center, and right alignment. One could
                   3198:    imagine such a toolbar as part of a text editor. The toolbar also
                   3199:    has a separator followed by another button labeled "Publish",
                   3200:    though that button is disabled.</p>
                   3201: 
                   3202:    <pre>&lt;menu type="toolbar"&gt;
                   3203:  &lt;command type="radio" radiogroup="alignment" checked="checked"
                   3204:           label="Left" icon="icons/alL.png" onclick="setAlign('left')"&gt;
                   3205:  &lt;command type="radio" radiogroup="alignment"
                   3206:           label="Center" icon="icons/alC.png" onclick="setAlign('center')"&gt;
                   3207:  &lt;command type="radio" radiogroup="alignment"
                   3208:           label="Right" icon="icons/alR.png" onclick="setAlign('right')"&gt;
                   3209:  &lt;hr&gt;
                   3210:  &lt;command type="command" disabled
                   3211:           label="Publish" icon="icons/pub.png" onclick="publish()"&gt;
                   3212: &lt;/menu&gt;</pre>
                   3213: 
1.1001    mike     3214:   </div><h4 id="menus"><span class="secno">4.11.4 </span>The <dfn><code>menu</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
1.987     mike     3215:    <dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
                   3216:    <dd>If the element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#toolbar-state" title="toolbar state">toolbar</a> state: <a href="content-models.html#interactive-content">Interactive content</a>.</dd>
1.1002    mike     3217:    <dt>Contexts in which this element can be used:</dt>
1.987     mike     3218:    <dd>Where <a href="content-models.html#flow-content">flow content</a> is expected.</dd>
1.1       mike     3219:    <dt>Content model:</dt>
1.987     mike     3220:    <dd>Either: Zero or more <code><a href="grouping-content.html#the-li-element">li</a></code> elements.</dd>
                   3221:    <dd>Or: <a href="content-models.html#flow-content">Flow content</a>.</dd>
1.1       mike     3222:    <dt>Content attributes:</dt>
1.987     mike     3223:    <dd><a href="elements.html#global-attributes">Global attributes</a></dd>
1.1       mike     3224:    <dd><code title="attr-menu-type"><a href="#attr-menu-type">type</a></code></dd>
                   3225:    <dd><code title="attr-menu-label"><a href="#attr-menu-label">label</a></code></dd>
                   3226:    <dt>DOM interface:</dt>
                   3227:    <dd>
1.987     mike     3228: <pre class="idl">interface <dfn id="htmlmenuelement">HTMLMenuElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
1.1       mike     3229:            attribute DOMString <a href="#dom-menu-type" title="dom-menu-type">type</a>;
                   3230:            attribute DOMString <a href="#dom-menu-label" title="dom-menu-label">label</a>;
                   3231: };</pre>
1.117     mike     3232:   </dd></dl><p>The <code><a href="#menus">menu</a></code> element represents a list of commands.</p><!-- v2 idea: <menu> should get an icon, like <command> --><p>The <dfn id="attr-menu-type" title="attr-menu-type"><code>type</code></dfn> attribute
1.987     mike     3233:   is an <a href="common-microsyntaxes.html#enumerated-attribute">enumerated attribute</a> indicating the kind of menu
1.1       mike     3234:   being declared. The attribute has three states. The <code title="attr-menu-type-context">context</code> keyword maps to the
                   3235:   <dfn id="context-menu-state" title="context menu state">context menu</dfn> state, in which
                   3236:   the element is declaring a context menu. The <code title="attr-menu-type-toolbar">toolbar</code> keyword maps to the
1.385     mike     3237:   <dfn id="toolbar-state" title="toolbar state">toolbar</dfn> state, in which the
                   3238:   element is declaring a toolbar. The attribute may also be
1.1       mike     3239:   omitted. The <i>missing value default</i> is the <dfn id="list-state" title="list
                   3240:   state">list</dfn> state, which indicates that the element is merely
                   3241:   a list of commands that is neither declaring a context menu nor
1.385     mike     3242:   defining a toolbar.</p><p>If a <code><a href="#menus">menu</a></code> element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#context-menu-state" title="context menu state">context menu</a> state, then the
1.987     mike     3243:   element <a href="rendering.html#represents">represents</a> the commands of a context menu, and
1.1       mike     3244:   the user can only interact with the commands if that context menu is
1.385     mike     3245:   activated.</p><p>If a <code><a href="#menus">menu</a></code> element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#toolbar-state" title="toolbar state">toolbar</a> state, then the element
1.987     mike     3246:   <a href="rendering.html#represents">represents</a> a list of active commands that the user can
1.117     mike     3247:   immediately interact with.</p><p>If a <code><a href="#menus">menu</a></code> element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#list-state" title="list state">list</a> state, then the element either
1.987     mike     3248:   <a href="rendering.html#represents">represents</a> an unordered list of items (each represented
                   3249:   by an <code><a href="grouping-content.html#the-li-element">li</a></code> element), each of which represents a command
1.1       mike     3250:   that the user can perform or activate, or, if the element has no
1.987     mike     3251:   <code><a href="grouping-content.html#the-li-element">li</a></code> element children, <a href="content-models.html#flow-content">flow content</a>
1.117     mike     3252:   describing available commands.</p><p>The <dfn id="attr-menu-label" title="attr-menu-label"><code>label</code></dfn>
1.1       mike     3253:   attribute gives the label of the menu. It is used by user agents to
                   3254:   display nested menus in the UI. For example, a context menu
                   3255:   containing another menu would use the nested menu's <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute for the submenu's
1.117     mike     3256:   menu label.</p><div class="impl">
1.1       mike     3257: 
1.186     mike     3258:   <p>The <dfn id="dom-menu-type" title="dom-menu-type"><code>type</code></dfn> and <dfn id="dom-menu-label" title="dom-menu-label"><code>label</code></dfn> IDL attributes must
1.987     mike     3259:   <a href="common-dom-interfaces.html#reflect">reflect</a> the respective content attributes of the same
1.1       mike     3260:   name.</p>
                   3261: 
1.1001    mike     3262:   </div><h5 id="menus-intro"><span class="secno">4.11.4.1 </span>Introduction</h5><p><i>This section is non-normative.</i></p><p>The <code><a href="#menus">menu</a></code> element is used to define context menus and
1.385     mike     3263:   toolbars.</p><p>For example, the following represents a toolbar with three menu
1.148     mike     3264:   buttons on it, each of which has a dropdown menu with a series of
                   3265:   options:</p><pre>&lt;menu type="toolbar"&gt;
1.1       mike     3266:  &lt;li&gt;
                   3267:   &lt;menu label="File"&gt;
                   3268:    &lt;button type="button" onclick="fnew()"&gt;New...&lt;/button&gt;
                   3269:    &lt;button type="button" onclick="fopen()"&gt;Open...&lt;/button&gt;
1.290     mike     3270:    &lt;button type="button" onclick="fsave()"&gt;Save&lt;/button&gt;
1.1       mike     3271:    &lt;button type="button" onclick="fsaveas()"&gt;Save as...&lt;/button&gt;
                   3272:   &lt;/menu&gt;
                   3273:  &lt;/li&gt;
                   3274:  &lt;li&gt;
                   3275:   &lt;menu label="Edit"&gt;
                   3276:    &lt;button type="button" onclick="ecopy()"&gt;Copy&lt;/button&gt;
                   3277:    &lt;button type="button" onclick="ecut()"&gt;Cut&lt;/button&gt;
                   3278:    &lt;button type="button" onclick="epaste()"&gt;Paste&lt;/button&gt;
                   3279:   &lt;/menu&gt;
                   3280:  &lt;/li&gt;
                   3281:  &lt;li&gt;
                   3282:   &lt;menu label="Help"&gt;
                   3283:    &lt;li&gt;&lt;a href="help.html"&gt;Help&lt;/a&gt;&lt;/li&gt;
                   3284:    &lt;li&gt;&lt;a href="about.html"&gt;About&lt;/a&gt;&lt;/li&gt;
                   3285:   &lt;/menu&gt;
                   3286:  &lt;/li&gt;
1.1002    mike     3287: &lt;/menu&gt;</pre><p>In a supporting user agent, this might look like this:</p><p><img alt="A toolbar with three buttons, labeled 'File', 'Edit', and 'Help'; where if you select the 'Edit' button you get a drop-down menu with three more options, 'Copy', 'Cut', and 'Paste'." height="101" src="http://dev.w3.org/html5/spec/images/sample-toolbar-1.png" width="303"></p><p>In a legacy user agent, the above would look like a bulleted list
1.148     mike     3288:   with three items, the first of which has four buttons, the second of
                   3289:   which has three, and the third of which has two nested bullet points
                   3290:   with two items consisting of links.</p><hr><p>The following implements a similar toolbar, with a single button
                   3291:   whose values, when selected, redirect the user to Web sites.</p><pre>&lt;form action="redirect.cgi"&gt;
                   3292:  &lt;menu type="toolbar"&gt;
1.1       mike     3293:   &lt;label for="goto"&gt;Go to...&lt;/label&gt;
                   3294:   &lt;menu label="Go"&gt;
1.746     mike     3295:    &lt;select id="goto"<!--
1.1       mike     3296:            onchange="if (this.options[this.selectedIndex].value)
1.746     mike     3297:                      window.location = this.options[this.selectedIndex].value"-->&gt;
1.1       mike     3298:     &lt;option value="" selected="selected"&gt; Select site: &lt;/option&gt;
                   3299:     &lt;option value="http://www.apple.com/"&gt; Apple &lt;/option&gt;
                   3300:     &lt;option value="http://www.mozilla.org/"&gt; Mozilla &lt;/option&gt;
                   3301:     &lt;option value="http://www.opera.com/"&gt; Opera &lt;/option&gt;
                   3302:    &lt;/select&gt;
                   3303:    &lt;span&gt;&lt;input type="submit" value="Go"&gt;&lt;/span&gt;
                   3304:   &lt;/menu&gt;
                   3305:  &lt;/menu&gt;
1.148     mike     3306: &lt;/form&gt;</pre><p>The behavior in supporting user agents is similar to the example
1.875     mike     3307:   above, but here the legacy behavior consists of a single
1.987     mike     3308:   <code><a href="the-button-element.html#the-select-element">select</a></code> element with a submit button. The submit button
1.148     mike     3309:   doesn't appear in the toolbar, because it is not a direct child of
1.987     mike     3310:   the <code><a href="#menus">menu</a></code> element or of its <code><a href="grouping-content.html#the-li-element">li</a></code>
1.148     mike     3311:   children.</p><div class="impl">
1.1       mike     3312: 
1.1001    mike     3313:   <h5 id="building-menus-and-toolbars"><span class="secno">4.11.4.2 </span><dfn>Building menus and toolbars</dfn></h5>
1.1       mike     3314: 
1.385     mike     3315:   <p>A menu (or toolbar) consists of a list of zero or more of the
1.1       mike     3316:   following components:</p>
                   3317: 
1.987     mike     3318:   <ul class="brief"><li><a href="commands.html#concept-command" title="concept-command">Commands</a>, which can be marked as default commands</li>
1.1       mike     3319:    <li>Separators</li>
                   3320:    <li>Other menus (which allows the list to be nested)</li>
                   3321:   </ul><p>The list corresponding to a particular <code><a href="#menus">menu</a></code> element
                   3322:   is built by iterating over its child nodes. For each child node in
                   3323:   <a href="infrastructure.html#tree-order">tree order</a>, the required behavior depends on what the
                   3324:   node is, as follows:</p>
                   3325: 
1.987     mike     3326:   <dl class="switch"><dt>An element that <a href="commands.html#concept-command" title="concept-command">defines a command</a></dt>
1.1       mike     3327: 
1.987     mike     3328:    <dd>Append the command to the menu, respecting its <a href="commands.html#concept-facet" title="concept-facet">facets</a><!-- we might need to be
1.1       mike     3329:    explicit about what this means for each facet, if testing shows
                   3330:    this isn't well-implemented. e.g.: If there's an Icon facet for the
1.408     mike     3331:    command, it should be <span title="fetch">fetched</span> (this
                   3332:    would be http-origin privacy-sensitive), and then that image should
                   3333:    be associated with the command, such that each command only has its
                   3334:    image fetched once, to prevent changes to the base URL from having
                   3335:    effects after the image has been fetched once. (no need to resolve
                   3336:    the Icon facet, it's an absolute URL) -->. <!--If the element is a
                   3337:    <code>command</code> element with a <code
                   3338:    title="attr-command-default">default</code> attribute, mark the
                   3339:    command as being a default command.--></dd>
1.1       mike     3340: 
                   3341: 
1.987     mike     3342:    <dt>An <code><a href="grouping-content.html#the-hr-element">hr</a></code> element</dt>
                   3343:    <dt>An <code><a href="the-button-element.html#the-option-element">option</a></code> element that has a <code title="attr-option-value"><a href="the-button-element.html#attr-option-value">value</a></code> attribute set to the empty
                   3344:    string, and has a <code title="attr-option-disabled"><a href="the-button-element.html#attr-option-disabled">disabled</a></code> attribute, and whose
1.804     mike     3345:    <code><a href="infrastructure.html#textcontent">textContent</a></code> consists of a string of one or more
1.1       mike     3346:    hyphens (U+002D HYPHEN-MINUS)</dt>
                   3347: 
                   3348:    <dd>Append a separator to the menu.</dd>
                   3349: 
                   3350: 
1.987     mike     3351:    <dt>An <code><a href="grouping-content.html#the-li-element">li</a></code> element</dt>
1.1       mike     3352:    <dt>A <code><a href="forms.html#the-label-element">label</a></code> element</dt>
                   3353: 
                   3354:    <dd>Iterate over the children of the element.</dd>
                   3355: 
                   3356: 
                   3357:    <dt>A <code><a href="#menus">menu</a></code> element with no <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute</dt>
1.987     mike     3358:    <dt>A <code><a href="the-button-element.html#the-select-element">select</a></code> element</dt>
1.1       mike     3359: 
                   3360:    <dd>Append a separator to the menu, then iterate over the children
1.987     mike     3361:    of the <code><a href="#menus">menu</a></code> or <code><a href="the-button-element.html#the-select-element">select</a></code> element, then
1.1       mike     3362:    append another separator.</dd>
                   3363: 
                   3364:    <!-- v2: we might want to support <select> in <label> as giving a named submenu -->
                   3365: 
                   3366: 
                   3367:    <dt>A <code><a href="#menus">menu</a></code> element with a <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute</dt>
1.987     mike     3368:    <dt>An <code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element with a <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute</dt>
1.1       mike     3369: 
                   3370:    <dd>Append a submenu to the menu, using the value of the element's
                   3371:    <code title="">label</code> attribute as the label of the menu. The
                   3372:    submenu must be constructed by taking the element and creating a
                   3373:    new menu for it using the complete process described in this
                   3374:    section.</dd>
                   3375: 
                   3376: 
                   3377:    <dt>Any other node</dt>
                   3378: 
                   3379:    <dd><a href="infrastructure.html#ignore">Ignore</a> the node.</dd>
                   3380: 
                   3381:   </dl><p>Once all the nodes have been processed as described above, the
                   3382:   user agent must the post-process the menu as follows:</p>
                   3383: 
1.521     mike     3384:   <ol><li>Except for separators, any menu item with no label, or whose
                   3385:    label is the empty string, must be removed.</li>
1.1       mike     3386: 
1.521     mike     3387:    <li>Any sequence of two or more separators in a row must be
                   3388:    collapsed to a single separator.</li>
1.1       mike     3389: 
1.521     mike     3390:    <li>Any separator at the start or end of the menu must be
                   3391:    removed.</li>
1.1       mike     3392: 
1.1001    mike     3393:   </ol></div><h5 id="context-menus"><span class="secno">4.11.4.3 </span><dfn>Context menus</dfn></h5><p>The <dfn id="attr-contextmenu" title="attr-contextmenu"><code>contextmenu</code></dfn>
1.1       mike     3394:   attribute gives the element's <a href="#context-menus" title="context menus">context
1.1000    mike     3395:   menu</a>. The value must be the <a href="elements.html#concept-id" title="concept-id">ID</a> of a <code><a href="#menus">menu</a></code> element
1.1       mike     3396:   in the DOM. <span class="impl">If the node that would be obtained by
1.875     mike     3397:   the invoking the <code title="dom-Document-getElementById"><a href="infrastructure.html#dom-document-getelementbyid">getElementById()</a></code> method
                   3398:   using the attribute's value as the only argument is null or not a
1.1       mike     3399:   <code><a href="#menus">menu</a></code> element, then the element has no assigned context
                   3400:   menu. Otherwise, the element's assigned context menu is the element
1.117     mike     3401:   so identified.</span></p><div class="impl">
1.1       mike     3402: 
                   3403:   <p>When an element's context menu is requested (e.g. by the user
                   3404:   right-clicking the element, or pressing a context menu key), the UA
1.788     mike     3405:   must <a href="webappapis.html#fire-a-simple-event">fire a simple event</a> named <code title="event-contextmenu">contextmenu</code> that bubbles and is
1.1       mike     3406:   cancelable at the element for which the menu was requested.</p>
                   3407: 
                   3408:   <p class="note">Typically, therefore, the firing of the <code title="event-contextmenu">contextmenu</code> event will be the
                   3409:   default action of a <code title="mouseup">mouseup</code> or <code title="event-keyup">keyup</code> event. The exact sequence of events
                   3410:   is UA-dependent, as it will vary based on platform conventions.</p>
                   3411: 
                   3412:   <p>The default action of the <code title="event-contextmenu">contextmenu</code> event depends on
                   3413:   whether the element or one of its ancestors has a context menu
                   3414:   assigned (using the <code title="attr-contextmenu"><a href="#attr-contextmenu">contextmenu</a></code> attribute) or not. If
                   3415:   there is no context menu assigned, the default action must be for
                   3416:   the user agent to show its default context menu, if it has one.</p>
                   3417: 
                   3418:   <p>If the element or one of its ancestors <em>does</em> have a
1.788     mike     3419:   context menu assigned, then the user agent must <a href="webappapis.html#fire-a-simple-event">fire a simple
1.454     mike     3420:   event</a> named <code title="event-show">show</code> at the
1.1       mike     3421:   <code><a href="#menus">menu</a></code> element of the context menu of the nearest
                   3422:   ancestor (including the element itself) with one assigned.</p>
                   3423:   <!-- v2: include modifier key information -->
                   3424: 
                   3425:   <p>The default action of <em>this</em> event is that the user agent
1.385     mike     3426:   must show a context menu <a href="#building-menus-and-toolbars" title="building menus and
                   3427:   toolbars">built</a> from the <code><a href="#menus">menu</a></code> element.</p>
1.1       mike     3428: 
                   3429:   <p>The user agent may also provide access to its default context
                   3430:   menu, if any, with the context menu shown. For example, it could
                   3431:   merge the menu items from the two menus together, or provide the
                   3432:   page's context menu as a submenu of the default menu.</p>
                   3433: 
                   3434:   <p>If the user dismisses the menu without making a selection,
                   3435:   nothing in particular happens.</p>
                   3436: 
1.987     mike     3437:   <p>If the user selects a menu item that represents a <a href="commands.html#concept-command" title="concept-command">command</a>, then the UA must invoke
                   3438:   that command's <a href="commands.html#command-facet-action" title="command-facet-Action">Action</a>.</p>
1.1       mike     3439: 
                   3440:   <p>Context menus must not, while being shown, reflect changes in the
1.521     mike     3441:   DOM; they are constructed as the default action of the <code title="event-show">show</code> event and must remain as constructed
                   3442:   until dismissed.</p>
1.1       mike     3443: 
                   3444:   <p>User agents may provide means for bypassing the context menu
                   3445:   processing model, ensuring that the user can always access the UA's
                   3446:   default context menus. For example, the user agent could handle
                   3447:   right-clicks that have the Shift key depressed in such a way that it
                   3448:   does not fire the <code title="event-contextmenu">contextmenu</code>
                   3449:   event and instead always shows the default context menu.</p>
                   3450: 
                   3451:   <p>The <dfn id="dom-contextmenu" title="dom-contextMenu"><code>contextMenu</code></dfn>
1.987     mike     3452:   attribute must <a href="common-dom-interfaces.html#reflect">reflect</a> the <code title="attr-contextmenu"><a href="#attr-contextmenu">contextmenu</a></code> content attribute.</p>
1.1       mike     3453: 
1.520     mike     3454:   </div><div class="example">
                   3455: 
                   3456:    <p>Here is an example of a context menu for an input control:</p>
                   3457: 
                   3458:    <pre>&lt;form name="npc"&gt;
                   3459:  &lt;label&gt;Character name: &lt;input name=char type=text contextmenu=namemenu required&gt;&lt;/label&gt;
                   3460:  &lt;menu type=context id=namemenu&gt;
                   3461:   &lt;command label="Pick random name" onclick="document.forms.npc.elements.char.value = getRandomName()"&gt;
                   3462:   &lt;command label="Prefill other fields based on name" onclick="prefillFields(document.forms.npc.elements.char.value)"&gt;
                   3463:  &lt;/menu&gt;
                   3464: &lt;/form&gt;</pre>
                   3465: 
1.994     mike     3466:    <p>This adds two items to the control's context menu, one called
1.520     mike     3467:    "Pick random name", and one called "Prefill other fields based on
                   3468:    name". They invoke scripts that are not shown in the example
                   3469:    above.</p>
                   3470: 
1.117     mike     3471:   </div><div class="impl">
1.1       mike     3472: 
1.1001    mike     3473:   <h5 id="toolbars"><span class="secno">4.11.4.4 </span><dfn>Toolbars</dfn></h5>
1.1       mike     3474: 
1.385     mike     3475:   <p>When a <code><a href="#menus">menu</a></code> element has a <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute in the <a href="#toolbar-state" title="toolbar state">toolbar</a> state, then the user agent
                   3476:   must <a href="#building-menus-and-toolbars" title="building menus and toolbars">build</a> the
1.1       mike     3477:   menu for that <code><a href="#menus">menu</a></code> element, and use the result in the
                   3478:   rendering.</p>
                   3479: 
                   3480:   <p>The user agent must reflect changes made to the
1.385     mike     3481:   <code><a href="#menus">menu</a></code>'s DOM, by immediately <a href="#building-menus-and-toolbars" title="building menus
                   3482:   and toolbars">rebuilding</a> the menu.</p>
1.1       mike     3483: 
1.117     mike     3484:   </div></body></html>

Webmaster