Skip to content
Permalink
Browse files

Added AttrValue::from_atomic_tokens & Element::set_atomic_tokenlist_a…

…ttribute
  • Loading branch information
brunoabinader committed Dec 26, 2014
1 parent c5f7e55 commit 8859286a99f31ca25e516eb23db79a5fedbef980
Showing with 14 additions and 0 deletions.
  1. +8 −0 components/script/dom/attr.rs
  2. +6 −0 components/script/dom/element.rs
@@ -47,6 +47,14 @@ impl AttrValue {
AttrValue::TokenList(tokens, atoms)
}

pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
let tokens = {
let slices: Vec<&str> = atoms.iter().map(|atom| atom.as_slice()).collect();
slices.connect("\x20")
};
AttrValue::TokenList(tokens, atoms)
}

pub fn from_u32(string: DOMString, default: u32) -> AttrValue {
let result: u32 = from_str(string.as_slice()).unwrap_or(default);
AttrValue::UInt(string, result)
@@ -656,6 +656,7 @@ pub trait AttributeHandlers {
fn get_string_attribute(self, name: &Atom) -> DOMString;
fn set_string_attribute(self, name: &Atom, value: DOMString);
fn set_tokenlist_attribute(self, name: &Atom, value: DOMString);
fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>);
fn get_uint_attribute(self, name: &Atom) -> u32;
fn set_uint_attribute(self, name: &Atom, value: u32);
}
@@ -851,6 +852,11 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
self.set_attribute(name, AttrValue::from_serialized_tokenlist(value));
}

fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) {
assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice());
self.set_attribute(name, AttrValue::from_atomic_tokens(tokens));
}

fn get_uint_attribute(self, name: &Atom) -> u32 {
assert!(name.as_slice().chars().all(|ch| {
!ch.is_ascii() || ch.to_ascii().to_lowercase() == ch.to_ascii()

0 comments on commit 8859286

Please sign in to comment.
You can’t perform that action at this time.