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', |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 306 |
307 def RenameInterface(self, interface): | 307 def RenameInterface(self, interface): |
308 if interface.id in html_interface_renames: | 308 if interface.id in html_interface_renames: |
309 return html_interface_renames[interface.id] | 309 return html_interface_renames[interface.id] |
310 elif interface.id.startswith('HTML'): | 310 elif interface.id.startswith('HTML'): |
311 if any(interface.id in ['Element', 'Document'] | 311 if any(interface.id in ['Element', 'Document'] |
312 for interface in self._database.Hierarchy(interface)): | 312 for interface in self._database.Hierarchy(interface)): |
313 return interface.id[len('HTML'):] | 313 return interface.id[len('HTML'):] |
314 return self.DartifyTypeName(interface.id) | 314 return self.DartifyTypeName(interface.id) |
315 | 315 |
| 316 |
316 def RenameMember(self, interface_name, member_node, member, member_prefix=''): | 317 def RenameMember(self, interface_name, member_node, member, member_prefix=''): |
317 """ | 318 """ |
318 Returns the name of the member in the HTML library or None if the member is | 319 Returns the name of the member in the HTML library or None if the member is |
319 suppressed in the HTML library | 320 suppressed in the HTML library |
320 """ | 321 """ |
321 interface = self._database.GetInterface(interface_name) | 322 interface = self._database.GetInterface(interface_name) |
322 | 323 |
323 if self._FindMatch(interface, member, member_prefix, _removed_html_members): | 324 if self._FindMatch(interface, member, member_prefix, _removed_html_members): |
324 return None | 325 return None |
325 | 326 |
(...skipping 22 matching lines...) Expand all Loading... |
348 return self._GetLibraryName(interface.id) | 349 return self._GetLibraryName(interface.id) |
349 | 350 |
350 def _GetLibraryName(self, idl_type_name): | 351 def _GetLibraryName(self, idl_type_name): |
351 """ | 352 """ |
352 Gets the name of the library this type should live in. | 353 Gets the name of the library this type should live in. |
353 This is private because this should use interfaces to resolve the library. | 354 This is private because this should use interfaces to resolve the library. |
354 """ | 355 """ |
355 | 356 |
356 if idl_type_name.startswith('SVG'): | 357 if idl_type_name.startswith('SVG'): |
357 return 'svg' | 358 return 'svg' |
| 359 if 'Audio' in idl_type_name: |
| 360 return 'audio' |
| 361 |
| 362 if self._database.HasInterface(idl_type_name): |
| 363 interface = self._database.GetInterface(idl_type_name) |
| 364 for parent in self._database.Hierarchy(interface): |
| 365 if parent.id == 'AudioNode': |
| 366 return 'audio' |
| 367 |
358 return 'html' | 368 return 'html' |
359 | 369 |
360 def DartifyTypeName(self, type_name): | 370 def DartifyTypeName(self, type_name): |
361 """Converts a DOM name to a Dart-friendly class name. """ | 371 """Converts a DOM name to a Dart-friendly class name. """ |
362 library_name = self._GetLibraryName(type_name) | 372 library_name = self._GetLibraryName(type_name) |
363 # Only renaming SVG for now. | 373 # Only renaming SVG for now. |
364 if library_name != 'svg': | 374 if library_name != 'svg': |
365 return type_name | 375 return type_name |
366 | 376 |
367 # Strip off the SVG prefix. | 377 # Strip off the SVG prefix. |
368 name = re.sub(r'^SVG', '', type_name) | 378 name = re.sub(r'^SVG', '', type_name) |
369 | 379 |
370 def toLower(match): | 380 def toLower(match): |
371 return match.group(1) + match.group(2).lower() + match.group(3) | 381 return match.group(1) + match.group(2).lower() + match.group(3) |
372 | 382 |
373 # We're looking for a sequence of letters which start with capital letter | 383 # We're looking for a sequence of letters which start with capital letter |
374 # then a series of caps and finishes with either the end of the string or | 384 # then a series of caps and finishes with either the end of the string or |
375 # a capital letter. | 385 # a capital letter. |
376 # The [0-9] check is for names such as 2D or 3D | 386 # The [0-9] check is for names such as 2D or 3D |
377 # The following test cases should match as: | 387 # The following test cases should match as: |
378 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue | 388 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue |
379 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) | 389 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) |
380 # IFrameElement: (I)()(F)rameElement (no change) | 390 # IFrameElement: (I)()(F)rameElement (no change) |
381 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) | 391 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) |
OLD | NEW |