mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
Make Attr handles all setting value.
This commit is contained in:
parent
b2fa6fa221
commit
cdbe179acb
2 changed files with 24 additions and 15 deletions
|
@ -14,6 +14,11 @@ use servo_util::namespace;
|
||||||
use servo_util::namespace::Namespace;
|
use servo_util::namespace::Namespace;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
|
pub enum AttrSettingType {
|
||||||
|
FirstSetAttr,
|
||||||
|
ReplacedAttr,
|
||||||
|
}
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub struct Attr {
|
pub struct Attr {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -59,12 +64,17 @@ impl Attr {
|
||||||
reflect_dom_object(~attr, window, AttrBinding::Wrap)
|
reflect_dom_object(~attr, window, AttrBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_value(&mut self, value: DOMString) {
|
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
|
||||||
let node: JS<Node> = NodeCast::from(&self.owner);
|
let node: JS<Node> = NodeCast::from(&self.owner);
|
||||||
let namespace_is_null = self.namespace == namespace::Null;
|
let namespace_is_null = self.namespace == namespace::Null;
|
||||||
|
|
||||||
if namespace_is_null {
|
match set_type {
|
||||||
vtable_for(&node).before_remove_attr(self.local_name.clone(), self.value.clone());
|
ReplacedAttr => {
|
||||||
|
if namespace_is_null {
|
||||||
|
vtable_for(&node).before_remove_attr(self.local_name.clone(), self.value.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FirstSetAttr => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.value = value;
|
self.value = value;
|
||||||
|
@ -89,7 +99,7 @@ impl Attr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn SetValue(&mut self, value: DOMString) {
|
pub fn SetValue(&mut self, value: DOMString) {
|
||||||
self.set_value(value);
|
self.set_value(ReplacedAttr, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Name(&self) -> DOMString {
|
pub fn Name(&self) -> DOMString {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
//! Element nodes.
|
//! Element nodes.
|
||||||
|
|
||||||
use dom::attr::Attr;
|
use dom::attr::{Attr, AttrSettingType, ReplacedAttr, FirstSetAttr};
|
||||||
use dom::attrlist::AttrList;
|
use dom::attrlist::AttrList;
|
||||||
use dom::bindings::codegen::ElementBinding;
|
use dom::bindings::codegen::ElementBinding;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast};
|
use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast};
|
||||||
|
@ -263,23 +263,22 @@ impl AttributeHandlers for JS<Element> {
|
||||||
prefix: Option<DOMString>, cb: |&JS<Attr>| -> bool) {
|
prefix: Option<DOMString>, cb: |&JS<Attr>| -> bool) {
|
||||||
let node: JS<Node> = NodeCast::from(self);
|
let node: JS<Node> = NodeCast::from(self);
|
||||||
let idx = self.get().attrs.iter().position(cb);
|
let idx = self.get().attrs.iter().position(cb);
|
||||||
match idx {
|
let (mut attr, set_type): (JS<Attr>, AttrSettingType) = match idx {
|
||||||
Some(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 => {
|
None => {
|
||||||
let doc = node.get().owner_doc().get();
|
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());
|
name, namespace.clone(), prefix, self.clone());
|
||||||
self.get_mut().attrs.push(new_attr);
|
self.get_mut().attrs.push(attr.clone());
|
||||||
|
(attr, FirstSetAttr)
|
||||||
// FIXME: This part should be handled in `Attr`.
|
|
||||||
if namespace == namespace::Null {
|
|
||||||
vtable_for(&node).after_set_attr(local_name, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
attr.get_mut().set_value(set_type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-element-setattribute
|
// http://dom.spec.whatwg.org/#dom-element-setattribute
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue