mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Improve support of limited unsigned long attributes
This commit is contained in:
parent
15c4372a8b
commit
fedad2af1f
15 changed files with 106 additions and 483 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue