Browse Source

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
Luke Wilde 3 years ago
parent
commit
3bb5c62

+ 2 - 2
Userland/Libraries/LibWeb/HTML/FormAssociatedElement.cpp

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

+ 7 - 4
Userland/Libraries/LibWeb/HTML/FormAssociatedElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLButtonElement.cpp

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

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp

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

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp

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

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLImageElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp

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

+ 1 - 6
Userland/Libraries/LibWeb/HTML/HTMLInputElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp

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

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLOutputElement.cpp

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

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLOutputElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp

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

+ 1 - 6
Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h

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

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp

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

+ 2 - 2
Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h

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