Make use of the list of Atoms in ClassSelector

Make use of the list of Atoms in the class attribute selector
(ClassSelector) in selector_matching.

Fixes #3111
This commit is contained in:
Gilles Leblanc 2014-09-11 23:19:26 -04:00
parent a18633b163
commit 81a0d065f1
8 changed files with 71 additions and 5 deletions

View file

@ -168,6 +168,7 @@ impl Element {
pub trait RawLayoutElementHelpers {
unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) -> Option<&'static str>;
unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str) -> Option<Atom>;
unsafe fn has_class_for_layout(&self, name: &str) -> bool;
}
impl RawLayoutElementHelpers for Element {
@ -200,6 +201,18 @@ impl RawLayoutElementHelpers for Element {
(*attr).value_atom_forever()
})
}
#[inline]
unsafe fn has_class_for_layout(&self, name: &str) -> bool {
let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs);
(*attrs).iter().find(|attr: & &JS<Attr>| {
let attr = attr.unsafe_get();
(*attr).local_name_atom_forever().as_slice() == "class"
}).map_or(false, |attr| {
let attr = attr.unsafe_get();
(*attr).value_tokens_forever().map(|mut tokens| { tokens.any(|atom| atom.as_slice() == name) })
}.take().unwrap())
}
}
pub trait LayoutElementHelpers {
@ -955,4 +968,7 @@ impl<'a> style::TElement for JSRef<'a, Element> {
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.get_enabled_state()
}
fn has_class(&self, name: &str) -> bool {
(self as &AttributeHandlers).has_class(name)
}
}