LibWeb: Make FormAssociatedElement inherit from HTMLElement
The new event target implementation requires us to downcast an EventTarget to a FormAssociatedElement to check if the current Element EventTarget has a form owner to setup a with scope for the form owner. This also makes all form associated elements inherit from FormAssociatedElement where it was previously missing. https://html.spec.whatwg.org/#form-associated-element
This commit is contained in:
parent
f71f404e0c
commit
3bb5c6207f
Notes:
sideshowbarker
2024-07-18 03:20:18 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/3bb5c6207f Pull-request: https://github.com/SerenityOS/serenity/pull/12308 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/linusg ✅
18 changed files with 31 additions and 38 deletions
|
@ -12,10 +12,10 @@ namespace Web::HTML {
|
|||
void FormAssociatedElement::set_form(HTMLFormElement* form)
|
||||
{
|
||||
if (m_form)
|
||||
m_form->remove_associated_element({}, form_associated_element_to_html_element());
|
||||
m_form->remove_associated_element({}, *this);
|
||||
m_form = form;
|
||||
if (m_form)
|
||||
m_form->add_associated_element({}, form_associated_element_to_html_element());
|
||||
m_form->add_associated_element({}, *this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class FormAssociatedElement {
|
||||
class FormAssociatedElement : public HTMLElement {
|
||||
public:
|
||||
HTMLFormElement* form() { return m_form; }
|
||||
HTMLFormElement const* form() const { return m_form; }
|
||||
|
@ -19,10 +20,12 @@ public:
|
|||
void set_form(HTMLFormElement*);
|
||||
|
||||
protected:
|
||||
FormAssociatedElement() = default;
|
||||
virtual ~FormAssociatedElement() = default;
|
||||
FormAssociatedElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
virtual HTMLElement& form_associated_element_to_html_element() = 0;
|
||||
virtual ~FormAssociatedElement() = default;
|
||||
|
||||
private:
|
||||
WeakPtr<HTMLFormElement> m_form;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLButtonElement::HTMLButtonElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLButtonElement final : public HTMLElement {
|
||||
class HTMLButtonElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLButtonElementWrapper;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLFieldSetElement::HTMLFieldSetElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLFieldSetElement final : public HTMLElement {
|
||||
class HTMLFieldSetElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLFieldSetElementWrapper;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLImageElement::HTMLImageElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
, m_image_loader(*this)
|
||||
{
|
||||
m_image_loader.on_load = [this] {
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
#include <LibWeb/Loader/ImageLoader.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLImageElement final : public HTMLElement {
|
||||
class HTMLImageElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLImageElementWrapper;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLInputElement::HTMLInputElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,7 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLInputElement final
|
||||
: public HTMLElement
|
||||
, public FormAssociatedElement {
|
||||
class HTMLInputElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLInputElementWrapper;
|
||||
|
||||
|
@ -43,9 +41,6 @@ private:
|
|||
virtual void inserted() override;
|
||||
virtual void removed_from(Node*) override;
|
||||
|
||||
// ^HTML::FormAssociatedElement
|
||||
virtual HTMLElement& form_associated_element_to_html_element() override { return *this; }
|
||||
|
||||
// ^DOM::EventTarget
|
||||
virtual void did_receive_focus() override;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLObjectElement::HTMLObjectElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
, m_image_loader(*this)
|
||||
{
|
||||
m_image_loader.on_load = [this] {
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
#include <LibWeb/Loader/ImageLoader.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLObjectElement final : public HTMLElement {
|
||||
class HTMLObjectElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLObjectElementWrapper;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLOutputElement::HTMLOutputElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLOutputElement final : public HTMLElement {
|
||||
class HTMLOutputElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLOutputElementWrapper;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLSelectElement::HTMLSelectElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLSelectElement final
|
||||
: public HTMLElement
|
||||
, public FormAssociatedElement {
|
||||
class HTMLSelectElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLSelectElementWrapper;
|
||||
|
||||
|
@ -25,9 +23,6 @@ private:
|
|||
// ^DOM::Node
|
||||
virtual void inserted() override;
|
||||
virtual void removed_from(DOM::Node*) override;
|
||||
|
||||
// ^HTML::FormAssociatedElement
|
||||
virtual HTMLElement& form_associated_element_to_html_element() override { return *this; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Web::HTML {
|
||||
|
||||
HTMLTextAreaElement::HTMLTextAreaElement(DOM::Document& document, QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
: FormAssociatedElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class HTMLTextAreaElement final : public HTMLElement {
|
||||
class HTMLTextAreaElement final : public FormAssociatedElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLTextAreaElementWrapper;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue