diff options
author | Tetsuharu OHZEKI <saneyuki.snyk@gmail.com> | 2014-07-26 04:33:54 +0900 |
---|---|---|
committer | Tetsuharu OHZEKI <saneyuki.snyk@gmail.com> | 2014-07-30 06:22:09 +0900 |
commit | 794ce9cd4d6058a8aa30120742f292fbc7d95e2a (patch) | |
tree | b05fa05c7b72ae2e73560dea11d58cffaa38e88c /src/components/script/dom/element.rs | |
parent | f2db7faf19c34165c08f1d5839a7461bc04c20a5 (diff) | |
download | servo-794ce9cd4d6058a8aa30120742f292fbc7d95e2a.tar.gz servo-794ce9cd4d6058a8aa30120742f292fbc7d95e2a.zip |
Use atom to match id selector.
Diffstat (limited to 'src/components/script/dom/element.rs')
-rw-r--r-- | src/components/script/dom/element.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 6fc0ba1b4c0..afc176b8a26 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -6,7 +6,7 @@ use cssparser::tokenize; use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrHelpersForLayout}; -use dom::attr::{AttrValue, StringAttrValue, UIntAttrValue}; +use dom::attr::{AttrValue, StringAttrValue, UIntAttrValue, AtomAttrValue}; use dom::attrlist::AttrList; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::ElementBinding; @@ -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>; } impl RawLayoutElementHelpers for Element { @@ -184,6 +185,20 @@ impl RawLayoutElementHelpers for Element { (*attr).value_ref_forever() }) } + + #[inline] + unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str) + -> Option<Atom> { + // cast to point to T in RefCell<T> directly + let attrs: *Vec<JS<Attr>> = mem::transmute(&self.attrs); + (*attrs).iter().find(|attr: & &JS<Attr>| { + let attr = attr.unsafe_get(); + name == (*attr).local_name.as_slice() && (*attr).namespace == *namespace + }).and_then(|attr| { + let attr = attr.unsafe_get(); + (*attr).value_atom_forever() + }) + } } pub trait LayoutElementHelpers { @@ -901,4 +916,13 @@ impl<'a> style::TElement for JSRef<'a, Element> { let node: &JSRef<Node> = NodeCast::from_ref(self); node.get_hover_state() } + fn get_id<'a>(&self) -> Option<Atom> { + self.get_attribute(namespace::Null, "id").map(|attr| { + let attr = attr.root(); + match *attr.value() { + AtomAttrValue(ref val) => val.clone(), + _ => fail!("`id` attribute should be AtomAttrValue"), + } + }) + } } |