mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWeb: Implement HTMLTableCellElement.cellIndex
See: - http://wpt.live/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html
This commit is contained in:
parent
a58704296c
commit
fa5800ebc5
Notes:
github-actions[bot]
2024-08-06 23:54:34 +00:00
Author: https://github.com/jamierocks
Commit: fa5800ebc5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/996
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 50 additions and 1 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
lone td.cellIndex = -1
|
||||||
|
parented td.cellIndex = 0
|
||||||
|
lone th.cellIndex = -1
|
||||||
|
parented th.cellIndex = 0
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const testElements = ["td", "th"];
|
||||||
|
|
||||||
|
for (const elementName of testElements) {
|
||||||
|
// Test a <td> / <th> element with no parent.
|
||||||
|
{
|
||||||
|
const element = document.createElement(elementName);
|
||||||
|
println(`lone ${elementName}.cellIndex = ${element.cellIndex}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test a <td> / <th> element with a parent <tr> element>.
|
||||||
|
{
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
const element = tr.appendChild(document.createElement(elementName));
|
||||||
|
println(`parented ${elementName}.cellIndex = ${element.cellIndex}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
|
#include <LibWeb/DOM/HTMLCollection.h>
|
||||||
#include <LibWeb/HTML/HTMLTableCellElement.h>
|
#include <LibWeb/HTML/HTMLTableCellElement.h>
|
||||||
#include <LibWeb/HTML/HTMLTableElement.h>
|
#include <LibWeb/HTML/HTMLTableElement.h>
|
||||||
#include <LibWeb/HTML/Numbers.h>
|
#include <LibWeb/HTML/Numbers.h>
|
||||||
|
@ -150,6 +152,24 @@ WebIDL::ExceptionOr<void> HTMLTableCellElement::set_row_span(unsigned int value)
|
||||||
return set_attribute(HTML::AttributeNames::rowspan, MUST(String::number(value)));
|
return set_attribute(HTML::AttributeNames::rowspan, MUST(String::number(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/tables.html#dom-tdth-cellindex
|
||||||
|
WebIDL::Long HTMLTableCellElement::cell_index() const
|
||||||
|
{
|
||||||
|
// The cellIndex IDL attribute must, if the element has a parent tr element, return the index of the cell's
|
||||||
|
// element in the parent element's cells collection. If there is no such parent element, then the attribute
|
||||||
|
// must return −1.
|
||||||
|
auto const* parent = first_ancestor_of_type<HTMLTableRowElement>();
|
||||||
|
if (!parent)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
auto rows = parent->cells()->collect_matching_elements();
|
||||||
|
for (size_t i = 0; i < rows.size(); ++i) {
|
||||||
|
if (rows[i] == this)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
Optional<ARIA::Role> HTMLTableCellElement::default_role() const
|
Optional<ARIA::Role> HTMLTableCellElement::default_role() const
|
||||||
{
|
{
|
||||||
// TODO: For td:
|
// TODO: For td:
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibWeb/HTML/HTMLElement.h>
|
#include <LibWeb/HTML/HTMLElement.h>
|
||||||
|
#include <LibWeb/WebIDL/Types.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -23,6 +24,8 @@ public:
|
||||||
WebIDL::ExceptionOr<void> set_col_span(unsigned);
|
WebIDL::ExceptionOr<void> set_col_span(unsigned);
|
||||||
WebIDL::ExceptionOr<void> set_row_span(unsigned);
|
WebIDL::ExceptionOr<void> set_row_span(unsigned);
|
||||||
|
|
||||||
|
WebIDL::Long cell_index() const;
|
||||||
|
|
||||||
virtual Optional<ARIA::Role> default_role() const override;
|
virtual Optional<ARIA::Role> default_role() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -9,7 +9,7 @@ interface HTMLTableCellElement : HTMLElement {
|
||||||
[CEReactions] attribute unsigned long colSpan;
|
[CEReactions] attribute unsigned long colSpan;
|
||||||
[CEReactions] attribute unsigned long rowSpan;
|
[CEReactions] attribute unsigned long rowSpan;
|
||||||
[CEReactions, Reflect] attribute DOMString headers;
|
[CEReactions, Reflect] attribute DOMString headers;
|
||||||
[FIXME] readonly attribute long cellIndex;
|
readonly attribute long cellIndex;
|
||||||
|
|
||||||
[FIXME, CEReactions] attribute DOMString scope; // only conforming for th elements
|
[FIXME, CEReactions] attribute DOMString scope; // only conforming for th elements
|
||||||
[CEReactions, Reflect] attribute DOMString abbr; // only conforming for th elements
|
[CEReactions, Reflect] attribute DOMString abbr; // only conforming for th elements
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue