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 'Location': 'LocalLocation', | 13 'Location': 'LocalLocation', |
14 'SVGDocument': 'SvgDocument', # Manual to avoid name conflicts. | |
15 'SVGElement': 'SvgElement', # Manual to avoid name conflicts. | |
16 'SVGSVGElement': 'SvgSvgElement', # Manual to avoid name conflicts. | |
13 'WebKitAnimation': 'Animation', | 17 'WebKitAnimation': 'Animation', |
14 'WebKitAnimationEvent': 'AnimationEvent', | 18 'WebKitAnimationEvent': 'AnimationEvent', |
15 'WebKitBlobBuilder': 'BlobBuilder', | 19 'WebKitBlobBuilder': 'BlobBuilder', |
16 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', | 20 'WebKitCSSKeyframeRule': 'CSSKeyframeRule', |
17 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', | 21 'WebKitCSSKeyframesRule': 'CSSKeyframesRule', |
18 'WebKitCSSMatrix': 'CSSMatrix', | 22 'WebKitCSSMatrix': 'CSSMatrix', |
19 'WebKitCSSTransformValue': 'CSSTransformValue', | 23 'WebKitCSSTransformValue': 'CSSTransformValue', |
20 'WebKitFlags': 'Flags', | 24 'WebKitFlags': 'Flags', |
21 'WebKitLoseContext': 'LoseContext', | 25 'WebKitLoseContext': 'LoseContext', |
22 'WebKitPoint': 'Point', | 26 'WebKitPoint': 'Point', |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 _renamed_html_members = { | 94 _renamed_html_members = { |
91 'Document.defaultView': 'window', | 95 'Document.defaultView': 'window', |
92 'Element.webkitMatchesSelector' : 'matchesSelector', | 96 'Element.webkitMatchesSelector' : 'matchesSelector', |
93 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', | 97 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', |
94 'Node.cloneNode': 'clone', | 98 'Node.cloneNode': 'clone', |
95 'Node.nextSibling': 'nextNode', | 99 'Node.nextSibling': 'nextNode', |
96 'Node.ownerDocument': 'document', | 100 'Node.ownerDocument': 'document', |
97 'Node.parentNode': 'parent', | 101 'Node.parentNode': 'parent', |
98 'Node.previousSibling': 'previousNode', | 102 'Node.previousSibling': 'previousNode', |
99 'Node.textContent': 'text', | 103 'Node.textContent': 'text', |
100 'SVGElement.className': '$dom_svgClassName', | 104 'SvgElement.className': '$dom_svgClassName', |
101 'SVGAnimatedString.className': '$dom_svgClassName', | 105 'AnimatedString.className': '$dom_svgClassName', |
102 'SVGStylable.className': '$dom_svgClassName', | 106 'Stylable.className': '$dom_svgClassName', |
103 'Url.createObjectURL': 'createObjectUrl', | 107 'Url.createObjectURL': 'createObjectUrl', |
104 'Url.revokeObjectURL': 'revokeObjectUrl', | 108 'Url.revokeObjectURL': 'revokeObjectUrl', |
105 } | 109 } |
106 | 110 |
107 # Members and classes from the dom that should be removed completely from | 111 # Members and classes from the dom that should be removed completely from |
108 # dart:html. These could be expressed in the IDL instead but expressing this | 112 # dart:html. These could be expressed in the IDL instead but expressing this |
109 # as a simple table instead is more concise. | 113 # as a simple table instead is more concise. |
110 # Syntax is: ClassName.(get\.|set\.)?MemberName | 114 # Syntax is: ClassName.(get\.|set\.)?MemberName |
111 # Using get: and set: is optional and should only be used when a getter needs | 115 # Using get: and set: is optional and should only be used when a getter needs |
112 # to be suppressed but not the setter, etc. | 116 # to be suppressed but not the setter, etc. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 def __init__(self, database): | 274 def __init__(self, database): |
271 self._database = database | 275 self._database = database |
272 | 276 |
273 def RenameInterface(self, interface): | 277 def RenameInterface(self, interface): |
274 if interface.id.startswith('HTML'): | 278 if interface.id.startswith('HTML'): |
275 if any(interface.id in ['Element', 'Document'] | 279 if any(interface.id in ['Element', 'Document'] |
276 for interface in self._database.Hierarchy(interface)): | 280 for interface in self._database.Hierarchy(interface)): |
277 return interface.id[len('HTML'):] | 281 return interface.id[len('HTML'):] |
278 elif interface.id in html_interface_renames: | 282 elif interface.id in html_interface_renames: |
279 return html_interface_renames[interface.id] | 283 return html_interface_renames[interface.id] |
280 return interface.id | 284 return self.DartifyTypeName(interface.id) |
281 | 285 |
282 def RenameMember(self, interface_name, member_node, member, member_prefix=''): | 286 def RenameMember(self, interface_name, member_node, member, member_prefix=''): |
283 """ | 287 """ |
284 Returns the name of the member in the HTML library or None if the member is | 288 Returns the name of the member in the HTML library or None if the member is |
285 suppressed in the HTML library | 289 suppressed in the HTML library |
286 """ | 290 """ |
287 interface = self._database.GetInterface(interface_name) | 291 interface = self._database.GetInterface(interface_name) |
288 | 292 |
289 if self._FindMatch(interface, member, member_prefix, _removed_html_members): | 293 if self._FindMatch(interface, member, member_prefix, _removed_html_members): |
290 return None | 294 return None |
(...skipping 13 matching lines...) Expand all Loading... | |
304 for interface in self._database.Hierarchy(interface): | 308 for interface in self._database.Hierarchy(interface): |
305 html_interface_name = self.RenameInterface(interface) | 309 html_interface_name = self.RenameInterface(interface) |
306 member_name = html_interface_name + '.' + member | 310 member_name = html_interface_name + '.' + member |
307 if member_name in candidates: | 311 if member_name in candidates: |
308 return member_name | 312 return member_name |
309 member_name = html_interface_name + '.' + member_prefix + member | 313 member_name = html_interface_name + '.' + member_prefix + member |
310 if member_name in candidates: | 314 if member_name in candidates: |
311 return member_name | 315 return member_name |
312 | 316 |
313 def GetLibraryName(self, interface): | 317 def GetLibraryName(self, interface): |
314 if interface.id.startswith('SVG'): | 318 return self._GetLibraryName(interface.id) |
319 | |
320 def _GetLibraryName(self, idl_type_name): | |
321 """ | |
322 Gets the name of the library this type should live in. | |
323 This is private because this should use interfaces to resolve the library. | |
324 """ | |
325 | |
326 if idl_type_name.startswith('SVG'): | |
315 return 'svg' | 327 return 'svg' |
316 return 'html' | 328 return 'html' |
329 | |
330 def DartifyTypeName(self, type_name): | |
331 """Converts a DOM name to a Dart-friendly class name. """ | |
332 library_name = self._GetLibraryName(type_name) | |
333 # Only renaming SVG for now. | |
334 if library_name != 'svg': | |
335 return type_name | |
336 | |
337 # Strip off the SVG prefix. | |
338 name = re.sub(r'^SVG', '', type_name) | |
339 | |
340 def toLower(match): | |
341 return match.group(1) + match.group(2).lower() + match.group(3) | |
342 | |
343 # We're looking for a sequence of letters which start with capital letter | |
344 # then a series of caps and finishes with either the end of the string or | |
345 # a capital letter. | |
346 # The [0-9] check is for names such as 2D or 3D | |
347 # The following test cases should match as: | |
348 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue | |
349 # CanvasRenderingContext2D: CanvasRenderingContext(2)(D)$ | |
350 # XPathNSResolver: X()Path(N)(S)(R)esolver | |
Anton Muhin
2012/11/15 17:49:23
nit: you may want to put (X) and (P) to match thre
| |
351 # IFrameElement: I()FrameElement (no change) | |
352 return re.sub(r"([A-Z]|[0-9])([A-Z]*)([A-Z]|$)", toLower, name) | |
OLD | NEW |