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 logging | 5 import logging |
6 import monitored | 6 import monitored |
7 import re | 7 import re |
8 | 8 |
9 typed_array_renames = { | 9 typed_array_renames = { |
10 'ArrayBuffer': 'ByteBuffer', | 10 'ArrayBuffer': 'ByteBuffer', |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 'RTCPeerConnection.setLocalDescription', | 144 'RTCPeerConnection.setLocalDescription', |
145 'RTCPeerConnection.setRemoteDescription', | 145 'RTCPeerConnection.setRemoteDescription', |
146 'StorageInfo.requestQuota', | 146 'StorageInfo.requestQuota', |
147 'WorkerContext.webkitResolveLocalFileSystemURL', | 147 'WorkerContext.webkitResolveLocalFileSystemURL', |
148 'WorkerContext.webkitRequestFileSystem', | 148 'WorkerContext.webkitRequestFileSystem', |
149 ]) | 149 ]) |
150 | 150 |
151 # Members from the standard dom that should not be exposed publicly in dart:html | 151 # Members from the standard dom that should not be exposed publicly in dart:html |
152 # but need to be exposed internally to implement dart:html on top of a standard | 152 # but need to be exposed internally to implement dart:html on top of a standard |
153 # browser. | 153 # browser. |
154 _private_html_members = monitored.Set('htmlrenamer._private_html_members', [ | 154 private_html_members = monitored.Set('htmlrenamer.private_html_members', [ |
| 155 'AudioNode.connect', |
155 'CanvasRenderingContext2D.arc', | 156 'CanvasRenderingContext2D.arc', |
156 'CompositionEvent.initCompositionEvent', | 157 'CompositionEvent.initCompositionEvent', |
157 'CustomEvent.initCustomEvent', | 158 'CustomEvent.initCustomEvent', |
158 'DeviceOrientationEvent.initDeviceOrientationEvent', | 159 'DeviceOrientationEvent.initDeviceOrientationEvent', |
159 'Document.createElement', | 160 'Document.createElement', |
160 'Document.createElementNS', | 161 'Document.createElementNS', |
161 'Document.createEvent', | 162 'Document.createEvent', |
162 'Document.createNodeIterator', | 163 'Document.createNodeIterator', |
163 'Document.createRange', | 164 'Document.createRange', |
164 'Document.createTextNode', | 165 'Document.createTextNode', |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 'URL.createObjectURL': 'createObjectUrl', | 342 'URL.createObjectURL': 'createObjectUrl', |
342 'URL.revokeObjectURL': 'revokeObjectUrl', | 343 'URL.revokeObjectURL': 'revokeObjectUrl', |
343 'WebGLRenderingContext.texImage2D': '_texImage2D', | 344 'WebGLRenderingContext.texImage2D': '_texImage2D', |
344 'WebGLRenderingContext.texSubImage2D': '_texSubImageImage2D', | 345 'WebGLRenderingContext.texSubImage2D': '_texSubImageImage2D', |
345 'WheelEvent.wheelDeltaX': '_wheelDeltaX', | 346 'WheelEvent.wheelDeltaX': '_wheelDeltaX', |
346 'WheelEvent.wheelDeltaY': '_wheelDeltaY', | 347 'WheelEvent.wheelDeltaY': '_wheelDeltaY', |
347 #'WorkerContext.webkitRequestFileSystem': '_requestFileSystem', | 348 #'WorkerContext.webkitRequestFileSystem': '_requestFileSystem', |
348 #'WorkerContext.webkitRequestFileSystemSync': '_requestFileSystemSync', | 349 #'WorkerContext.webkitRequestFileSystemSync': '_requestFileSystemSync', |
349 }) | 350 }) |
350 | 351 |
| 352 # Members that have multiple definitions, but their types are vary, so we rename |
| 353 # them to make them distinct. |
| 354 renamed_overloads = monitored.Dict('htmldartgenreator.renamed_overloads', { |
| 355 'AudioContext.createBuffer(ArrayBuffer buffer, boolean mixToMono)': |
| 356 'createBufferFromBuffer', |
| 357 'CSS.supports(DOMString conditionText)': 'supportsCondition', |
| 358 'CanvasRenderingContext2D.createPattern(HTMLImageElement image, ' |
| 359 'DOMString repetitionType)': 'createPatternFromImage', |
| 360 'DataTransferItemList.add(File file)': 'addFile', |
| 361 'DataTransferItemList.add(DOMString data, DOMString type)': 'addData', |
| 362 'IDBDatabase.transaction(DOMStringList storeNames, DOMString mode)': |
| 363 'transactionStores', |
| 364 'IDBDatabase.transaction(sequence<DOMString> storeNames, DOMString mode)': |
| 365 'transactionList', |
| 366 'IDBDatabase.transaction(DOMString storeName, DOMString mode)': |
| 367 'transactionStore', |
| 368 'RTCDataChannel.send(ArrayBuffer data)': 'sendByteBuffer', |
| 369 'RTCDataChannel.send(ArrayBufferView data)': 'sendTypedData', |
| 370 'RTCDataChannel.send(Blob data)': 'sendBlob', |
| 371 'RTCDataChannel.send(DOMString data)': 'sendString', |
| 372 'URL.createObjectURL(WebKitMediaSource source)': |
| 373 'createObjectUrlFromSource', |
| 374 'URL.createObjectURL(MediaStream stream)': 'createObjectUrlFromStream', |
| 375 'URL.createObjectURL(Blob blob)': 'createObjectUrlFromBlob', |
| 376 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
| 377 'unsigned long internalformat, unsigned long format, unsigned long ' |
| 378 'type, ImageData pixels)': 'texImage2DImageData', |
| 379 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
| 380 'unsigned long internalformat, unsigned long format, unsigned long ' |
| 381 'type, HTMLImageElement image)': 'texImage2DImage', |
| 382 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
| 383 'unsigned long internalformat, unsigned long format, unsigned long ' |
| 384 'type, HTMLCanvasElement canvas)': 'texImage2DCanvas', |
| 385 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
| 386 'unsigned long internalformat, unsigned long format, unsigned long ' |
| 387 'type, HTMLVideoElement video)': 'texImage2DVideo', |
| 388 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
| 389 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
| 390 'ImageData pixels)': 'texSubImage2DImageData', |
| 391 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
| 392 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
| 393 'HTMLImageElement image)': 'texSubImage2DImage', |
| 394 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
| 395 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
| 396 'HTMLCanvasElement canvas)': 'texSubImage2DCanvas', |
| 397 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
| 398 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
| 399 'HTMLVideoElement video)': 'texSubImage2DVideo', |
| 400 'WebGLRenderingContext.bufferData(unsigned long target, ArrayBuffer data, ' |
| 401 'unsigned long usage)': 'bufferByteData', |
| 402 'WebGLRenderingContext.bufferData(unsigned long target, ' |
| 403 'ArrayBufferView data, unsigned long usage)': 'bufferDataTyped', |
| 404 'WebGLRenderingContext.bufferSubData(unsigned long target, ' |
| 405 'long long offset, ArrayBuffer data)': 'bufferSubByteData', |
| 406 'WebGLRenderingContext.bufferSubData(unsigned long target, ' |
| 407 'long long offset, ArrayBufferView data)': 'bufferSubDataTyped', |
| 408 }) |
| 409 |
| 410 # Members that have multiple definitions, but their types are identical (only |
| 411 # number of arguments vary), so we do not rename them as a _raw method. |
| 412 keep_overloaded_members = monitored.Set( |
| 413 'htmldartgenerator.keep_overloaded_members', [ |
| 414 'AudioBufferSourceNode.start', |
| 415 'CanvasRenderingContext2D.putImageData', |
| 416 'CanvasRenderingContext2D.webkitPutImageDataHD', |
| 417 'DataTransferItemList.add', |
| 418 'FormData.append', # TODO(efortuna): Split out into appendBlob. |
| 419 'HTMLInputElement.setRangeText', |
| 420 'HTMLTextAreaElement.setRangeText', |
| 421 'IDBDatabase.transaction', |
| 422 'RTCDataChannel.send', |
| 423 'URL.createObjectURL', |
| 424 'WebSocket.send', # TODO(efortuna): Add sendBlob, sendString, and family. |
| 425 'XMLHttpRequest.send' |
| 426 ]) |
| 427 |
351 for member in convert_to_future_members: | 428 for member in convert_to_future_members: |
352 if member in renamed_html_members: | 429 if member in renamed_html_members: |
353 renamed_html_members[member] = '_' + renamed_html_members[member] | 430 renamed_html_members[member] = '_' + renamed_html_members[member] |
354 else: | 431 else: |
355 renamed_html_members[member] = '_' + member[member.find('.') + 1 :] | 432 renamed_html_members[member] = '_' + member[member.find('.') + 1 :] |
356 | 433 |
357 # Members and classes from the dom that should be removed completely from | 434 # Members and classes from the dom that should be removed completely from |
358 # dart:html. These could be expressed in the IDL instead but expressing this | 435 # dart:html. These could be expressed in the IDL instead but expressing this |
359 # as a simple table instead is more concise. | 436 # as a simple table instead is more concise. |
360 # Syntax is: ClassName.(get\:|set\:|call\:|on\:)?MemberName | 437 # Syntax is: ClassName.(get\:|set\:|call\:|on\:)?MemberName |
361 # Using get: and set: is optional and should only be used when a getter needs | 438 # Using get: and set: is optional and should only be used when a getter needs |
362 # to be suppressed but not the setter, etc. | 439 # to be suppressed but not the setter, etc. |
363 # TODO(jacobr): cleanup and augment this list. | 440 # TODO(jacobr): cleanup and augment this list. |
364 _removed_html_members = monitored.Set('htmlrenamer._removed_html_members', [ | 441 removed_html_members = monitored.Set('htmlrenamer.removed_html_members', [ |
365 'AudioBufferSourceNode.looping', # TODO(vsm): Use deprecated IDL annotation | 442 'AudioBufferSourceNode.looping', # TODO(vsm): Use deprecated IDL annotation |
366 'CSSStyleDeclaration.getPropertyCSSValue', | 443 'CSSStyleDeclaration.getPropertyCSSValue', |
367 'CanvasRenderingContext2D.clearShadow', | 444 'CanvasRenderingContext2D.clearShadow', |
368 'CanvasRenderingContext2D.drawImageFromRect', | 445 'CanvasRenderingContext2D.drawImageFromRect', |
369 'CanvasRenderingContext2D.setAlpha', | 446 'CanvasRenderingContext2D.setAlpha', |
370 'CanvasRenderingContext2D.setCompositeOperation', | 447 'CanvasRenderingContext2D.setCompositeOperation', |
371 'CanvasRenderingContext2D.setFillColor', | 448 'CanvasRenderingContext2D.setFillColor', |
372 'CanvasRenderingContext2D.setLineCap', | 449 'CanvasRenderingContext2D.setLineCap', |
373 'CanvasRenderingContext2D.setLineJoin', | 450 'CanvasRenderingContext2D.setLineJoin', |
374 'CanvasRenderingContext2D.setLineWidth', | 451 'CanvasRenderingContext2D.setLineWidth', |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 if self.ShouldSuppressMember(interface, member, member_prefix): | 745 if self.ShouldSuppressMember(interface, member, member_prefix): |
669 return None | 746 return None |
670 | 747 |
671 if 'CheckSecurityForNode' in member_node.ext_attrs: | 748 if 'CheckSecurityForNode' in member_node.ext_attrs: |
672 return None | 749 return None |
673 | 750 |
674 name = self._FindMatch(interface, member, member_prefix, | 751 name = self._FindMatch(interface, member, member_prefix, |
675 renamed_html_members) | 752 renamed_html_members) |
676 | 753 |
677 target_name = renamed_html_members[name] if name else member | 754 target_name = renamed_html_members[name] if name else member |
678 if self._FindMatch(interface, member, member_prefix, _private_html_members): | 755 if self._FindMatch(interface, member, member_prefix, private_html_members): |
679 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName | 756 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName |
680 target_name = '$dom_' + target_name | 757 target_name = '$dom_' + target_name |
681 | 758 |
682 if not name and target_name.startswith('webkit'): | 759 if not name and target_name.startswith('webkit'): |
683 target_name = member[len('webkit'):] | 760 target_name = member[len('webkit'):] |
684 target_name = target_name[:1].lower() + target_name[1:] | 761 target_name = target_name[:1].lower() + target_name[1:] |
685 | 762 |
686 if dartify_name: | 763 if dartify_name: |
687 target_name = self._DartifyMemberName(target_name) | 764 target_name = self._DartifyMemberName(target_name) |
688 return target_name | 765 return target_name |
689 | 766 |
690 def ShouldSuppressMember(self, interface, member, member_prefix=''): | 767 def ShouldSuppressMember(self, interface, member, member_prefix=''): |
691 """ Returns true if the member should be suppressed.""" | 768 """ Returns true if the member should be suppressed.""" |
692 if self._FindMatch(interface, member, member_prefix, | 769 if self._FindMatch(interface, member, member_prefix, removed_html_members): |
693 _removed_html_members): | |
694 return True | 770 return True |
695 if interface.id in _removed_html_interfaces: | 771 if interface.id in _removed_html_interfaces: |
696 return True | 772 return True |
697 return False | 773 return False |
698 | 774 |
699 def ShouldSuppressInterface(self, interface): | 775 def ShouldSuppressInterface(self, interface): |
700 """ Returns true if the interface should be suppressed.""" | 776 """ Returns true if the interface should be suppressed.""" |
701 if interface.id in _removed_html_interfaces: | 777 if interface.id in _removed_html_interfaces: |
702 return True | 778 return True |
703 | 779 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 848 |
773 # We're looking for a sequence of letters which start with capital letter | 849 # We're looking for a sequence of letters which start with capital letter |
774 # then a series of caps and finishes with either the end of the string or | 850 # then a series of caps and finishes with either the end of the string or |
775 # a capital letter. | 851 # a capital letter. |
776 # The [0-9] check is for names such as 2D or 3D | 852 # The [0-9] check is for names such as 2D or 3D |
777 # The following test cases should match as: | 853 # The following test cases should match as: |
778 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue | 854 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue |
779 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) | 855 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) |
780 # IFrameElement: (I)()(F)rameElement (no change) | 856 # IFrameElement: (I)()(F)rameElement (no change) |
781 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) | 857 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) |
OLD | NEW |