aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Taubert <tim@timtaubert.de>2014-10-11 23:25:42 +0200
committerTim Taubert <tim@timtaubert.de>2014-10-13 13:18:57 +0200
commit78fef7eec5b6f29396f6ffdcb08826173a3742f8 (patch)
tree4fd7b005fb3e207e6dd366af01d97134c75901ea
parent9a52bb8310eb9d479a5211b0048bb682da0ac123 (diff)
downloadservo-78fef7eec5b6f29396f6ffdcb08826173a3742f8.tar.gz
servo-78fef7eec5b6f29396f6ffdcb08826173a3742f8.zip
Privatize Attr
-rw-r--r--components/script/dom/attr.rs22
-rw-r--r--components/script/dom/element.rs12
-rw-r--r--components/script/dom/htmlserializer.rs10
-rw-r--r--components/script/dom/node.rs6
4 files changed, 33 insertions, 17 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 0a3bacc856f..d54be57b8e0 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<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>,
@@ -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> {
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 82b54229201..a00fd1e9945 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<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()
@@ -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()
@@ -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))
}
@@ -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 1dd648a6514..c6f5252f3df 100644
--- a/components/script/dom/htmlserializer.rs
+++ b/components/script/dom/htmlserializer.rs
@@ -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);
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 98f39bf4888..3ca5515aeb9 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())
})