Auto merge of #7089 - dzbarsky:createtbody, r=Ms2ger

Implement HTMLTableElement#createTBody



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7089)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-08-09 13:56:47 -06:00
commit 44d93bc37a
5 changed files with 32 additions and 54 deletions

View file

@ -6,14 +6,16 @@ use dom::attr::{Attr, AttrHelpers, AttrValue};
use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
use dom::bindings::codegen::Bindings::HTMLTableElementBinding;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableCaptionElementCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLTableCaptionElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, NodeCast};
use dom::bindings::js::Root;
use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementDerived;
use dom::bindings::js::{Root, RootedReference};
use dom::document::Document;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::ElementTypeId;
use dom::element::{ElementHelpers, ElementTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmltablecaptionelement::HTMLTableCaptionElement;
use dom::htmltablesectionelement::HTMLTableSectionElement;
use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node};
use dom::virtualmethods::VirtualMethods;
@ -110,6 +112,24 @@ impl<'a> HTMLTableElementMethods for &'a HTMLTableElement {
NodeCast::from_ref(caption.r()).remove_self();
}
}
// https://html.spec.whatwg.org/multipage/#dom-table-createtbody
fn CreateTBody(self) -> Root<HTMLTableSectionElement> {
let tbody = HTMLTableSectionElement::new("tbody".to_owned(),
None,
document_from_node(self).r());
let node = NodeCast::from_ref(self);
let last_tbody =
node.rev_children()
.filter_map(ElementCast::to_root)
.find(|n| n.is_htmltablesectionelement() && n.local_name() == &atom!("tbody"));
let reference_element =
last_tbody.and_then(|t| NodeCast::from_root(t).GetNextSibling());
assert!(node.InsertBefore(NodeCast::from_ref(tbody.r()),
reference_element.r()).is_ok());
tbody
}
}
pub trait HTMLTableElementHelpers {

View file

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

View file

@ -4587,9 +4587,6 @@
[HTMLTableElement interface: attribute tBodies]
expected: FAIL
[HTMLTableElement interface: operation createTBody()]
expected: FAIL
[HTMLTableElement interface: attribute rows]
expected: FAIL
@ -4653,9 +4650,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 "createTBody" with the proper type (10)]
expected: FAIL
[HTMLTableElement interface: document.createElement("table") must inherit property "rows" with the proper type (11)]
expected: FAIL

View file

@ -1,44 +0,0 @@
[createTBody.html]
type: testharness
[No child nodes]
expected: FAIL
[One tbody child node]
expected: FAIL
[Two tbody child nodes]
expected: FAIL
[A thead and a tbody child node]
expected: FAIL
[A tfoot and a tbody child node]
expected: FAIL
[A tbody and a thead child node]
expected: FAIL
[A tbody and a tfoot child node]
expected: FAIL
[Two tbody child nodes and a div]
expected: FAIL
[One HTML and one namespaced tbody child node]
expected: FAIL
[Two nested tbody child nodes]
expected: FAIL
[A tbody node inside a thead child node]
expected: FAIL
[A tbody node inside a tfoot child node]
expected: FAIL
[A tbody node inside a thead child node after a tbody child node]
expected: FAIL
[A tbody node inside a tfoot child node after a tbody child node]
expected: FAIL

View file

@ -162,4 +162,12 @@ test(function() {
assert_array_equals(table.childNodes, [before, tbody, after1]);
assert_tbody(tbody);
}, "A tbody node inside a tfoot child node after a tbody child node");
test(function() {
var table = document.createElementNS(htmlNS, "foo:table");
var tbody = table.createTBody();
assert_equals(tbody.prefix, null);
}, "A prefixed table creates tbody without prefix");
</script>