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 | 6 |
6 html_interface_renames = { | 7 html_interface_renames = { |
7 'DOMCoreException': 'DOMException', | 8 'DOMCoreException': 'DOMException', |
8 'DOMFormData': 'FormData', | 9 'DOMFormData': 'FormData', |
9 'DOMURL': 'Url', | 10 'DOMURL': 'Url', |
10 'DOMWindow': 'LocalWindow', | 11 'DOMWindow': 'LocalWindow', |
11 'History': 'LocalHistory', | 12 'History': 'LocalHistory', |
12 'HTMLDocument' : 'HtmlDocument', | 13 'HTMLDocument' : 'HtmlDocument', |
13 'Location': 'LocalLocation', | 14 'Location': 'LocalLocation', |
| 15 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts. |
| 16 'SVGElement': 'SvgElement', # Manual to avoid name conflicts. |
| 17 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts. |
14 'WebKitAnimation': 'Animation', | 18 'WebKitAnimation': 'Animation', |
15 'WebKitAnimationEvent': 'AnimationEvent', | 19 'WebKitAnimationEvent': 'AnimationEvent', |
16 'WebKitBlobBuilder': 'BlobBuilder', | 20 'WebKitBlobBuilder': 'BlobBuilder', |
17 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', | 21 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', |
18 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', | 22 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', |
19 'WebKitCSSMatrix': 'CSSMatrix', | 23 'WebKitCSSMatrix': 'CSSMatrix', |
20 'WebKitCSSTransformValue': 'CSSTransformValue', | 24 'WebKitCSSTransformValue': 'CSSTransformValue', |
21 'WebKitFlags': 'Flags', | 25 'WebKitFlags': 'Flags', |
22 'WebKitLoseContext': 'LoseContext', | 26 'WebKitLoseContext': 'LoseContext', |
23 'WebKitPoint': 'Point', | 27 'WebKitPoint': 'Point', |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 _renamed_html_members = { | 114 _renamed_html_members = { |
111 'Document.defaultView': 'window', | 115 'Document.defaultView': 'window', |
112 'Element.webkitMatchesSelector' : 'matchesSelector', | 116 'Element.webkitMatchesSelector' : 'matchesSelector', |
113 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', | 117 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', |
114 'Node.cloneNode': 'clone', | 118 'Node.cloneNode': 'clone', |
115 'Node.nextSibling': 'nextNode', | 119 'Node.nextSibling': 'nextNode', |
116 'Node.ownerDocument': 'document', | 120 'Node.ownerDocument': 'document', |
117 'Node.parentNode': 'parent', | 121 'Node.parentNode': 'parent', |
118 'Node.previousSibling': 'previousNode', | 122 'Node.previousSibling': 'previousNode', |
119 'Node.textContent': 'text', | 123 'Node.textContent': 'text', |
120 'SVGElement.className': '$dom_svgClassName', | 124 'SvgElement.className': '$dom_svgClassName', |
121 'SVGAnimatedString.className': '$dom_svgClassName', | 125 'AnimatedString.className': '$dom_svgClassName', |
122 'SVGStylable.className': '$dom_svgClassName', | 126 'Stylable.className': '$dom_svgClassName', |
123 'Url.createObjectURL': 'createObjectUrl', | 127 'Url.createObjectURL': 'createObjectUrl', |
124 'Url.revokeObjectURL': 'revokeObjectUrl', | 128 'Url.revokeObjectURL': 'revokeObjectUrl', |
125 } | 129 } |
126 | 130 |
127 # Members and classes from the dom that should be removed completely from | 131 # Members and classes from the dom that should be removed completely from |
128 # dart:html. These could be expressed in the IDL instead but expressing this | 132 # dart:html. These could be expressed in the IDL instead but expressing this |
129 # as a simple table instead is more concise. | 133 # as a simple table instead is more concise. |
130 # Syntax is: ClassName.(get\.|set\.)?MemberName | 134 # Syntax is: ClassName.(get\.|set\.)?MemberName |
131 # Using get: and set: is optional and should only be used when a getter needs | 135 # Using get: and set: is optional and should only be used when a getter needs |
132 # to be suppressed but not the setter, etc. | 136 # to be suppressed but not the setter, etc. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 def __init__(self, database): | 302 def __init__(self, database): |
299 self._database = database | 303 self._database = database |
300 | 304 |
301 def RenameInterface(self, interface): | 305 def RenameInterface(self, interface): |
302 if interface.id in html_interface_renames: | 306 if interface.id in html_interface_renames: |
303 return html_interface_renames[interface.id] | 307 return html_interface_renames[interface.id] |
304 elif interface.id.startswith('HTML'): | 308 elif interface.id.startswith('HTML'): |
305 if any(interface.id in ['Element', 'Document'] | 309 if any(interface.id in ['Element', 'Document'] |
306 for interface in self._database.Hierarchy(interface)): | 310 for interface in self._database.Hierarchy(interface)): |
307 return interface.id[len('HTML'):] | 311 return interface.id[len('HTML'):] |
308 return interface.id | 312 return self.DartifyTypeName(interface.id) |
309 | 313 |
310 def RenameMember(self, interface_name, member_node, member, member_prefix=''): | 314 def RenameMember(self, interface_name, member_node, member, member_prefix=''): |
311 """ | 315 """ |
312 Returns the name of the member in the HTML library or None if the member is | 316 Returns the name of the member in the HTML library or None if the member is |
313 suppressed in the HTML library | 317 suppressed in the HTML library |
314 """ | 318 """ |
315 interface = self._database.GetInterface(interface_name) | 319 interface = self._database.GetInterface(interface_name) |
316 | 320 |
317 if self._FindMatch(interface, member, member_prefix, _removed_html_members): | 321 if self._FindMatch(interface, member, member_prefix, _removed_html_members): |
318 return None | 322 return None |
(...skipping 13 matching lines...) Expand all Loading... |
332 for interface in self._database.Hierarchy(interface): | 336 for interface in self._database.Hierarchy(interface): |
333 html_interface_name = self.RenameInterface(interface) | 337 html_interface_name = self.RenameInterface(interface) |
334 member_name = html_interface_name + '.' + member | 338 member_name = html_interface_name + '.' + member |
335 if member_name in candidates: | 339 if member_name in candidates: |
336 return member_name | 340 return member_name |
337 member_name = html_interface_name + '.' + member_prefix + member | 341 member_name = html_interface_name + '.' + member_prefix + member |
338 if member_name in candidates: | 342 if member_name in candidates: |
339 return member_name | 343 return member_name |
340 | 344 |
341 def GetLibraryName(self, interface): | 345 def GetLibraryName(self, interface): |
342 if interface.id.startswith('SVG'): | 346 return self._GetLibraryName(interface.id) |
| 347 |
| 348 def _GetLibraryName(self, idl_type_name): |
| 349 """ |
| 350 Gets the name of the library this type should live in. |
| 351 This is private because this should use interfaces to resolve the library. |
| 352 """ |
| 353 |
| 354 if idl_type_name.startswith('SVG'): |
343 return 'svg' | 355 return 'svg' |
344 return 'html' | 356 return 'html' |
| 357 |
| 358 def DartifyTypeName(self, type_name): |
| 359 """Converts a DOM name to a Dart-friendly class name. """ |
| 360 library_name = self._GetLibraryName(type_name) |
| 361 # Only renaming SVG for now. |
| 362 if library_name != 'svg': |
| 363 return type_name |
| 364 |
| 365 # Strip off the SVG prefix. |
| 366 name = re.sub(r'^SVG', '', type_name) |
| 367 |
| 368 def toLower(match): |
| 369 return match.group(1) + match.group(2).lower() + match.group(3) |
| 370 |
| 371 # We're looking for a sequence of letters which start with capital letter |
| 372 # then a series of caps and finishes with either the end of the string or |
| 373 # a capital letter. |
| 374 # The [0-9] check is for names such as 2D or 3D |
| 375 # The following test cases should match as: |
| 376 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue |
| 377 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) |
| 378 # IFrameElement: (I)()(F)rameElement (no change) |
| 379 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) |
OLD | NEW |