mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 18:54:57 +00:00
LibHTML: Move Element construction to a separate file
We now have create_element(document, tag_name) in ElementFactory. This will be useful for constructing new elements outside of parsing.
This commit is contained in:
parent
1f9c4ffd21
commit
35def88c8b
5 changed files with 59 additions and 50 deletions
|
@ -3,59 +3,12 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <LibHTML/DOM/DocumentType.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/DOM/HTMLAnchorElement.h>
|
||||
#include <LibHTML/DOM/HTMLBlinkElement.h>
|
||||
#include <LibHTML/DOM/HTMLBodyElement.h>
|
||||
#include <LibHTML/DOM/HTMLFontElement.h>
|
||||
#include <LibHTML/DOM/HTMLHRElement.h>
|
||||
#include <LibHTML/DOM/HTMLHeadElement.h>
|
||||
#include <LibHTML/DOM/HTMLHeadingElement.h>
|
||||
#include <LibHTML/DOM/HTMLHtmlElement.h>
|
||||
#include <LibHTML/DOM/HTMLImageElement.h>
|
||||
#include <LibHTML/DOM/HTMLLinkElement.h>
|
||||
#include <LibHTML/DOM/HTMLStyleElement.h>
|
||||
#include <LibHTML/DOM/HTMLTitleElement.h>
|
||||
#include <LibHTML/DOM/ElementFactory.h>
|
||||
#include <LibHTML/DOM/Text.h>
|
||||
#include <LibHTML/Parser/HTMLParser.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static NonnullRefPtr<Element> create_element(Document& document, const String& tag_name)
|
||||
{
|
||||
auto lowercase_tag_name = tag_name.to_lowercase();
|
||||
if (lowercase_tag_name == "a")
|
||||
return adopt(*new HTMLAnchorElement(document, tag_name));
|
||||
if (lowercase_tag_name == "html")
|
||||
return adopt(*new HTMLHtmlElement(document, tag_name));
|
||||
if (lowercase_tag_name == "head")
|
||||
return adopt(*new HTMLHeadElement(document, tag_name));
|
||||
if (lowercase_tag_name == "body")
|
||||
return adopt(*new HTMLBodyElement(document, tag_name));
|
||||
if (lowercase_tag_name == "font")
|
||||
return adopt(*new HTMLFontElement(document, tag_name));
|
||||
if (lowercase_tag_name == "hr")
|
||||
return adopt(*new HTMLHRElement(document, tag_name));
|
||||
if (lowercase_tag_name == "style")
|
||||
return adopt(*new HTMLStyleElement(document, tag_name));
|
||||
if (lowercase_tag_name == "title")
|
||||
return adopt(*new HTMLTitleElement(document, tag_name));
|
||||
if (lowercase_tag_name == "link")
|
||||
return adopt(*new HTMLLinkElement(document, tag_name));
|
||||
if (lowercase_tag_name == "img")
|
||||
return adopt(*new HTMLImageElement(document, tag_name));
|
||||
if (lowercase_tag_name == "blink")
|
||||
return adopt(*new HTMLBlinkElement(document, tag_name));
|
||||
if (lowercase_tag_name == "h1"
|
||||
|| lowercase_tag_name == "h2"
|
||||
|| lowercase_tag_name == "h3"
|
||||
|| lowercase_tag_name == "h4"
|
||||
|| lowercase_tag_name == "h5"
|
||||
|| lowercase_tag_name == "h6") {
|
||||
return adopt(*new HTMLHeadingElement(document, tag_name));
|
||||
}
|
||||
return adopt(*new Element(document, tag_name));
|
||||
}
|
||||
|
||||
static bool is_valid_in_attribute_name(char ch)
|
||||
{
|
||||
return isalnum(ch) || ch == '_' || ch == '-';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue