Move Attr::local_name() to AttrHelpers/AttrHelpersForLayout.

This commit is contained in:
Tetsuharu OHZEKI 2014-09-10 23:54:37 +09:00
parent b73b06b9a8
commit a4ec892dbc
2 changed files with 12 additions and 6 deletions

View file

@ -110,10 +110,6 @@ impl Attr {
let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner); let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner);
reflect_dom_object(box attr, &Window(*window), AttrBinding::Wrap) reflect_dom_object(box attr, &Window(*window), AttrBinding::Wrap)
} }
pub fn local_name<'a>(&'a self) -> &'a Atom {
&self.local_name
}
} }
impl<'a> AttrMethods for JSRef<'a, Attr> { impl<'a> AttrMethods for JSRef<'a, Attr> {
@ -151,6 +147,7 @@ impl<'a> AttrMethods for JSRef<'a, Attr> {
pub trait AttrHelpers { pub trait AttrHelpers {
fn set_value(&self, set_type: AttrSettingType, value: AttrValue); fn set_value(&self, set_type: AttrSettingType, value: AttrValue);
fn value<'a>(&'a self) -> Ref<'a, AttrValue>; fn value<'a>(&'a self) -> Ref<'a, AttrValue>;
fn local_name<'a>(&'a self) -> &'a Atom;
} }
impl<'a> AttrHelpers for JSRef<'a, Attr> { impl<'a> AttrHelpers for JSRef<'a, Attr> {
@ -182,11 +179,16 @@ impl<'a> AttrHelpers for JSRef<'a, Attr> {
fn value<'a>(&'a self) -> Ref<'a, AttrValue> { fn value<'a>(&'a self) -> Ref<'a, AttrValue> {
self.value.deref().borrow() self.value.deref().borrow()
} }
fn local_name<'a>(&'a self) -> &'a Atom {
&self.local_name
}
} }
pub trait AttrHelpersForLayout { pub trait AttrHelpersForLayout {
unsafe fn value_ref_forever(&self) -> &'static str; unsafe fn value_ref_forever(&self) -> &'static str;
unsafe fn value_atom_forever(&self) -> Option<Atom>; unsafe fn value_atom_forever(&self) -> Option<Atom>;
unsafe fn local_name_atom_forever(&self) -> Atom;
} }
impl AttrHelpersForLayout for Attr { impl AttrHelpersForLayout for Attr {
@ -204,4 +206,8 @@ impl AttrHelpersForLayout for Attr {
_ => None, _ => None,
} }
} }
unsafe fn local_name_atom_forever(&self) -> Atom {
self.local_name.clone()
}
} }

View file

@ -178,7 +178,7 @@ impl RawLayoutElementHelpers for Element {
let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs); let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs);
(*attrs).iter().find(|attr: & &JS<Attr>| { (*attrs).iter().find(|attr: & &JS<Attr>| {
let attr = attr.unsafe_get(); let attr = attr.unsafe_get();
name == (*attr).local_name().as_slice() && name == (*attr).local_name_atom_forever().as_slice() &&
(*attr).namespace == *namespace (*attr).namespace == *namespace
}).map(|attr| { }).map(|attr| {
let attr = attr.unsafe_get(); let attr = attr.unsafe_get();
@ -193,7 +193,7 @@ impl RawLayoutElementHelpers for Element {
let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs); let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs);
(*attrs).iter().find(|attr: & &JS<Attr>| { (*attrs).iter().find(|attr: & &JS<Attr>| {
let attr = attr.unsafe_get(); let attr = attr.unsafe_get();
name == (*attr).local_name().as_slice() && name == (*attr).local_name_atom_forever().as_slice() &&
(*attr).namespace == *namespace (*attr).namespace == *namespace
}).and_then(|attr| { }).and_then(|attr| {
let attr = attr.unsafe_get(); let attr = attr.unsafe_get();