Implement HTMLScriptElement.text

This commit is contained in:
Chris Paris 2014-08-14 14:52:57 -10:00
parent 5b2e08bb5c
commit c70b88c163
2 changed files with 25 additions and 3 deletions

View file

@ -4,15 +4,17 @@
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding;
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::HTMLScriptElementDerived;
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast, TextCast};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{HTMLScriptElementTypeId, Element, AttributeHandlers};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId};
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use dom::text::Text;
use servo_util::str::DOMString;
#[deriving(Encodable)]
@ -44,6 +46,25 @@ impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_url_attribute("src")
}
// http://www.whatwg.org/html/#dom-script-text
fn Text(&self) -> DOMString {
let node: &JSRef<Node> = NodeCast::from_ref(self);
let mut content = String::new();
for child in node.children() {
if child.is_text() {
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
content.push_str(text.deref().characterdata.data.deref().borrow().as_slice());
}
}
content
}
// http://www.whatwg.org/html/#dom-script-text
fn SetText(&self, value: DOMString) {
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.SetTextContent(Some(value))
}
}
impl Reflectable for HTMLScriptElement {