aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/element.rs
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-06-08 17:05:38 +0200
committerMs2ger <ms2ger@gmail.com>2014-06-13 14:13:29 +0200
commitb012c99e05ce6eb2bb4b55ebb3d5c1a5a3bd48f7 (patch)
tree0e4c5ae85cf0a138ede869e1d698c704bd03c4d6 /src/components/script/dom/element.rs
parent972c69883e2014a84a010790a88f234f9397583b (diff)
downloadservo-b012c99e05ce6eb2bb4b55ebb3d5c1a5a3bd48f7.tar.gz
servo-b012c99e05ce6eb2bb4b55ebb3d5c1a5a3bd48f7.zip
Implement parsed 'unsigned long' attributes.
This commit is partially based on earlier work by Bruno Abinader in #2073.
Diffstat (limited to 'src/components/script/dom/element.rs')
-rw-r--r--src/components/script/dom/element.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index dfc7fc13e67..551ff261b3c 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -5,7 +5,7 @@
//! Element nodes.
use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrMethods};
-use dom::attr::{AttrValue, StringAttrValue};
+use dom::attr::{AttrValue, StringAttrValue, UIntAttrValue};
use dom::attrlist::AttrList;
use dom::bindings::codegen::Bindings::ElementBinding;
use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast};
@@ -243,6 +243,7 @@ pub trait AttributeHandlers {
fn get_string_attribute(&self, name: &str) -> DOMString;
fn set_string_attribute(&self, name: &str, value: DOMString);
fn set_tokenlist_attribute(&self, name: &str, value: DOMString);
+ fn get_uint_attribute(&self, name: &str) -> u32;
fn set_uint_attribute(&self, name: &str, value: u32);
}
@@ -388,9 +389,22 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
self.set_attribute(name, AttrValue::from_tokenlist(value));
}
+ fn get_uint_attribute(&self, name: &str) -> u32 {
+ assert!(name == name.to_ascii_lower().as_slice());
+ let attribute = self.get_attribute(Null, name).root();
+ match attribute {
+ Some(attribute) => {
+ match *attribute.deref().value() {
+ UIntAttrValue(_, value) => value,
+ _ => fail!("Expected a UIntAttrValue"),
+ }
+ }
+ None => 0,
+ }
+ }
fn set_uint_attribute(&self, name: &str, value: u32) {
assert!(name == name.to_ascii_lower().as_slice());
- self.set_attribute(name, StringAttrValue(value.to_str()));
+ self.set_attribute(name, UIntAttrValue(value.to_str(), value));
}
}