mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Split out a do_set_attribute method.
This commit is contained in:
parent
6b1799caa3
commit
3347c3ef80
1 changed files with 17 additions and 9 deletions
|
@ -195,6 +195,10 @@ pub trait AttributeHandlers {
|
||||||
fn set_attr(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
|
fn set_attr(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
|
||||||
fn set_attribute(&mut self, namespace: Namespace, name: DOMString,
|
fn set_attribute(&mut self, namespace: Namespace, name: DOMString,
|
||||||
value: DOMString) -> ErrorResult;
|
value: DOMString) -> ErrorResult;
|
||||||
|
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
||||||
|
name: DOMString, namespace: Namespace,
|
||||||
|
prefix: Option<DOMString>, cb: |&JS<Attr>| -> bool);
|
||||||
|
|
||||||
fn after_set_attr(&mut self, local_name: DOMString, value: DOMString);
|
fn after_set_attr(&mut self, local_name: DOMString, value: DOMString);
|
||||||
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult;
|
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult;
|
||||||
fn before_remove_attr(&mut self, local_name: DOMString, old_value: DOMString);
|
fn before_remove_attr(&mut self, local_name: DOMString, old_value: DOMString);
|
||||||
|
@ -253,15 +257,20 @@ impl AttributeHandlers for JS<Element> {
|
||||||
let node: JS<Node> = NodeCast::from(self);
|
let node: JS<Node> = NodeCast::from(self);
|
||||||
node.get().wait_until_safe_to_modify_dom();
|
node.get().wait_until_safe_to_modify_dom();
|
||||||
|
|
||||||
// FIXME: reduce the time of `value.clone()`.
|
let position: |&JS<Attr>| -> bool =
|
||||||
let idx = self.get().attrs.iter().position(|attr| {
|
|
||||||
if self.get().html_element_in_html_document() {
|
if self.get().html_element_in_html_document() {
|
||||||
attr.get().local_name.eq_ignore_ascii_case(local_name)
|
|attr| attr.get().local_name.eq_ignore_ascii_case(local_name)
|
||||||
} else {
|
} else {
|
||||||
attr.get().local_name == local_name
|
|attr| attr.get().local_name == local_name
|
||||||
}
|
};
|
||||||
});
|
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, position);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
||||||
|
name: DOMString, namespace: Namespace,
|
||||||
|
prefix: Option<DOMString>, cb: |&JS<Attr>| -> bool) {
|
||||||
|
let idx = self.get().attrs.iter().position(cb);
|
||||||
match idx {
|
match idx {
|
||||||
Some(idx) => {
|
Some(idx) => {
|
||||||
if namespace == namespace::Null {
|
if namespace == namespace::Null {
|
||||||
|
@ -270,12 +279,12 @@ impl AttributeHandlers for JS<Element> {
|
||||||
}
|
}
|
||||||
self.get_mut().attrs[idx].get_mut().set_value(value.clone());
|
self.get_mut().attrs[idx].get_mut().set_value(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
let node: JS<Node> = NodeCast::from(self);
|
let node: JS<Node> = NodeCast::from(self);
|
||||||
let doc = node.get().owner_doc().get();
|
let doc = node.get().owner_doc().get();
|
||||||
let new_attr = Attr::new_ns(&doc.window, local_name.clone(), value.clone(),
|
let new_attr = Attr::new_ns(&doc.window, local_name.clone(), value.clone(),
|
||||||
name.clone(), namespace.clone(),
|
name, namespace.clone(), prefix);
|
||||||
prefix);
|
|
||||||
self.get_mut().attrs.push(new_attr);
|
self.get_mut().attrs.push(new_attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +292,6 @@ impl AttributeHandlers for JS<Element> {
|
||||||
if namespace == namespace::Null {
|
if namespace == namespace::Null {
|
||||||
self.after_set_attr(local_name, value);
|
self.after_set_attr(local_name, value);
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn after_set_attr(&mut self, local_name: DOMString, value: DOMString) {
|
fn after_set_attr(&mut self, local_name: DOMString, value: DOMString) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue