mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-08 04:02:52 +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
Notes:
sideshowbarker
2024-07-19 11:43:49 +09:00
Author: https://github.com/awesomekling
Commit: 35def88c8b
5 changed files with 59 additions and 50 deletions
49
Libraries/LibHTML/DOM/ElementFactory.cpp
Normal file
49
Libraries/LibHTML/DOM/ElementFactory.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <LibHTML/DOM/ElementFactory.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>
|
||||
|
||||
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));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue