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

Side by Side Diff: sdk/lib/html/scripts/htmlrenamer.py

Issue 11364186: Dartifying SVG library class names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review feedback. Created 8 years, 1 month 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
« no previous file with comments | « sdk/lib/html/scripts/generator.py ('k') | sdk/lib/html/scripts/systemhtml.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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
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._DartifyInterface(interface)
285
286 def RenameIDLName(self, name):
287 """
288 Renames an IDL type name which does not have an interface.
289 Normally RenameInterface should be used instead. """
290 return self._DartifyTypeName(name)
281 291
282 def RenameMember(self, interface_name, member_node, member, member_prefix=''): 292 def RenameMember(self, interface_name, member_node, member, member_prefix=''):
283 """ 293 """
284 Returns the name of the member in the HTML library or None if the member is 294 Returns the name of the member in the HTML library or None if the member is
285 suppressed in the HTML library 295 suppressed in the HTML library
286 """ 296 """
287 interface = self._database.GetInterface(interface_name) 297 interface = self._database.GetInterface(interface_name)
288 298
289 if self._FindMatch(interface, member, member_prefix, _removed_html_members): 299 if self._FindMatch(interface, member, member_prefix, _removed_html_members):
290 return None 300 return None
(...skipping 13 matching lines...) Expand all
304 for interface in self._database.Hierarchy(interface): 314 for interface in self._database.Hierarchy(interface):
305 html_interface_name = self.RenameInterface(interface) 315 html_interface_name = self.RenameInterface(interface)
306 member_name = html_interface_name + '.' + member 316 member_name = html_interface_name + '.' + member
307 if member_name in candidates: 317 if member_name in candidates:
308 return member_name 318 return member_name
309 member_name = html_interface_name + '.' + member_prefix + member 319 member_name = html_interface_name + '.' + member_prefix + member
310 if member_name in candidates: 320 if member_name in candidates:
311 return member_name 321 return member_name
312 322
313 def GetLibraryName(self, interface): 323 def GetLibraryName(self, interface):
314 if interface.id.startswith('SVG'): 324 return self._GetLibraryName(interface.id)
325
326 def _GetLibraryName(self, idl_type_name):
327 """
328 Gets the name of the library this type should live in.
329 This is private because this should use interfaces to resolve the library.
330 """
331
332 if idl_type_name.startswith('SVG'):
315 return 'svg' 333 return 'svg'
316 return 'html' 334 return 'html'
335
336 def _DartifyInterface(self, interface):
337 """Gets the Dart-friend class name for an IDL interface. """
338 return self._DartifyTypeName(interface.id)
339
340 def _DartifyTypeName(self, type_name):
341 """Converts a DOM name to a Dart-friendly class name. """
342 library_name = self._GetLibraryName(type_name)
343 # Only renaming SVG for now.
344 if library_name != 'svg':
345 return type_name
346
347 # Strip off the SVG prefix.
348 name = type_name[3:]
sra1 2012/11/15 01:10:11 Do you think there is anything in SVG that does no
blois 2012/11/15 01:17:07 I had simplified it when only dealing with SVG typ
349
350 def toLower(match):
351 return match.group(1) + match.group(2).lower() + match.group(3)
352
353 # We're looking for a sequence of letters which start with capitol letter
354 # then a series of caps and finishes with either the end of the string or
355 # a capitol letter.
356 # The [0-9] check is for names such as 2D or 3D
357 # The following test cases should match as:
358 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue
359 # CanvasRenderingContext2D: CanvasRenderingContext(2)(D)$
360 # XPathNSResolver: XPath(N)(S)(R)esolver
361 # IFrameElement: IFrameElement (no change)
362 return re.sub(r"([A-Z]|[0-9])([A-Z]*)([A-Z]+|$)", toLower, name)
OLDNEW
« no previous file with comments | « sdk/lib/html/scripts/generator.py ('k') | sdk/lib/html/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698