Usage of JSRef<Attr> in before_remove_attr & after_set_attr

JSRef<Attr> does not require allocating a DOMString for value, which are
unused in most cases. It also provides more access to Attr data.
This commit is contained in:
Bruno de Oliveira Abinader 2014-10-21 14:00:48 -04:00
parent f5e8df9dac
commit bbab8831e0
18 changed files with 255 additions and 225 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::attr::Attr;
use dom::attr::AttrHelpers;
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived;
@ -67,19 +68,19 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> {
Some(htmlelement as &VirtualMethods)
}
fn after_set_attr(&self, name: &Atom, value: DOMString) {
fn after_set_attr(&self, attr: JSRef<Attr>) {
match self.super_type() {
Some(ref s) => s.after_set_attr(name, value.clone()),
_ => (),
Some(ref s) => s.after_set_attr(attr),
_ => ()
}
let element: JSRef<Element> = ElementCast::from_ref(*self);
let rel = get_attr(element, &atom!("rel"));
match (rel, name.as_slice()) {
(ref rel, "href") => {
match (rel, attr.local_name()) {
(ref rel, &atom!("href")) => {
if is_stylesheet(rel) {
self.handle_stylesheet_url(value.as_slice());
self.handle_stylesheet_url(attr.value().as_slice());
}
}
(_, _) => ()