mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Added AttrValue::from_atomic_tokens & Element::set_atomic_tokenlist_attribute
This commit is contained in:
parent
c5f7e553e4
commit
8859286a99
2 changed files with 14 additions and 0 deletions
|
@ -47,6 +47,14 @@ impl AttrValue {
|
||||||
AttrValue::TokenList(tokens, atoms)
|
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 {
|
pub fn from_u32(string: DOMString, default: u32) -> AttrValue {
|
||||||
let result: u32 = from_str(string.as_slice()).unwrap_or(default);
|
let result: u32 = from_str(string.as_slice()).unwrap_or(default);
|
||||||
AttrValue::UInt(string, result)
|
AttrValue::UInt(string, result)
|
||||||
|
|
|
@ -656,6 +656,7 @@ pub trait AttributeHandlers {
|
||||||
fn get_string_attribute(self, name: &Atom) -> DOMString;
|
fn get_string_attribute(self, name: &Atom) -> DOMString;
|
||||||
fn set_string_attribute(self, name: &Atom, value: DOMString);
|
fn set_string_attribute(self, name: &Atom, value: DOMString);
|
||||||
fn set_tokenlist_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 get_uint_attribute(self, name: &Atom) -> u32;
|
||||||
fn set_uint_attribute(self, name: &Atom, value: 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));
|
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 {
|
fn get_uint_attribute(self, name: &Atom) -> u32 {
|
||||||
assert!(name.as_slice().chars().all(|ch| {
|
assert!(name.as_slice().chars().all(|ch| {
|
||||||
!ch.is_ascii() || ch.to_ascii().to_lowercase() == ch.to_ascii()
|
!ch.is_ascii() || ch.to_ascii().to_lowercase() == ch.to_ascii()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue