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

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

Issue 11418075: Dartifying members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixing menuelement.compact exclusion. Created 8 years 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/dartium/html_dartium.dart ('k') | sdk/lib/html/src/shared_FactoryProviders.dart » ('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 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 'Storage.length', 111 'Storage.length',
112 'Storage.removeItem', 112 'Storage.removeItem',
113 'Storage.setItem', 113 'Storage.setItem',
114 'WheelEvent.wheelDeltaX', 114 'WheelEvent.wheelDeltaX',
115 'WheelEvent.wheelDeltaY', 115 'WheelEvent.wheelDeltaY',
116 ]) 116 ])
117 117
118 # Members from the standard dom that exist in the dart:html library with 118 # Members from the standard dom that exist in the dart:html library with
119 # identical functionality but with cleaner names. 119 # identical functionality but with cleaner names.
120 _renamed_html_members = { 120 _renamed_html_members = {
121 'Document.createCDATASection': 'createCDataSection',
121 'Document.defaultView': 'window', 122 'Document.defaultView': 'window',
122 'Element.webkitMatchesSelector' : 'matchesSelector', 123 'Element.webkitMatchesSelector' : 'matchesSelector',
123 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', 124 'Element.scrollIntoViewIfNeeded': 'scrollIntoView',
124 'Node.cloneNode': 'clone', 125 'Node.cloneNode': 'clone',
125 'Node.nextSibling': 'nextNode', 126 'Node.nextSibling': 'nextNode',
126 'Node.ownerDocument': 'document', 127 'Node.ownerDocument': 'document',
127 'Node.parentNode': 'parent', 128 'Node.parentNode': 'parent',
128 'Node.previousSibling': 'previousNode', 129 'Node.previousSibling': 'previousNode',
129 'Node.textContent': 'text', 130 'Node.textContent': 'text',
130 'SvgElement.className': '$dom_svgClassName', 131 'SvgElement.className': '$dom_svgClassName',
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 "Document.getElementsByTagNameNS", 197 "Document.getElementsByTagNameNS",
197 'Document.webkitCurrentFullScreenElement', 198 'Document.webkitCurrentFullScreenElement',
198 'Document.webkitFullScreenKeyboardInputAllowed', 199 'Document.webkitFullScreenKeyboardInputAllowed',
199 "DocumentType.*", 200 "DocumentType.*",
200 "Element.setAttributeNode", 201 "Element.setAttributeNode",
201 "Element.getAttributeNode", 202 "Element.getAttributeNode",
202 "Element.removeAttributeNode", 203 "Element.removeAttributeNode",
203 "Element.setAttributeNodeNS", 204 "Element.setAttributeNodeNS",
204 "Element.getAttributeNodeNS", 205 "Element.getAttributeNodeNS",
205 "Event.srcElement", 206 "Event.srcElement",
207 "EventSource.URL",
206 "BodyElement.text", 208 "BodyElement.text",
207 "AnchorElement.text", 209 "AnchorElement.text",
208 "OptionElement.text", 210 "OptionElement.text",
209 "ScriptElement.text", 211 "ScriptElement.text",
210 "TitleElement.text", 212 "TitleElement.text",
211 # "EventSource.get:url", 213 # "EventSource.get:url",
212 # TODO(jacobr): should these be removed? 214 # TODO(jacobr): should these be removed?
213 "Document.close", 215 "Document.close",
214 "Document.hasFocus", 216 "Document.hasFocus",
215 217
(...skipping 28 matching lines...) Expand all
244 'Element.scrollIntoView', 246 'Element.scrollIntoView',
245 'Element.get:classList', 247 'Element.get:classList',
246 "FormElement.get:elements", 248 "FormElement.get:elements",
247 "HTMLFrameElement.*", 249 "HTMLFrameElement.*",
248 "HTMLFrameSetElement.*", 250 "HTMLFrameSetElement.*",
249 "HtmlElement.version", 251 "HtmlElement.version",
250 "HtmlElement.manifest", 252 "HtmlElement.manifest",
251 "Document.version", 253 "Document.version",
252 "Document.manifest", 254 "Document.manifest",
253 "HTMLIsIndexElement.*", 255 "HTMLIsIndexElement.*",
256 "HTMLMenuElement.compact",
254 "HTMLOptionsCollection.*", 257 "HTMLOptionsCollection.*",
255 "HTMLPropertiesCollection.*", 258 "HTMLPropertiesCollection.*",
256 "SelectElement.remove", 259 "SelectElement.remove",
257 "MenuElement.compact",
258 "NamedNodeMap.*", 260 "NamedNodeMap.*",
259 "Node.isEqualNode", 261 "Node.isEqualNode",
260 "Node.get:TEXT_NODE", 262 "Node.get:TEXT_NODE",
261 "Node.hasAttributes", 263 "Node.hasAttributes",
262 "Node.get:DOCUMENT_TYPE_NODE", 264 "Node.get:DOCUMENT_TYPE_NODE",
263 "Node.get:DOCUMENT_POSITION_FOLLOWING", 265 "Node.get:DOCUMENT_POSITION_FOLLOWING",
264 "Node.lookupNamespaceURI", 266 "Node.lookupNamespaceURI",
265 "Node.get:ELEMENT_NODE", 267 "Node.get:ELEMENT_NODE",
266 "Node.get:DOCUMENT_FRAGMENT_NODE", 268 "Node.get:DOCUMENT_FRAGMENT_NODE",
267 "Node.isDefaultNamespace", 269 "Node.isDefaultNamespace",
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 interface = self._database.GetInterface(interface_name) 324 interface = self._database.GetInterface(interface_name)
323 325
324 if self._FindMatch(interface, member, member_prefix, _removed_html_members): 326 if self._FindMatch(interface, member, member_prefix, _removed_html_members):
325 return None 327 return None
326 328
327 if 'CheckSecurityForNode' in member_node.ext_attrs: 329 if 'CheckSecurityForNode' in member_node.ext_attrs:
328 return None 330 return None
329 331
330 name = self._FindMatch(interface, member, member_prefix, 332 name = self._FindMatch(interface, member, member_prefix,
331 _renamed_html_members) 333 _renamed_html_members)
334
332 target_name = _renamed_html_members[name] if name else member 335 target_name = _renamed_html_members[name] if name else member
333 if self._FindMatch(interface, member, member_prefix, _private_html_members): 336 if self._FindMatch(interface, member, member_prefix, _private_html_members):
334 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName 337 if not target_name.startswith('$dom_'): # e.g. $dom_svgClassName
335 target_name = '$dom_' + target_name 338 target_name = '$dom_' + target_name
339
340 target_name = self._DartifyMemberName(target_name)
336 return target_name 341 return target_name
337 342
338 def _FindMatch(self, interface, member, member_prefix, candidates): 343 def _FindMatch(self, interface, member, member_prefix, candidates):
339 for interface in self._database.Hierarchy(interface): 344 for interface in self._database.Hierarchy(interface):
340 html_interface_name = self.RenameInterface(interface) 345 html_interface_name = self.DartifyTypeName(interface.id)
341 member_name = html_interface_name + '.' + member 346 member_name = html_interface_name + '.' + member
342 if member_name in candidates: 347 if member_name in candidates:
343 return member_name 348 return member_name
344 member_name = html_interface_name + '.' + member_prefix + member 349 member_name = html_interface_name + '.' + member_prefix + member
345 if member_name in candidates: 350 if member_name in candidates:
346 return member_name 351 return member_name
347 352
348 def GetLibraryName(self, interface): 353 def GetLibraryName(self, interface):
349 return self._GetLibraryName(interface.id) 354 return self._GetLibraryName(interface.id)
350 355
351 def _GetLibraryName(self, idl_type_name): 356 def _GetLibraryName(self, idl_type_name):
352 """ 357 """
353 Gets the name of the library this type should live in. 358 Gets the name of the library this type should live in.
354 This is private because this should use interfaces to resolve the library. 359 This is private because this should use interfaces to resolve the library.
355 """ 360 """
356
357 if idl_type_name.startswith('SVG'): 361 if idl_type_name.startswith('SVG'):
358 return 'svg' 362 return 'svg'
359 return 'html' 363 return 'html'
360 364
365
361 def DartifyTypeName(self, type_name): 366 def DartifyTypeName(self, type_name):
362 """Converts a DOM name to a Dart-friendly class name. """ 367 """Converts a DOM name to a Dart-friendly class name. """
363 library_name = self._GetLibraryName(type_name) 368 library_name = self._GetLibraryName(type_name)
364 # Only renaming SVG for now. 369 # Only renaming SVG for now.
365 if library_name != 'svg': 370 if library_name != 'svg':
366 return type_name 371 return type_name
367 372
368 # Strip off the SVG prefix. 373 # Strip off the SVG prefix.
369 name = re.sub(r'^SVG', '', type_name) 374 name = re.sub(r'^SVG', '', type_name)
375 return self._CamelCaseName(name)
376
377 def _DartifyMemberName(self, member_name):
378 # Strip off any OpenGL ES suffixes.
379 name = re.sub(r'OES$', '', member_name)
380 return self._CamelCaseName(name)
381
382 def _CamelCaseName(self, name):
370 383
371 def toLower(match): 384 def toLower(match):
372 return match.group(1) + match.group(2).lower() + match.group(3) 385 return match.group(1) + match.group(2).lower() + match.group(3)
373 386
374 # We're looking for a sequence of letters which start with capital letter 387 # We're looking for a sequence of letters which start with capital letter
375 # then a series of caps and finishes with either the end of the string or 388 # then a series of caps and finishes with either the end of the string or
376 # a capital letter. 389 # a capital letter.
377 # The [0-9] check is for names such as 2D or 3D 390 # The [0-9] check is for names such as 2D or 3D
378 # The following test cases should match as: 391 # The following test cases should match as:
379 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue 392 # WebKitCSSFilterValue: WebKit(C)(SS)(F)ilterValue
380 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change) 393 # XPathNSResolver: (X)()(P)ath(N)(S)(R)esolver (no change)
381 # IFrameElement: (I)()(F)rameElement (no change) 394 # IFrameElement: (I)()(F)rameElement (no change)
382 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name) 395 return re.sub(r'([A-Z])([A-Z]{2,})([A-Z]|$)', toLower, name)
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | sdk/lib/html/src/shared_FactoryProviders.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698