From 5608bc4eaf6bbc72def4cdb09052a6e91e14a3c1 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 23 Mar 2022 18:55:54 -0400 Subject: 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. --- Userland/Libraries/LibWeb/DOM/EventTarget.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Userland/Libraries/LibWeb/DOM') diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp index 2a2e113a03..95c74d0090 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp @@ -336,9 +336,11 @@ Bindings::CallbackType* EventTarget::get_current_value_of_event_handler(FlyStrin // 5. If element is not null and element has a form owner, let form owner be that form owner. Otherwise, let form owner be null. RefPtr form_owner; if (is(element.ptr())) { - auto& form_associated_element = verify_cast(*element); - if (form_associated_element.form()) - form_owner = form_associated_element.form(); + auto* form_associated_element = dynamic_cast(element.ptr()); + VERIFY(form_associated_element); + + if (form_associated_element->form()) + form_owner = form_associated_element->form(); } // 6. Let settings object be the relevant settings object of document. -- cgit v1.2.3