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:
Luke Wilde 2021-10-14 16:18:49 +01:00 committed by Linus Groh
parent f71f404e0c
commit 3bb5c6207f
Notes: sideshowbarker 2024-07-18 03:20:18 +09:00
18 changed files with 31 additions and 38 deletions

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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))
{
}

View file

@ -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;

View file

@ -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))
{
}

View file

@ -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;

View file

@ -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] {

View file

@ -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;

View file

@ -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))
{
}

View file

@ -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;

View file

@ -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] {

View file

@ -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;

View file

@ -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))
{
}

View file

@ -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;

View file

@ -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))
{
}

View file

@ -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; }
};
}

View file

@ -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))
{
}

View file

@ -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;