Serenity Operating System
at portability 84 lines 4.1 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <LibHTML/DOM/ElementFactory.h> 28#include <LibHTML/DOM/HTMLAnchorElement.h> 29#include <LibHTML/DOM/HTMLBRElement.h> 30#include <LibHTML/DOM/HTMLBlinkElement.h> 31#include <LibHTML/DOM/HTMLBodyElement.h> 32#include <LibHTML/DOM/HTMLFontElement.h> 33#include <LibHTML/DOM/HTMLFormElement.h> 34#include <LibHTML/DOM/HTMLHRElement.h> 35#include <LibHTML/DOM/HTMLHeadElement.h> 36#include <LibHTML/DOM/HTMLHeadingElement.h> 37#include <LibHTML/DOM/HTMLHtmlElement.h> 38#include <LibHTML/DOM/HTMLImageElement.h> 39#include <LibHTML/DOM/HTMLInputElement.h> 40#include <LibHTML/DOM/HTMLLinkElement.h> 41#include <LibHTML/DOM/HTMLStyleElement.h> 42#include <LibHTML/DOM/HTMLTitleElement.h> 43 44NonnullRefPtr<Element> create_element(Document& document, const String& tag_name) 45{ 46 auto lowercase_tag_name = tag_name.to_lowercase(); 47 if (lowercase_tag_name == "a") 48 return adopt(*new HTMLAnchorElement(document, lowercase_tag_name)); 49 if (lowercase_tag_name == "html") 50 return adopt(*new HTMLHtmlElement(document, lowercase_tag_name)); 51 if (lowercase_tag_name == "head") 52 return adopt(*new HTMLHeadElement(document, lowercase_tag_name)); 53 if (lowercase_tag_name == "body") 54 return adopt(*new HTMLBodyElement(document, lowercase_tag_name)); 55 if (lowercase_tag_name == "font") 56 return adopt(*new HTMLFontElement(document, lowercase_tag_name)); 57 if (lowercase_tag_name == "hr") 58 return adopt(*new HTMLHRElement(document, lowercase_tag_name)); 59 if (lowercase_tag_name == "style") 60 return adopt(*new HTMLStyleElement(document, lowercase_tag_name)); 61 if (lowercase_tag_name == "title") 62 return adopt(*new HTMLTitleElement(document, lowercase_tag_name)); 63 if (lowercase_tag_name == "link") 64 return adopt(*new HTMLLinkElement(document, lowercase_tag_name)); 65 if (lowercase_tag_name == "img") 66 return adopt(*new HTMLImageElement(document, lowercase_tag_name)); 67 if (lowercase_tag_name == "blink") 68 return adopt(*new HTMLBlinkElement(document, lowercase_tag_name)); 69 if (lowercase_tag_name == "form") 70 return adopt(*new HTMLFormElement(document, lowercase_tag_name)); 71 if (lowercase_tag_name == "input") 72 return adopt(*new HTMLInputElement(document, lowercase_tag_name)); 73 if (lowercase_tag_name == "br") 74 return adopt(*new HTMLBRElement(document, lowercase_tag_name)); 75 if (lowercase_tag_name == "h1" 76 || lowercase_tag_name == "h2" 77 || lowercase_tag_name == "h3" 78 || lowercase_tag_name == "h4" 79 || lowercase_tag_name == "h5" 80 || lowercase_tag_name == "h6") { 81 return adopt(*new HTMLHeadingElement(document, lowercase_tag_name)); 82 } 83 return adopt(*new Element(document, lowercase_tag_name)); 84}