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