mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Introduce methods to simplify implementing reflecting attributes.
This commit is contained in:
parent
cb336a1831
commit
6e6d45ca26
2 changed files with 26 additions and 11 deletions
|
@ -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 {
|
impl Element {
|
||||||
pub fn TagName(&self) -> DOMString {
|
pub fn TagName(&self) -> DOMString {
|
||||||
self.tag_name.to_ascii_upper()
|
self.tag_name.to_ascii_upper()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Id(&self, _abstract_self: AbstractNode) -> DOMString {
|
pub fn Id(&self, _abstract_self: AbstractNode) -> DOMString {
|
||||||
match self.get_attr(Null, "id") {
|
self.get_string_attribute("id")
|
||||||
Some(x) => x,
|
|
||||||
None => ~""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn SetId(&mut self, abstract_self: AbstractNode, id: DOMString) {
|
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 {
|
pub fn Attributes(&mut self, abstract_self: AbstractNode) -> @mut AttrList {
|
||||||
|
|
|
@ -7,9 +7,7 @@ use dom::bindings::utils::{DOMString, ErrorResult};
|
||||||
use dom::document::AbstractDocument;
|
use dom::document::AbstractDocument;
|
||||||
use dom::element::HTMLScriptElementTypeId;
|
use dom::element::HTMLScriptElementTypeId;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::namespace::Null;
|
|
||||||
use dom::node::{AbstractNode, Node};
|
use dom::node::{AbstractNode, Node};
|
||||||
use style::TElement;
|
|
||||||
|
|
||||||
pub struct HTMLScriptElement {
|
pub struct HTMLScriptElement {
|
||||||
htmlelement: HTMLElement,
|
htmlelement: HTMLElement,
|
||||||
|
@ -30,10 +28,7 @@ impl HTMLScriptElement {
|
||||||
|
|
||||||
impl HTMLScriptElement {
|
impl HTMLScriptElement {
|
||||||
pub fn Src(&self) -> DOMString {
|
pub fn Src(&self) -> DOMString {
|
||||||
match self.htmlelement.element.get_attr(Null, "src") {
|
self.htmlelement.element.get_url_attribute("src")
|
||||||
Some(s) => s.to_owned(),
|
|
||||||
None => ~""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult {
|
pub fn SetSrc(&mut self, _src: DOMString) -> ErrorResult {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue