| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 import re | 5 import re |
| 6 | 6 |
| 7 html_interface_renames = { | 7 html_interface_renames = { |
| 8 'DOMCoreException': 'DOMException', | 8 'DOMCoreException': 'DOMException', |
| 9 'DOMFormData': 'FormData', | 9 'DOMFormData': 'FormData', |
| 10 'DOMURL': 'Url', | 10 'DOMURL': 'Url', |
| 11 'DOMWindow': 'LocalWindow', | 11 'DOMWindow': 'LocalWindow', |
| 12 'History': 'LocalHistory', | 12 'History': 'LocalHistory', |
| 13 'HTMLDocument' : 'HtmlDocument', | 13 'HTMLDocument' : 'HtmlDocument', |
| 14 'IDBFactory': 'IdbFactory', # Manual to avoid name conflicts. |
| 14 'Location': 'LocalLocation', | 15 'Location': 'LocalLocation', |
| 15 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts. | 16 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts. |
| 16 'SVGElement': 'SvgElement', # Manual to avoid name conflicts. | 17 'SVGElement': 'SvgElement', # Manual to avoid name conflicts. |
| 17 'SVGException': 'SvgException', # Manual of avoid conflict with Exception. | 18 'SVGException': 'SvgException', # Manual of avoid conflict with Exception. |
| 18 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts. | 19 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts. |
| 19 'WebKitAnimation': 'Animation', | 20 'WebKitAnimation': 'Animation', |
| 20 'WebKitAnimationEvent': 'AnimationEvent', | 21 'WebKitAnimationEvent': 'AnimationEvent', |
| 21 'WebKitBlobBuilder': 'BlobBuilder', | 22 'WebKitBlobBuilder': 'BlobBuilder', |
| 22 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', | 23 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', |
| 23 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', | 24 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 "Node.get:nodeName", | 299 "Node.get:nodeName", |
| 299 "Node.lookupPrefix", | 300 "Node.lookupPrefix", |
| 300 "Node.get:PROCESSING_INSTRUCTION_NODE", | 301 "Node.get:PROCESSING_INSTRUCTION_NODE", |
| 301 'ShadowRoot.getElementsByTagNameNS', | 302 'ShadowRoot.getElementsByTagNameNS', |
| 302 "LocalWindow.blur", | 303 "LocalWindow.blur", |
| 303 "LocalWindow.clientInformation", | 304 "LocalWindow.clientInformation", |
| 304 "LocalWindow.get:frames", | 305 "LocalWindow.get:frames", |
| 305 "LocalWindow.get:length", | 306 "LocalWindow.get:length", |
| 306 "LocalWindow.focus", | 307 "LocalWindow.focus", |
| 307 "LocalWindow.prompt", | 308 "LocalWindow.prompt", |
| 309 "LocalWindow.webkitIndexedDB", |
| 308 "LocalWindow.webkitCancelRequestAnimationFrame", | 310 "LocalWindow.webkitCancelRequestAnimationFrame", |
| 309 "WheelEvent.wheelDelta", | 311 "WheelEvent.wheelDelta", |
| 312 "WorkerContext.webkitIndexedDB", |
| 310 ]) | 313 ]) |
| 311 | 314 |
| 312 class HtmlRenamer(object): | 315 class HtmlRenamer(object): |
| 313 def __init__(self, database): | 316 def __init__(self, database): |
| 314 self._database = database | 317 self._database = database |
| 315 | 318 |
| 316 def RenameInterface(self, interface): | 319 def RenameInterface(self, interface): |
| 317 if interface.id in html_interface_renames: | 320 if interface.id in html_interface_renames: |
| 318 return html_interface_renames[interface.id] | 321 return html_interface_renames[interface.id] |
| 319 elif interface.id.startswith('HTML'): | 322 elif interface.id.startswith('HTML'): |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 def GetLibraryName(self, interface): | 363 def GetLibraryName(self, interface): |
| 361 return self._GetLibraryName(interface.id) | 364 return self._GetLibraryName(interface.id) |
| 362 | 365 |
| 363 def _GetLibraryName(self, idl_type_name): | 366 def _GetLibraryName(self, idl_type_name): |
| 364 """ | 367 """ |
| 365 Gets the name of the library this type should live in. | 368 Gets the name of the library this type should live in. |
| 366 This is private because this should use interfaces to resolve the library. | 369 This is private because this should use interfaces to resolve the library. |
| 367 """ | 370 """ |
| 368 if idl_type_name.startswith('SVG'): | 371 if idl_type_name.startswith('SVG'): |
| 369 return 'svg' | 372 return 'svg' |
| 373 |
| 374 if idl_type_name.startswith('IDB'): |
| 375 return 'indexed_db' |
| 376 |
| 370 if 'Audio' in idl_type_name: | 377 if 'Audio' in idl_type_name: |
| 371 return 'web_audio' | 378 return 'web_audio' |
| 372 | 379 |
| 373 if self._database.HasInterface(idl_type_name): | 380 if self._database.HasInterface(idl_type_name): |
| 374 interface = self._database.GetInterface(idl_type_name) | 381 interface = self._database.GetInterface(idl_type_name) |
| 375 for parent in self._database.Hierarchy(interface): | 382 for parent in self._database.Hierarchy(interface): |
| 376 if parent.id == 'AudioNode': | 383 if parent.id == 'AudioNode': |
| 377 return 'web_audio' | 384 return 'web_audio' |
| 378 | 385 |
| 379 return 'html' | 386 return 'html' |
| 380 | 387 |
| 381 | 388 |
| 382 def DartifyTypeName(self, type_name): | 389 def DartifyTypeName(self, type_name): |
| 383 """Converts a DOM name to a Dart-friendly class name. """ | 390 """Converts a DOM name to a Dart-friendly class name. """ |
| 384 library_name = self._GetLibraryName(type_name) | 391 library_name = self._GetLibraryName(type_name) |
| 385 # Only renaming SVG for now. | 392 # Rename everything except html. |
| 386 if library_name != 'svg': | 393 if library_name == 'html': |
| 387 return type_name | 394 return type_name |
| 388 | 395 |
| 389 # Strip off the SVG prefix. | 396 # Strip off any SVG prefix. |
| 390 name = re.sub(r'^SVG', '', type_name) | 397 name = re.sub(r'^SVG', '', type_name) |
| 398 # Strip off any IDB prefix. |
| 399 name = re.sub(r'^IDB', '', name) |
| 400 |
| 391 return self._CamelCaseName(name) | 401 return self._CamelCaseName(name) |
| 392 | 402 |
| 393 def _DartifyMemberName(self, member_name): | 403 def _DartifyMemberName(self, member_name): |
| 394 # Strip off any OpenGL ES suffixes. | 404 # Strip off any OpenGL ES suffixes. |
| 395 name = re.sub(r'OES$', '', member_name) | 405 name = re.sub(r'OES$', '', member_name) |
| 396 return self._CamelCaseName(name) | 406 return self._CamelCaseName(name) |
| 397 | 407 |
| 398 def _CamelCaseName(self, name): | 408 def _CamelCaseName(self, name): |
| 399 | 409 |
| 400 def toLower(match): | 410 def toLower(match): |
| 401 return match.group(1) + match.group(2).lower() + match.group(3) | 411 return match.group(1) + match.group(2).lower() + match.group(3) |
| 402 | 412 |
| 403 # We're looking for a sequence of letters which start with capital letter | 413 # We're looking for a sequence of letters which start with capital letter |
| 404 # then a series of caps and finishes with either the end of the string or | 414 # then a series of caps and finishes with either the end of the string or |
| 405 # a capital letter. | 415 # a capital letter. |
| 406 # The [0-9] check is for names such as 2D or 3D | 416 # The [0-9] check is for names such as 2D or 3D |
| 407 # The following test cases should match as: | 417 # The following test cases should match as: |
| 408 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue | 418 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue |
| 409 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) | 419 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) |
| 410 # IFrameElement: (I)()(F)rameElement (no change) | 420 # IFrameElement: (I)()(F)rameElement (no change) |
| 411 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) | 421 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) |
| OLD | NEW |