style: Implement basic column spans.

This patch provides some of the groundwork for column spans greater than
1. It implements the column-span CSS property (prefixed so as not to be
exposed to content) as well as the corresponding colspan attribute;
although the former is not well-specified outside of CSS multi-column
layout, INTRINSIC refers to it. Although width is distributed to
spanning columns, they do not yet contribute minimum and preferred
widths; this will be implemented in a follow-up.

Additionally, this patch cleans up some miscellaneous formatting issues
and improves the handling of table rowgroups.
This commit is contained in:
Patrick Walton 2014-12-07 23:01:35 -08:00
parent 14bafb11be
commit 56b78de5bc
13 changed files with 269 additions and 129 deletions

View file

@ -44,8 +44,9 @@ use dom::node::{window_from_node};
use dom::nodelist::NodeList;
use dom::virtualmethods::{VirtualMethods, vtable_for};
use devtools_traits::AttrInfo;
use style::{mod, BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute, IntegerAttribute};
use style::{LengthAttribute, SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute};
use style::{mod, BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute};
use style::{ColSpanUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
use style::{SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute};
use style::{WidthLengthAttribute, matches, parse_selector_list_from_str};
use servo_util::namespace;
use servo_util::str::{DOMString, LengthOrPercentageOrAuto, SimpleColor};
@ -349,6 +350,14 @@ impl RawLayoutElementHelpers for Element {
None
}
}
ColSpanUnsignedIntegerAttribute => {
if self.is_htmltablecellelement() {
let this: &HTMLTableCellElement = mem::transmute(self);
this.get_colspan()
} else {
panic!("I'm not a table cell!")
}
}
}
}

View file

@ -22,6 +22,7 @@ pub struct HTMLTableCellElement {
htmlelement: HTMLElement,
background_color: Cell<Option<SimpleColor>>,
border: Cell<Option<u32>>,
colspan: Cell<Option<u32>>,
width: Cell<LengthOrPercentageOrAuto>,
}
@ -45,6 +46,7 @@ impl HTMLTableCellElement {
htmlelement: HTMLElement::new_inherited(type_id, tag_name, prefix, document),
background_color: Cell::new(None),
border: Cell::new(None),
colspan: Cell::new(None),
width: Cell::new(AutoLpa),
}
}
@ -58,6 +60,7 @@ impl HTMLTableCellElement {
pub trait HTMLTableCellElementHelpers {
fn get_background_color(&self) -> Option<SimpleColor>;
fn get_border(&self) -> Option<u32>;
fn get_colspan(&self) -> Option<u32>;
fn get_width(&self) -> LengthOrPercentageOrAuto;
}
@ -70,6 +73,10 @@ impl HTMLTableCellElementHelpers for HTMLTableCellElement {
self.border.get()
}
fn get_colspan(&self) -> Option<u32> {
self.colspan.get()
}
fn get_width(&self) -> LengthOrPercentageOrAuto {
self.width.get()
}
@ -97,6 +104,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
.as_slice()
.chars()).unwrap_or(1)))
}
&atom!("colspan") => {
self.colspan.set(str::parse_unsigned_integer(attr.value().as_slice().chars()));
}
&atom!("width") => self.width.set(str::parse_length(attr.value().as_slice())),
_ => ()
}
@ -111,6 +121,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
match attr.local_name() {
&atom!("bgcolor") => self.background_color.set(None),
&atom!("border") => self.border.set(None),
&atom!("colspan") => self.colspan.set(None),
&atom!("width") => self.width.set(AutoLpa),
_ => ()
}

View file

@ -108,6 +108,7 @@ impl HTMLTableElementHelpers for HTMLTableElement {
fn get_border(&self) -> Option<u32> {
self.border.get()
}
fn get_width(&self) -> LengthOrPercentageOrAuto {
self.width.get()
}
@ -135,6 +136,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
.as_slice()
.chars()).unwrap_or(1)))
}
&atom!("width") => self.width.set(str::parse_length(attr.value().as_slice())),
_ => ()
}
}
@ -148,6 +150,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),
&atom!("width") => self.width.set(AutoLpa),
_ => ()
}
}