Implement HTMLTableRowElement::Cells

Extracted from #6936
This commit is contained in:
David Zbarsky 2015-10-01 19:53:35 -04:00 committed by Corey Farwell
parent ba2714f4f6
commit 4e64ff499b
5 changed files with 64 additions and 11 deletions

View file

@ -5,20 +5,37 @@
use cssparser::RGBA; use cssparser::RGBA;
use dom::attr::Attr; use dom::attr::Attr;
use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods}; use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableRowElementDerived}; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::js::Root; use dom::bindings::codegen::InheritTypes::HTMLElementCast;
use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived;
use dom::bindings::codegen::InheritTypes::HTMLTableHeaderCellElementDerived;
use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived;
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
use dom::document::Document; use dom::document::Document;
use dom::element::{AttributeMutation, ElementTypeId}; use dom::element::{AttributeMutation, Element, ElementTypeId};
use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId}; use dom::node::{Node, NodeTypeId, window_from_node};
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use std::cell::Cell; use std::cell::Cell;
use util::str::{self, DOMString}; use util::str::{self, DOMString};
#[derive(JSTraceable)]
struct CellsFilter;
impl CollectionFilter for CellsFilter {
fn filter(&self, elem: &Element, root: &Node) -> bool {
(elem.is_htmltableheadercellelement() || elem.is_htmltabledatacellelement())
&& NodeCast::from_ref(elem).GetParentNode().r() == Some(root)
}
}
#[dom_struct] #[dom_struct]
pub struct HTMLTableRowElement { pub struct HTMLTableRowElement {
htmlelement: HTMLElement, htmlelement: HTMLElement,
cells: MutNullableHeap<JS<HTMLCollection>>,
background_color: Cell<Option<RGBA>>, background_color: Cell<Option<RGBA>>,
} }
@ -38,6 +55,7 @@ impl HTMLTableRowElement {
localName, localName,
prefix, prefix,
document), document),
cells: Default::default(),
background_color: Cell::new(None), background_color: Cell::new(None),
} }
} }
@ -61,6 +79,15 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
// https://html.spec.whatwg.org/multipage/#dom-tr-bgcolor // https://html.spec.whatwg.org/multipage/#dom-tr-bgcolor
make_setter!(SetBgColor, "bgcolor"); make_setter!(SetBgColor, "bgcolor");
// https://html.spec.whatwg.org/multipage/#dom-tr-cells
fn Cells(&self) -> Root<HTMLCollection> {
self.cells.or_init(|| {
let window = window_from_node(self);
let filter = box CellsFilter;
HTMLCollection::create(window.r(), NodeCast::from_ref(self), filter)
})
}
} }
impl VirtualMethods for HTMLTableRowElement { impl VirtualMethods for HTMLTableRowElement {

View file

@ -7,7 +7,7 @@
interface HTMLTableRowElement : HTMLElement { interface HTMLTableRowElement : HTMLElement {
//readonly attribute long rowIndex; //readonly attribute long rowIndex;
//readonly attribute long sectionRowIndex; //readonly attribute long sectionRowIndex;
//readonly attribute HTMLCollection cells; readonly attribute HTMLCollection cells;
//HTMLElement insertCell(optional long index = -1); //HTMLElement insertCell(optional long index = -1);
//void deleteCell(long index); //void deleteCell(long index);

View file

@ -17743,6 +17743,10 @@
"path": "html/semantics/tabular-data/the-tbody-element/insertRow.html", "path": "html/semantics/tabular-data/the-tbody-element/insertRow.html",
"url": "/html/semantics/tabular-data/the-tbody-element/insertRow.html" "url": "/html/semantics/tabular-data/the-tbody-element/insertRow.html"
}, },
{
"path": "html/semantics/tabular-data/the-tr-element/cells.html",
"url": "/html/semantics/tabular-data/the-tr-element/cells.html"
},
{ {
"path": "html/semantics/tabular-data/the-tr-element/deleteCell.html", "path": "html/semantics/tabular-data/the-tr-element/deleteCell.html",
"url": "/html/semantics/tabular-data/the-tr-element/deleteCell.html" "url": "/html/semantics/tabular-data/the-tr-element/deleteCell.html"

View file

@ -4791,9 +4791,6 @@
[HTMLTableRowElement interface: attribute sectionRowIndex] [HTMLTableRowElement interface: attribute sectionRowIndex]
expected: FAIL expected: FAIL
[HTMLTableRowElement interface: attribute cells]
expected: FAIL
[HTMLTableRowElement interface: operation insertCell(long)] [HTMLTableRowElement interface: operation insertCell(long)]
expected: FAIL expected: FAIL
@ -4818,9 +4815,6 @@
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "sectionRowIndex" with the proper type (1)] [HTMLTableRowElement interface: document.createElement("tr") must inherit property "sectionRowIndex" with the proper type (1)]
expected: FAIL expected: FAIL
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "cells" with the proper type (2)]
expected: FAIL
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "insertCell" with the proper type (3)] [HTMLTableRowElement interface: document.createElement("tr") must inherit property "insertCell" with the proper type (3)]
expected: FAIL expected: FAIL

View file

@ -0,0 +1,28 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTMLTableRowElement#cells</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<table>
<tr id="testTr">
<td>First</td>
<div><td>Second</td></div>
<td>Third
<table>
<tr><td>Nested first</td></tr>
</table>
</td>
<img>
</tr>
</table>
<script>
var tr = document.getElementById("testTr");
test(function () {
tr.insertBefore(document.createElementNS("foo", "td"), tr.children[1]);
assert_array_equals(tr.cells, [tr.children[0], tr.children[2], tr.children[3]]);
}, "HTMLTableRowElement cells ignores nested tables and non-HTML elements");
</script>