mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +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),
|
StringAttrValue(DOMString),
|
||||||
TokenListAttrValue(DOMString, Vec<(uint, uint)>),
|
TokenListAttrValue(DOMString, Vec<(uint, uint)>),
|
||||||
UIntAttrValue(DOMString, u32),
|
UIntAttrValue(DOMString, u32),
|
||||||
|
AtomAttrValue(Atom),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AttrValue {
|
impl AttrValue {
|
||||||
|
@ -50,11 +51,17 @@ impl AttrValue {
|
||||||
UIntAttrValue(string, result)
|
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 {
|
pub fn as_slice<'a>(&'a self) -> &'a str {
|
||||||
match *self {
|
match *self {
|
||||||
StringAttrValue(ref value) |
|
StringAttrValue(ref value) |
|
||||||
TokenListAttrValue(ref value, _) |
|
TokenListAttrValue(ref value, _) |
|
||||||
UIntAttrValue(ref value, _) => value.as_slice(),
|
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 notify_attribute_changed(&self, local_name: DOMString);
|
||||||
fn has_class(&self, name: &str) -> bool;
|
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
|
// http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes
|
||||||
fn get_url_attribute(&self, name: &str) -> DOMString;
|
fn get_url_attribute(&self, name: &str) -> DOMString;
|
||||||
fn set_url_attribute(&self, name: &str, value: 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)
|
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 {
|
fn get_url_attribute(&self, name: &str) -> DOMString {
|
||||||
// XXX Resolve URL.
|
// XXX Resolve URL.
|
||||||
self.get_string_attribute(name)
|
self.get_string_attribute(name)
|
||||||
|
@ -459,7 +467,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-element-id
|
// http://dom.spec.whatwg.org/#dom-element-id
|
||||||
fn SetId(&self, id: DOMString) {
|
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
|
// 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 {
|
fn parse_plain_attribute(&self, name: &str, value: DOMString) -> AttrValue {
|
||||||
match name {
|
match name {
|
||||||
|
"id" => AttrValue::from_atomic(value),
|
||||||
"class" => AttrValue::from_tokenlist(value),
|
"class" => AttrValue::from_tokenlist(value),
|
||||||
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
|
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue