summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/Parser
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-03-23 18:55:54 -0400
committerAndreas Kling <kling@serenityos.org>2022-03-24 03:35:11 +0100
commit5608bc4eaf6bbc72def4cdb09052a6e91e14a3c1 (patch)
tree4bc6851c520c52647b4f88d9db17d8281b3a11dd /Userland/Libraries/LibWeb/HTML/Parser
parentf7f0195fae3f4a1296213256b5bda12b3264c5dc (diff)
downloadserenity-5608bc4eaf6bbc72def4cdb09052a6e91e14a3c1.zip
LibWeb: Remove inheritance of FormAssociatedElement from HTMLElement
HTMLObjectElement will need to be both a FormAssociatedElement and a BrowsingContextContainer. Currently, both of these classes inherit from HTMLElement. This can work in C++, but is generally frowned upon, and doesn't play particularly well with the rest of LibWeb. Instead, we can essentially revert commit 3bb5c62 to remove HTMLElement from FormAssociatedElement's hierarchy. This means that objects such as HTMLObjectElement individually inherit from FormAssociatedElement and HTMLElement now. Some caveats are: * FormAssociatedElement still needs to know when the HTMLElement is inserted into and removed from the DOM. This hook is automatically injected via a macro now, while still allowing classes like HTMLInputElement to also know when the element is inserted. * Casting from a DOM::Element to a FormAssociatedElement is now a sideways cast, rather than directly following an inheritance chain. This means static_cast cannot be used here; but we can safely use dynamic_cast since the only 2 instances of this already use RTTI to verify the cast.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/Parser')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index 01b3e91fba..b8731acec0 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -632,14 +632,17 @@ NonnullRefPtr<DOM::Element> HTMLParser::create_element_for(HTMLToken const& toke
// then associate element with the form element pointed to by the form element pointer and set element's parser inserted flag.
// FIXME: Check if the element is not a form-associated custom element.
if (is<FormAssociatedElement>(*element)) {
- auto& form_associated_element = static_cast<FormAssociatedElement&>(*element);
+ auto* form_associated_element = dynamic_cast<FormAssociatedElement*>(element.ptr());
+ VERIFY(form_associated_element);
+
+ auto& html_element = form_associated_element->form_associated_element_to_html_element();
if (m_form_element
&& !m_stack_of_open_elements.contains(HTML::TagNames::template_)
- && (!form_associated_element.is_listed() || !form_associated_element.has_attribute(HTML::AttributeNames::form))
+ && (!form_associated_element->is_listed() || !html_element.has_attribute(HTML::AttributeNames::form))
&& &intended_parent.root() == &m_form_element->root()) {
- form_associated_element.set_form(m_form_element);
- form_associated_element.set_parser_inserted({});
+ form_associated_element->set_form(m_form_element);
+ form_associated_element->set_parser_inserted({});
}
}