mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Privatize Attr
This commit is contained in:
parent
9a52bb8310
commit
78fef7eec5
4 changed files with 33 additions and 17 deletions
|
@ -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> {
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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())
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue