auto merge of #3897 : Ms2ger/servo/enable-reflection, r=Manishearth

This commit is contained in:
bors-servo 2014-11-05 11:12:40 -07:00
commit fba6cb9c42
5 changed files with 26915 additions and 13 deletions

View file

@ -509,7 +509,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
value: DOMString) -> AttrValue { value: DOMString) -> AttrValue {
if *namespace == ns!("") { if *namespace == ns!("") {
vtable_for(&NodeCast::from_ref(self)) vtable_for(&NodeCast::from_ref(self))
.parse_plain_attribute(local_name.as_slice(), value) .parse_plain_attribute(local_name, value)
} else { } else {
StringAttrValue(value) StringAttrValue(value)
} }
@ -1028,10 +1028,10 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
self.notify_content_changed(); 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 { match name {
"id" => AttrValue::from_atomic(value), &atom!("id") => AttrValue::from_atomic(value),
"class" => AttrValue::from_tokenlist(value), &atom!("class") => AttrValue::from_tokenlist(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value), _ => self.super_type().unwrap().parse_plain_attribute(name, value),
} }
} }

View file

@ -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 { 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), _ => self.super_type().unwrap().parse_plain_attribute(name, value),
} }
} }

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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::attr::AttrHelpers;
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; 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::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use servo_util::str::{DOMString, parse_unsigned_integer}; use servo_util::str::DOMString;
use string_cache::Atom; use string_cache::Atom;
use std::ascii::OwnedStrAsciiExt; use std::ascii::OwnedStrAsciiExt;
@ -282,9 +282,10 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
self.update_checked_state(true); self.update_checked_state(true);
} }
&atom!("size") => { &atom!("size") => {
let value = attr.value(); match *attr.value() {
let parsed = parse_unsigned_integer(value.as_slice().chars()); UIntAttrValue(_, value) => self.size.set(value),
self.size.set(parsed.unwrap_or(DEFAULT_INPUT_SIZE)); _ => fail!("Expected a UIntAttrValue"),
}
self.force_relayout(); self.force_relayout();
} }
&atom!("type") => { &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) { fn bind_to_tree(&self, tree_in_doc: bool) {
match self.super_type() { match self.super_type() {
Some(ref s) => s.bind_to_tree(tree_in_doc), Some(ref s) => s.bind_to_tree(tree_in_doc),

View file

@ -68,6 +68,8 @@ use dom::node::{Node, NodeHelpers, ElementNodeTypeId, CloneChildrenFlag};
use servo_util::str::DOMString; use servo_util::str::DOMString;
use string_cache::Atom;
/// Trait to allow DOM nodes to opt-in to overriding (or adding to) common /// Trait to allow DOM nodes to opt-in to overriding (or adding to) common
/// behaviours. Replicates the effect of C++ virtual methods. /// behaviours. Replicates the effect of C++ virtual methods.
pub trait VirtualMethods { pub trait VirtualMethods {
@ -95,7 +97,7 @@ pub trait VirtualMethods {
/// Returns the right AttrValue variant for the attribute with name `name` /// Returns the right AttrValue variant for the attribute with name `name`
/// on this element. /// 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() { match self.super_type() {
Some(ref s) => s.parse_plain_attribute(name, value), Some(ref s) => s.parse_plain_attribute(name, value),
_ => StringAttrValue(value), _ => StringAttrValue(value),

File diff suppressed because it is too large Load diff