18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#!/usr/bin/perl -w
28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project# Copyright (C) 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
4635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project# Copyright (C) 2009, Julien Chaffraix <jchaffraix@webkit.org>
55f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian# Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# Redistribution and use in source and binary forms, with or without
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# modification, are permitted provided that the following conditions
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# are met:
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# 1.  Redistributions of source code must retain the above copyright
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#     notice, this list of conditions and the following disclaimer.
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# 2.  Redistributions in binary form must reproduce the above copyright
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#     notice, this list of conditions and the following disclaimer in the
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#     documentation and/or other materials provided with the distribution.
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#     its contributors may be used to endorse or promote products derived
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#     from this software without specific prior written permission.
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectuse strict;
328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectuse Config;
348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectuse Getopt::Long;
358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectuse File::Path;
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectuse IO::File;
378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectuse InFilesParser;
388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectuse Switch;
398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy $printFactory = 0;
415e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockmy $printWrapperFactory = 0;
425e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockmy $printWrapperFactoryV8 = 0;
438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy $tagsFile = "";
448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy $attrsFile = "";
458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy $outputDir = ".";
468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy %tags = ();
478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy %attrs = ();
488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy %parameters = ();
498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy $extraDefines = 0;
508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmy $preprocessor = "/usr/bin/gcc -E -P -x c++";
518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
52231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve BlockGetOptions(
53231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    'tags=s' => \$tagsFile,
548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    'attrs=s' => \$attrsFile,
558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    'factory' => \$printFactory,
568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    'outputDir=s' => \$outputDir,
578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    'extraDefines=s' => \$extraDefines,
588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    'preprocessor=s' => \$preprocessor,
595e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    'wrapperFactory' => \$printWrapperFactory,
605e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    'wrapperFactoryV8' => \$printWrapperFactoryV8
61231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block);
628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectdie "You must specify at least one of --tags <file> or --attrs <file>" unless (length($tagsFile) || length($attrsFile));
648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectreadNames($tagsFile, "tags") if length($tagsFile);
668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectreadNames($attrsFile, "attrs") if length($attrsFile);
678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
68231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockdie "You must specify a namespace (e.g. SVG) for <namespace>Names.h" unless $parameters{namespace};
69231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockdie "You must specify a namespaceURI (e.g. http://www.w3.org/2000/svg)" unless $parameters{namespaceURI};
708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
71231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block$parameters{namespacePrefix} = $parameters{namespace} unless $parameters{namespacePrefix};
728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectmkpath($outputDir);
74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockmy $namesBasePath = "$outputDir/$parameters{namespace}Names";
75231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockmy $factoryBasePath = "$outputDir/$parameters{namespace}ElementFactory";
765e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockmy $wrapperFactoryFileName = "$parameters{namespace}ElementWrapperFactory";
778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectprintNamesHeaderFile("$namesBasePath.h");
798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectprintNamesCppFile("$namesBasePath.cpp");
808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectif ($printFactory) {
828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    printFactoryCppFile("$factoryBasePath.cpp");
838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    printFactoryHeaderFile("$factoryBasePath.h");
848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
865e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockdie "You cannot specify both --wrapperFactory and --wrapperFactoryV8" if $printWrapperFactory && $printWrapperFactoryV8;
875e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockmy $wrapperFactoryType = "";
888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectif ($printWrapperFactory) {
895e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    $wrapperFactoryType = "JS";
905e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block} elsif ($printWrapperFactoryV8) {
915e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    $wrapperFactoryType = "V8";
925e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block}
935e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
945e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockif ($wrapperFactoryType) {
955e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    printWrapperFactoryCppFile($outputDir, $wrapperFactoryType, $wrapperFactoryFileName);
965e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    printWrapperFactoryHeaderFile($outputDir, $wrapperFactoryType, $wrapperFactoryFileName);
978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project### Hash initialization
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
101231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blocksub defaultTagPropertyHash
1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
103231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return (
104231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'constructorNeedsCreatedByParser' => 0,
105231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'constructorNeedsFormElement' => 0,
106231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'createWithNew' => 0,
107231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'interfaceName' => defaultInterfaceName($_[0]),
108231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        # By default, the JSInterfaceName is the same as the interfaceName.
109231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'JSInterfaceName' => defaultInterfaceName($_[0]),
110231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'mapToTagName' => '',
111231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'wrapperOnlyIfMediaIsAvailable' => 0,
112231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'conditional' => 0
113231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    );
1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
116231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blocksub defaultParametersHash
1178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
118231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return (
119231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'namespace' => '',
120231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'namespacePrefix' => '',
121231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'namespaceURI' => '',
122231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'guardFactoryWith' => '',
123231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        'tagsNullNamespace' => 0,
124d0825bca7fe65beaee391d30da42e937db621564Steve Block        'attrsNullNamespace' => 0
125231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    );
1268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
128635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectsub defaultInterfaceName
129635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project{
130231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    die "No namespace found" if !$parameters{namespace};
131231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return $parameters{namespace} . upperCaseName($_[0]) . "Element"
132635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project}
133635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
1348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project### Parsing handlers
1358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub tagsHandler
1378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my ($tag, $property, $value) = @_;
1398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    $tag =~ s/-/_/g;
1418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
142231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    # Initialize default property values.
143231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    $tags{$tag} = { defaultTagPropertyHash($tag) } if !defined($tags{$tag});
1448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if ($property) {
1468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        die "Unknown property $property for tag $tag\n" if !defined($tags{$tag}{$property});
147231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
148231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        # The code relies on JSInterfaceName deriving from interfaceName to check for custom JSInterfaceName.
149231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        # So override JSInterfaceName if it was not already set.
150231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        $tags{$tag}{JSInterfaceName} = $value if $property eq "interfaceName" && $tags{$tag}{JSInterfaceName} eq $tags{$tag}{interfaceName};
151231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
1528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        $tags{$tag}{$property} = $value;
1538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
1548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub attrsHandler
1578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my ($attr, $property, $value) = @_;
1598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    $attr =~ s/-/_/g;
1618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    # Initialize default properties' values.
163d0825bca7fe65beaee391d30da42e937db621564Steve Block    $attrs{$attr} = {} if !defined($attrs{$attr});
1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if ($property) {
1668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        die "Unknown property $property for attribute $attr\n" if !defined($attrs{$attr}{$property});
1678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        $attrs{$attr}{$property} = $value;
1688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
1698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub parametersHandler
1728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my ($parameter, $value) = @_;
1748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    # Initialize default properties' values.
176231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    %parameters = defaultParametersHash() if !(keys %parameters);
1778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    die "Unknown parameter $parameter for tags/attrs\n" if !defined($parameters{$parameter});
1798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    $parameters{$parameter} = $value;
1808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project## Support routines
1838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub readNames
1858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my ($namesFile, $type) = @_;
1878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $names = new IO::File;
1898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if ($extraDefines eq 0) {
1918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        open($names, $preprocessor . " " . $namesFile . "|") or die "Failed to open file: $namesFile";
1928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    } else {
1938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        open($names, $preprocessor . " -D" . join(" -D", split(" ", $extraDefines)) . " " . $namesFile . "|") or die "Failed to open file: $namesFile";
1948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
1958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    # Store hashes keys count to know if some insertion occured.
1978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $tagsCount = keys %tags;
1988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $attrsCount = keys %attrs;
1998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $InParser = InFilesParser->new();
2018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    switch ($type) {
2038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        case "tags" {
2048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project            $InParser->parse($names, \&parametersHandler, \&tagsHandler);
2058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
2068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        case "attrs" {
2078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project            $InParser->parse($names, \&parametersHandler, \&attrsHandler);
2088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
2098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        else {
2108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project            die "Do not know how to parse $type";
2118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
2128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
2138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    close($names);
2158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    die "Failed to read names from file: $namesFile" if ((keys %tags == $tagsCount) && (keys %attrs == $attrsCount));
2178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printMacros
2208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my ($F, $macro, $suffix, $namesRef) = @_;
2228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my %names = %$namesRef;
2238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    for my $name (sort keys %$namesRef) {
2258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "$macro $name","$suffix;\n";
2268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
2278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2298f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiansub usesDefaultWrapper
2308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2318f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my $tagName = shift;
232231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return $tagName eq $parameters{namespace} . "Element";
2338f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
2348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2358f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian# Build a direct mapping from the tags to the Element to create, excluding
2368f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian# Element that have not constructor.
2378f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiansub buildConstructorMap
2388f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian{
2398f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my %tagConstructorMap = ();
2408f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    for my $tagName (keys %tags) {
241231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $interfaceName = $tags{$tagName}{interfaceName};
2428f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        next if (usesDefaultWrapper($interfaceName));
2438f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
244231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        if ($tags{$tagName}{mapToTagName}) {
245231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            die "Cannot handle multiple mapToTagName for $tagName\n" if $tags{$tags{$tagName}{mapToTagName}}{mapToTagName};
246231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            $interfaceName = $tags{ $tags{$tagName}{mapToTagName} }{interfaceName};
247635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        }
2488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2498f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        # Chop the string to keep the interesting part.
250231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        $interfaceName =~ s/$parameters{namespace}(.*)Element/$1/;
2518f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        $tagConstructorMap{$tagName} = lc($interfaceName);
2528f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    }
2538f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
2548f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    return %tagConstructorMap;
2558f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
2568f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
2578f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian# Helper method that print the constructor's signature avoiding
2588f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian# unneeded arguments.
2598f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiansub printConstructorSignature
2608f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian{
2618f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my ($F, $tagName, $constructorName, $constructorTagName) = @_;
2628f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
263231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "static PassRefPtr<$parameters{namespace}Element> ${constructorName}Constructor(const QualifiedName& $constructorTagName, Document* document";
264231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    if ($parameters{namespace} eq "HTML") {
2658f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        print F ", HTMLFormElement*";
266231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F " formElement" if $tags{$tagName}{constructorNeedsFormElement};
2678f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    }
2688f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    print F ", bool";
269231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F " createdByParser" if $tags{$tagName}{constructorNeedsCreatedByParser};
2708f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    print F ")\n{\n";
2718f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
2728f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
2738f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian# Helper method to dump the constructor interior and call the
2748f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian# Element constructor with the right arguments.
2758f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian# The variable names should be kept in sync with the previous method.
2768f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiansub printConstructorInterior
2778f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian{
2788f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my ($F, $tagName, $interfaceName, $constructorTagName) = @_;
2798f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
2808f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    # Handle media elements.
281231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
2828f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        print F <<END
2838f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    if (!MediaPlayer::isAvailable())
284231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        return HTMLElement::create($constructorTagName, document);
2858f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng QianEND
2868f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian;
2878f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    }
2888f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
289231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    my $newPrefix = "";
290231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    my $createSuffix = "::create";
291231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
292231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    if ($tags{$tagName}{createWithNew}) {
293231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        $newPrefix = "new ";
294231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        $createSuffix = "";
2958f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    }
296231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
297231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    # Call the constructor with the right parameters.
298231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "    return $newPrefix$interfaceName${createSuffix}($constructorTagName, document";
299231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F ", formElement" if $tags{$tagName}{constructorNeedsFormElement};
300231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F ", createdByParser" if $tags{$tagName}{constructorNeedsCreatedByParser};
3018f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    print F ");\n}\n\n";
3028f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
3038f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
3048f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiansub printConstructors
3058f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian{
3068f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my ($F, $tagConstructorMapRef) = @_;
3078f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my %tagConstructorMap = %$tagConstructorMapRef;
3088f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
309231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith};
3108f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
3118f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    # This is to avoid generating the same constructor several times.
3128f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my %uniqueTags = ();
3138f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    for my $tagName (sort keys %tagConstructorMap) {
314231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $interfaceName = $tags{$tagName}{interfaceName};
3158f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
3168f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        # Ignore the mapped tag
3178f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        # FIXME: It could be moved inside this loop but was split for readibility.
318231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        next if (defined($uniqueTags{$interfaceName}) || $tags{$tagName}{mapToTagName});
3198f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
3208f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        $uniqueTags{$interfaceName} = '1';
3218f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
322231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $conditional = $tags{$tagName}{conditional};
3235f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
3245f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
3255f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            print F "#if ${conditionalString}\n\n";
3265f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
3275f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
3288f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        printConstructorSignature($F, $tagName, $tagConstructorMap{$tagName}, "tagName");
3298f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        printConstructorInterior($F, $tagName, $interfaceName, "tagName");
3305f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
3315f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
332231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            print F "#endif\n";
3335f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
3348f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    }
3358f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
3368f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    # Mapped tag name uses a special wrapper to keep their prefix and namespaceURI while using the mapped localname.
3378f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    for my $tagName (sort keys %tagConstructorMap) {
338231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        if ($tags{$tagName}{mapToTagName}) {
339231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            my $mappedName = $tags{$tagName}{mapToTagName};
3408f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian            printConstructorSignature($F, $mappedName, $mappedName . "To" . $tagName, "tagName");
341231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            printConstructorInterior($F, $mappedName, $tags{$mappedName}{interfaceName}, "QualifiedName(tagName.prefix(), ${mappedName}Tag.localName(), tagName.namespaceURI())");
342635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        }
3438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
3448f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
345231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#endif\n" if $parameters{guardFactoryWith};
3468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printFunctionInits
3498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
3508f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my ($F, $tagConstructorMap) = @_;
3518f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    my %tagConstructorMap = %$tagConstructorMap;
3528f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
3538f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    for my $tagName (sort keys %tagConstructorMap) {
3545f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
355231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $conditional = $tags{$tagName}{conditional};
3565f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
3575f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
3585f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            print F "#if ${conditionalString}\n";
3595f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
3605f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
361231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        if ($tags{$tagName}{mapToTagName}) {
362231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block            print F "    addTag(${tagName}Tag, $tags{$tagName}{mapToTagName}To${tagName}Constructor);\n";
3638f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        } else {
3648f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian            print F "    addTag(${tagName}Tag, $tagConstructorMap{$tagName}Constructor);\n";
3658f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        }
3665f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
3675f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
3685f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            print F "#endif\n\n";
3695f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
3708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
3718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub svgCapitalizationHacks
3748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
3758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $name = shift;
3768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
377231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    $name = "FE" . ucfirst $1 if $name =~ /^fe(.+)$/;
3788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return $name;
3808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub upperCaseName
3838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
3848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $name = shift;
3858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
386231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    $name = svgCapitalizationHacks($name) if ($parameters{namespace} eq "SVG");
3878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    while ($name =~ /^(.*?)_(.*)/) {
3898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        $name = $1 . ucfirst $2;
3908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
3918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return ucfirst $name;
3938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printLicenseHeader
3968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
3978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $F = shift;
3988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "/*
399231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT.
4008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
401231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * This file was generated by the dom/make_names.pl script.
4028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
403231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc.  All rights reserved.
4048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
4058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without
4068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions
4078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met:
4088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 1. Redistributions of source code must retain the above copyright
4098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
4108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
4118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer in the
4128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    documentation and/or other materials provided with the distribution.
4138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
4148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
4158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
4188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
4198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
4208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
4218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
4228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
424231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
4268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project";
4288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
4298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printNamesHeaderFile
4318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
4328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my ($headerPath) = shift;
4338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $F;
4348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    open F, ">$headerPath";
435231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
4368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    printLicenseHeader($F);
437231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#ifndef DOM_$parameters{namespace}NAMES_H\n";
438231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#define DOM_$parameters{namespace}NAMES_H\n\n";
4398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "#include \"QualifiedName.h\"\n\n";
440231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
441231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "namespace WebCore {\n\n namespace $parameters{namespace}Names {\n\n";
442231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
443231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    my $lowerNamespace = lc($parameters{namespacePrefix});
444231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#ifndef DOM_$parameters{namespace}NAMES_HIDE_GLOBALS\n";
4458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "// Namespace\n";
4468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "extern const WebCore::AtomicString ${lowerNamespace}NamespaceURI;\n\n";
4478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (keys %tags) {
4498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "// Tags\n";
4508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        printMacros($F, "extern const WebCore::QualifiedName", "Tag", \%tags);
4518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
4528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (keys %attrs) {
4548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "// Attributes\n";
4558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        printMacros($F, "extern const WebCore::QualifiedName", "Attr", \%attrs);
4568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
4578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "#endif\n\n";
458231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
459635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    if (keys %tags) {
460231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "WebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size);\n";
461635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    }
462635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
463635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    if (keys %attrs) {
464231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "WebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size);\n";
465635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    }
466231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
467635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    print F "\nvoid init();\n\n";
4688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "} }\n\n";
4698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "#endif\n\n";
470231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
4718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    close F;
4728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
4738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printNamesCppFile
4758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
4768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $cppPath = shift;
4778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $F;
4788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    open F, ">$cppPath";
4798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    printLicenseHeader($F);
4818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
482231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    my $lowerNamespace = lc($parameters{namespacePrefix});
4838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "#include \"config.h\"\n";
4858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "#ifdef SKIP_STATIC_CONSTRUCTORS_ON_GCC\n";
487231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "#define DOM_$parameters{namespace}NAMES_HIDE_GLOBALS 1\n";
4888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "#else\n";
4898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "#define QNAME_DEFAULT_CONSTRUCTOR 1\n";
4908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "#endif\n\n";
4918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
493231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "#include \"$parameters{namespace}Names.h\"\n\n";
4948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "#include \"StaticConstructors.h\"\n";
4958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
496231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "namespace WebCore {\n\n namespace $parameters{namespace}Names {
4978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace WebCore;
4998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
500231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve BlockDEFINE_GLOBAL(AtomicString, ${lowerNamespace}NamespaceURI, \"$parameters{namespaceURI}\")
5018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project";
5028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (keys %tags) {
5048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "// Tags\n";
5058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        for my $name (sort keys %tags) {
5068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project            print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Tag, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n";
5078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
5088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
509231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Tags(size_t* size)\n";
510231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "{\n    static WebCore::QualifiedName* $parameters{namespace}Tags[] = {\n";
5118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        for my $name (sort keys %tags) {
5128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project            print F "        (WebCore::QualifiedName*)&${name}Tag,\n";
5138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
5148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "    };\n";
5158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "    *size = ", scalar(keys %tags), ";\n";
516231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "    return $parameters{namespace}Tags;\n";
5178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "}\n";
5188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
5198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (keys %attrs) {
5218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "\n// Attributes\n";
5228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        for my $name (sort keys %attrs) {
5238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project            print F "DEFINE_GLOBAL(QualifiedName, ", $name, "Attr, nullAtom, \"$name\", ${lowerNamespace}NamespaceURI);\n";
5248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
525231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "\n\nWebCore::QualifiedName** get$parameters{namespace}Attrs(size_t* size)\n";
526231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "{\n    static WebCore::QualifiedName* $parameters{namespace}Attr[] = {\n";
5278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        for my $name (sort keys %attrs) {
5288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project            print F "        (WebCore::QualifiedName*)&${name}Attr,\n";
5298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
5308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "    };\n";
5318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "    *size = ", scalar(keys %attrs), ";\n";
532231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        print F "    return $parameters{namespace}Attr;\n";
5338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "}\n";
5348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
5358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "\nvoid init()
5378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
5388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static bool initialized = false;
5398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (initialized)
5408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return;
5418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    initialized = true;
5428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Use placement new to initialize the globals.
5448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    AtomicString::init();
5468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project";
5478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
548231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print(F "    AtomicString ${lowerNamespace}NS(\"$parameters{namespaceURI}\");\n\n");
5498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print(F "    // Namespace\n");
5518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print(F "    new ((void*)&${lowerNamespace}NamespaceURI) AtomicString(${lowerNamespace}NS);\n\n");
5528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (keys %tags) {
553231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $tagsNamespace = $parameters{tagsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS";
5548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        printDefinitions($F, \%tags, "tags", $tagsNamespace);
5558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
5568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (keys %attrs) {
557231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $attrsNamespace = $parameters{attrsNullNamespace} ? "nullAtom" : "${lowerNamespace}NS";
5588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        printDefinitions($F, \%attrs, "attributes", $attrsNamespace);
5598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
5608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "}\n\n} }\n\n";
5628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    close F;
5638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
5648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printJSElementIncludes
5668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
567635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    my $F = shift;
5685e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $wrapperFactoryType = shift;
569635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
570635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    my %tagsSeen;
571635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    for my $tagName (sort keys %tags) {
572231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $JSInterfaceName = $tags{$tagName}{JSInterfaceName};
573635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);
574635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        $tagsSeen{$JSInterfaceName} = 1;
5758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5765e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F "#include \"${wrapperFactoryType}${JSInterfaceName}.h\"\n";
5778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
5788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
5798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printElementIncludes
5818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
582635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    my $F = shift;
5838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
584635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    my %tagsSeen;
585635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    for my $tagName (sort keys %tags) {
586231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $interfaceName = $tags{$tagName}{interfaceName};
587635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        next if defined($tagsSeen{$interfaceName});
588635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        $tagsSeen{$interfaceName} = 1;
589635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
590635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        print F "#include \"${interfaceName}.h\"\n";
5918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
5928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
5938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printDefinitions
5958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
5968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my ($F, $namesRef, $type, $namespaceURI) = @_;
5978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $singularType = substr($type, 0, -1);
5988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $shortType = substr($singularType, 0, 4);
5998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $shortCamelType = ucfirst($shortType);
6008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $shortUpperType = uc($shortType);
6018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "    // " . ucfirst($type) . "\n";
6038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    for my $name (sort keys %$namesRef) {
6058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        my $realName = $name;
6068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        $realName =~ s/_/-/g;
607d0825bca7fe65beaee391d30da42e937db621564Steve Block        print F "    new ((void*)&$name","${shortCamelType}) QualifiedName(nullAtom, \"$realName\", $namespaceURI);\n";
6088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
6098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
6108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project## ElementFactory routines
6128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printFactoryCppFile
6148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
6158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $cppPath = shift;
6168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $F;
6178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    open F, ">$cppPath";
6188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectprintLicenseHeader($F);
6208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F <<END
6228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h"
623231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "$parameters{namespace}ElementFactory.h"
6248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
625231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "$parameters{namespace}Names.h"
6268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
6278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
6288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
629635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source ProjectprintElementIncludes($F);
6308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F <<END
6328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/HashMap.h>
6338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
634231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#if ENABLE(DASHBOARD_SUPPORT)
635231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "Document.h"
636231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#include "Settings.h"
637231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#endif
638231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
6398f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiannamespace WebCore {
6408f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
641231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockusing namespace $parameters{namespace}Names;
6428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
643635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source ProjectEND
644635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project;
645635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
646231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "typedef PassRefPtr<$parameters{namespace}Element> (*ConstructorFunction)(const QualifiedName&, Document*";
647231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F ", HTMLFormElement*" if $parameters{namespace} eq "HTML";
648635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectprint F ", bool createdByParser);\n";
649635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectprint F <<END
6508f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qiantypedef HashMap<AtomicStringImpl*, ConstructorFunction> FunctionMap;
6518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstatic FunctionMap* gFunctionMap = 0;
6538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
6558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
6568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6578f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianmy %tagConstructorMap = buildConstructorMap();
6588f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
6598f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng QianprintConstructors($F, \%tagConstructorMap);
6608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
661231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith};
6628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F <<END
6648f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianstatic void addTag(const QualifiedName& tag, ConstructorFunction func)
6658f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian{
6668f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    gFunctionMap->set(tag.localName().impl(), func);
6678f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
6688f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
669231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockstatic void createFunctionMap()
6708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
671231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    ASSERT(!gFunctionMap);
672231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
6738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Create the table.
6748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    gFunctionMap = new FunctionMap;
6758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Populate it with constructor functions.
6778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
6788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
6798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6808f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng QianprintFunctionInits($F, \%tagConstructorMap);
6818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F "}\n";
683231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "#endif\n" if $parameters{guardFactoryWith};
684635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
685231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "\nPassRefPtr<$parameters{namespace}Element> $parameters{namespace}ElementFactory::create$parameters{namespace}Element(const QualifiedName& qName, Document* document";
686231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F ", HTMLFormElement* formElement" if $parameters{namespace} eq "HTML";
687635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectprint F ", bool createdByParser)\n{\n";
6888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
689231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith};
6908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F <<END
692231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    if (!document)
6938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return 0;
6948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6958f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng QianEND
6968f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian;
6978f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
698231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockif ($parameters{namespace} ne "HTML") {
6998f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianprint F <<END
7008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#if ENABLE(DASHBOARD_SUPPORT)
701231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    Settings* settings = document->settings();
7028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (settings && settings->usesDashboardBackwardCompatibilityMode())
7038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return 0;
7048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
7058f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng QianEND
7068f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian;
7078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7088f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
7098f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
7108f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qianprint F <<END
711231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    if (!gFunctionMap)
712231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        createFunctionMap();
713231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    if (ConstructorFunction function = gFunctionMap->get(qName.localName().impl()))
7148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
7158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
7168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
717231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockif ($parameters{namespace} eq "HTML") {
718231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "        return function(qName, document, formElement, createdByParser);\n";
719635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project} else {
720231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "        return function(qName, document, createdByParser);\n";
721635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project}
722635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
723231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "    return $parameters{namespace}Element::create(qName, document);\n";
724635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
725231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockif ($parameters{guardFactoryWith}) {
7268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F <<END
7288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#else
7298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return 0;
7308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
7318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
7328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
7338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
7358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprint F <<END
7378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
7388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
739635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project} // namespace WebCore
7408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
7428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
7438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    close F;
7458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
7468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printFactoryHeaderFile
7488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
7498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $headerPath = shift;
7508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $F;
7518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    open F, ">$headerPath";
7528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    printLicenseHeader($F);
7548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
755635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    print F<<END
756231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#ifndef $parameters{namespace}ElementFactory_h
757231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#define $parameters{namespace}ElementFactory_h
758635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
759635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <wtf/PassRefPtr.h>
7608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
7628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    class Element;
7638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    class Document;
7648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    class QualifiedName;
7658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    class AtomicString;
7668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
7678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
7698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
770231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    class $parameters{namespace}Element;
771635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source ProjectEND
772635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project;
773635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
774231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "     class HTMLFormElement;\n" if $parameters{namespace} eq "HTML";
7758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
776635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectprint F<<END
7778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // The idea behind this class is that there will eventually be a mapping from namespace URIs to ElementFactories that can dispense
778635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    // elements. In a compound document world, the generic createElement function (will end up being virtual) will be called.
779231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    class $parameters{namespace}ElementFactory {
7808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    public:
781635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        PassRefPtr<Element> createElement(const WebCore::QualifiedName&, WebCore::Document*, bool createdByParser = true);
782635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source ProjectEND
783635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project;
784231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F "        static PassRefPtr<$parameters{namespace}Element> create$parameters{namespace}Element(const WebCore::QualifiedName&, WebCore::Document*";
785231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockprint F ", HTMLFormElement* = 0" if $parameters{namespace} eq "HTML";
786635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectprint F ", bool /*createdByParser*/ = true);\n";
787635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
788635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectprintf F<<END
7898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    };
7908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
7918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
792231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#endif // $parameters{namespace}ElementFactory_h
7938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
794635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source ProjectEND
795635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project;
7968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    close F;
7988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
7998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project## Wrapper Factory routines
8018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
802635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectsub usesDefaultJSWrapper
8038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
8048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $name = shift;
805635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
806635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    # A tag reuses the default wrapper if its JSInterfaceName matches the default namespace Element.
807231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return $tags{$name}{JSInterfaceName} eq $parameters{namespace} . "Element" || $tags{$name}{JSInterfaceName} eq "HTMLNoScriptElement";
8088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
8098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printWrapperFunctions
8118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
812635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    my $F = shift;
8135e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $wrapperFactoryType = shift;
814635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
815635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    my %tagsSeen;
816635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    for my $tagName (sort keys %tags) {
817635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        # Avoid defining the same wrapper method twice.
818231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $JSInterfaceName = $tags{$tagName}{JSInterfaceName};
819635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        next if defined($tagsSeen{$JSInterfaceName}) || usesDefaultJSWrapper($tagName);
820635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        $tagsSeen{$JSInterfaceName} = 1;
8218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
822231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $conditional = $tags{$tagName}{conditional};
8235f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
8245f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
8255f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            print F "#if ${conditionalString}\n\n";
8265f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
8275f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
8285e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        if ($wrapperFactoryType eq "JS") {
8295e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block            # Hack for the media tags
8305e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block            # FIXME: This should have been done via a CustomWrapper attribute and a separate *Custom file.
8315e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block            if ($tags{$tagName}{wrapperOnlyIfMediaIsAvailable}) {
8325e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block                print F <<END
833231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockstatic JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element)
8348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
8358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!MediaPlayer::isAvailable())
836231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        return CREATE_DOM_NODE_WRAPPER(exec, globalObject, $parameters{namespace}Element, element.get());
8370bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    return CREATE_DOM_NODE_WRAPPER(exec, globalObject, ${JSInterfaceName}, element.get());
8388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
8398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
8418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
8425e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block            } else {
8435e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block                print F <<END
844231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockstatic JSNode* create${JSInterfaceName}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element)
8458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
8460bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    return CREATE_DOM_NODE_WRAPPER(exec, globalObject, ${JSInterfaceName}, element.get());
8478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
8488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
8508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
8515e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block            }
8525e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        } elsif ($wrapperFactoryType eq "V8") {
8535e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block            print F <<END
8545e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockstatic v8::Handle<v8::Value> create${JSInterfaceName}Wrapper($parameters{namespace}Element* element)
8555e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block{
8565e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    return toV8(static_cast<${JSInterfaceName}*>(element));
8575e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block}
8585e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
8595e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
8605e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
8618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        }
862231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
8635f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
8645f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            print F "#endif\n\n";
8655f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
8668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
8678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
8688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printWrapperFactoryCppFile
8708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
8715e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $outputDir = shift;
8725e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $wrapperFactoryType = shift;
8735e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $wrapperFactoryFileName = shift;
8748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $F;
8755e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    open F, ">" . $outputDir . "/" . $wrapperFactoryType . $wrapperFactoryFileName . ".cpp";
8768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    printLicenseHeader($F);
8788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F "#include \"config.h\"\n\n";
8808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
881231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#if $parameters{guardFactoryWith}\n\n" if $parameters{guardFactoryWith};
8828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8835e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    print F "#include \"$wrapperFactoryType$parameters{namespace}ElementWrapperFactory.h\"\n";
8848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
8855e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    printJSElementIncludes($F, $wrapperFactoryType);
8868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
887231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "\n#include \"$parameters{namespace}Names.h\"\n\n";
8888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
889635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    printElementIncludes($F);
8908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
891635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    print F "\n#include <wtf/StdLibExtras.h>\n\n";
8925e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
8935e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    if ($wrapperFactoryType eq "JS") {
8945e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
8958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace JSC;
8965e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
8975e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
8985e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    } elsif ($wrapperFactoryType eq "V8") {
8995e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
9005e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include "V8$parameters{namespace}Element.h"
9015e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
9025e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include <v8.h>
9035e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
9045e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
9055e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    }
9065e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
9075e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    print F <<END
9088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
9108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
911231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockusing namespace $parameters{namespace}Names;
9128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9135e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
9145e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
9155e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    if ($wrapperFactoryType eq "JS") {
9165e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
917231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blocktypedef JSNode* (*Create$parameters{namespace}ElementWrapperFunction)(ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{namespace}Element>);
9188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
9208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
9215e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    } elsif ($wrapperFactoryType eq "V8") {
9225e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
9235e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blocktypedef v8::Handle<v8::Value> (*Create$parameters{namespace}ElementWrapperFunction)($parameters{namespace}Element*);
9245e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
9255e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
9265e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
9275e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    }
9288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9295e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    printWrapperFunctions($F, $wrapperFactoryType);
9308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9315e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    if ($wrapperFactoryType eq "JS") {
9325e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
933231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve BlockJSNode* createJS$parameters{namespace}Wrapper(ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<$parameters{namespace}Element> element)
9345e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block{
9355e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    typedef HashMap<WebCore::AtomicStringImpl*, Create$parameters{namespace}ElementWrapperFunction> FunctionMap;
9365e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    DEFINE_STATIC_LOCAL(FunctionMap, map, ());
9375e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    if (map.isEmpty()) {
9385e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
9395e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
9405e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    } elsif ($wrapperFactoryType eq "V8") {
9415e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
9425e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockv8::Handle<v8::Value> createV8$parameters{namespace}Wrapper($parameters{namespace}Element* element, bool forceNewObject)
9435e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block{
944231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    typedef HashMap<WebCore::AtomicStringImpl*, Create$parameters{namespace}ElementWrapperFunction> FunctionMap;
945635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    DEFINE_STATIC_LOCAL(FunctionMap, map, ());
9468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (map.isEmpty()) {
9478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
9488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
9495e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    }
9508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    for my $tag (sort keys %tags) {
952635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        # Do not add the name to the map if it does not have a JS wrapper constructor or uses the default wrapper.
953635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        next if usesDefaultJSWrapper($tag, \%tags);
9548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
955231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $conditional = $tags{$tag}{conditional};
9565f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
9575f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            my $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
9585f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            print F "#if ${conditionalString}\n";
9595f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
9605f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
961231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        my $ucTag = $tags{$tag}{JSInterfaceName};
9628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        print F "       map.set(${tag}Tag.localName().impl(), create${ucTag}Wrapper);\n";
9635f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
9645f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        if ($conditional) {
9655f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            print F "#endif\n";
9665f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        }
9678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
9688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    print F <<END
9708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
971231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    Create$parameters{namespace}ElementWrapperFunction createWrapperFunction = map.get(element->localName().impl());
9728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (createWrapperFunction)
9735e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
9745e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
9755e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    if ($wrapperFactoryType eq "JS") {
9765e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
9770bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        return createWrapperFunction(exec, globalObject, element);
978231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    return CREATE_DOM_NODE_WRAPPER(exec, globalObject, $parameters{namespace}Element, element.get());
9795e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
9805e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
9815e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    } elsif ($wrapperFactoryType eq "V8") {
9825e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
9835e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        return createWrapperFunction(element);
9845e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    return V8$parameters{namespace}Element::wrap(element, forceNewObject);
9855e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
9865e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
9875e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    }
9885e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    print F <<END
9898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
9908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
9928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
9948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
9958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
996231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#endif\n" if $parameters{guardFactoryWith};
9978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
9988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    close F;
9998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
10008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectsub printWrapperFactoryHeaderFile
10028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
10035e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $outputDir = shift;
10045e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $wrapperFactoryType = shift;
10055e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    my $wrapperFactoryFileName = shift;
10068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    my $F;
10075e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    open F, ">" . $outputDir . "/" . $wrapperFactoryType . $wrapperFactoryFileName . ".h";
10088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    printLicenseHeader($F);
10108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10115e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    print F "#ifndef $wrapperFactoryType$parameters{namespace}ElementWrapperFactory_h\n";
10125e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    print F "#define $wrapperFactoryType$parameters{namespace}ElementWrapperFactory_h\n\n";
10138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1014231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#if $parameters{guardFactoryWith}\n" if $parameters{guardFactoryWith};
10158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10165e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    if ($wrapperFactoryType eq "JS") {
10175e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
10188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/Forward.h>
10198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace JSC {
10218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    class ExecState;
10228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
10238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
10258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    class JSNode;
10270bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    class JSDOMGlobalObject;
1028231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    class $parameters{namespace}Element;
10298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1030231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    JSNode* createJS$parameters{namespace}Wrapper(JSC::ExecState*, JSDOMGlobalObject*, PassRefPtr<$parameters{namespace}Element>);
10318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
10338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectEND
10358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project;
10365e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    } elsif ($wrapperFactoryType eq "V8") {
10375e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        print F <<END
10385e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include <v8.h>
10395e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
10405e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blocknamespace WebCore {
10415e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
10425e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    class $parameters{namespace}Element;
10435e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block
10445e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    v8::Handle<v8::Value> createV8$parameters{namespace}Wrapper($parameters{namespace}Element*, bool);
10455e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block}
10465e2bc6953fe6923165b8a5d7679939693a1d58d6Steve BlockEND
10475e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block;
10485e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    }
10498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1050231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    print F "#endif // $parameters{guardFactoryWith}\n\n" if $parameters{guardFactoryWith};
10518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10525e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    print F "#endif // $wrapperFactoryType$parameters{namespace}ElementWrapperFactory_h\n";
10538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    close F;
10558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1056