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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 'Storage.length', | 105 'Storage.length', |
106 'Storage.removeItem', | 106 'Storage.removeItem', |
107 'Storage.setItem', | 107 'Storage.setItem', |
108 'WheelEvent.wheelDeltaX', | 108 'WheelEvent.wheelDeltaX', |
109 'WheelEvent.wheelDeltaY', | 109 'WheelEvent.wheelDeltaY', |
110 ]) | 110 ]) |
111 | 111 |
112 # Members from the standard dom that exist in the dart:html library with | 112 # Members from the standard dom that exist in the dart:html library with |
113 # identical functionality but with cleaner names. | 113 # identical functionality but with cleaner names. |
114 _renamed_html_members = { | 114 _renamed_html_members = { |
| 115 'Document.createCDATASection': 'createCDataSection', |
115 'Document.defaultView': 'window', | 116 'Document.defaultView': 'window', |
116 'Element.webkitMatchesSelector' : 'matchesSelector', | 117 'Element.webkitMatchesSelector' : 'matchesSelector', |
117 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', | 118 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', |
118 'Node.cloneNode': 'clone', | 119 'Node.cloneNode': 'clone', |
119 'Node.nextSibling': 'nextNode', | 120 'Node.nextSibling': 'nextNode', |
120 'Node.ownerDocument': 'document', | 121 'Node.ownerDocument': 'document', |
121 'Node.parentNode': 'parent', | 122 'Node.parentNode': 'parent', |
122 'Node.previousSibling': 'previousNode', | 123 'Node.previousSibling': 'previousNode', |
123 'Node.textContent': 'text', | 124 'Node.textContent': 'text', |
124 'SvgElement.className': '$dom_svgClassName', | 125 'SvgElement.className': '$dom_svgClassName', |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 "Element.hasAttributeNS", | 195 "Element.hasAttributeNS", |
195 "Element.getAttributeNS", | 196 "Element.getAttributeNS", |
196 "Element.setAttributeNode", | 197 "Element.setAttributeNode", |
197 "Element.getAttributeNode", | 198 "Element.getAttributeNode", |
198 "Element.removeAttributeNode", | 199 "Element.removeAttributeNode", |
199 "Element.removeAttributeNS", | 200 "Element.removeAttributeNS", |
200 "Element.setAttributeNodeNS", | 201 "Element.setAttributeNodeNS", |
201 "Element.getAttributeNodeNS", | 202 "Element.getAttributeNodeNS", |
202 "Element.setAttributeNS", | 203 "Element.setAttributeNS", |
203 "Event.srcElement", | 204 "Event.srcElement", |
| 205 "EventSource.URL", |
204 "BodyElement.text", | 206 "BodyElement.text", |
205 "AnchorElement.text", | 207 "AnchorElement.text", |
206 "OptionElement.text", | 208 "OptionElement.text", |
207 "ScriptElement.text", | 209 "ScriptElement.text", |
208 "TitleElement.text", | 210 "TitleElement.text", |
209 # "EventSource.get:url", | 211 # "EventSource.get:url", |
210 # TODO(jacobr): should these be removed? | 212 # TODO(jacobr): should these be removed? |
211 "Document.close", | 213 "Document.close", |
212 "Document.hasFocus", | 214 "Document.hasFocus", |
213 | 215 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 interface = self._database.GetInterface(interface_name) | 321 interface = self._database.GetInterface(interface_name) |
320 | 322 |
321 if self._FindMatch(interface, member, member_prefix, _removed_html_members): | 323 if self._FindMatch(interface, member, member_prefix, _removed_html_members): |
322 return None | 324 return None |
323 | 325 |
324 if 'CheckSecurityForNode' in member_node.ext_attrs: | 326 if 'CheckSecurityForNode' in member_node.ext_attrs: |
325 return None | 327 return None |
326 | 328 |
327 name = self._FindMatch(interface, member, member_prefix, | 329 name = self._FindMatch(interface, member, member_prefix, |
328 _renamed_html_members) | 330 _renamed_html_members) |
| 331 |
329 target_name = _renamed_html_members[name] if name else member | 332 target_name = _renamed_html_members[name] if name else member |
330 if self._FindMatch(interface, member, member_prefix, _private_html_members): | 333 if self._FindMatch(interface, member, member_prefix, _private_html_members): |
331 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName | 334 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName |
332 target_name = '$dom_' + target_name | 335 target_name = '$dom_' + target_name |
| 336 |
| 337 target_name = self._CamelCaseName(target_name) |
333 return target_name | 338 return target_name |
334 | 339 |
335 def _FindMatch(self, interface, member, member_prefix, candidates): | 340 def _FindMatch(self, interface, member, member_prefix, candidates): |
336 for interface in self._database.Hierarchy(interface): | 341 for interface in self._database.Hierarchy(interface): |
337 html_interface_name = self.RenameInterface(interface) | 342 html_interface_name = self.RenameInterface(interface) |
338 member_name = html_interface_name + '.' + member | 343 member_name = html_interface_name + '.' + member |
339 if member_name in candidates: | 344 if member_name in candidates: |
340 return member_name | 345 return member_name |
341 member_name = html_interface_name + '.' + member_prefix + member | 346 member_name = html_interface_name + '.' + member_prefix + member |
342 if member_name in candidates: | 347 if member_name in candidates: |
343 return member_name | 348 return member_name |
344 | 349 |
345 def GetLibraryName(self, interface): | 350 def GetLibraryName(self, interface): |
346 return self._GetLibraryName(interface.id) | 351 return self._GetLibraryName(interface.id) |
347 | 352 |
| 353 |
348 def _GetLibraryName(self, idl_type_name): | 354 def _GetLibraryName(self, idl_type_name): |
349 """ | 355 """ |
350 Gets the name of the library this type should live in. | 356 Gets the name of the library this type should live in. |
351 This is private because this should use interfaces to resolve the library. | 357 This is private because this should use interfaces to resolve the library. |
352 """ | 358 """ |
353 | 359 |
354 if idl_type_name.startswith('SVG'): | 360 if idl_type_name.startswith('SVG'): |
355 return 'svg' | 361 return 'svg' |
356 return 'html' | 362 return 'html' |
357 | 363 |
358 def DartifyTypeName(self, type_name): | 364 def DartifyTypeName(self, type_name): |
359 """Converts a DOM name to a Dart-friendly class name. """ | 365 """Converts a DOM name to a Dart-friendly class name. """ |
360 library_name = self._GetLibraryName(type_name) | 366 library_name = self._GetLibraryName(type_name) |
361 # Only renaming SVG for now. | 367 # Only renaming SVG for now. |
362 if library_name != 'svg': | 368 if library_name != 'svg': |
363 return type_name | 369 return type_name |
364 | 370 |
365 # Strip off the SVG prefix. | 371 # Strip off the SVG prefix. |
366 name = re.sub(r'^SVG', '', type_name) | 372 name = re.sub(r'^SVG', '', type_name) |
367 | 373 |
| 374 return self._CamelCaseName(name) |
| 375 |
| 376 def _CamelCaseName(self, name): |
| 377 |
368 def toLower(match): | 378 def toLower(match): |
369 return match.group(1) + match.group(2).lower() + match.group(3) | 379 return match.group(1) + match.group(2).lower() + match.group(3) |
370 | 380 |
371 # We're looking for a sequence of letters which start with capital letter | 381 # 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 | 382 # then a series of caps and finishes with either the end of the string or |
373 # a capital letter. | 383 # a capital letter. |
374 # The [0-9] check is for names such as 2D or 3D | 384 # The [0-9] check is for names such as 2D or 3D |
375 # The following test cases should match as: | 385 # The following test cases should match as: |
376 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue | 386 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue |
377 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) | 387 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) |
378 # IFrameElement: (I)()(F)rameElement (no change) | 388 # IFrameElement: (I)()(F)rameElement (no change) |
379 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) | 389 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) |
OLD | NEW |