style: Parse the legacy bgcolor attribute per the HTML5 specification.

Additionally, this patch cleans up some miscellaneous formatting issues.
This commit is contained in:
Patrick Walton 2014-12-07 22:59:38 -08:00
parent 10f1ed5e31
commit 14bafb11be
19 changed files with 370 additions and 36 deletions

View file

@ -18,12 +18,13 @@ use dom::htmltablecaptionelement::HTMLTableCaptionElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods;
use servo_util::str::{mod, AutoLpa, DOMString, LengthOrPercentageOrAuto};
use servo_util::str::{mod, AutoLpa, DOMString, LengthOrPercentageOrAuto, SimpleColor};
use std::cell::Cell;
#[dom_struct]
pub struct HTMLTableElement {
htmlelement: HTMLElement,
background_color: Cell<Option<SimpleColor>>,
border: Cell<Option<u32>>,
width: Cell<LengthOrPercentageOrAuto>,
}
@ -42,6 +43,7 @@ impl HTMLTableElement {
localName,
prefix,
document),
background_color: Cell::new(None),
border: Cell::new(None),
width: Cell::new(AutoLpa),
}
@ -93,11 +95,16 @@ impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> {
}
pub trait HTMLTableElementHelpers {
fn get_background_color(&self) -> Option<SimpleColor>;
fn get_border(&self) -> Option<u32>;
fn get_width(&self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableElementHelpers for HTMLTableElement {
fn get_background_color(&self) -> Option<SimpleColor> {
self.background_color.get()
}
fn get_border(&self) -> Option<u32> {
self.border.get()
}
@ -119,6 +126,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
}
match attr.local_name() {
&atom!("bgcolor") => {
self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
}
&atom!("border") => {
// According to HTML5 § 14.3.9, invalid values map to 1px.
self.border.set(Some(str::parse_unsigned_integer(attr.value()
@ -136,6 +146,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
}
match attr.local_name() {
&atom!("bgcolor") => self.background_color.set(None),
&atom!("border") => self.border.set(None),
_ => ()
}