summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp17
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl3
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp16
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h3
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl3
6 files changed, 43 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
index 78af359fd0..fe3716d20c 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
@@ -1,9 +1,11 @@
/*
- * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/DOM/HTMLCollection.h>
+#include <LibWeb/HTML/HTMLTableCellElement.h>
#include <LibWeb/HTML/HTMLTableRowElement.h>
namespace Web::HTML {
@@ -17,4 +19,17 @@ HTMLTableRowElement::~HTMLTableRowElement()
{
}
+// https://html.spec.whatwg.org/multipage/tables.html#dom-tr-cells
+NonnullRefPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const
+{
+ // The cells attribute must return an HTMLCollection rooted at this tr element,
+ // whose filter matches only td and th elements that are children of the tr element.
+ // FIXME: This should return the same HTMLCollection object every time,
+ // but that would cause a reference cycle since HTMLCollection refs the root.
+ return DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), [this](Element const& element) {
+ return element.parent() == this
+ && is<HTMLTableCellElement>(element);
+ });
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
index 16408cb81b..1a85e95da4 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
@@ -16,6 +16,8 @@ public:
HTMLTableRowElement(DOM::Document&, DOM::QualifiedName);
virtual ~HTMLTableRowElement() override;
+
+ NonnullRefPtr<DOM::HTMLCollection> cells() const;
};
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl
index 0b97272bc1..8ddaa33eb3 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl
@@ -1,3 +1,4 @@
+#import <DOM/HTMLCollection.idl>
#import <HTML/HTMLElement.idl>
interface HTMLTableRowElement : HTMLElement {
@@ -9,4 +10,6 @@ interface HTMLTableRowElement : HTMLElement {
[LegacyNullToEmptyString, Reflect=bgcolor] attribute DOMString bgColor;
+ [SameObject] readonly attribute HTMLCollection cells;
+
};
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
index 22698165c8..0e08d6f8f6 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
@@ -1,9 +1,12 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/DOM/HTMLCollection.h>
+#include <LibWeb/HTML/HTMLTableRowElement.h>
#include <LibWeb/HTML/HTMLTableSectionElement.h>
namespace Web::HTML {
@@ -17,4 +20,17 @@ HTMLTableSectionElement::~HTMLTableSectionElement()
{
}
+// https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-rows
+NonnullRefPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
+{
+ // The rows attribute must return an HTMLCollection rooted at this element,
+ // whose filter matches only tr elements that are children of this element.
+ // FIXME: This should return the same HTMLCollection object every time,
+ // but that would cause a reference cycle since HTMLCollection refs the root.
+ return DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), [this](Element const& element) {
+ return element.parent() == this
+ && is<HTMLTableRowElement>(element);
+ });
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h
index 0e83b7681a..ebba9b8322 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -16,6 +17,8 @@ public:
HTMLTableSectionElement(DOM::Document&, DOM::QualifiedName);
virtual ~HTMLTableSectionElement() override;
+
+ NonnullRefPtr<DOM::HTMLCollection> rows() const;
};
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl
index c7c678ab01..8c7325a338 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl
@@ -1,3 +1,4 @@
+#import <DOM/HTMLCollection.idl>
#import <HTML/HTMLElement.idl>
interface HTMLTableSectionElement : HTMLElement {
@@ -7,4 +8,6 @@ interface HTMLTableSectionElement : HTMLElement {
[Reflect=charoff] attribute DOMString chOff;
[Reflect=valign] attribute DOMString vAlign;
+ [SameObject] readonly attribute HTMLCollection rows;
+
};