mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
LibWeb: Implement HTMLTableSectionElement::insertRow()
This commit is contained in:
parent
57090f75ae
commit
009588eb28
3 changed files with 29 additions and 0 deletions
|
@ -5,9 +5,11 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/DOM/ElementFactory.h>
|
||||||
#include <LibWeb/DOM/HTMLCollection.h>
|
#include <LibWeb/DOM/HTMLCollection.h>
|
||||||
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
||||||
#include <LibWeb/HTML/HTMLTableSectionElement.h>
|
#include <LibWeb/HTML/HTMLTableSectionElement.h>
|
||||||
|
#include <LibWeb/Namespace.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
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;
|
virtual ~HTMLTableSectionElement() override;
|
||||||
|
|
||||||
NonnullRefPtr<DOM::HTMLCollection> rows() const;
|
NonnullRefPtr<DOM::HTMLCollection> rows() const;
|
||||||
|
DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> insert_row(long index);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#import <DOM/HTMLCollection.idl>
|
#import <DOM/HTMLCollection.idl>
|
||||||
#import <HTML/HTMLElement.idl>
|
#import <HTML/HTMLElement.idl>
|
||||||
|
#import <HTML/HTMLTableRowElement.idl>
|
||||||
|
|
||||||
interface HTMLTableSectionElement : HTMLElement {
|
interface HTMLTableSectionElement : HTMLElement {
|
||||||
|
|
||||||
|
@ -9,5 +10,6 @@ interface HTMLTableSectionElement : HTMLElement {
|
||||||
[Reflect=valign] attribute DOMString vAlign;
|
[Reflect=valign] attribute DOMString vAlign;
|
||||||
|
|
||||||
[SameObject] readonly attribute HTMLCollection rows;
|
[SameObject] readonly attribute HTMLCollection rows;
|
||||||
|
HTMLTableRowElement insertRow(optional long index = -1);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue