Auto merge of #10086 - KiChjang:table-rows, r=Manishearth

Implement HTMLTableElement#rows

Fixes #8084.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10086)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-09 16:36:40 +05:30
commit 32e53b80e2
6 changed files with 31 additions and 29 deletions

View file

@ -8,13 +8,15 @@ use dom::bindings::codegen::Bindings::HTMLTableElementBinding;
use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{LayoutJS, Root, RootedReference};
use dom::bindings::js::{JS, LayoutJS, Root, RootedReference};
use dom::document::Document;
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
use dom::htmlelement::HTMLElement;
use dom::htmltablecaptionelement::HTMLTableCaptionElement;
use dom::htmltablerowelement::HTMLTableRowElement;
use dom::htmltablesectionelement::HTMLTableSectionElement;
use dom::node::{Node, document_from_node};
use dom::node::{Node, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use std::cell::Cell;
use string_cache::Atom;
@ -51,6 +53,32 @@ impl HTMLTableElement {
}
impl HTMLTableElementMethods for HTMLTableElement {
// https://html.spec.whatwg.org/multipage/#dom-table-rows
fn Rows(&self) -> Root<HTMLCollection> {
#[allow(unrooted_must_root)]
#[derive(JSTraceable, HeapSizeOf)]
struct TableRowFilter {
sections: Vec<JS<Node>>
}
impl CollectionFilter for TableRowFilter {
fn filter(&self, elem: &Element, root: &Node) -> bool {
elem.is::<HTMLTableRowElement>()
&& (root.is_parent_of(elem.upcast())
|| self.sections.iter().any(|ref section| section.is_parent_of(elem.upcast())))
}
}
let filter = TableRowFilter {
sections: self.upcast::<Node>()
.children()
.filter_map(|ref node|
node.downcast::<HTMLTableSectionElement>().map(|_| JS::from_rooted(node)))
.collect()
};
HTMLCollection::new(window_from_node(self).r(), self.upcast(), box filter)
}
// https://html.spec.whatwg.org/multipage/#dom-table-caption
fn GetCaption(&self) -> Option<Root<HTMLTableCaptionElement>> {
self.upcast::<Node>().children().filter_map(Root::downcast).next()

View file

@ -16,7 +16,7 @@ interface HTMLTableElement : HTMLElement {
//void deleteTFoot();
//readonly attribute HTMLCollection tBodies;
HTMLTableSectionElement createTBody();
//readonly attribute HTMLCollection rows;
readonly attribute HTMLCollection rows;
//HTMLElement insertRow(optional long index = -1);
//void deleteRow(long index);
// attribute boolean sortable;

View file

@ -4179,9 +4179,6 @@
[HTMLTableElement interface: attribute tBodies]
expected: FAIL
[HTMLTableElement interface: attribute rows]
expected: FAIL
[HTMLTableElement interface: operation insertRow(long)]
expected: FAIL
@ -4236,9 +4233,6 @@
[HTMLTableElement interface: document.createElement("table") must inherit property "tBodies" with the proper type (9)]
expected: FAIL
[HTMLTableElement interface: document.createElement("table") must inherit property "rows" with the proper type (11)]
expected: FAIL
[HTMLTableElement interface: document.createElement("table") must inherit property "insertRow" with the proper type (12)]
expected: FAIL

View file

@ -1,5 +0,0 @@
[caption_001.html]
type: testharness
[caption of the third table element should be null]
expected: FAIL

View file

@ -3,9 +3,6 @@
[insertRow(): Empty table]
expected: FAIL
[table should start out empty]
expected: FAIL
[insertRow should insert a tr element]
expected: FAIL

View file

@ -1,17 +1,5 @@
[table-rows.html]
type: testharness
[Children of table]
expected: FAIL
[Children of thead]
expected: FAIL
[Children of tbody]
expected: FAIL
[Children of tfoot]
expected: FAIL
[Complicated case]
expected: FAIL