mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
LibWeb: Implement HTMLTableSectionElement::insertRow()
This commit is contained in:
parent
57090f75ae
commit
009588eb28
Notes:
sideshowbarker
2024-07-17 17:32:16 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/009588eb28 Pull-request: https://github.com/SerenityOS/serenity/pull/13014 Reviewed-by: https://github.com/awesomekling ✅
@ -5,9 +5,11 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableSectionElement.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
@ -33,4 +35,28 @@ NonnullRefPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
|
||||
});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-insertrow
|
||||
DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableSectionElement::insert_row(long index)
|
||||
{
|
||||
auto rows_collection = rows();
|
||||
auto rows_collection_size = static_cast<long>(rows_collection->length());
|
||||
|
||||
// 1. If index is less than −1 or greater than the number of elements in the rows collection, throw an "IndexSizeError" DOMException.
|
||||
if (index < -1 || index > rows_collection_size)
|
||||
return DOM::IndexSizeError::create("Index is negative or greater than the number of rows");
|
||||
|
||||
// 2. Let table row be the result of creating an element given this element's node document, tr, and the HTML namespace.
|
||||
auto table_row = static_ptr_cast<HTMLTableRowElement>(DOM::create_element(document(), TagNames::tr, Namespace::HTML));
|
||||
|
||||
// 3. If index is −1 or equal to the number of items in the rows collection, then append table row to this element.
|
||||
if (index == -1 || index == rows_collection_size)
|
||||
append_child(table_row);
|
||||
// 4. Otherwise, insert table row as a child of this element, immediately before the index-th tr element in the rows collection.
|
||||
else
|
||||
table_row->insert_before(*this, rows_collection->item(index));
|
||||
|
||||
// 5. Return table row.
|
||||
return table_row;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
virtual ~HTMLTableSectionElement() override;
|
||||
|
||||
NonnullRefPtr<DOM::HTMLCollection> rows() const;
|
||||
DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> insert_row(long index);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#import <DOM/HTMLCollection.idl>
|
||||
#import <HTML/HTMLElement.idl>
|
||||
#import <HTML/HTMLTableRowElement.idl>
|
||||
|
||||
interface HTMLTableSectionElement : HTMLElement {
|
||||
|
||||
@ -9,5 +10,6 @@ interface HTMLTableSectionElement : HTMLElement {
|
||||
[Reflect=valign] attribute DOMString vAlign;
|
||||
|
||||
[SameObject] readonly attribute HTMLCollection rows;
|
||||
HTMLTableRowElement insertRow(optional long index = -1);
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user