aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmltablecellelement.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/htmltablecellelement.rs')
-rw-r--r--components/script/dom/htmltablecellelement.rs34
1 files changed, 29 insertions, 5 deletions
diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs
index 378a804c361..02d32d55968 100644
--- a/components/script/dom/htmltablecellelement.rs
+++ b/components/script/dom/htmltablecellelement.rs
@@ -2,7 +2,8 @@
* 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, AttrHelpers};
+use dom::attr::{Attr, AttrHelpers, AttrValue};
+use dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods;
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableCellElementDerived};
use dom::bindings::js::JSRef;
use dom::document::Document;
@@ -12,9 +13,15 @@ use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::NodeTypeId;
use dom::virtualmethods::VirtualMethods;
-use cssparser::RGBA;
use util::str::{self, DOMString, LengthOrPercentageOrAuto};
+
+use cssparser::RGBA;
+use string_cache::Atom;
+
use std::cell::Cell;
+use std::cmp::max;
+
+const DEFAULT_COLSPAN: u32 = 1;
#[derive(Copy, Clone, PartialEq, Debug)]
#[jstraceable]
@@ -60,6 +67,12 @@ impl HTMLTableCellElement {
}
}
+impl<'a> HTMLTableCellElementMethods for JSRef<'a, HTMLTableCellElement> {
+ // https://html.spec.whatwg.org/multipage/#dom-tdth-colspan
+ make_uint_getter!(ColSpan, "colspan", DEFAULT_COLSPAN);
+ make_uint_setter!(SetColSpan, "colspan");
+}
+
pub trait HTMLTableCellElementHelpers {
fn get_background_color(&self) -> Option<RGBA>;
fn get_colspan(&self) -> Option<u32>;
@@ -96,8 +109,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
self.background_color.set(str::parse_legacy_color(&attr.value()).ok())
}
&atom!("colspan") => {
- self.colspan.set(str::parse_unsigned_integer(attr.value().chars()));
- }
+ match *attr.value() {
+ AttrValue::UInt(_, colspan) => {
+ self.colspan.set(Some(max(DEFAULT_COLSPAN, colspan)))
+ },
+ _ => unreachable!(),
+ }
+ },
&atom!("width") => self.width.set(str::parse_length(&attr.value())),
_ => ()
}
@@ -115,5 +133,11 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
_ => ()
}
}
-}
+ fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
+ match local_name {
+ &atom!("colspan") => AttrValue::from_u32(value, DEFAULT_COLSPAN),
+ _ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
+ }
+ }
+}