aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/attr.rs10
-rw-r--r--components/script/dom/document.rs1
-rw-r--r--components/script/dom/element.rs33
3 files changed, 35 insertions, 9 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 02945088bbb..4da59b96b55 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -188,6 +188,7 @@ impl<'a> AttrHelpers for JSRef<'a, Attr> {
pub trait AttrHelpersForLayout {
unsafe fn value_ref_forever(&self) -> &'static str;
unsafe fn value_atom_forever(&self) -> Option<Atom>;
+ unsafe fn value_tokens_forever(&self) -> Option<Items<Atom>>;
unsafe fn local_name_atom_forever(&self) -> Atom;
}
@@ -207,6 +208,15 @@ impl AttrHelpersForLayout for Attr {
}
}
+ unsafe fn value_tokens_forever(&self) -> Option<Items<Atom>> {
+ // cast to point to T in RefCell<T> directly
+ let value = mem::transmute::<&RefCell<AttrValue>, &AttrValue>(self.value.deref());
+ match *value {
+ TokenListAttrValue(_, ref tokens) => Some(tokens.iter()),
+ _ => None,
+ }
+ }
+
unsafe fn local_name_atom_forever(&self) -> Atom {
self.local_name.clone()
}
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index f8f83183dc2..8f8f8e5c607 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -569,7 +569,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let window = self.window.root();
match interface.as_slice().to_ascii_lower().as_slice() {
- // FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent)
"uievents" | "uievent" => Ok(EventCast::from_temporary(UIEvent::new_uninitialized(&*window))),
"mouseevents" | "mouseevent" => Ok(EventCast::from_temporary(MouseEvent::new_uninitialized(&*window))),
"customevent" => Ok(EventCast::from_temporary(CustomEvent::new_uninitialized(&Window(*window)))),
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index a4df58eb06e..2150e67f0eb 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -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 {
@@ -239,7 +252,10 @@ impl<'a> ElementHelpers for JSRef<'a, Element> {
}
pub trait AttributeHandlers {
- fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>>;
+ /// Returns the attribute with given namespace and case-sensitive local
+ /// name, if any.
+ fn get_attribute(&self, namespace: Namespace, local_name: &str)
+ -> Option<Temporary<Attr>>;
fn set_attribute_from_parser(&self, local_name: Atom,
value: DOMString, namespace: Namespace,
prefix: Option<DOMString>);
@@ -269,13 +285,9 @@ pub trait AttributeHandlers {
}
impl<'a> AttributeHandlers for JSRef<'a, Element> {
- fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>> {
- let element: &Element = self.deref();
- let local_name = match self.html_element_in_html_document() {
- true => Atom::from_slice(name.to_ascii_lower().as_slice()),
- false => Atom::from_slice(name)
- };
- element.attrs.borrow().iter().map(|attr| attr.root()).find(|attr| {
+ fn get_attribute(&self, namespace: Namespace, local_name: &str) -> Option<Temporary<Attr>> {
+ let local_name = Atom::from_slice(local_name);
+ self.attrs.borrow().iter().map(|attr| attr.root()).find(|attr| {
*attr.local_name() == local_name && attr.namespace == namespace
}).map(|x| Temporary::from_rooted(&*x))
}
@@ -410,6 +422,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
fn get_url_attribute(&self, name: &str) -> DOMString {
+ assert!(name == name.to_ascii_lower().as_slice());
// XXX Resolve URL.
self.get_string_attribute(name)
}
@@ -418,6 +431,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}
fn get_string_attribute(&self, name: &str) -> DOMString {
+ assert!(name == name.to_ascii_lower().as_slice());
match self.get_attribute(Null, name) {
Some(x) => {
let x = x.root();
@@ -955,4 +969,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)
+ }
}