Browse Source

LibWeb: Add form associated element categories

Luke Wilde 3 years ago
parent
commit
432d496ed6

+ 12 - 0
Userland/Libraries/LibWeb/HTML/FormAssociatedElement.h

@@ -21,6 +21,18 @@ public:
 
     bool enabled() const;
 
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const { return false; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-submit
+    virtual bool is_submittable() const { return false; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-reset
+    virtual bool is_resettable() const { return false; }
+
+    // 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))

+ 14 - 0
Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h

@@ -16,6 +16,20 @@ public:
 
     HTMLButtonElement(DOM::Document&, DOM::QualifiedName);
     virtual ~HTMLButtonElement() override;
+
+    // ^FormAssociatedElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-submit
+    virtual bool is_submittable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
+    virtual bool is_auto_capitalize_inheriting() const override { return true; }
+
+    // ^HTMLElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const override { return true; }
 };
 
 }

+ 3 - 0
Userland/Libraries/LibWeb/HTML/HTMLElement.h

@@ -46,6 +46,9 @@ public:
 
     bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted);
 
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const { return false; }
+
 protected:
     virtual void parse_attribute(const FlyString& name, const String& value) override;
 

+ 7 - 0
Userland/Libraries/LibWeb/HTML/HTMLFieldSetElement.h

@@ -22,6 +22,13 @@ public:
         static String fieldset = "fieldset";
         return fieldset;
     }
+
+    // ^FormAssociatedElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
+    virtual bool is_auto_capitalize_inheriting() const override { return true; }
 };
 
 }

+ 17 - 0
Userland/Libraries/LibWeb/HTML/HTMLInputElement.h

@@ -83,6 +83,23 @@ public:
     virtual void parse_attribute(FlyString const&, String const&) override;
     virtual void did_remove_attribute(FlyString const&) override;
 
+    // ^FormAssociatedElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-submit
+    virtual bool is_submittable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-reset
+    virtual bool is_resettable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
+    virtual bool is_auto_capitalize_inheriting() const override { return true; }
+
+    // ^HTMLElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const override { return type_state() != TypeAttributeState::Hidden; }
+
 private:
     // ^DOM::Node
     virtual void inserted() override;

+ 5 - 0
Userland/Libraries/LibWeb/HTML/HTMLMeterElement.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020, the SerenityOS developers.
+ * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -16,6 +17,10 @@ public:
 
     HTMLMeterElement(DOM::Document&, DOM::QualifiedName);
     virtual ~HTMLMeterElement() override;
+
+    // ^HTMLElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const override { return true; }
 };
 
 }

+ 4 - 0
Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h

@@ -25,6 +25,10 @@ public:
     String data() const { return attribute(HTML::AttributeNames::data); }
     String type() const { return attribute(HTML::AttributeNames::type); }
 
+    // ^FormAssociatedElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const override { return true; }
+
 private:
     virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
 

+ 15 - 0
Userland/Libraries/LibWeb/HTML/HTMLOutputElement.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020, the SerenityOS developers.
+ * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -22,6 +23,20 @@ public:
         static String output = "output";
         return output;
     }
+
+    // ^FormAssociatedElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
+    virtual bool is_resettable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
+    virtual bool is_auto_capitalize_inheriting() const override { return true; }
+
+    // ^HTMLElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const override { return true; }
 };
 
 }

+ 4 - 0
Userland/Libraries/LibWeb/HTML/HTMLProgressElement.h

@@ -27,6 +27,10 @@ public:
 
     double position() const;
 
+    // ^HTMLElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const override { return true; }
+
 private:
     bool is_determinate() const { return has_attribute(HTML::AttributeNames::value); }
 };

+ 18 - 0
Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h

@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2020, the SerenityOS developers.
  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -19,6 +20,23 @@ public:
     HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
     virtual ~HTMLSelectElement() override;
 
+    // ^FormAssociatedElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-submit
+    virtual bool is_submittable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-reset
+    virtual bool is_resettable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
+    virtual bool is_auto_capitalize_inheriting() const override { return true; }
+
+    // ^HTMLElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const override { return true; }
+
 private:
     // ^DOM::Node
     virtual void inserted() override;

+ 18 - 0
Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020, the SerenityOS developers.
+ * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -22,6 +23,23 @@ public:
         static String textarea = "textarea";
         return textarea;
     }
+
+    // ^FormAssociatedElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
+    virtual bool is_listed() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-submit
+    virtual bool is_submittable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-reset
+    virtual bool is_resettable() const override { return true; }
+
+    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
+    virtual bool is_auto_capitalize_inheriting() const override { return true; }
+
+    // ^HTMLElement
+    // https://html.spec.whatwg.org/multipage/forms.html#category-label
+    virtual bool is_labelable() const override { return true; }
 };
 
 }