| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 3 # for details. All rights reserved. Use of this source code is governed by a | |
| 4 # BSD-style license that can be found in the LICENSE file. | |
| 5 import re | |
| 6 | |
| 7 html_interface_renames = { | |
| 8 'CDATASection': 'CDataSection', | |
| 9 'DOMApplicationCache': 'ApplicationCache', | |
| 10 'DOMCoreException': 'DomException', | |
| 11 'DOMFileSystem': 'FileSystem', | |
| 12 'DOMFileSystemSync': 'FileSystemSync', | |
| 13 'DOMFormData': 'FormData', | |
| 14 'DOMURL': 'Url', | |
| 15 'DOMWindow': 'Window', | |
| 16 'HTMLDocument' : 'HtmlDocument', | |
| 17 'IDBAny': '_Any', # Suppressed, but needs to exist for Dartium. | |
| 18 'IDBFactory': 'IdbFactory', # Manual to avoid name conflicts. | |
| 19 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts. | |
| 20 'SVGElement': 'SvgElement', # Manual to avoid name conflicts. | |
| 21 'SVGException': 'SvgException', # Manual of avoid conflict with Exception. | |
| 22 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts. | |
| 23 'WebGLVertexArrayObjectOES': 'WebGLVertexArrayObject', | |
| 24 'WebKitAnimation': 'Animation', | |
| 25 'WebKitAnimationEvent': 'AnimationEvent', | |
| 26 'WebKitBlobBuilder': 'BlobBuilder', | |
| 27 'WebKitCSSKeyframeRule': 'CssKeyframeRule', | |
| 28 'WebKitCSSKeyframesRule': 'CssKeyframesRule', | |
| 29 'WebKitCSSMatrix': 'CssMatrix', | |
| 30 'WebKitCSSTransformValue': 'CssTransformValue', | |
| 31 'WebKitFlags': 'Flags', | |
| 32 'WebKitLoseContext': 'LoseContext', | |
| 33 'WebKitPoint': 'Point', | |
| 34 'WebKitTransitionEvent': 'TransitionEvent', | |
| 35 'XMLHttpRequest': 'HttpRequest', | |
| 36 'XMLHttpRequestException': 'HttpRequestException', | |
| 37 'XMLHttpRequestProgressEvent': 'HttpRequestProgressEvent', | |
| 38 'XMLHttpRequestUpload': 'HttpRequestUpload', | |
| 39 } | |
| 40 | |
| 41 # Members from the standard dom that should not be exposed publicly in dart:html | |
| 42 # but need to be exposed internally to implement dart:html on top of a standard | |
| 43 # browser. | |
| 44 _private_html_members = set([ | |
| 45 'CustomEvent.initCustomEvent', | |
| 46 'Document.createElement', | |
| 47 'Document.createElementNS', | |
| 48 'Document.createEvent', | |
| 49 'Document.createRange', | |
| 50 'Document.createTextNode', | |
| 51 'Document.createTouch', | |
| 52 'Document.createTouchList', | |
| 53 'Document.getElementById', | |
| 54 'Document.getElementsByClassName', | |
| 55 'Document.getElementsByName', | |
| 56 'Document.getElementsByTagName', | |
| 57 'Document.querySelector', | |
| 58 'Document.querySelectorAll', | |
| 59 | |
| 60 # Moved to HTMLDocument. | |
| 61 'Document.body', | |
| 62 'Document.caretRangeFromPoint', | |
| 63 'Document.elementFromPoint', | |
| 64 'Document.getCSSCanvasContext', | |
| 65 'Document.head', | |
| 66 'Document.lastModified', | |
| 67 'Document.preferredStylesheetSet', | |
| 68 'Document.referrer', | |
| 69 'Document.selectedStylesheetSet', | |
| 70 'Document.styleSheets', | |
| 71 'Document.title', | |
| 72 'Document.webkitCancelFullScreen', | |
| 73 'Document.webkitExitFullscreen', | |
| 74 'Document.webkitExitPointerLock', | |
| 75 'Document.webkitFullscreenElement', | |
| 76 'Document.webkitFullscreenEnabled', | |
| 77 'Document.webkitHidden', | |
| 78 'Document.webkitIsFullScreen', | |
| 79 'Document.webkitPointerLockElement', | |
| 80 'Document.webkitVisibilityState', | |
| 81 | |
| 82 'DocumentFragment.querySelector', | |
| 83 'DocumentFragment.querySelectorAll', | |
| 84 'Element.childElementCount', | |
| 85 'Element.children', | |
| 86 'Element.className', | |
| 87 'Element.firstElementChild', | |
| 88 'Element.getAttribute', | |
| 89 'Element.getAttributeNS', | |
| 90 'Element.getElementsByClassName', | |
| 91 'Element.getElementsByTagName', | |
| 92 'Element.hasAttribute', | |
| 93 'Element.hasAttributeNS', | |
| 94 'Element.lastElementChild', | |
| 95 'Element.querySelector', | |
| 96 'Element.querySelectorAll', | |
| 97 'Element.removeAttribute', | |
| 98 'Element.removeAttributeNS', | |
| 99 'Element.setAttribute', | |
| 100 'Element.setAttributeNS', | |
| 101 'ElementTraversal.childElementCount', | |
| 102 'ElementTraversal.firstElementChild', | |
| 103 'ElementTraversal.lastElementChild', | |
| 104 'Event.initEvent', | |
| 105 'UIEvent.initUIEvent', | |
| 106 'EventTarget.addEventListener', | |
| 107 'EventTarget.dispatchEvent', | |
| 108 'EventTarget.removeEventListener', | |
| 109 'KeyboardEvent.keyIdentifier', | |
| 110 'KeyboardEvent.initKeyboardEvent', | |
| 111 'Window.getComputedStyle', | |
| 112 'MouseEvent.initMouseEvent', | |
| 113 'Node.appendChild', | |
| 114 'Node.attributes', | |
| 115 'Node.childNodes', | |
| 116 'Node.firstChild', | |
| 117 'Node.lastChild', | |
| 118 "Node.localName", | |
| 119 'Node.namespaceURI', | |
| 120 'Node.removeChild', | |
| 121 'Node.replaceChild', | |
| 122 'UIEvent.keyCode', | |
| 123 'UIEvent.charCode', | |
| 124 'ShadowRoot.getElementById', | |
| 125 'ShadowRoot.getElementsByClassName', | |
| 126 'ShadowRoot.getElementsByTagName', | |
| 127 'Storage.clear', | |
| 128 'Storage.getItem', | |
| 129 'Storage.key', | |
| 130 'Storage.length', | |
| 131 'Storage.removeItem', | |
| 132 'Storage.setItem', | |
| 133 'WheelEvent.wheelDeltaX', | |
| 134 'WheelEvent.wheelDeltaY', | |
| 135 ]) | |
| 136 | |
| 137 # Members from the standard dom that exist in the dart:html library with | |
| 138 # identical functionality but with cleaner names. | |
| 139 _renamed_html_members = { | |
| 140 'Document.createCDATASection': 'createCDataSection', | |
| 141 'Document.defaultView': 'window', | |
| 142 'Element.webkitMatchesSelector' : 'matchesSelector', | |
| 143 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', | |
| 144 'Node.cloneNode': 'clone', | |
| 145 'Node.nextSibling': 'nextNode', | |
| 146 'Node.ownerDocument': 'document', | |
| 147 'Node.parentElement': 'parent', | |
| 148 'Node.previousSibling': 'previousNode', | |
| 149 'Node.textContent': 'text', | |
| 150 'SvgElement.className': '$dom_svgClassName', | |
| 151 'AnimatedString.className': '$dom_svgClassName', | |
| 152 'Stylable.className': '$dom_svgClassName', | |
| 153 'Url.createObjectURL': 'createObjectUrl', | |
| 154 'Url.revokeObjectURL': 'revokeObjectUrl', | |
| 155 } | |
| 156 | |
| 157 # Members and classes from the dom that should be removed completely from | |
| 158 # dart:html. These could be expressed in the IDL instead but expressing this | |
| 159 # as a simple table instead is more concise. | |
| 160 # Syntax is: ClassName.(get\.|set\.)?MemberName | |
| 161 # Using get: and set: is optional and should only be used when a getter needs | |
| 162 # to be suppressed but not the setter, etc. | |
| 163 # TODO(jacobr): cleanup and augment this list. | |
| 164 _removed_html_members = set([ | |
| 165 'NodeList.item', | |
| 166 "Attr.*", | |
| 167 # "BarProp.*", | |
| 168 # "BarInfo.*", | |
| 169 # "Blob.webkitSlice", | |
| 170 # "CDATASection.*", | |
| 171 # "Comment.*", | |
| 172 # "DOMImplementation.*", | |
| 173 "CanvasRenderingContext2D.clearShadow", | |
| 174 "CanvasRenderingContext2D.drawImageFromRect", | |
| 175 "CanvasRenderingContext2D.setAlpha", | |
| 176 "CanvasRenderingContext2D.setCompositeOperation", | |
| 177 "CanvasRenderingContext2D.setFillColor", | |
| 178 "CanvasRenderingContext2D.setLineCap", | |
| 179 "CanvasRenderingContext2D.setLineJoin", | |
| 180 "CanvasRenderingContext2D.setLineWidth", | |
| 181 "CanvasRenderingContext2D.setMiterLimit", | |
| 182 "CanvasRenderingContext2D.setShadow", | |
| 183 "CanvasRenderingContext2D.setStrokeColor", | |
| 184 "DivElement.align", | |
| 185 'Document.applets', | |
| 186 "Document.get:forms", | |
| 187 # "Document.get:selectedStylesheetSet", | |
| 188 # "Document.set:selectedStylesheetSet", | |
| 189 # "Document.get:preferredStylesheetSet", | |
| 190 "Document.get:links", | |
| 191 "Document.set:domain", | |
| 192 "Document.createAttributeNS", | |
| 193 "Document.get:inputEncoding", | |
| 194 "Document.get:height", | |
| 195 "Document.get:width", | |
| 196 "Element.getElementsByTagNameNS", | |
| 197 "Document.get:compatMode", | |
| 198 'Document.images', | |
| 199 "Document.importNode", | |
| 200 "Document.evaluate", | |
| 201 "Document.get:images", | |
| 202 "Document.createExpression", | |
| 203 "Document.getOverrideStyle", | |
| 204 "Document.xmlStandalone", | |
| 205 "Document.createComment", | |
| 206 "Document.adoptNode", | |
| 207 "Document.get:characterSet", | |
| 208 "Document.createAttribute", | |
| 209 "Document.get:URL", | |
| 210 "Document.createEntityReference", | |
| 211 "Document.get:documentURI", | |
| 212 "Document.set:documentURI", | |
| 213 "Document.createNodeIterator", | |
| 214 "Document.createProcessingInstruction", | |
| 215 "Document.get:doctype", | |
| 216 "Document.createTreeWalker", | |
| 217 "Document.location", | |
| 218 "Document.createNSResolver", | |
| 219 "Document.get:xmlEncoding", | |
| 220 "Document.get:defaultCharset", | |
| 221 "Document.get:applets", | |
| 222 "Document.getSelection", | |
| 223 "Document.xmlVersion", | |
| 224 "Document.get:anchors", | |
| 225 "Document.getElementsByTagNameNS", | |
| 226 'Document.webkitCurrentFullScreenElement', | |
| 227 'Document.webkitFullScreenKeyboardInputAllowed', | |
| 228 "DocumentType.*", | |
| 229 "Element.setAttributeNode", | |
| 230 "Element.getAttributeNode", | |
| 231 "Element.removeAttributeNode", | |
| 232 "Element.setAttributeNodeNS", | |
| 233 "Element.getAttributeNodeNS", | |
| 234 "Event.srcElement", | |
| 235 "EventSource.URL", | |
| 236 "BodyElement.text", | |
| 237 "AnchorElement.text", | |
| 238 "OptionElement.text", | |
| 239 "ScriptElement.text", | |
| 240 "TitleElement.text", | |
| 241 # "EventSource.get:url", | |
| 242 # TODO(jacobr): should these be removed? | |
| 243 "Document.close", | |
| 244 "Document.hasFocus", | |
| 245 | |
| 246 "Document.vlinkColor", | |
| 247 "Document.captureEvents", | |
| 248 "Document.releaseEvents", | |
| 249 "Document.get:compatMode", | |
| 250 "Document.designMode", | |
| 251 "Document.dir", | |
| 252 "Document.all", | |
| 253 "Document.write", | |
| 254 "Document.fgColor", | |
| 255 "Document.bgColor", | |
| 256 "Document.get:plugins", | |
| 257 "Document.alinkColor", | |
| 258 "Document.get:embeds", | |
| 259 "Document.open", | |
| 260 "Document.clear", | |
| 261 "Document.get:scripts", | |
| 262 "Document.writeln", | |
| 263 "Document.linkColor", | |
| 264 "Element.get:itemRef", | |
| 265 "Element.outerText", | |
| 266 "Element.accessKey", | |
| 267 "Element.get:itemType", | |
| 268 "Element.innerText", | |
| 269 "Element.set:outerHTML", | |
| 270 "Element.itemScope", | |
| 271 "Element.itemValue", | |
| 272 "Element.itemId", | |
| 273 "Element.get:itemProp", | |
| 274 'Element.scrollIntoView', | |
| 275 'Element.get:classList', | |
| 276 "FormElement.get:elements", | |
| 277 "HTMLFrameElement.*", | |
| 278 "HTMLFrameSetElement.*", | |
| 279 "HtmlElement.version", | |
| 280 "HtmlElement.manifest", | |
| 281 'SelectElement.options', | |
| 282 'SelectElement.selectedOptions', | |
| 283 "Cursor.PREV", | |
| 284 "Cursor.PREV_NO_DUPLICATE", | |
| 285 "Cursor.NEXT", | |
| 286 "Cursor.NEXT_NO_DUPLICATE", | |
| 287 "Transaction.READ_ONLY", | |
| 288 "Transaction.READ_WRITE", | |
| 289 "Document.version", | |
| 290 "Document.manifest", | |
| 291 "HTMLIsIndexElement.*", | |
| 292 "MenuElement.compact", | |
| 293 "HTMLOptionsCollection.*", | |
| 294 "HTMLPropertiesCollection.*", | |
| 295 "SelectElement.remove", | |
| 296 "NamedNodeMap.*", | |
| 297 "Node.isEqualNode", | |
| 298 "Node.get:TEXT_NODE", | |
| 299 "Node.hasAttributes", | |
| 300 "Node.get:DOCUMENT_TYPE_NODE", | |
| 301 "Node.get:DOCUMENT_POSITION_FOLLOWING", | |
| 302 "Node.lookupNamespaceURI", | |
| 303 "Node.get:ELEMENT_NODE", | |
| 304 "Node.get:DOCUMENT_FRAGMENT_NODE", | |
| 305 "Node.isDefaultNamespace", | |
| 306 "Node.compareDocumentPosition", | |
| 307 "Node.get:baseURI", | |
| 308 "Node.isSameNode", | |
| 309 "Node.get:DOCUMENT_POSITION_DISCONNECTED", | |
| 310 "Node.get:DOCUMENT_NODE", | |
| 311 "Node.get:DOCUMENT_POSITION_CONTAINS", | |
| 312 "Node.get:COMMENT_NODE", | |
| 313 "Node.get:ENTITY_REFERENCE_NODE", | |
| 314 "Node.isSupported", | |
| 315 "Node.get:DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC", | |
| 316 "Node.get:NOTATION_NODE", | |
| 317 "Node.normalize", | |
| 318 "Node.get:ATTRIBUTE_NODE", | |
| 319 "Node.get:ENTITY_NODE", | |
| 320 "Node.get:DOCUMENT_POSITION_CONTAINED_BY", | |
| 321 "Node.get:prefix", | |
| 322 "Node.set:prefix", | |
| 323 "Node.get:DOCUMENT_POSITION_PRECEDING", | |
| 324 "Node.get:nodeValue", | |
| 325 "Node.set:nodeValue", | |
| 326 "Node.get:CDATA_SECTION_NODE", | |
| 327 "Node.get:nodeName", | |
| 328 "Node.lookupPrefix", | |
| 329 "Node.get:PROCESSING_INSTRUCTION_NODE", | |
| 330 'ShadowRoot.getElementsByTagNameNS', | |
| 331 "Window.blur", | |
| 332 "Window.clientInformation", | |
| 333 "Window.get:frames", | |
| 334 "Window.get:length", | |
| 335 "Window.focus", | |
| 336 "Window.prompt", | |
| 337 "Window.webkitIndexedDB", | |
| 338 "Window.webkitCancelRequestAnimationFrame", | |
| 339 "WheelEvent.wheelDelta", | |
| 340 "WorkerContext.webkitIndexedDB", | |
| 341 ]) | |
| 342 | |
| 343 class HtmlRenamer(object): | |
| 344 def __init__(self, database): | |
| 345 self._database = database | |
| 346 | |
| 347 def RenameInterface(self, interface): | |
| 348 if interface.id in html_interface_renames: | |
| 349 return html_interface_renames[interface.id] | |
| 350 elif interface.id.startswith('HTML'): | |
| 351 if any(interface.id in ['Element', 'Document'] | |
| 352 for interface in self._database.Hierarchy(interface)): | |
| 353 return interface.id[len('HTML'):] | |
| 354 return self.DartifyTypeName(interface.id) | |
| 355 | |
| 356 | |
| 357 def RenameMember(self, interface_name, member_node, member, member_prefix='', | |
| 358 dartify_name=True): | |
| 359 """ | |
| 360 Returns the name of the member in the HTML library or None if the member is | |
| 361 suppressed in the HTML library | |
| 362 """ | |
| 363 interface = self._database.GetInterface(interface_name) | |
| 364 | |
| 365 if self._FindMatch(interface, member, member_prefix, _removed_html_members): | |
| 366 return None | |
| 367 | |
| 368 if 'CheckSecurityForNode' in member_node.ext_attrs: | |
| 369 return None | |
| 370 | |
| 371 name = self._FindMatch(interface, member, member_prefix, | |
| 372 _renamed_html_members) | |
| 373 | |
| 374 target_name = _renamed_html_members[name] if name else member | |
| 375 if self._FindMatch(interface, member, member_prefix, _private_html_members): | |
| 376 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName | |
| 377 target_name = '$dom_' + target_name | |
| 378 | |
| 379 if dartify_name: | |
| 380 target_name = self._DartifyMemberName(target_name) | |
| 381 return target_name | |
| 382 | |
| 383 def _FindMatch(self, interface, member, member_prefix, candidates): | |
| 384 for interface in self._database.Hierarchy(interface): | |
| 385 html_interface_name = self.RenameInterface(interface) | |
| 386 member_name = html_interface_name + '.' + member | |
| 387 if member_name in candidates: | |
| 388 return member_name | |
| 389 member_name = html_interface_name + '.' + member_prefix + member | |
| 390 if member_name in candidates: | |
| 391 return member_name | |
| 392 | |
| 393 def GetLibraryName(self, interface): | |
| 394 if 'Conditional' in interface.ext_attrs: | |
| 395 if 'WEB_AUDIO' in interface.ext_attrs['Conditional']: | |
| 396 return 'web_audio' | |
| 397 if 'SVG' in interface.ext_attrs['Conditional']: | |
| 398 return 'svg' | |
| 399 if 'INDEXED_DATABASE' in interface.ext_attrs['Conditional']: | |
| 400 return 'indexed_db' | |
| 401 | |
| 402 return 'html' | |
| 403 | |
| 404 def DartifyTypeName(self, type_name): | |
| 405 """Converts a DOM name to a Dart-friendly class name. """ | |
| 406 | |
| 407 # Strip off any standard prefixes. | |
| 408 name = re.sub(r'^SVG', '', type_name) | |
| 409 name = re.sub(r'^IDB', '', name) | |
| 410 | |
| 411 return self._CamelCaseName(name) | |
| 412 | |
| 413 def _DartifyMemberName(self, member_name): | |
| 414 # Strip off any OpenGL ES suffixes. | |
| 415 name = re.sub(r'OES$', '', member_name) | |
| 416 return self._CamelCaseName(name) | |
| 417 | |
| 418 def _CamelCaseName(self, name): | |
| 419 | |
| 420 def toLower(match): | |
| 421 return match.group(1) + match.group(2).lower() + match.group(3) | |
| 422 | |
| 423 # We're looking for a sequence of letters which start with capital letter | |
| 424 # then a series of caps and finishes with either the end of the string or | |
| 425 # a capital letter. | |
| 426 # The [0-9] check is for names such as 2D or 3D | |
| 427 # The following test cases should match as: | |
| 428 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue | |
| 429 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) | |
| 430 # IFrameElement: (I)()(F)rameElement (no change) | |
| 431 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) | |
| OLD | NEW |