diff options
5 files changed, 32 insertions, 54 deletions
diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index a8a1cdf1b7b..96db990368b 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -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 { diff --git a/components/script/dom/webidls/HTMLTableElement.webidl b/components/script/dom/webidls/HTMLTableElement.webidl index 26639442ee4..3a614efce1f 100644 --- a/components/script/dom/webidls/HTMLTableElement.webidl +++ b/components/script/dom/webidls/HTMLTableElement.webidl @@ -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); diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 8082c6e4c4b..45c273d6e75 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -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 diff --git a/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/createTBody.html.ini b/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/createTBody.html.ini deleted file mode 100644 index 03db1f0dadd..00000000000 --- a/tests/wpt/metadata/html/semantics/tabular-data/the-table-element/createTBody.html.ini +++ /dev/null @@ -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 - diff --git a/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/createTBody.html b/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/createTBody.html index 7927e43cae6..6100aedfdfc 100644 --- a/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/createTBody.html +++ b/tests/wpt/web-platform-tests/html/semantics/tabular-data/the-table-element/createTBody.html @@ -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> |