Make Attr handles all setting value.

This commit is contained in:
Tetsuharu OHZEKI 2014-04-18 23:53:00 +09:00
parent b2fa6fa221
commit cdbe179acb
2 changed files with 24 additions and 15 deletions

View file

@ -4,7 +4,7 @@
//! Element nodes.
use dom::attr::Attr;
use dom::attr::{Attr, AttrSettingType, ReplacedAttr, FirstSetAttr};
use dom::attrlist::AttrList;
use dom::bindings::codegen::ElementBinding;
use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast};
@ -263,23 +263,22 @@ impl AttributeHandlers for JS<Element> {
prefix: Option<DOMString>, cb: |&JS<Attr>| -> bool) {
let node: JS<Node> = NodeCast::from(self);
let idx = self.get().attrs.iter().position(cb);
match idx {
let (mut attr, set_type): (JS<Attr>, AttrSettingType) = match idx {
Some(idx) => {
self.get_mut().attrs[idx].get_mut().set_value(value.clone());
let attr = self.get_mut().attrs[idx].clone();
(attr, ReplacedAttr)
}
None => {
let doc = node.get().owner_doc().get();
let new_attr = Attr::new(&doc.window, local_name.clone(), value.clone(),
let attr = Attr::new(&doc.window, local_name.clone(), value.clone(),
name, namespace.clone(), prefix, self.clone());
self.get_mut().attrs.push(new_attr);
// FIXME: This part should be handled in `Attr`.
if namespace == namespace::Null {
vtable_for(&node).after_set_attr(local_name, value);
}
self.get_mut().attrs.push(attr.clone());
(attr, FirstSetAttr)
}
}
};
attr.get_mut().set_value(set_type, value);
}
// http://dom.spec.whatwg.org/#dom-element-setattribute