aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/element.rs19
-rw-r--r--components/script/dom/htmlimageelement.rs5
-rw-r--r--components/script/dom/htmlinputelement.rs18
-rw-r--r--components/script/dom/virtualmethods.rs4
4 files changed, 24 insertions, 22 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index a81c515aef8..9c02a92d68f 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -509,7 +509,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
value: DOMString) -> AttrValue {
if *namespace == ns!("") {
vtable_for(&NodeCast::from_ref(self))
- .parse_plain_attribute(local_name.as_slice(), value)
+ .parse_plain_attribute(local_name, value)
} else {
StringAttrValue(value)
}
@@ -854,16 +854,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
// http://dom.spec.whatwg.org/#dom-element-hasattribute
fn HasAttribute(self, name: DOMString) -> bool {
- // Step 1.
- if self.html_element_in_html_document() {
- // TODO(pcwalton): Small string optimization here.
- return self.has_attribute(&Atom::from_slice(name.as_slice()
- .to_ascii_lower()
- .as_slice()))
- }
-
- // Step 2.
- self.has_attribute(&Atom::from_slice(name.as_slice()))
+ self.GetAttribute(name).is_some()
}
// http://dom.spec.whatwg.org/#dom-element-hasattributens
@@ -1037,10 +1028,10 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
self.notify_content_changed();
}
- fn parse_plain_attribute(&self, name: &str, value: DOMString) -> AttrValue {
+ fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
- "id" => AttrValue::from_atomic(value),
- "class" => AttrValue::from_tokenlist(value),
+ &atom!("id") => AttrValue::from_atomic(value),
+ &atom!("class") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index 635839805c3..3cdd4a4eaee 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -195,9 +195,10 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
}
}
- fn parse_plain_attribute(&self, name: &str, value: DOMString) -> AttrValue {
+ fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
- "width" | "height" | "hspace" | "vspace" => AttrValue::from_u32(value, 0),
+ &atom!("width") | &atom!("height") |
+ &atom!("hspace") | &atom!("vspace") => AttrValue::from_u32(value, 0),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 3690a504da4..b47e3c91098 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use dom::attr::Attr;
+use dom::attr::{Attr, AttrValue, UIntAttrValue};
use dom::attr::AttrHelpers;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
@@ -24,7 +24,7 @@ use dom::htmlformelement::{InputElement, FormOwner, HTMLFormElement, HTMLFormEle
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
-use servo_util::str::{DOMString, parse_unsigned_integer};
+use servo_util::str::DOMString;
use string_cache::Atom;
use std::ascii::OwnedStrAsciiExt;
@@ -282,9 +282,10 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
self.update_checked_state(true);
}
&atom!("size") => {
- let value = attr.value();
- let parsed = parse_unsigned_integer(value.as_slice().chars());
- self.size.set(parsed.unwrap_or(DEFAULT_INPUT_SIZE));
+ match *attr.value() {
+ UIntAttrValue(_, value) => self.size.set(value),
+ _ => fail!("Expected a UIntAttrValue"),
+ }
self.force_relayout();
}
&atom!("type") => {
@@ -363,6 +364,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
}
}
+ fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
+ match name {
+ &atom!("size") => AttrValue::from_u32(value, DEFAULT_INPUT_SIZE),
+ _ => self.super_type().unwrap().parse_plain_attribute(name, value),
+ }
+ }
+
fn bind_to_tree(&self, tree_in_doc: bool) {
match self.super_type() {
Some(ref s) => s.bind_to_tree(tree_in_doc),
diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs
index 0b23ffc37ea..03c4b27c737 100644
--- a/components/script/dom/virtualmethods.rs
+++ b/components/script/dom/virtualmethods.rs
@@ -68,6 +68,8 @@ use dom::node::{Node, NodeHelpers, ElementNodeTypeId, CloneChildrenFlag};
use servo_util::str::DOMString;
+use string_cache::Atom;
+
/// Trait to allow DOM nodes to opt-in to overriding (or adding to) common
/// behaviours. Replicates the effect of C++ virtual methods.
pub trait VirtualMethods {
@@ -95,7 +97,7 @@ pub trait VirtualMethods {
/// Returns the right AttrValue variant for the attribute with name `name`
/// on this element.
- fn parse_plain_attribute(&self, name: &str, value: DOMString) -> AttrValue {
+ fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match self.super_type() {
Some(ref s) => s.parse_plain_attribute(name, value),
_ => StringAttrValue(value),