diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/build/scripts/make_element_type_helpers.py')
-rwxr-xr-x | chromium/third_party/WebKit/Source/build/scripts/make_element_type_helpers.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/chromium/third_party/WebKit/Source/build/scripts/make_element_type_helpers.py b/chromium/third_party/WebKit/Source/build/scripts/make_element_type_helpers.py new file mode 100755 index 00000000000..69817fc0839 --- /dev/null +++ b/chromium/third_party/WebKit/Source/build/scripts/make_element_type_helpers.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import sys +from collections import defaultdict + +import hasher +import in_generator +import name_utilities +import template_expander + +from in_file import InFile + + +def _symbol(tag): + # FIXME: Remove this special case for the ugly x-webkit-foo attributes. + if tag['name'].startswith('-webkit-'): + return tag['name'].replace('-', '_')[1:] + return name_utilities.cpp_name(tag).replace('-', '_') + +class MakeElementTypeHelpersWriter(in_generator.Writer): + defaults = { + 'Conditional': None, + 'ImplementedAs': None, + 'JSInterfaceName': None, + 'constructorNeedsCreatedByParser': None, + 'constructorNeedsFormElement': None, + 'contextConditional': None, + 'interfaceName': None, + 'noConstructor': None, + 'noConstructor': None, + 'noTypeHelpers': None, + 'runtimeEnabled': None, + } + default_parameters = { + 'attrsNullNamespace': None, + 'fallbackInterfaceName': '', + 'namespace': '', + 'namespacePrefix': '', + 'namespaceURI': '', + 'fallbackJSInterfaceName': '', + } + filters = { + 'enable_conditional': name_utilities.enable_conditional_if_endif, + 'hash': hasher.hash, + 'symbol': _symbol, + } + + def __init__(self, in_file_path): + super(MakeElementTypeHelpersWriter, self).__init__(in_file_path) + + self.namespace = self.in_file.parameters['namespace'].strip('"') + self.fallbackInterface = self.in_file.parameters['fallbackInterfaceName'].strip('"') + + assert self.namespace, 'A namespace is required.' + + self._outputs = { + (self.namespace + "ElementTypeHelpers.h"): self.generate_helper_header, + } + + self._template_context = { + 'namespace': self.namespace, + 'tags': self.in_file.name_dictionaries, + } + + tags = self._template_context['tags'] + interface_counts = defaultdict(int) + for tag in tags: + tag['interface'] = self._interface(tag) + interface_counts[tag['interface']] += 1 + + for tag in tags: + tag['multipleTagNames'] = (interface_counts[tag['interface']] > 1 or tag['interface'] == self.fallbackInterface) + + @template_expander.use_jinja("ElementTypeHelpers.h.tmpl", filters=filters) + def generate_helper_header(self): + return self._template_context + + def _interface(self, tag): + if tag['interfaceName']: + return tag['interfaceName'] + name = name_utilities.upper_first(tag['name']) + # FIXME: We shouldn't hard-code HTML here. + if name == 'HTML': + name = 'Html' + dash = name.find('-') + while dash != -1: + name = name[:dash] + name[dash + 1].upper() + name[dash + 2:] + dash = name.find('-') + return '%s%sElement' % (self.namespace, name) + +if __name__ == "__main__": + in_generator.Maker(MakeElementTypeHelpersWriter).main(sys.argv) |