Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(jmesserly): html5lib might be a better home for this. | 5 // TODO(jmesserly): html5lib might be a better home for this. |
| 6 // But at the moment we only need it here. | 6 // But at the moment we only need it here. |
| 7 | 7 |
| 8 library html5_utils; | 8 library html5_utils; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 'time': 'Element', // see doc comment, was: 'TimeElement' | 122 'time': 'Element', // see doc comment, was: 'TimeElement' |
| 123 'title': 'TitleElement', | 123 'title': 'TitleElement', |
| 124 'tr': 'TableRowElement', | 124 'tr': 'TableRowElement', |
| 125 'track': 'TrackElement', | 125 'track': 'TrackElement', |
| 126 'u': 'Element', | 126 'u': 'Element', |
| 127 'ul': 'UListElement', | 127 'ul': 'UListElement', |
| 128 'var': 'Element', | 128 'var': 'Element', |
| 129 'video': 'VideoElement', | 129 'video': 'VideoElement', |
| 130 'wbr': 'Element', | 130 'wbr': 'Element', |
| 131 }; | 131 }; |
| 132 | |
| 133 /** A constant used as a special value in [htmlAttributeTags]. */ | |
| 134 const allHtmlElements = const ['*']; | |
|
Siggi Cherem (dart-lang)
2012/10/27 00:46:45
nit: => ALL_HTML_ELEMENTS?
or are we leaning towa
Jennifer Messerly
2012/10/30 06:08:45
IMO, we should not use CAPS.
It does not really m
| |
| 135 | |
| 136 // TODO(jmesserly): it'd be much better to use compile time mirrors on the | |
| 137 // HTML library to build this list. | |
| 138 // TODO(jmesserly): there are some odd cases, like "border" on img. It is | |
| 139 // not listed as an HTML attribute but it's supported by the DOM IDL. Do we | |
| 140 // need any special handling for those? | |
| 141 /** | |
| 142 * For each HTML attributes, maps to a list of tags that support it. | |
| 143 * If the value is equal to [allHtmlElements] it implies that it is supported | |
| 144 * by all elements. Source: | |
| 145 * <http://dev.w3.org/html5/spec/section-index.html#attributes-1> | |
| 146 * | |
| 147 * Be sure to use [elementFieldRenames] to see if the attribute has been | |
| 148 * renamed. | |
|
Siggi Cherem (dart-lang)
2012/10/27 00:46:45
... in 'dart:html'?
| |
| 149 * | |
| 150 * Note that 'command', 'data', 'dialog', and 'time' tags were removed, because | |
| 151 * the corresponding element types do not exist. See [htmlElementNames]. | |
| 152 * | |
| 153 * Also removed are attributes that don't have DOM fields (yet?): accesskey, | |
| 154 * class, contextmenu, manifest, seamless, typemustmatch. | |
| 155 * | |
| 156 * Also these attriubtes have no setter: style, form, list. | |
| 157 * | |
| 158 * Finally a few other things that are missing: | |
| 159 * - 'type' on MenuElement and AreaElement. | |
| 160 * - 'crossorigin' on MediaElement. | |
| 161 * - 'media' on AreaElement and AnchorElement. | |
| 162 * - 'hreflang' on AreaElement. | |
| 163 * - 'rel' on AreaElement. | |
| 164 * - 'label' on MenuElement. | |
| 165 * - 'charset' on MetaElement. | |
| 166 */ | |
| 167 const htmlAttributeTags = const <List<String>>{ | |
| 168 'accept': const ['input'], | |
| 169 'accept-charset': const ['form'], | |
| 170 'action': const ['form'], | |
| 171 'alt': const ['area', 'img', 'input'], | |
| 172 'async': const ['script'], | |
| 173 'autocomplete': const ['form', 'input'], | |
| 174 'autofocus': const ['button', 'input', 'keygen', 'select', 'textarea'], | |
| 175 'autoplay': const ['audio', 'video'], | |
| 176 'border': const ['table'], | |
| 177 'challenge': const ['keygen'], | |
| 178 'charset': const ['script'], | |
| 179 'checked': const ['input'], | |
| 180 'cite': const ['blockquote', 'del', 'ins', 'q'], | |
| 181 'cols': const ['textarea'], | |
| 182 'colspan': const ['td', 'th'], | |
| 183 'content': const ['meta'], | |
| 184 'contenteditable': allHtmlElements, | |
| 185 'controls': const ['audio', 'video'], | |
| 186 'coords': const ['area'], | |
| 187 'crossorigin': const ['img'], | |
| 188 'datetime': const ['del', 'ins'], | |
| 189 'default': const ['track'], | |
| 190 'defer': const ['script'], | |
| 191 'dir': allHtmlElements, | |
| 192 // TODO(jmesserly): CL out to add this back. | |
| 193 // 'dirname': const ['input', 'textarea'], | |
| 194 'disabled': const ['button', 'fieldset', 'input', 'keygen', 'optgroup', 'optio n', 'select', 'textarea'], | |
|
Siggi Cherem (dart-lang)
2012/10/27 00:46:45
80 col? (here & below)
| |
| 195 'draggable': allHtmlElements, | |
| 196 'dropzone': allHtmlElements, | |
| 197 'enctype': const ['form'], | |
| 198 'for': const ['label', 'output'], | |
| 199 'formaction': const ['button', 'input'], | |
| 200 'formenctype': const ['button', 'input'], | |
| 201 'formmethod': const ['button', 'input'], | |
| 202 'formnovalidate': const ['button', 'input'], | |
| 203 'formtarget': const ['button', 'input'], | |
| 204 'headers': const ['td', 'th'], | |
| 205 'height': const ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video '], | |
| 206 'hidden': allHtmlElements, | |
| 207 'high': const ['meter'], | |
| 208 'href': const ['a', 'area', 'link', 'base'], | |
| 209 'hreflang': const ['a', 'link'], | |
| 210 'http-equiv': const ['meta'], | |
| 211 'id': allHtmlElements, | |
| 212 'ismap': const ['img'], | |
| 213 'keytype': const ['keygen'], | |
| 214 'kind': const ['track'], | |
| 215 'label': const ['optgroup', 'option', 'track'], | |
| 216 'lang': allHtmlElements, | |
| 217 'loop': const ['audio', 'video'], | |
| 218 'low': const ['meter'], | |
| 219 'max': const ['input', 'meter', 'progress'], | |
| 220 'maxlength': const ['input', 'textarea'], | |
| 221 'media': const ['link', 'source', 'style'], | |
| 222 'mediagroup': const ['audio', 'video'], | |
| 223 'method': const ['form'], | |
| 224 'min': const ['input', 'meter'], | |
| 225 'multiple': const ['input', 'select'], | |
| 226 'muted': const ['audio', 'video'], | |
| 227 'name': const ['button', 'fieldset', 'input', 'keygen', 'output', 'select', 't extarea', 'form', 'iframe', 'object', 'map', 'meta', 'param'], | |
| 228 'novalidate': const ['form'], | |
| 229 'open': const ['details'], | |
| 230 'optimum': const ['meter'], | |
| 231 'pattern': const ['input'], | |
| 232 'placeholder': const ['input', 'textarea'], | |
| 233 'poster': const ['video'], | |
| 234 'preload': const ['audio', 'video'], | |
| 235 'readonly': const ['input', 'textarea'], | |
| 236 'rel': const ['a', 'link'], | |
| 237 'required': const ['input', 'select', 'textarea'], | |
| 238 'reversed': const ['ol'], | |
| 239 'rows': const ['textarea'], | |
| 240 'rowspan': const ['td', 'th'], | |
| 241 'sandbox': const ['iframe'], | |
| 242 'spellcheck': allHtmlElements, | |
| 243 'scope': const ['th'], | |
| 244 'scoped': const ['style'], | |
| 245 'selected': const ['option'], | |
| 246 'shape': const ['area'], | |
| 247 'size': const ['input', 'select'], | |
| 248 'sizes': const ['link'], | |
| 249 'span': const ['col', 'colgroup'], | |
| 250 'src': const ['audio', 'embed', 'iframe', 'img', 'input', 'script', 'source', 'track', 'video'], | |
| 251 'srcdoc': const ['iframe'], | |
| 252 'srclang': const ['track'], | |
| 253 'start': const ['ol'], | |
| 254 'step': const ['input'], | |
| 255 'tabindex': allHtmlElements, | |
| 256 'target': const ['a', 'area', 'base', 'form'], | |
| 257 'title': allHtmlElements, | |
| 258 'translate': allHtmlElements, | |
| 259 'type': const ['a', 'link', 'button', 'embed', 'object', 'script', 'source', ' style', 'input'], | |
| 260 'usemap': const ['img', 'object'], | |
| 261 'value': const ['button', 'option', 'input', 'li', 'meter', 'progress', 'param '], | |
| 262 'width': const ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video' ], | |
| 263 'wrap': const ['textarea'], | |
| 264 }; | |
| 265 | |
| 266 /** | |
| 267 * Gets the DOM field name in `dart:html` for an HTML attribute. | |
| 268 * Generally this means making it camel case. If the field is not in this table, | |
| 269 * that means the name is unchanged from HTML. | |
| 270 */ | |
| 271 const elementFieldRenames = const { | |
|
Siggi Cherem (dart-lang)
2012/10/27 00:46:45
maybe rename to also use ALL_CAPS
| |
| 272 'accept-charset': 'acceptCharset', | |
| 273 'colspan': 'colSpan', | |
| 274 'contenteditable': 'contentEditable', | |
| 275 'contextmenu': 'contextMenu', | |
| 276 'crossorigin': 'crossOrigin', | |
| 277 'datetime': 'dateTime', | |
| 278 'default': 'defaultValue', | |
| 279 'dropzone': 'webkitdropzone', // Yuck. http://dartbug.com/4550 | |
| 280 'for': 'htmlFor', | |
| 281 'formaction': 'formAction', | |
| 282 'formenctype': 'formEnctype', | |
| 283 'formmethod': 'formMethod', | |
| 284 'formnovalidate': 'formNoValidate', | |
| 285 'formtarget': 'formTarget', | |
| 286 'http-equiv': 'httpEquiv', | |
| 287 'ismap': 'isMap', | |
| 288 'maxlength': 'maxLength', | |
| 289 'mediagroup': 'mediaGroup', | |
| 290 'novalidate': 'noValidate', | |
| 291 'readonly': 'readOnly', | |
| 292 'rowspan': 'rowSpan', | |
| 293 'tabindex': 'tabIndex', | |
| 294 'usemap': 'useMap' | |
| 295 }; | |
| OLD | NEW |