mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implement HTMLTableElement.caption
This commit is contained in:
parent
fe3b62e9b4
commit
795fd68032
3 changed files with 63 additions and 3 deletions
|
@ -3,14 +3,18 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::HTMLTableElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLTableElementBinding;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTableElementDerived;
|
use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
|
||||||
|
use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, NodeCast, HTMLTableCaptionElementCast};
|
||||||
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::js::{JSRef, Temporary};
|
use dom::bindings::js::{JSRef, Temporary};
|
||||||
use dom::bindings::utils::{Reflectable, Reflector};
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
use dom::element::HTMLTableCaptionElementTypeId;
|
||||||
use dom::element::HTMLTableElementTypeId;
|
use dom::element::HTMLTableElementTypeId;
|
||||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, ElementNodeTypeId};
|
use dom::htmltablecaptionelement::HTMLTableCaptionElement;
|
||||||
|
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
|
@ -42,3 +46,36 @@ impl Reflectable for HTMLTableElement {
|
||||||
self.htmlelement.reflector()
|
self.htmlelement.reflector()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> {
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#dom-table-caption
|
||||||
|
fn GetCaption(&self) -> Option<Temporary<HTMLTableCaptionElement>> {
|
||||||
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
|
node.children().find(|child| {
|
||||||
|
child.type_id() == ElementNodeTypeId(HTMLTableCaptionElementTypeId)
|
||||||
|
}).map(|node| {
|
||||||
|
Temporary::from_rooted(HTMLTableCaptionElementCast::to_ref(&node).unwrap())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#dom-table-caption
|
||||||
|
fn SetCaption(&self, new_caption: Option<JSRef<HTMLTableCaptionElement>>) {
|
||||||
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
|
let old_caption = self.GetCaption();
|
||||||
|
|
||||||
|
match old_caption {
|
||||||
|
Some(htmlelem) => {
|
||||||
|
let htmlelem_jsref = &*htmlelem.root();
|
||||||
|
let old_caption_node: &JSRef<Node> = NodeCast::from_ref(htmlelem_jsref);
|
||||||
|
assert!(node.RemoveChild(old_caption_node).is_ok());
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
|
||||||
|
new_caption.map(|caption| {
|
||||||
|
let new_caption_node: &JSRef<Node> = NodeCast::from_ref(&caption);
|
||||||
|
assert!(node.AppendChild(new_caption_node).is_ok());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
// http://www.whatwg.org/html/#htmltableelement
|
// http://www.whatwg.org/html/#htmltableelement
|
||||||
interface HTMLTableElement : HTMLElement {
|
interface HTMLTableElement : HTMLElement {
|
||||||
// attribute HTMLTableCaptionElement? caption;
|
attribute HTMLTableCaptionElement? caption;
|
||||||
//HTMLElement createCaption();
|
//HTMLElement createCaption();
|
||||||
//void deleteCaption();
|
//void deleteCaption();
|
||||||
// attribute HTMLTableSectionElement? tHead;
|
// attribute HTMLTableSectionElement? tHead;
|
||||||
|
|
23
src/test/content/test_caption.html
Normal file
23
src/test/content/test_caption.html
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="harness.js"></script>
|
||||||
|
</head>
|
||||||
|
<table id="t">
|
||||||
|
<caption id="tcaption">old caption</caption>
|
||||||
|
</table>
|
||||||
|
<script>
|
||||||
|
var t = document.getElementById("t");
|
||||||
|
var tcaption = document.getElementById("tcaption");
|
||||||
|
is(t.caption, tcaption);
|
||||||
|
is(t.caption.innerHTML, "old caption");
|
||||||
|
|
||||||
|
var newCaption = document.createElement("caption");
|
||||||
|
newCaption.innerHTML = "new caption";
|
||||||
|
|
||||||
|
t.caption = newCaption;
|
||||||
|
is(newCaption.parentNode, t);
|
||||||
|
is(t.caption, newCaption);
|
||||||
|
|
||||||
|
finish();
|
||||||
|
</script>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue