Skip to content

Commit

Permalink
Added AttrValue::from_atomic_tokens & Element::set_atomic_tokenlist_a…
Browse files Browse the repository at this point in the history
…ttribute
  • Loading branch information
brunoabinader committed Dec 26, 2014
1 parent c5f7e55 commit 8859286
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions components/script/dom/attr.rs
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/element.rs
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8859286

Please sign in to comment.