Skip to content

Commit

Permalink
Privatize Attr
Browse files Browse the repository at this point in the history
  • Loading branch information
ttaubert committed Oct 13, 2014
1 parent 9a52bb8 commit 78fef7e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
22 changes: 19 additions & 3 deletions components/script/dom/attr.rs
Expand Up @@ -72,13 +72,14 @@ impl Str for AttrValue {

#[jstraceable]
#[must_root]
#[privatize]
pub struct Attr {
reflector_: Reflector,
local_name: Atom,
value: RefCell<AttrValue>,
pub name: Atom,
pub namespace: Namespace,
pub prefix: Option<DOMString>,
name: Atom,
namespace: Namespace,
prefix: Option<DOMString>,

/// the element that owns this attribute.
owner: JS<Element>,
Expand Down Expand Up @@ -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<DOMString> {
&self.prefix
}
}

impl<'a> AttrMethods for JSRef<'a, Attr> {
Expand Down
12 changes: 6 additions & 6 deletions components/script/dom/element.rs
Expand Up @@ -191,7 +191,7 @@ impl RawLayoutElementHelpers for Element {
(*attrs).iter().find(|attr: & &JS<Attr>| {
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()
Expand Down Expand Up @@ -222,7 +222,7 @@ impl RawLayoutElementHelpers for Element {
(*attrs).iter().find(|attr: & &JS<Attr>| {
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()
Expand Down Expand Up @@ -360,7 +360,7 @@ pub trait AttributeHandlers {
impl<'a> AttributeHandlers for JSRef<'a, Element> {
fn get_attribute(self, namespace: Namespace, local_name: &str) -> Option<Temporary<Attr>> {
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))
}

Expand Down Expand Up @@ -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!("")
})
}

Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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(())
}
Expand Down
10 changes: 5 additions & 5 deletions components/script/dom/htmlserializer.rs
Expand Up @@ -137,20 +137,20 @@ fn serialize_elem(elem: JSRef<Element>, open_elements: &mut Vec<String>, html: &

fn serialize_attr(attr: JSRef<Attr>, 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);
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/node.rs
Expand Up @@ -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));
}
},
_ => ()
Expand Down Expand Up @@ -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())
})
Expand Down

0 comments on commit 78fef7e

Please sign in to comment.