servo: Merge #7089 - Implement HTMLTableElement#createTBody (from dzbarsky:createtbody); r=Ms2ger
authorDavid Zbarsky <dzbarsky@gmail.com>
Sun, 09 Aug 2015 13:56:47 -0600
changeset 336899 357e97613c1caaa835cb61e235f53d88e355377f
parent 336898 be24dbe6c7db539c82b1cf4094e344c2c1a01d2c
child 336900 29cfb6f578b491315bd905881294587c2a67e2f6
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
servo: Merge #7089 - Implement HTMLTableElement#createTBody (from dzbarsky:createtbody); r=Ms2ger Source-Repo: https://github.com/servo/servo Source-Revision: 44d93bc37aa8226554fc73bba20421a150b002de
servo/components/script/dom/htmltableelement.rs
servo/components/script/dom/webidls/HTMLTableElement.webidl
--- a/servo/components/script/dom/htmltableelement.rs
+++ b/servo/components/script/dom/htmltableelement.rs
@@ -1,24 +1,26 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 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;
 
 use util::str::{self, DOMString, LengthOrPercentageOrAuto};
 
 use cssparser::RGBA;
 use string_cache::Atom;
 
@@ -105,16 +107,34 @@ impl<'a> HTMLTableElementMethods for &'a
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-table-deletecaption
     fn DeleteCaption(self) {
         if let Some(caption) = self.GetCaption() {
             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 {
     fn get_background_color(self) -> Option<RGBA>;
     fn get_border(self) -> Option<u32>;
     fn get_cellspacing(self) -> Option<u32>;
     fn get_width(self) -> LengthOrPercentageOrAuto;
 }
--- a/servo/components/script/dom/webidls/HTMLTableElement.webidl
+++ b/servo/components/script/dom/webidls/HTMLTableElement.webidl
@@ -10,17 +10,17 @@ interface HTMLTableElement : HTMLElement
   void deleteCaption();
   //         attribute HTMLTableSectionElement? tHead;
   //HTMLElement createTHead();
   //void deleteTHead();
   //         attribute HTMLTableSectionElement? tFoot;
   //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);
   //         attribute boolean sortable;
   //void stopSorting();
 
   // also has obsolete members
 };