mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-01 06:31:53 +00:00
LibWeb: Implement the HTMLLabelElement.form
attribute
This returns the form element associated with the given label element's control or null if the label has no control.
This commit is contained in:
parent
5296338e7a
commit
6bf22075ed
Notes:
sideshowbarker
2024-07-17 00:49:59 +09:00
Author: https://github.com/tcl3
Commit: 6bf22075ed
Pull-request: https://github.com/SerenityOS/serenity/pull/24346
Reviewed-by: https://github.com/shannonbooth ✅
5 changed files with 60 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <LibWeb/Bindings/HTMLLabelElementPrototype.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/FormAssociatedElement.h>
|
||||
#include <LibWeb/HTML/HTMLLabelElement.h>
|
||||
#include <LibWeb/Layout/Label.h>
|
||||
|
||||
|
@ -66,4 +67,21 @@ JS::GCPtr<HTMLElement> HTMLLabelElement::control() const
|
|||
return control;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#dom-label-form
|
||||
JS::GCPtr<HTMLFormElement> HTMLLabelElement::form() const
|
||||
{
|
||||
auto labeled_control = control();
|
||||
|
||||
// 1. If the label element has no labeled control, then return null.
|
||||
if (!labeled_control)
|
||||
return {};
|
||||
|
||||
// 2. If the label element's labeled control is not a form-associated element, then return null.
|
||||
if (!is<FormAssociatedElement>(*labeled_control))
|
||||
return {};
|
||||
|
||||
// 3. Return the label element's labeled control's form owner (which can still be null).
|
||||
return dynamic_cast<FormAssociatedElement*>(labeled_control.ptr())->form();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue