mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Port id
attribute to use atom.
This commit is contained in:
parent
63b0e1568f
commit
f2db7faf19
2 changed files with 17 additions and 1 deletions
|
@ -30,6 +30,7 @@ pub enum AttrValue {
|
|||
StringAttrValue(DOMString),
|
||||
TokenListAttrValue(DOMString, Vec<(uint, uint)>),
|
||||
UIntAttrValue(DOMString, u32),
|
||||
AtomAttrValue(Atom),
|
||||
}
|
||||
|
||||
impl AttrValue {
|
||||
|
@ -50,11 +51,17 @@ impl AttrValue {
|
|||
UIntAttrValue(string, result)
|
||||
}
|
||||
|
||||
pub fn from_atomic(string: DOMString) -> AttrValue {
|
||||
let value = Atom::from_slice(string.as_slice());
|
||||
AtomAttrValue(value)
|
||||
}
|
||||
|
||||
pub fn as_slice<'a>(&'a self) -> &'a str {
|
||||
match *self {
|
||||
StringAttrValue(ref value) |
|
||||
TokenListAttrValue(ref value, _) |
|
||||
UIntAttrValue(ref value, _) => value.as_slice(),
|
||||
AtomAttrValue(ref value) => value.as_slice(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,6 +239,8 @@ pub trait AttributeHandlers {
|
|||
fn notify_attribute_changed(&self, local_name: DOMString);
|
||||
fn has_class(&self, name: &str) -> bool;
|
||||
|
||||
fn set_atomic_attribute(&self, name: &str, value: DOMString);
|
||||
|
||||
// http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes
|
||||
fn get_url_attribute(&self, name: &str) -> DOMString;
|
||||
fn set_url_attribute(&self, name: &str, value: DOMString);
|
||||
|
@ -362,6 +364,12 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
classes.any(|class| name == class)
|
||||
}
|
||||
|
||||
fn set_atomic_attribute(&self, name: &str, value: DOMString) {
|
||||
assert!(name == name.to_ascii_lower().as_slice());
|
||||
let value = AttrValue::from_atomic(value);
|
||||
self.set_attribute(name, value);
|
||||
}
|
||||
|
||||
fn get_url_attribute(&self, name: &str) -> DOMString {
|
||||
// XXX Resolve URL.
|
||||
self.get_string_attribute(name)
|
||||
|
@ -459,7 +467,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-element-id
|
||||
fn SetId(&self, id: DOMString) {
|
||||
self.set_string_attribute("id", id);
|
||||
self.set_atomic_attribute("id", id);
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-element-classname
|
||||
|
@ -824,6 +832,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
|
||||
fn parse_plain_attribute(&self, name: &str, value: DOMString) -> AttrValue {
|
||||
match name {
|
||||
"id" => AttrValue::from_atomic(value),
|
||||
"class" => AttrValue::from_tokenlist(value),
|
||||
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue