Currently, each HTML*Element has JS-facing getters and setters that look like this (if unimplemented):
pub fn Align(&self) -> DOMString {
~""
}
pub fn SetAlign(&mut self, _align: DOMString) -> ErrorResult {
Ok(())
}
These are required since the IDL enforces them, each attribute must have a getter/setter of this type.
In some cases example, we do need to do more than just storing/fetching attributes from the contained element, like triggering layout, however almost all of these getters / setters will have no more than the following contents:
pub fn SomeAttr(&self, _abstract_self: &JS<HTMLImageElement>) -> DOMString {
let element = &self.htmlelement.element;
match element.get_attribute(namespace::Null, "someattr") {
Some(value) => value.get().Value(),
None => ~ ""
}
}
pub fn SetSomeAttr(&mut self, abstract_self: &JS<HTMLImageElement>, newattr: DOMString) -> ErrorResult {
let element = &mut self.htmlelement.element;
element.set_attr(&ElementCast::from(abstract_self), ~"someattr", newattr.clone());
Ok(())
}
It may be worth centralizing this code in HTMLElement, so we just have to return self.get_attribute or self.set_attribute instead of duplicating the above code every time.
I can do this part myself.
Another thing we can do is tweak the codegen to use this. We could have a default state for an attribute where the codegen automatically adds the call to self.get_attribute (or whatever) and we don't have to mention it at all in the html*element.rs file, and if a method is going to be more than a bare getter/setter, we note it as such in Bindings.conf.
I don't know enough about codegen (yet) to be able to check feasibility / necessity of the above, though.
Currently, each HTML*Element has JS-facing getters and setters that look like this (if unimplemented):
These are required since the IDL enforces them, each
attributemust have a getter/setter of this type.In some cases example, we do need to do more than just storing/fetching attributes from the contained element, like triggering layout, however almost all of these getters / setters will have no more than the following contents:
It may be worth centralizing this code in HTMLElement, so we just have to return self.get_attribute or self.set_attribute instead of duplicating the above code every time.
I can do this part myself.
Another thing we can do is tweak the codegen to use this. We could have a default state for an attribute where the codegen automatically adds the call to self.get_attribute (or whatever) and we don't have to mention it at all in the html*element.rs file, and if a method is going to be more than a bare getter/setter, we note it as such in Bindings.conf.
I don't know enough about codegen (yet) to be able to check feasibility / necessity of the above, though.