diff options
author | bors-servo <metajack+bors@gmail.com> | 2014-12-26 13:18:45 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2014-12-26 13:18:45 -0700 |
commit | 3af73e9962fe810de0c556693ec2eb0559b06a67 (patch) | |
tree | 3a6220ae9a6c05c5b43bdf5fc6f822e597e39d7a /components/script/dom/element.rs | |
parent | 0e6304dcf7fd6712f4455151b55a361de857359d (diff) | |
parent | 3624673d2faf7a36face3321af70fc55117a24a7 (diff) | |
download | servo-3af73e9962fe810de0c556693ec2eb0559b06a67.tar.gz servo-3af73e9962fe810de0c556693ec2eb0559b06a67.zip |
auto merge of #4353 : brunoabinader/servo/domtokenlist, r=Ms2ger
Specs:
https://dom.spec.whatwg.org/#dom-domtokenlist-add
https://dom.spec.whatwg.org/#dom-domtokenlist-remove
https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
https://dom.spec.whatwg.org/#concept-dtl-update
https://dom.spec.whatwg.org/#concept-ordered-set-serializer
Closes #3138.
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r-- | components/script/dom/element.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 52a16fc6ea4..60c12399160 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -655,7 +655,9 @@ pub trait AttributeHandlers { fn set_url_attribute(self, name: &Atom, value: DOMString); fn get_string_attribute(self, name: &Atom) -> DOMString; fn set_string_attribute(self, name: &Atom, value: DOMString); + fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom>; 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); } @@ -846,9 +848,23 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { self.set_attribute(name, AttrValue::String(value)); } + fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom> { + self.get_attribute(ns!(""), name).root().map(|attr| { + attr.value() + .tokens() + .expect("Expected a TokenListAttrValue") + .to_vec() + }).unwrap_or(vec!()) + } + fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) { assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); - self.set_attribute(name, AttrValue::from_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 { @@ -1290,7 +1306,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { match name { &atom!("id") => AttrValue::from_atomic(value), - &atom!("class") => AttrValue::from_tokenlist(value), + &atom!("class") => AttrValue::from_serialized_tokenlist(value), _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } |