2020-07-31 23:05:43 -03:00
/*
2021-04-28 17:46:44 -03:00
* Copyright ( c ) 2020 , the SerenityOS developers .
2020-07-31 23:05:43 -03:00
*
2021-04-22 05:24:48 -03:00
* SPDX - License - Identifier : BSD - 2 - Clause
2020-07-31 23:05:43 -03:00
*/
2024-04-26 21:09:58 -03:00
# include <LibWeb/Bindings/HTMLLegendElementPrototype.h>
2022-09-30 20:16:16 -03:00
# include <LibWeb/Bindings/Intrinsics.h>
2023-11-24 13:38:31 -03:00
# include <LibWeb/HTML/HTMLFieldSetElement.h>
2020-07-31 23:05:43 -03:00
# include <LibWeb/HTML/HTMLLegendElement.h>
2024-11-05 05:07:13 -03:00
# include <LibWeb/Layout/LegendBox.h>
2020-07-31 23:05:43 -03:00
namespace Web : : HTML {
2024-11-14 12:01:23 -03:00
GC_DEFINE_ALLOCATOR ( HTMLLegendElement ) ;
2023-11-19 15:47:52 -03:00
2022-02-18 17:00:52 -03:00
HTMLLegendElement : : HTMLLegendElement ( DOM : : Document & document , DOM : : QualifiedName qualified_name )
2021-02-07 07:20:15 -03:00
: HTMLElement ( document , move ( qualified_name ) )
2020-07-31 23:05:43 -03:00
{
}
2022-03-14 16:21:51 -03:00
HTMLLegendElement : : ~ HTMLLegendElement ( ) = default ;
2023-01-10 08:28:20 -03:00
2023-08-07 03:41:28 -03:00
void HTMLLegendElement : : initialize ( JS : : Realm & realm )
2023-01-10 08:28:20 -03:00
{
2023-08-07 03:41:28 -03:00
Base : : initialize ( realm ) ;
2024-03-16 09:13:08 -03:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( HTMLLegendElement ) ;
2023-01-10 08:28:20 -03:00
}
2023-11-24 13:38:31 -03:00
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-legend-form
HTMLFormElement * HTMLLegendElement : : form ( )
{
// The form IDL attribute's behavior depends on whether the legend element is in a fieldset element or not.
// If the legend has a fieldset element as its parent, then the form IDL attribute must return the same value as the form IDL attribute on that fieldset element.
2025-04-17 23:19:19 -03:00
if ( auto * field_set = as_if < HTML : : HTMLFieldSetElement > ( parent_element ( ) . ptr ( ) ) ) {
return field_set - > form ( ) ;
2023-11-24 13:38:31 -03:00
}
// Otherwise, it must return null.
return nullptr ;
}
2024-12-20 12:35:12 -03:00
GC : : Ptr < Layout : : Node > HTMLLegendElement : : create_layout_node ( GC : : Ref < CSS : : ComputedProperties > style )
2024-11-05 05:07:13 -03:00
{
return heap ( ) . allocate < Layout : : LegendBox > ( document ( ) , * this , move ( style ) ) ;
}
Layout : : LegendBox * HTMLLegendElement : : layout_node ( )
{
return static_cast < Layout : : LegendBox * > ( Node : : layout_node ( ) ) ;
}
Layout : : LegendBox const * HTMLLegendElement : : layout_node ( ) const
{
return static_cast < Layout : : LegendBox const * > ( Node : : layout_node ( ) ) ;
}
2020-07-31 23:05:43 -03:00
}