mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
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.
This commit is contained in:
parent
f7f0195fae
commit
5608bc4eaf
21 changed files with 137 additions and 61 deletions
|
@ -8,11 +8,39 @@
|
|||
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class FormAssociatedElement : public HTMLElement {
|
||||
// Form-associated elements should invoke this macro to inject overidden FormAssociatedElement and HTMLElement
|
||||
// methods as needed. If your class wished to override an HTMLElement method that is overidden here, use the
|
||||
// following methods instead:
|
||||
//
|
||||
// HTMLElement::inserted() -> Use form_associated_element_was_inserted()
|
||||
// HTMLElement::removed_from() -> Use form_associated_element_was_removed()
|
||||
//
|
||||
#define FORM_ASSOCIATED_ELEMENT(ElementBaseClass, ElementClass) \
|
||||
private: \
|
||||
virtual HTMLElement& form_associated_element_to_html_element() override \
|
||||
{ \
|
||||
static_assert(IsBaseOf<HTMLElement, ElementClass>); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
virtual void inserted() override \
|
||||
{ \
|
||||
ElementBaseClass::inserted(); \
|
||||
form_node_was_inserted(); \
|
||||
form_associated_element_was_inserted(); \
|
||||
} \
|
||||
\
|
||||
virtual void removed_from(DOM::Node* node) override \
|
||||
{ \
|
||||
ElementBaseClass::removed_from(node); \
|
||||
form_node_was_removed(); \
|
||||
form_associated_element_was_removed(node); \
|
||||
}
|
||||
|
||||
class FormAssociatedElement {
|
||||
public:
|
||||
HTMLFormElement* form() { return m_form; }
|
||||
HTMLFormElement const* form() const { return m_form; }
|
||||
|
@ -21,7 +49,7 @@ public:
|
|||
|
||||
bool enabled() const;
|
||||
|
||||
void set_parser_inserted(Badge<HTMLParser>) { m_parser_inserted = true; }
|
||||
void set_parser_inserted(Badge<HTMLParser>);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
||||
virtual bool is_listed() const { return false; }
|
||||
|
@ -35,14 +63,18 @@ public:
|
|||
// https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
|
||||
virtual bool is_auto_capitalize_inheriting() const { return false; }
|
||||
|
||||
protected:
|
||||
FormAssociatedElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
virtual HTMLElement& form_associated_element_to_html_element() = 0;
|
||||
|
||||
protected:
|
||||
FormAssociatedElement() = default;
|
||||
virtual ~FormAssociatedElement() = default;
|
||||
|
||||
virtual void form_associated_element_was_inserted() { }
|
||||
virtual void form_associated_element_was_removed(DOM::Node*) { }
|
||||
|
||||
void form_node_was_inserted();
|
||||
void form_node_was_removed();
|
||||
|
||||
private:
|
||||
WeakPtr<HTMLFormElement> m_form;
|
||||
|
||||
|
@ -50,10 +82,6 @@ private:
|
|||
bool m_parser_inserted { false };
|
||||
|
||||
void reset_form_owner();
|
||||
|
||||
// ^DOM::Node
|
||||
virtual void inserted() override;
|
||||
virtual void removed_from(DOM::Node*) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue