Introduce methods to simplify implementing reflecting attributes.

This commit is contained in:
Ms2ger 2013-12-23 13:36:25 +01:00
parent cb336a1831
commit 6e6d45ca26
2 changed files with 26 additions and 11 deletions

View file

@ -280,20 +280,40 @@ impl<'self> Element {
}
}
// http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes
impl Element {
pub fn get_url_attribute(&self, name: &str) -> DOMString {
// XXX Resolve URL.
self.get_string_attribute(name)
}
pub fn set_url_attribute(&mut self, abstract_self: AbstractNode,
name: &str, value: DOMString) {
self.set_string_attribute(abstract_self, name, value);
}
pub fn get_string_attribute(&self, name: &str) -> DOMString {
match self.get_attr(Null, name) {
Some(x) => x,
None => ~""
}
}
pub fn set_string_attribute(&mut self, abstract_self: AbstractNode,
name: &str, value: DOMString) {
self.set_attribute(abstract_self, Null, name.to_owned(), value);
}
}
impl Element {
pub fn TagName(&self) -> DOMString {
self.tag_name.to_ascii_upper()
}
pub fn Id(&self, _abstract_self: AbstractNode) -> DOMString {
match self.get_attr(Null, "id") {
Some(x) => x,
None => ~""
}
self.get_string_attribute("id")
}
pub fn SetId(&mut self, abstract_self: AbstractNode, id: DOMString) {
self.set_attribute(abstract_self, namespace::Null, ~"id", id);
self.set_string_attribute(abstract_self, "id", id);
}
pub fn Attributes(&mut self, abstract_self: AbstractNode) -> @mut AttrList {

View file

@ -7,9 +7,7 @@ use dom::bindings::utils::{DOMString, ErrorResult};
use dom::document::AbstractDocument;
use dom::element::HTMLScriptElementTypeId;
use dom::htmlelement::HTMLElement;
use dom::namespace::Null;
use dom::node::{AbstractNode, Node};
use style::TElement;
pub struct HTMLScriptElement {
htmlelement: HTMLElement,
@ -30,10 +28,7 @@ impl HTMLScriptElement {
impl HTMLScriptElement {
pub fn Src(&self) -> DOMString {
match self.htmlelement.element.get_attr(Null, "src") {
Some(s) => s.to_owned(),
None => ~""
}
self.htmlelement.element.get_url_attribute("src")
}
pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult {