diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 0a3bacc856f1..d54be57b8e06 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -72,13 +72,14 @@ impl Str for AttrValue { #[jstraceable] #[must_root] +#[privatize] pub struct Attr { reflector_: Reflector, local_name: Atom, value: RefCell, - pub name: Atom, - pub namespace: Namespace, - pub prefix: Option, + name: Atom, + namespace: Namespace, + prefix: Option, /// the element that owns this attribute. owner: JS, @@ -111,6 +112,21 @@ impl Attr { reflect_dom_object(box Attr::new_inherited(local_name, value, name, namespace, prefix, owner), &global::Window(window), AttrBinding::Wrap) } + + #[inline] + pub fn name<'a>(&'a self) -> &'a Atom { + &self.name + } + + #[inline] + pub fn namespace<'a>(&'a self) -> &'a Namespace { + &self.namespace + } + + #[inline] + pub fn prefix<'a>(&'a self) -> &'a Option { + &self.prefix + } } impl<'a> AttrMethods for JSRef<'a, Attr> { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 82b542292012..a00fd1e99454 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -191,7 +191,7 @@ impl RawLayoutElementHelpers for Element { (*attrs).iter().find(|attr: & &JS| { let attr = attr.unsafe_get(); name == (*attr).local_name_atom_forever().as_slice() && - (*attr).namespace == *namespace + *(*attr).namespace() == *namespace }).map(|attr| { let attr = attr.unsafe_get(); (*attr).value_ref_forever() @@ -222,7 +222,7 @@ impl RawLayoutElementHelpers for Element { (*attrs).iter().find(|attr: & &JS| { let attr = attr.unsafe_get(); name == (*attr).local_name_atom_forever().as_slice() && - (*attr).namespace == *namespace + *(*attr).namespace() == *namespace }).and_then(|attr| { let attr = attr.unsafe_get(); (*attr).value_atom_forever() @@ -360,7 +360,7 @@ pub trait AttributeHandlers { impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_attribute(self, namespace: Namespace, local_name: &str) -> Option> { self.get_attributes(local_name).iter().map(|attr| attr.root()) - .find(|attr| attr.namespace == namespace) + .find(|attr| *attr.namespace() == namespace) .map(|x| Temporary::from_rooted(*x)) } @@ -496,7 +496,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { false => Atom::from_slice(name) }; self.attrs.borrow().iter().map(|attr| attr.root()).any(|attr| { - *attr.local_name() == name && attr.namespace == ns!("") + *attr.local_name() == name && *attr.namespace() == ns!("") }) } @@ -684,7 +684,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { let name = Atom::from_slice(name.as_slice()); let value = self.parse_attribute(&ns!(""), &name, value); self.do_set_attribute(name.clone(), value, name.clone(), ns!(""), None, |attr| { - attr.name.as_slice() == name.as_slice() + attr.name().as_slice() == name.as_slice() }); Ok(()) } @@ -753,7 +753,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { namespace.clone(), prefix.map(|s| s.to_string()), |attr| { *attr.local_name() == local_name && - attr.namespace == namespace + *attr.namespace() == namespace }); Ok(()) } diff --git a/components/script/dom/htmlserializer.rs b/components/script/dom/htmlserializer.rs index 1dd648a6514d..c6f5252f3df4 100644 --- a/components/script/dom/htmlserializer.rs +++ b/components/script/dom/htmlserializer.rs @@ -137,20 +137,20 @@ fn serialize_elem(elem: JSRef, open_elements: &mut Vec, html: & fn serialize_attr(attr: JSRef, html: &mut String) { html.push_char(' '); - if attr.namespace == ns!(XML) { + if *attr.namespace() == ns!(XML) { html.push_str("xml:"); html.push_str(attr.local_name().as_slice()); - } else if attr.namespace == ns!(XMLNS) && + } else if *attr.namespace() == ns!(XMLNS) && *attr.local_name() == Atom::from_slice("xmlns") { html.push_str("xmlns"); - } else if attr.namespace == ns!(XMLNS) { + } else if *attr.namespace() == ns!(XMLNS) { html.push_str("xmlns:"); html.push_str(attr.local_name().as_slice()); - } else if attr.namespace == ns!(XLink) { + } else if *attr.namespace() == ns!(XLink) { html.push_str("xlink:"); html.push_str(attr.local_name().as_slice()); } else { - html.push_str(attr.name.as_slice()); + html.push_str(attr.name().as_slice()); }; html.push_str("=\""); escape(attr.value().as_slice(), true, html); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 98f39bf48882..3ca5515aeb9a 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1529,8 +1529,8 @@ impl Node { copy_elem.attrs.borrow_mut().push_unrooted( &Attr::new(*window, attr.local_name().clone(), attr.value().clone(), - attr.name.clone(), attr.namespace.clone(), - attr.prefix.clone(), copy_elem)); + attr.name().clone(), attr.namespace().clone(), + attr.prefix().clone(), copy_elem)); } }, _ => () @@ -1988,7 +1988,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { assert!(element.attrs.borrow().len() == other_element.attrs.borrow().len()); element.attrs.borrow().iter().map(|attr| attr.root()).all(|attr| { other_element.attrs.borrow().iter().map(|attr| attr.root()).any(|other_attr| { - (attr.namespace == other_attr.namespace) && + (*attr.namespace() == *other_attr.namespace()) && (attr.local_name() == other_attr.local_name()) && (attr.value().as_slice() == other_attr.value().as_slice()) })