Commit 156fda72 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

make_event_factory.py: Simplify |namespace| handling.

namespace is always "Event". We don't need to treat it as a variable.
This CL helps move_blink_source.py to replace "Event*Factory.h" in
EventFactory.cpp.tmpl with "event_*_factory.h".

Bug: 578345
Change-Id: Ib46b4c39549cd5e564d836fa705c4f574762d38f
Reviewed-on: https://chromium-review.googlesource.com/663800Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501552}
parent a63a88f2
...@@ -38,12 +38,12 @@ import template_expander ...@@ -38,12 +38,12 @@ import template_expander
HEADER_TEMPLATE = """%(license)s HEADER_TEMPLATE = """%(license)s
#ifndef %(namespace)s%(suffix)sHeaders_h #ifndef Event%(suffix)sHeaders_h
#define %(namespace)s%(suffix)sHeaders_h #define Event%(suffix)sHeaders_h
%(base_header_for_suffix)s %(base_header_for_suffix)s
%(includes)s %(includes)s
#endif // %(namespace)s%(suffix)sHeaders_h #endif // Event%(suffix)sHeaders_h
""" """
...@@ -121,9 +121,10 @@ class EventFactoryWriter(json5_generator.Writer): ...@@ -121,9 +121,10 @@ class EventFactoryWriter(json5_generator.Writer):
def __init__(self, json5_file_path): def __init__(self, json5_file_path):
super(EventFactoryWriter, self).__init__(json5_file_path) super(EventFactoryWriter, self).__init__(json5_file_path)
self.namespace = self.json5_file.metadata['namespace'].strip('"') self.namespace = self.json5_file.metadata['namespace'].strip('"')
assert self.namespace == 'Event', 'namespace field should be "Event".'
self.suffix = self.json5_file.metadata['suffix'].strip('"') self.suffix = self.json5_file.metadata['suffix'].strip('"')
self._outputs = {(self.namespace + self.suffix + "Headers.h"): self.generate_headers_header, self._outputs = {('Event%sHeaders.h' % self.suffix): self.generate_headers_header,
(self.namespace + self.suffix + ".cpp"): self.generate_implementation, ('Event%s.cpp' % self.suffix): self.generate_implementation,
} }
def _fatal(self, message): def _fatal(self, message):
...@@ -171,11 +172,10 @@ class EventFactoryWriter(json5_generator.Writer): ...@@ -171,11 +172,10 @@ class EventFactoryWriter(json5_generator.Writer):
def generate_headers_header(self): def generate_headers_header(self):
base_header_for_suffix = '' base_header_for_suffix = ''
if self.suffix: if self.suffix:
base_header_for_suffix = '\n#include "core/%(namespace)sHeaders.h"\n' % {'namespace': self.namespace} base_header_for_suffix = '\n#include "core/EventHeaders.h"\n'
return HEADER_TEMPLATE % { return HEADER_TEMPLATE % {
'input_files': self._input_files, 'input_files': self._input_files,
'license': license.license_for_generated_cpp(), 'license': license.license_for_generated_cpp(),
'namespace': self.namespace,
'suffix': self.suffix, 'suffix': self.suffix,
'base_header_for_suffix': base_header_for_suffix, 'base_header_for_suffix': base_header_for_suffix,
'includes': '\n'.join(self._headers_header_includes(self.json5_file.name_dictionaries)), 'includes': '\n'.join(self._headers_header_includes(self.json5_file.name_dictionaries)),
...@@ -185,7 +185,6 @@ class EventFactoryWriter(json5_generator.Writer): ...@@ -185,7 +185,6 @@ class EventFactoryWriter(json5_generator.Writer):
def generate_implementation(self): def generate_implementation(self):
return { return {
'input_files': self._input_files, 'input_files': self._input_files,
'namespace': self.namespace,
'suffix': self.suffix, 'suffix': self.suffix,
'events': self.json5_file.name_dictionaries, 'events': self.json5_file.name_dictionaries,
} }
......
...@@ -4,18 +4,18 @@ ...@@ -4,18 +4,18 @@
{{source_files_for_generated_file(template_file, input_files)}} {{source_files_for_generated_file(template_file, input_files)}}
{% if suffix == 'Modules' %} {% if suffix == 'Modules' %}
#include "modules/{{namespace}}{{suffix}}Factory.h" #include "modules/EventModulesFactory.h"
{% else %} {% else %}
#include "core/events/{{namespace}}Factory.h" #include "core/events/EventFactory.h"
{% endif %} {% endif %}
#include "{{namespace}}{{suffix}}Headers.h" #include "Event{{suffix}}Headers.h"
#include "core/frame/Deprecation.h" #include "core/frame/Deprecation.h"
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
namespace blink { namespace blink {
{{namespace}}* {{namespace}}{{suffix}}Factory::Create(ExecutionContext* executionContext, const String& type) { Event* Event{{suffix}}Factory::Create(ExecutionContext* executionContext, const String& type) {
{% for event in events if event|script_name|create_event_whitelist or event|script_name|create_event_measure_whitelist %} {% for event in events if event|script_name|create_event_whitelist or event|script_name|create_event_measure_whitelist %}
{% if event|script_name|create_event_whitelist or event|script_name|create_event_measure_whitelist %} {% if event|script_name|create_event_whitelist or event|script_name|create_event_measure_whitelist %}
if (DeprecatedEqualIgnoringCase(type, "{{event|script_name}}"){% if event.RuntimeEnabled %} && RuntimeEnabledFeatures::{{event.RuntimeEnabled}}(){% endif %}) { if (DeprecatedEqualIgnoringCase(type, "{{event|script_name}}"){% if event.RuntimeEnabled %} && RuntimeEnabledFeatures::{{event.RuntimeEnabled}}(){% endif %}) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment