Use getter macros in HTMLImageElement

This commit is contained in:
Manish Goregaokar 2014-08-19 23:14:12 +05:30
parent 32fb907384
commit 738ee342b3
2 changed files with 8 additions and 65 deletions

View file

@ -435,7 +435,6 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
} }
fn get_uint_attribute(&self, name: &str) -> u32 { fn get_uint_attribute(&self, name: &str) -> u32 {
assert!(name == name.to_ascii_lower().as_slice());
let attribute = self.get_attribute(Null, name).root(); let attribute = self.get_attribute(Null, name).root();
match attribute { match attribute {
Some(attribute) => { Some(attribute) => {

View file

@ -96,123 +96,67 @@ impl LayoutHTMLImageElementHelpers for JS<HTMLImageElement> {
} }
impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> {
fn Alt(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(self); make_getters!(Alt, Src, UseMap, Name, Align, LongDesc, Border)
element.get_string_attribute("alt") make_bool_getters!(IsMap)
} make_uint_getters!(Width, Height, Hspace, Vspace)
fn SetAlt(&self, alt: DOMString) { fn SetAlt(&self, alt: DOMString) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute("alt", alt) element.set_string_attribute("alt", alt)
} }
fn Src(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("src")
}
fn SetSrc(&self, src: DOMString) { fn SetSrc(&self, src: DOMString) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_url_attribute("src", src) element.set_url_attribute("src", src)
} }
fn UseMap(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("useMap")
}
fn SetUseMap(&self, use_map: DOMString) { fn SetUseMap(&self, use_map: DOMString) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute("useMap", use_map) element.set_string_attribute("useMap", use_map)
} }
fn IsMap(&self) -> bool {
let element: &JSRef<Element> = ElementCast::from_ref(self);
from_str::<bool>(element.get_string_attribute("hspace").as_slice()).unwrap()
}
fn SetIsMap(&self, is_map: bool) { fn SetIsMap(&self, is_map: bool) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute("isMap", is_map.to_string()) element.set_string_attribute("isMap", is_map.to_string())
} }
fn Width(&self) -> u32 {
let node: &JSRef<Node> = NodeCast::from_ref(self);
let rect = node.get_bounding_content_box();
to_px(rect.size.width) as u32
}
fn SetWidth(&self, width: u32) { fn SetWidth(&self, width: u32) {
let elem: &JSRef<Element> = ElementCast::from_ref(self); let elem: &JSRef<Element> = ElementCast::from_ref(self);
elem.set_uint_attribute("width", width) elem.set_uint_attribute("width", width)
} }
fn Height(&self) -> u32 {
let node: &JSRef<Node> = NodeCast::from_ref(self);
let rect = node.get_bounding_content_box();
to_px(rect.size.height) as u32
}
fn SetHeight(&self, height: u32) { fn SetHeight(&self, height: u32) {
let elem: &JSRef<Element> = ElementCast::from_ref(self); let elem: &JSRef<Element> = ElementCast::from_ref(self);
elem.set_uint_attribute("height", height) elem.set_uint_attribute("height", height)
} }
fn Name(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("name")
}
fn SetName(&self, name: DOMString) { fn SetName(&self, name: DOMString) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute("name", name) element.set_string_attribute("name", name)
} }
fn Align(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("align")
}
fn SetAlign(&self, align: DOMString) { fn SetAlign(&self, align: DOMString) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute("align", align) element.set_string_attribute("align", align)
} }
fn Hspace(&self) -> u32 {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_uint_attribute("hspace")
}
fn SetHspace(&self, hspace: u32) { fn SetHspace(&self, hspace: u32) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_uint_attribute("hspace", hspace) element.set_uint_attribute("hspace", hspace)
} }
fn Vspace(&self) -> u32 {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_uint_attribute("vspace")
}
fn SetVspace(&self, vspace: u32) { fn SetVspace(&self, vspace: u32) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_uint_attribute("vspace", vspace) element.set_uint_attribute("vspace", vspace)
} }
fn LongDesc(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("longdesc")
}
fn SetLongDesc(&self, longdesc: DOMString) { fn SetLongDesc(&self, longdesc: DOMString) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute("longdesc", longdesc) element.set_string_attribute("longdesc", longdesc)
} }
fn Border(&self) -> DOMString {
let element: &JSRef<Element> = ElementCast::from_ref(self);
element.get_string_attribute("border")
}
fn SetBorder(&self, border: DOMString) { fn SetBorder(&self, border: DOMString) {
let element: &JSRef<Element> = ElementCast::from_ref(self); let element: &JSRef<Element> = ElementCast::from_ref(self);
element.set_string_attribute("border", border) element.set_string_attribute("border", border)
@ -225,9 +169,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
Some(htmlelement as &VirtualMethods) Some(htmlelement as &VirtualMethods)
} }
fn after_set_attr(&self, name: &Atom, value: DOMString) { fn after_set_attr(&self, name: DOMString, value: DOMString) {
match self.super_type() { match self.super_type() {
Some(ref s) => s.after_set_attr(name, value.clone()), Some(ref s) => s.after_set_attr(name.clone(), value.clone()),
_ => (), _ => (),
} }
@ -238,9 +182,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
} }
} }
fn before_remove_attr(&self, name: &Atom, value: DOMString) { fn before_remove_attr(&self, name: DOMString, value: DOMString) {
match self.super_type() { match self.super_type() {
Some(ref s) => s.before_remove_attr(name, value.clone()), Some(ref s) => s.before_remove_attr(name.clone(), value.clone()),
_ => (), _ => (),
} }