/* * Copyright (c) 2018-2022, Andreas Kling * Copyright (c) 2020, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Web::DOM { // https://dom.spec.whatwg.org/#concept-create-element JS::NonnullGCPtr create_element(Document& document, FlyString local_name, FlyString namespace_, FlyString prefix) { // 1. If prefix was not given, let prefix be null. // NOTE: This is already taken care of by `prefix` having a default value. // FIXME: 2. If is was not given, let is be null. // FIXME: 3. Let result be null. // FIXME: 4. Let definition be the result of looking up a custom element definition given document, namespace, localName, and is. // FIXME: 5. If definition is non-null, and definition’s name is not equal to its local name (i.e., definition represents a customized built-in element), then: ... // FIXME: 6. Otherwise, if definition is non-null, then: ... // 7. Otherwise: // 1. Let interface be the element interface for localName and namespace. // 2. Set result to a new element that implements interface, with no attributes, namespace set to namespace, namespace prefix set to prefix, // local name set to localName, custom element state set to "uncustomized", custom element definition set to null, is value set to is, // and node document set to document. // FIXME: 3. If namespace is the HTML namespace, and either localName is a valid custom element name or is is non-null, // then set result’s custom element state to "undefined". // 8. Return result. auto& realm = document.realm(); auto lowercase_tag_name = local_name.to_lowercase(); auto qualified_name = QualifiedName { local_name, prefix, namespace_ }; if (lowercase_tag_name == HTML::TagNames::a) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::area) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::audio) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::base) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::blink) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::body) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::br) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::button) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::canvas) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::data) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::datalist) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::details) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::dialog) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::dir) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::div) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::dl) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::embed) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::fieldset) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::font) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::form) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::frame) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::frameset) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::head) return *realm.heap().allocate(realm, document, move(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 *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::hr) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::html) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::iframe) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::img) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::input) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::label) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::legend) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::li) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::link) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::map) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::marquee) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::menu) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::meta) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::meter) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name.is_one_of(HTML::TagNames::ins, HTML::TagNames::del)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::object) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::ol) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::optgroup) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::option) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::output) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::p) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::param) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::picture) return *realm.heap().allocate(realm, document, move(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 *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::progress) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name.is_one_of(HTML::TagNames::blockquote, HTML::TagNames::q)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::script) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::select) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::slot) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::source) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::span) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::style) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::caption) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name.is_one_of(Web::HTML::TagNames::td, Web::HTML::TagNames::th)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name.is_one_of(HTML::TagNames::colgroup, HTML::TagNames::col)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::table) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::tr) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name.is_one_of(HTML::TagNames::tbody, HTML::TagNames::thead, HTML::TagNames::tfoot)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::template_) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::textarea) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::time) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::title) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::track) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::ul) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == HTML::TagNames::video) return *realm.heap().allocate(realm, document, move(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 *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::svg) return *realm.heap().allocate(realm, document, move(qualified_name)); // FIXME: Support SVG's mixedCase tag names properly. if (lowercase_tag_name.equals_ignoring_case(SVG::TagNames::clipPath)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::circle) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name.equals_ignoring_case(SVG::TagNames::defs)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::ellipse) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name.equals_ignoring_case(SVG::TagNames::foreignObject)) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::line) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::path) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::polygon) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::polyline) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::rect) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::g) return *realm.heap().allocate(realm, document, move(qualified_name)); if (lowercase_tag_name == SVG::TagNames::text) return *realm.heap().allocate(realm, document, move(qualified_name)); // FIXME: If name is a valid custom element name, then return HTMLElement. return *realm.heap().allocate(realm, document, move(qualified_name)); } }