Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: tools/dom/scripts/htmlrenamer.py

Issue 16494002: Expand overloaded methods and optional parameters in the html library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 'SVGElement.className': '$dom_svgClassName', 340 'SVGElement.className': '$dom_svgClassName',
340 'SVGStopElement.offset': 'gradientOffset', 341 'SVGStopElement.offset': 'gradientOffset',
341 'URL.createObjectURL': 'createObjectUrl', 342 'URL.createObjectURL': 'createObjectUrl',
342 'URL.revokeObjectURL': 'revokeObjectUrl', 343 'URL.revokeObjectURL': 'revokeObjectUrl',
343 'WheelEvent.wheelDeltaX': '_wheelDeltaX', 344 'WheelEvent.wheelDeltaX': '_wheelDeltaX',
344 'WheelEvent.wheelDeltaY': '_wheelDeltaY', 345 'WheelEvent.wheelDeltaY': '_wheelDeltaY',
345 #'WorkerContext.webkitRequestFileSystem': '_requestFileSystem', 346 #'WorkerContext.webkitRequestFileSystem': '_requestFileSystem',
346 #'WorkerContext.webkitRequestFileSystemSync': '_requestFileSystemSync', 347 #'WorkerContext.webkitRequestFileSystemSync': '_requestFileSystemSync',
347 }) 348 })
348 349
350 # Members that have multiple definitions, but their types are vary, so we rename
351 # them to make them distinct.
352 renamed_overloads = monitored.Dict('htmldartgenreator.renamed_overloads', {
353 'AudioContext.createBuffer(ArrayBuffer buffer, boolean mixToMono)':
354 'createBufferFromBuffer',
355 'CSS.supports(DOMString conditionText)': 'supportsCondition',
356 'CanvasRenderingContext2D.createPattern(HTMLImageElement image, '
357 'DOMString repetitionType)': 'createPatternFromImage',
358 'DataTransferItemList.add(File file)': 'addFile',
359 'DataTransferItemList.add(DOMString data, DOMString type)': 'addData',
360 'FormData.append(DOMString name, DOMString value)': 'appendString',
361 'FormData.append(DOMString name, Blob value, DOMString filename)':
362 'appendBlob',
363 'IDBDatabase.transaction(DOMStringList storeNames, DOMString mode)':
364 'transactionStores',
365 'IDBDatabase.transaction(sequence<DOMString> storeNames, DOMString mode)':
366 'transactionList',
367 'IDBDatabase.transaction(DOMString storeName, DOMString mode)':
368 'transactionStore',
369 'RTCDataChannel.send(ArrayBuffer data)': 'sendByteBuffer',
370 'RTCDataChannel.send(ArrayBufferView data)': 'sendTypedData',
371 'RTCDataChannel.send(Blob data)': 'sendBlob',
372 'RTCDataChannel.send(DOMString data)': 'sendString',
373 'URL.createObjectURL(WebKitMediaSource source)':
374 'createObjectUrlFromSource',
375 'URL.createObjectURL(MediaStream stream)': 'createObjectUrlFromStream',
376 'URL.createObjectURL(Blob blob)': 'createObjectUrlFromBlob',
377 'WebGLRenderingContext.texImage2D(unsigned long target, long level, '
378 'unsigned long internalformat, long width, long height, long border, '
379 'unsigned long format, unsigned long type, ArrayBufferView pixels)':
380 'texImage2DTypedData',
381 'WebGLRenderingContext.texImage2D(unsigned long target, long level, '
382 'unsigned long internalformat, unsigned long format, unsigned long '
383 'type, HTMLImageElement image)': 'texImage2DImage',
384 'WebGLRenderingContext.texImage2D(unsigned long target, long level, '
385 'unsigned long internalformat, unsigned long format, unsigned long '
386 'type, HTMLCanvasElement canvas)': 'texImage2DCanvas',
387 'WebGLRenderingContext.texImage2D(unsigned long target, long level, '
388 'unsigned long internalformat, unsigned long format, unsigned long '
389 'type, HTMLVideoElement video)': 'texImage2DVideo',
390 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, '
391 'long xoffset, long yoffset, long width, long height, unsigned long '
392 'format, unsigned long type, ArrayBufferView pixels)':
393 'texSubImage2DTypedData',
394 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, '
395 'long xoffset, long yoffset, unsigned long format, unsigned long type, '
396 'HTMLImageElement image)': 'texSubImage2DImage',
397 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, '
398 'long xoffset, long yoffset, unsigned long format, unsigned long type, '
399 'HTMLCanvasElement canvas)': 'texSubImage2DCanvas',
400 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, '
401 'long xoffset, long yoffset, unsigned long format, unsigned long type, '
402 'HTMLVideoElement video)': 'texSubImage2DVideo',
403 'WebGLRenderingContext.bufferData(unsigned long target, ArrayBuffer data, '
404 'unsigned long usage)': 'bufferByteData',
405 'WebGLRenderingContext.bufferData(unsigned long target, '
406 'ArrayBufferView data, unsigned long usage)': 'bufferTypedData',
407 'WebGLRenderingContext.bufferSubData(unsigned long target, '
408 'long long offset, ArrayBuffer data)': 'bufferSubByteData',
409 'WebGLRenderingContext.bufferSubData(unsigned long target, '
410 'long long offset, ArrayBufferView data)': 'bufferSubTypedData',
411 'WebSocket.send(ArrayBuffer data)': 'sendByteBuffer',
412 'WebSocket.send(ArrayBufferView data)': 'sendTypeData',
413 'WebSocket.send(DOMString data)': 'sendString',
414 'WebSocket.send(Blob data)': 'sendBlob'
415 })
416
417 # Members that have multiple definitions, but their types are identical (only
418 # number of arguments vary), so we do not rename them as a _raw method.
419 keep_overloaded_members = monitored.Set(
420 'htmldartgenerator.keep_overloaded_members', [
421 'AudioBufferSourceNode.start',
422 'CanvasRenderingContext2D.putImageData',
423 'CanvasRenderingContext2D.webkitPutImageDataHD',
424 'DataTransferItemList.add',
425 'HTMLInputElement.setRangeText',
426 'HTMLTextAreaElement.setRangeText',
427 'IDBDatabase.transaction',
428 'RTCDataChannel.send',
429 'URL.createObjectURL',
430 'WebSocket.send',
431 'XMLHttpRequest.send'
432 ])
433
349 for member in convert_to_future_members: 434 for member in convert_to_future_members:
350 if member in renamed_html_members: 435 if member in renamed_html_members:
351 renamed_html_members[member] = '_' + renamed_html_members[member] 436 renamed_html_members[member] = '_' + renamed_html_members[member]
352 else: 437 else:
353 renamed_html_members[member] = '_' + member[member.find('.') + 1 :] 438 renamed_html_members[member] = '_' + member[member.find('.') + 1 :]
354 439
355 # Members and classes from the dom that should be removed completely from 440 # Members and classes from the dom that should be removed completely from
356 # dart:html. These could be expressed in the IDL instead but expressing this 441 # dart:html. These could be expressed in the IDL instead but expressing this
357 # as a simple table instead is more concise. 442 # as a simple table instead is more concise.
358 # Syntax is: ClassName.(get\:|set\:|call\:|on\:)?MemberName 443 # Syntax is: ClassName.(get\:|set\:|call\:|on\:)?MemberName
359 # Using get: and set: is optional and should only be used when a getter needs 444 # Using get: and set: is optional and should only be used when a getter needs
360 # to be suppressed but not the setter, etc. 445 # to be suppressed but not the setter, etc.
361 # TODO(jacobr): cleanup and augment this list. 446 # TODO(jacobr): cleanup and augment this list.
362 _removed_html_members = monitored.Set('htmlrenamer._removed_html_members', [ 447 removed_html_members = monitored.Set('htmlrenamer.removed_html_members', [
363 'AudioBufferSourceNode.looping', # TODO(vsm): Use deprecated IDL annotation 448 'AudioBufferSourceNode.looping', # TODO(vsm): Use deprecated IDL annotation
364 'CSSStyleDeclaration.getPropertyCSSValue', 449 'CSSStyleDeclaration.getPropertyCSSValue',
365 'CanvasRenderingContext2D.clearShadow', 450 'CanvasRenderingContext2D.clearShadow',
366 'CanvasRenderingContext2D.drawImageFromRect', 451 'CanvasRenderingContext2D.drawImageFromRect',
367 'CanvasRenderingContext2D.setAlpha', 452 'CanvasRenderingContext2D.setAlpha',
368 'CanvasRenderingContext2D.setCompositeOperation', 453 'CanvasRenderingContext2D.setCompositeOperation',
369 'CanvasRenderingContext2D.setFillColor', 454 'CanvasRenderingContext2D.setFillColor',
370 'CanvasRenderingContext2D.setLineCap', 455 'CanvasRenderingContext2D.setLineCap',
371 'CanvasRenderingContext2D.setLineJoin', 456 'CanvasRenderingContext2D.setLineJoin',
372 'CanvasRenderingContext2D.setLineWidth', 457 'CanvasRenderingContext2D.setLineWidth',
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 if self.ShouldSuppressMember(interface, member, member_prefix): 751 if self.ShouldSuppressMember(interface, member, member_prefix):
667 return None 752 return None
668 753
669 if 'CheckSecurityForNode' in member_node.ext_attrs: 754 if 'CheckSecurityForNode' in member_node.ext_attrs:
670 return None 755 return None
671 756
672 name = self._FindMatch(interface, member, member_prefix, 757 name = self._FindMatch(interface, member, member_prefix,
673 renamed_html_members) 758 renamed_html_members)
674 759
675 target_name = renamed_html_members[name] if name else member 760 target_name = renamed_html_members[name] if name else member
676 if self._FindMatch(interface, member, member_prefix, _private_html_members): 761 if self._FindMatch(interface, member, member_prefix, private_html_members):
677 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName 762 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName
678 target_name = '$dom_' + target_name 763 target_name = '$dom_' + target_name
679 764
680 if not name and target_name.startswith('webkit'): 765 if not name and target_name.startswith('webkit'):
681 target_name = member[len('webkit'):] 766 target_name = member[len('webkit'):]
682 target_name = target_name[:1].lower() + target_name[1:] 767 target_name = target_name[:1].lower() + target_name[1:]
683 768
684 if dartify_name: 769 if dartify_name:
685 target_name = self._DartifyMemberName(target_name) 770 target_name = self._DartifyMemberName(target_name)
686 return target_name 771 return target_name
687 772
688 def ShouldSuppressMember(self, interface, member, member_prefix=''): 773 def ShouldSuppressMember(self, interface, member, member_prefix=''):
689 """ Returns true if the member should be suppressed.""" 774 """ Returns true if the member should be suppressed."""
690 if self._FindMatch(interface, member, member_prefix, 775 if self._FindMatch(interface, member, member_prefix, removed_html_members):
691 _removed_html_members):
692 return True 776 return True
693 if interface.id in _removed_html_interfaces: 777 if interface.id in _removed_html_interfaces:
694 return True 778 return True
695 return False 779 return False
696 780
697 def ShouldSuppressInterface(self, interface): 781 def ShouldSuppressInterface(self, interface):
698 """ Returns true if the interface should be suppressed.""" 782 """ Returns true if the interface should be suppressed."""
699 if interface.id in _removed_html_interfaces: 783 if interface.id in _removed_html_interfaces:
700 return True 784 return True
701 785
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 854
771 # We're looking for a sequence of letters which start with capital letter 855 # We're looking for a sequence of letters which start with capital letter
772 # then a series of caps and finishes with either the end of the string or 856 # then a series of caps and finishes with either the end of the string or
773 # a capital letter. 857 # a capital letter.
774 # The [0-9] check is for names such as 2D or 3D 858 # The [0-9] check is for names such as 2D or 3D
775 # The following test cases should match as: 859 # The following test cases should match as:
776 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue 860 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue
777 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) 861 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change)
778 # IFrameElement: (I)()(F)rameElement (no change) 862 # IFrameElement: (I)()(F)rameElement (no change)
779 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) 863 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698