/* * This file is part of the HTML DOM implementation for KDE. * * Copyright (C) 2005 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ #include "config.h" #include "HTMLElementFactory.h" #include "HTMLAnchorElement.h" #include "HTMLAppletElement.h" #include "HTMLAreaElement.h" #include "HTMLBaseFontElement.h" #include "HTMLBaseElement.h" #include "HTMLBlockquoteElement.h" #include "HTMLBodyElement.h" #include "HTMLBRElement.h" #include "HTMLButtonElement.h" #include "HTMLCanvasElement.h" #include "HTMLDivElement.h" #include "HTMLDListElement.h" #include "HTMLDocument.h" #include "HTMLDirectoryElement.h" #include "HTMLEmbedElement.h" #include "HTMLFontElement.h" #include "HTMLFrameSetElement.h" #include "HTMLFieldSetElement.h" #include "HTMLFormElement.h" #include "HTMLHeadElement.h" #include "HTMLHeadingElement.h" #include "HTMLHRElement.h" #include "HTMLHtmlElement.h" #include "HTMLFrameElement.h" #include "HTMLIFrameElement.h" #include "HTMLImageElement.h" #include "HTMLIsIndexElement.h" #include "HTMLKeygenElement.h" #include "HTMLLabelElement.h" #include "HTMLLegendElement.h" #include "HTMLLIElement.h" #include "HTMLLinkElement.h" #include "HTMLMapElement.h" #include "HTMLMarqueeElement.h" #include "HTMLMenuElement.h" #include "HTMLMetaElement.h" #include "HTMLModElement.h" #include "HTMLNames.h" #include "HTMLObjectElement.h" #include "HTMLOListElement.h" #include "HTMLOptGroupElement.h" #include "HTMLOptionElement.h" #include "HTMLParagraphElement.h" #include "HTMLParamElement.h" #include "HTMLPreElement.h" #include "HTMLScriptElement.h" #include "HTMLSelectElement.h" #include "HTMLStyleElement.h" #include "HTMLTextAreaElement.h" #include "HTMLTableElement.h" #include "HTMLTableCaptionElement.h" #include "HTMLTableCellElement.h" #include "HTMLTableColElement.h" #include "HTMLTableRowElement.h" #include "HTMLTableSectionElement.h" #include "HTMLTitleElement.h" #include "HTMLUListElement.h" #include "HTMLQuoteElement.h" namespace WebCore { using namespace HTMLNames; typedef PassRefPtr (*ConstructorFunc)(const AtomicString& tagName, Document*, HTMLFormElement*, bool createdByParser); typedef HashMap FunctionMap; static FunctionMap* gFunctionMap; static PassRefPtr htmlConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLHtmlElement(doc); } static PassRefPtr headConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLHeadElement(doc); } static PassRefPtr bodyConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLBodyElement(doc); } static PassRefPtr baseConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLBaseElement(doc); } static PassRefPtr linkConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLLinkElement(doc); } static PassRefPtr metaConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLMetaElement(doc); } static PassRefPtr styleConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLStyleElement(doc); } static PassRefPtr titleConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLTitleElement(doc); } static PassRefPtr frameConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLFrameElement(doc); } static PassRefPtr framesetConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLFrameSetElement(doc); } static PassRefPtr iframeConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLIFrameElement(doc); } static PassRefPtr formConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLFormElement(doc); } static PassRefPtr buttonConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLButtonElement(doc, form); } static PassRefPtr inputConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLInputElement(doc, form); } static PassRefPtr isindexConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLIsIndexElement(doc, form); } static PassRefPtr fieldsetConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLFieldSetElement(doc, form); } static PassRefPtr keygenConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLKeygenElement(doc, form); } static PassRefPtr labelConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLLabelElement(doc); } static PassRefPtr legendConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLLegendElement(doc, form); } static PassRefPtr optgroupConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLOptGroupElement(doc, form); } static PassRefPtr optionConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLOptionElement(doc, form); } static PassRefPtr selectConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLSelectElement(doc, form); } static PassRefPtr textareaConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLTextAreaElement(doc, form); } static PassRefPtr dlConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLDListElement(doc); } static PassRefPtr ulConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLUListElement(doc); } static PassRefPtr olConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLOListElement(doc); } static PassRefPtr dirConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLDirectoryElement(doc); } static PassRefPtr menuConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLMenuElement(doc); } static PassRefPtr liConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLLIElement(doc); } static PassRefPtr blockquoteConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLBlockquoteElement(doc); } static PassRefPtr divConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLDivElement(doc); } static PassRefPtr headingConstructor(const AtomicString& tagName, Document* doc, HTMLFormElement*, bool) { return new HTMLHeadingElement(QualifiedName(nullAtom, tagName, xhtmlNamespaceURI), doc); } static PassRefPtr hrConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLHRElement(doc); } static PassRefPtr paragraphConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLParagraphElement(doc); } static PassRefPtr preConstructor(const AtomicString& tagName, Document* doc, HTMLFormElement*, bool) { return new HTMLPreElement(QualifiedName(nullAtom, tagName, xhtmlNamespaceURI), doc); } static PassRefPtr basefontConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLBaseFontElement(doc); } static PassRefPtr fontConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLFontElement(doc); } static PassRefPtr modConstructor(const AtomicString& tagName, Document* doc, HTMLFormElement*, bool) { return new HTMLModElement(QualifiedName(nullAtom, tagName, xhtmlNamespaceURI), doc); } static PassRefPtr anchorConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLAnchorElement(doc); } static PassRefPtr imageConstructor(const AtomicString&, Document* doc, HTMLFormElement* form, bool) { return new HTMLImageElement(doc, form); } static PassRefPtr mapConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLMapElement(doc); } static PassRefPtr areaConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLAreaElement(doc); } static PassRefPtr canvasConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLCanvasElement(doc); } static PassRefPtr appletConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLAppletElement(doc); } static PassRefPtr embedConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLEmbedElement(doc); } static PassRefPtr objectConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool createdByParser) { RefPtr object = new HTMLObjectElement(doc); object->setComplete(!createdByParser); return object.release(); } static PassRefPtr paramConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLParamElement(doc); } static PassRefPtr scriptConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool createdByParser) { RefPtr script = new HTMLScriptElement(doc); script->setCreatedByParser(createdByParser); return script.release(); } static PassRefPtr tableConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLTableElement(doc); } static PassRefPtr tableCaptionConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLTableCaptionElement(doc); } static PassRefPtr tableColConstructor(const AtomicString& tagName, Document* doc, HTMLFormElement*, bool) { return new HTMLTableColElement(QualifiedName(nullAtom, tagName, xhtmlNamespaceURI), doc); } static PassRefPtr tableRowConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLTableRowElement(doc); } static PassRefPtr tableCellConstructor(const AtomicString& tagName, Document* doc, HTMLFormElement*, bool) { return new HTMLTableCellElement(QualifiedName(nullAtom, tagName, xhtmlNamespaceURI), doc); } static PassRefPtr tableSectionConstructor(const AtomicString& tagName, Document* doc, HTMLFormElement*, bool) { return new HTMLTableSectionElement(QualifiedName(nullAtom, tagName, xhtmlNamespaceURI), doc); } static PassRefPtr brConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLBRElement(doc); } static PassRefPtr quoteConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLQuoteElement(doc); } static PassRefPtr marqueeConstructor(const AtomicString&, Document* doc, HTMLFormElement*, bool) { return new HTMLMarqueeElement(doc); } static void addTag(const QualifiedName& tag, ConstructorFunc func) { gFunctionMap->set(tag.localName().impl(), func); } static void createFunctionMap() { // Create the table. gFunctionMap = new FunctionMap; // Populate it with constructor functions. addTag(aTag, anchorConstructor); addTag(appletTag, appletConstructor); addTag(areaTag, areaConstructor); addTag(baseTag, baseConstructor); addTag(basefontTag, basefontConstructor); addTag(blockquoteTag, blockquoteConstructor); addTag(bodyTag, bodyConstructor); addTag(brTag, brConstructor); addTag(buttonTag, buttonConstructor); addTag(canvasTag, canvasConstructor); addTag(captionTag, tableCaptionConstructor); addTag(colTag, tableColConstructor); addTag(colgroupTag, tableColConstructor); addTag(delTag, modConstructor); addTag(dirTag, dirConstructor); addTag(divTag, divConstructor); addTag(dlTag, dlConstructor); addTag(embedTag, embedConstructor); addTag(fieldsetTag, fieldsetConstructor); addTag(fontTag, fontConstructor); addTag(formTag, formConstructor); addTag(frameTag, frameConstructor); addTag(framesetTag, framesetConstructor); addTag(h1Tag, headingConstructor); addTag(h2Tag, headingConstructor); addTag(h3Tag, headingConstructor); addTag(h4Tag, headingConstructor); addTag(h5Tag, headingConstructor); addTag(h6Tag, headingConstructor); addTag(headTag, headConstructor); addTag(hrTag, hrConstructor); addTag(htmlTag, htmlConstructor); addTag(iframeTag, iframeConstructor); addTag(imageTag, imageConstructor); addTag(imgTag, imageConstructor); addTag(inputTag, inputConstructor); addTag(insTag, modConstructor); addTag(isindexTag, isindexConstructor); addTag(keygenTag, keygenConstructor); addTag(labelTag, labelConstructor); addTag(legendTag, legendConstructor); addTag(liTag, liConstructor); addTag(linkTag, linkConstructor); addTag(listingTag, preConstructor); addTag(mapTag, mapConstructor); addTag(marqueeTag, marqueeConstructor); addTag(menuTag, menuConstructor); addTag(metaTag, metaConstructor); addTag(objectTag, objectConstructor); addTag(olTag, olConstructor); addTag(optgroupTag, optgroupConstructor); addTag(optionTag, optionConstructor); addTag(pTag, paragraphConstructor); addTag(paramTag, paramConstructor); addTag(preTag, preConstructor); addTag(qTag, quoteConstructor); addTag(scriptTag, scriptConstructor); addTag(selectTag, selectConstructor); addTag(styleTag, styleConstructor); addTag(tableTag, tableConstructor); addTag(tbodyTag, tableSectionConstructor); addTag(tdTag, tableCellConstructor); addTag(textareaTag, textareaConstructor); addTag(tfootTag, tableSectionConstructor); addTag(thTag, tableCellConstructor); addTag(theadTag, tableSectionConstructor); addTag(titleTag, titleConstructor); addTag(trTag, tableRowConstructor); addTag(ulTag, ulConstructor); addTag(xmpTag, preConstructor); } PassRefPtr HTMLElementFactory::createHTMLElement(const AtomicString& tagName, Document* doc, HTMLFormElement* form, bool createdByParser) { if (!doc) return 0; // Don't allow elements to ever be made without having a doc. if (!gFunctionMap) createFunctionMap(); ConstructorFunc func = gFunctionMap->get(tagName.impl()); if (func) return func(tagName, doc, form, createdByParser); // elements with no special representation in the DOM return new HTMLElement(QualifiedName(nullAtom, tagName, xhtmlNamespaceURI), doc); } }