mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00: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: 009588eb28
Pull-request: https://github.com/SerenityOS/serenity/pull/13014
Reviewed-by: https://github.com/awesomekling ✅
3 changed files with 29 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue