summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibWeb/DOM')
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp4
-rw-r--r--Libraries/LibWeb/DOM/Element.cpp4
-rw-r--r--Libraries/LibWeb/DOM/Element.h14
-rw-r--r--Libraries/LibWeb/DOM/Element.idl3
-rw-r--r--Libraries/LibWeb/DOM/ElementFactory.cpp148
-rw-r--r--Libraries/LibWeb/DOM/ElementFactory.h2
6 files changed, 92 insertions, 83 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index edcde7700e..afe8aa30b6 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -54,6 +54,7 @@
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/LayoutDocument.h>
#include <LibWeb/Layout/LayoutTreeBuilder.h>
+#include <LibWeb/Namespace.h>
#include <LibWeb/Origin.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/SVG/TagNames.h>
@@ -460,7 +461,8 @@ JS::Value Document::run_javascript(const StringView& source)
NonnullRefPtr<Element> Document::create_element(const String& tag_name)
{
- return DOM::create_element(*this, tag_name);
+ // FIXME: Let namespace be the HTML namespace, if this is an HTML document or thisโ€™s content type is "application/xhtml+xml", and null otherwise.
+ return DOM::create_element(*this, tag_name, Namespace::HTML);
}
NonnullRefPtr<DocumentFragment> Document::create_document_fragment()
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index b5445ab593..11c6baa912 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -46,9 +46,9 @@
namespace Web::DOM {
-Element::Element(Document& document, const FlyString& tag_name)
+Element::Element(Document& document, const QualifiedName& qualified_name)
: ParentNode(document, NodeType::ELEMENT_NODE)
- , m_tag_name(tag_name)
+ , m_qualified_name(qualified_name)
{
}
diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h
index 253f532aff..19dba993e5 100644
--- a/Libraries/LibWeb/DOM/Element.h
+++ b/Libraries/LibWeb/DOM/Element.h
@@ -34,6 +34,7 @@
#include <LibWeb/DOM/TagNames.h>
#include <LibWeb/HTML/AttributeNames.h>
#include <LibWeb/Layout/LayoutNode.h>
+#include <LibWeb/QualifiedName.h>
namespace Web::DOM {
@@ -44,15 +45,20 @@ class Element
public:
using WrapperType = Bindings::ElementWrapper;
- Element(Document&, const FlyString& local_name);
+ Element(Document&, const QualifiedName& qualified_name);
virtual ~Element() override;
- virtual FlyString node_name() const final { return m_tag_name; }
- const FlyString& local_name() const { return m_tag_name; }
+ virtual FlyString node_name() const final { return m_qualified_name.local_name(); }
+ const FlyString& local_name() const { return m_qualified_name.local_name(); }
// NOTE: This is for the JS bindings
const FlyString& tag_name() const { return local_name(); }
+ const FlyString& namespace_() const { return m_qualified_name.namespace_(); }
+
+ // NOTE: This is for the JS bindings
+ const FlyString& namespace_uri() const { return namespace_(); }
+
bool has_attribute(const FlyString& name) const { return !attribute(name).is_null(); }
String attribute(const FlyString& name) const;
String get_attribute(const FlyString& name) const { return attribute(name); }
@@ -100,7 +106,7 @@ private:
Attribute* find_attribute(const FlyString& name);
const Attribute* find_attribute(const FlyString& name) const;
- FlyString m_tag_name;
+ QualifiedName m_qualified_name;
Vector<Attribute> m_attributes;
RefPtr<CSS::StyleProperties> m_resolved_style;
diff --git a/Libraries/LibWeb/DOM/Element.idl b/Libraries/LibWeb/DOM/Element.idl
index 34baef070e..009972252c 100644
--- a/Libraries/LibWeb/DOM/Element.idl
+++ b/Libraries/LibWeb/DOM/Element.idl
@@ -1,5 +1,5 @@
interface Element : Node {
-
+ readonly attribute DOMString? namespaceURI;
readonly attribute DOMString tagName;
DOMString? getAttribute(DOMString qualifiedName);
@@ -16,4 +16,3 @@ interface Element : Node {
readonly attribute Element? nextElementSibling;
readonly attribute Element? previousElementSibling;
}
-
diff --git a/Libraries/LibWeb/DOM/ElementFactory.cpp b/Libraries/LibWeb/DOM/ElementFactory.cpp
index 12d0cfe696..b50cd0550b 100644
--- a/Libraries/LibWeb/DOM/ElementFactory.cpp
+++ b/Libraries/LibWeb/DOM/ElementFactory.cpp
@@ -101,159 +101,161 @@
namespace Web::DOM {
-NonnullRefPtr<Element> create_element(Document& document, const FlyString& tag_name)
+NonnullRefPtr<Element> create_element(Document& document, const FlyString& tag_name, const FlyString& namespace_)
{
auto lowercase_tag_name = tag_name.to_lowercase();
+ // FIXME: Add prefix when we support it.
+ auto qualified_name = QualifiedName(tag_name, {}, namespace_);
if (lowercase_tag_name == HTML::TagNames::a)
- return adopt(*new HTML::HTMLAnchorElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLAnchorElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::area)
- return adopt(*new HTML::HTMLAreaElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLAreaElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::audio)
- return adopt(*new HTML::HTMLAudioElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLAudioElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::base)
- return adopt(*new HTML::HTMLBaseElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLBaseElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::blink)
- return adopt(*new HTML::HTMLBlinkElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLBlinkElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::body)
- return adopt(*new HTML::HTMLBodyElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLBodyElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::br)
- return adopt(*new HTML::HTMLBRElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLBRElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::button)
- return adopt(*new HTML::HTMLButtonElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLButtonElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::canvas)
- return adopt(*new HTML::HTMLCanvasElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLCanvasElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::data)
- return adopt(*new HTML::HTMLDataElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLDataElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::datalist)
- return adopt(*new HTML::HTMLDataListElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLDataListElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::details)
- return adopt(*new HTML::HTMLDetailsElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLDetailsElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::dialog)
- return adopt(*new HTML::HTMLDialogElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLDialogElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::div)
- return adopt(*new HTML::HTMLDivElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLDivElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::dl)
- return adopt(*new HTML::HTMLDListElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLDListElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::embed)
- return adopt(*new HTML::HTMLEmbedElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLEmbedElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::fieldset)
- return adopt(*new HTML::HTMLFieldSetElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLFieldSetElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::font)
- return adopt(*new HTML::HTMLFontElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLFontElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::form)
- return adopt(*new HTML::HTMLFormElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLFormElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::frame)
- return adopt(*new HTML::HTMLFrameElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLFrameElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::frameset)
- return adopt(*new HTML::HTMLFrameSetElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLFrameSetElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::head)
- return adopt(*new HTML::HTMLHeadElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLHeadElement(document, qualified_name));
if (lowercase_tag_name.is_one_of(HTML::TagNames::h1, HTML::TagNames::h2, HTML::TagNames::h3, HTML::TagNames::h4, HTML::TagNames::h5, HTML::TagNames::h6))
- return adopt(*new HTML::HTMLHeadingElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLHeadingElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::hr)
- return adopt(*new HTML::HTMLHRElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLHRElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::html)
- return adopt(*new HTML::HTMLHtmlElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLHtmlElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::iframe)
- return adopt(*new HTML::HTMLIFrameElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLIFrameElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::img)
- return adopt(*new HTML::HTMLImageElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLImageElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::input)
- return adopt(*new HTML::HTMLInputElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLInputElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::label)
- return adopt(*new HTML::HTMLLabelElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLLabelElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::legend)
- return adopt(*new HTML::HTMLLegendElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLLegendElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::li)
- return adopt(*new HTML::HTMLLIElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLLIElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::link)
- return adopt(*new HTML::HTMLLinkElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLLinkElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::map)
- return adopt(*new HTML::HTMLMapElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLMapElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::marquee)
- return adopt(*new HTML::HTMLMarqueeElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLMarqueeElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::menu)
- return adopt(*new HTML::HTMLMenuElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLMenuElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::meta)
- return adopt(*new HTML::HTMLMetaElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLMetaElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::meter)
- return adopt(*new HTML::HTMLMeterElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLMeterElement(document, qualified_name));
if (lowercase_tag_name.is_one_of(HTML::TagNames::ins, HTML::TagNames::del))
- return adopt(*new HTML::HTMLModElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLModElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::object)
- return adopt(*new HTML::HTMLObjectElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLObjectElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::ol)
- return adopt(*new HTML::HTMLOListElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLOListElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::optgroup)
- return adopt(*new HTML::HTMLOptGroupElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLOptGroupElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::option)
- return adopt(*new HTML::HTMLOptionElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLOptionElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::output)
- return adopt(*new HTML::HTMLOutputElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLOutputElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::p)
- return adopt(*new HTML::HTMLParagraphElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLParagraphElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::param)
- return adopt(*new HTML::HTMLParamElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLParamElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::picture)
- return adopt(*new HTML::HTMLPictureElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLPictureElement(document, qualified_name));
// NOTE: The obsolete elements "listing" and "xmp" are explicitly mapped to HTMLPreElement in the specification.
if (lowercase_tag_name.is_one_of(HTML::TagNames::pre, HTML::TagNames::listing, HTML::TagNames::xmp))
- return adopt(*new HTML::HTMLPreElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLPreElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::progress)
- return adopt(*new HTML::HTMLProgressElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLProgressElement(document, qualified_name));
if (lowercase_tag_name.is_one_of(HTML::TagNames::blockquote, HTML::TagNames::q))
- return adopt(*new HTML::HTMLQuoteElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLQuoteElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::script)
- return adopt(*new HTML::HTMLScriptElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLScriptElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::select)
- return adopt(*new HTML::HTMLSelectElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLSelectElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::slot)
- return adopt(*new HTML::HTMLSlotElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLSlotElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::source)
- return adopt(*new HTML::HTMLSourceElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLSourceElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::span)
- return adopt(*new HTML::HTMLSpanElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLSpanElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::style)
- return adopt(*new HTML::HTMLStyleElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLStyleElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::caption)
- return adopt(*new HTML::HTMLTableCaptionElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTableCaptionElement(document, qualified_name));
if (lowercase_tag_name.is_one_of(Web::HTML::TagNames::td, Web::HTML::TagNames::th))
- return adopt(*new HTML::HTMLTableCellElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTableCellElement(document, qualified_name));
if (lowercase_tag_name.is_one_of(HTML::TagNames::colgroup, HTML::TagNames::col))
- return adopt(*new HTML::HTMLTableColElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTableColElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::table)
- return adopt(*new HTML::HTMLTableElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTableElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::tr)
- return adopt(*new HTML::HTMLTableRowElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTableRowElement(document, qualified_name));
if (lowercase_tag_name.is_one_of(HTML::TagNames::tbody, HTML::TagNames::thead, HTML::TagNames::tfoot))
- return adopt(*new HTML::HTMLTableSectionElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTableSectionElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::template_)
- return adopt(*new HTML::HTMLTemplateElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTemplateElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::textarea)
- return adopt(*new HTML::HTMLTextAreaElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTextAreaElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::time)
- return adopt(*new HTML::HTMLTimeElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTimeElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::title)
- return adopt(*new HTML::HTMLTitleElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTitleElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::track)
- return adopt(*new HTML::HTMLTrackElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLTrackElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::ul)
- return adopt(*new HTML::HTMLUListElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLUListElement(document, qualified_name));
if (lowercase_tag_name == HTML::TagNames::video)
- return adopt(*new HTML::HTMLVideoElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLVideoElement(document, qualified_name));
if (lowercase_tag_name.is_one_of(
HTML::TagNames::article, HTML::TagNames::section, HTML::TagNames::nav, HTML::TagNames::aside, HTML::TagNames::hgroup, HTML::TagNames::header, HTML::TagNames::footer, HTML::TagNames::address, HTML::TagNames::dt, HTML::TagNames::dd, HTML::TagNames::figure, HTML::TagNames::figcaption, HTML::TagNames::main, HTML::TagNames::em, HTML::TagNames::strong, HTML::TagNames::small, HTML::TagNames::s, HTML::TagNames::cite, HTML::TagNames::dfn, HTML::TagNames::abbr, HTML::TagNames::ruby, HTML::TagNames::rt, HTML::TagNames::rp, HTML::TagNames::code, HTML::TagNames::var, HTML::TagNames::samp, HTML::TagNames::kbd, HTML::TagNames::sub, HTML::TagNames::sup, HTML::TagNames::i, HTML::TagNames::b, HTML::TagNames::u, HTML::TagNames::mark, HTML::TagNames::bdi, HTML::TagNames::bdo, HTML::TagNames::wbr, HTML::TagNames::summary, HTML::TagNames::noscript,
// Obsolete
HTML::TagNames::acronym, HTML::TagNames::basefont, HTML::TagNames::big, HTML::TagNames::center, HTML::TagNames::nobr, HTML::TagNames::noembed, HTML::TagNames::noframes, HTML::TagNames::plaintext, HTML::TagNames::rb, HTML::TagNames::rtc, HTML::TagNames::strike, HTML::TagNames::tt))
- return adopt(*new HTML::HTMLElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLElement(document, qualified_name));
if (lowercase_tag_name == SVG::TagNames::svg)
- return adopt(*new SVG::SVGSVGElement(document, lowercase_tag_name));
+ return adopt(*new SVG::SVGSVGElement(document, qualified_name));
if (lowercase_tag_name == SVG::TagNames::path)
- return adopt(*new SVG::SVGPathElement(document, lowercase_tag_name));
+ return adopt(*new SVG::SVGPathElement(document, qualified_name));
// FIXME: If name is a valid custom element name, then return HTMLElement.
- return adopt(*new HTML::HTMLUnknownElement(document, lowercase_tag_name));
+ return adopt(*new HTML::HTMLUnknownElement(document, qualified_name));
}
}
diff --git a/Libraries/LibWeb/DOM/ElementFactory.h b/Libraries/LibWeb/DOM/ElementFactory.h
index 2dc5ac3308..c1c811a9a4 100644
--- a/Libraries/LibWeb/DOM/ElementFactory.h
+++ b/Libraries/LibWeb/DOM/ElementFactory.h
@@ -30,6 +30,6 @@
namespace Web::DOM {
-NonnullRefPtr<Element> create_element(Document&, const FlyString& tag_name);
+NonnullRefPtr<Element> create_element(Document&, const FlyString& tag_name, const FlyString& namespace_);
}