mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Add fieldset elements property
This commit is contained in:
parent
0fe192dfd9
commit
ea04a86715
Notes:
sideshowbarker
2024-07-17 01:21:02 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/ea04a86715 Pull-request: https://github.com/SerenityOS/serenity/pull/22235
6 changed files with 66 additions and 1 deletions
2
Tests/LibWeb/Text/expected/fieldset-elements.txt
Normal file
2
Tests/LibWeb/Text/expected/fieldset-elements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
1. 3
|
||||
2. "PASS"
|
24
Tests/LibWeb/Text/input/fieldset-elements.html
Normal file
24
Tests/LibWeb/Text/input/fieldset-elements.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
<script src="./include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let testCounter = 1;
|
||||
function testPart(part) {
|
||||
println(`${testCounter++}. ${JSON.stringify(part())}`);
|
||||
}
|
||||
|
||||
// 1. Get fieldset elements length
|
||||
testPart(() => {
|
||||
const fieldset = document.createElement('fieldset');
|
||||
fieldset.innerHTML = `<input><input><button></button>`;
|
||||
return fieldset.elements.length;
|
||||
});
|
||||
|
||||
// 2. Get fieldset elements set stuff
|
||||
testPart(() => {
|
||||
const fieldset = document.createElement('fieldset');
|
||||
fieldset.innerHTML = `<input><input value="FAIL"><button></button>`;
|
||||
fieldset.elements[0].value = 'PASS';
|
||||
return fieldset.children[0].value;
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -5,8 +5,14 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/HTML/HTMLButtonElement.h>
|
||||
#include <LibWeb/HTML/HTMLFieldSetElement.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
#include <LibWeb/HTML/HTMLLegendElement.h>
|
||||
#include <LibWeb/HTML/HTMLObjectElement.h>
|
||||
#include <LibWeb/HTML/HTMLOutputElement.h>
|
||||
#include <LibWeb/HTML/HTMLSelectElement.h>
|
||||
#include <LibWeb/HTML/HTMLTextAreaElement.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -25,6 +31,12 @@ void HTMLFieldSetElement::initialize(JS::Realm& realm)
|
|||
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLFieldSetElementPrototype>(realm, "HTMLFieldSetElement"_fly_string));
|
||||
}
|
||||
|
||||
void HTMLFieldSetElement::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_elements);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-fieldset-disabled
|
||||
bool HTMLFieldSetElement::is_disabled() const
|
||||
{
|
||||
|
@ -45,4 +57,23 @@ bool HTMLFieldSetElement::is_disabled() const
|
|||
return false;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-fieldset-elements
|
||||
JS::GCPtr<DOM::HTMLCollection> const& HTMLFieldSetElement::elements()
|
||||
{
|
||||
// The elements IDL attribute must return an HTMLCollection rooted at the fieldset element, whose filter matches listed elements.
|
||||
if (!m_elements) {
|
||||
m_elements = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](DOM::Element const& element) {
|
||||
// FIXME: Form-associated custom elements return also true
|
||||
return is<HTMLButtonElement>(element)
|
||||
|| is<HTMLFieldSetElement>(element)
|
||||
|| is<HTMLInputElement>(element)
|
||||
|| is<HTMLObjectElement>(element)
|
||||
|| is<HTMLOutputElement>(element)
|
||||
|| is<HTMLSelectElement>(element)
|
||||
|| is<HTMLTextAreaElement>(element);
|
||||
});
|
||||
}
|
||||
return m_elements;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/ARIA/Roles.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
|
||||
|
@ -30,6 +31,8 @@ public:
|
|||
|
||||
bool is_disabled() const;
|
||||
|
||||
JS::GCPtr<DOM::HTMLCollection> const& elements();
|
||||
|
||||
// ^FormAssociatedElement
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
||||
virtual bool is_listed() const override { return true; }
|
||||
|
@ -43,6 +46,9 @@ private:
|
|||
HTMLFieldSetElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
JS::GCPtr<DOM::HTMLCollection> m_elements;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ interface HTMLFieldSetElement : HTMLElement {
|
|||
|
||||
readonly attribute DOMString type;
|
||||
|
||||
// FIXME: [SameObject] readonly attribute HTMLCollection elements;
|
||||
[SameObject] readonly attribute HTMLCollection elements;
|
||||
|
||||
// FIXME: readonly attribute boolean willValidate;
|
||||
// FIXME: [SameObject] readonly attribute ValidityState validity;
|
||||
|
|
|
@ -396,6 +396,8 @@ static bool is_form_control(DOM::Element const& element)
|
|||
return true;
|
||||
}
|
||||
|
||||
// FIXME: Form-associated custom elements return also true
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue