style: Address review comments relating to bgcolor and column spans

This commit is contained in:
Patrick Walton 2014-12-11 09:58:00 -08:00
parent 17835ba0cb
commit a1ea44b294
33 changed files with 712 additions and 422 deletions

View file

@ -31,6 +31,9 @@ path = "../net"
[dependencies.util]
path = "../util"
[dependencies.cssparser]
git = "https://github.com/servo/rust-cssparser"
[dependencies.encoding]
git = "https://github.com/lifthrasiir/rust-encoding"

View file

@ -14,6 +14,7 @@
#[phase(plugin, link)]
extern crate log;
extern crate cssparser;
extern crate geom;
extern crate gfx;
extern crate layout_traits;

View file

@ -106,9 +106,10 @@ impl TableFlow {
/// Update the corresponding value of `self_inline_sizes` if a value of `kid_inline_sizes` has
/// a larger value than one of `self_inline_sizes`. Returns the minimum and preferred inline
/// sizes.
fn update_automatic_column_inline_sizes(parent_inline_sizes: &mut Vec<ColumnInlineSize>,
child_cell_inline_sizes: &[CellIntrinsicInlineSize])
-> IntrinsicISizes {
fn update_automatic_column_inline_sizes(
parent_inline_sizes: &mut Vec<ColumnIntrinsicInlineSize>,
child_cell_inline_sizes: &[CellIntrinsicInlineSize])
-> IntrinsicISizes {
let mut total_inline_sizes = IntrinsicISizes::new();
let mut column_index = 0;
for child_cell_inline_size in child_cell_inline_sizes.iter() {
@ -122,7 +123,7 @@ impl TableFlow {
// 4. For now we make this column contribute no width.
} else {
let column_size = &child_cell_inline_size.column_size;
*parent_sizes = ColumnInlineSize {
*parent_sizes = ColumnIntrinsicInlineSize {
minimum_length: max(parent_sizes.minimum_length,
column_size.minimum_length),
percentage: parent_sizes.greatest_percentage(column_size),
@ -136,7 +137,7 @@ impl TableFlow {
if child_cell_inline_size.column_span > 1 {
// TODO(pcwalton): Perform the recursive algorithm specified in INTRINSIC §
// 4. For now we make this column contribute no width.
parent_inline_sizes.push(ColumnInlineSize::new())
parent_inline_sizes.push(ColumnIntrinsicInlineSize::new())
} else {
parent_inline_sizes.push(child_cell_inline_size.column_size)
}
@ -169,7 +170,7 @@ impl TableFlow {
/// Updates the minimum and preferred inline-size calculation for a single row. This is
/// factored out into a separate function because we process children of rowgroups too.
fn update_column_inline_sizes_for_row(child: &mut Flow,
column_inline_sizes: &mut Vec<ColumnInlineSize>,
column_inline_sizes: &mut Vec<ColumnIntrinsicInlineSize>,
computation: &mut IntrinsicISizesContribution,
did_first_row: &mut bool,
table_layout: TableLayout) {
@ -254,18 +255,20 @@ impl Flow for TableFlow {
}
} else if kid.is_table_rowgroup() {
for grandkid in flow::mut_base(kid).child_iter() {
TableFlow::update_column_inline_sizes_for_row(grandkid,
&mut self.column_inline_sizes,
&mut computation,
&mut did_first_row,
self.table_layout)
TableFlow::update_column_inline_sizes_for_row(
grandkid,
&mut self.column_intrinsic_inline_sizes,
&mut computation,
&mut did_first_row,
self.table_layout)
}
} else if kid.is_table_row() {
TableFlow::update_column_inline_sizes_for_row(kid,
&mut self.column_inline_sizes,
&mut computation,
&mut did_first_row,
self.table_layout)
TableFlow::update_column_inline_sizes_for_row(
kid,
&mut self.column_intrinsic_inline_sizes,
&mut computation,
&mut did_first_row,
self.table_layout)
}
}
@ -309,8 +312,7 @@ impl Flow for TableFlow {
// In fixed table layout, we distribute extra space among the unspecified columns
// if there are any, or among all the columns if all are specified.
self.column_computed_inline_sizes.clear();
if total_column_inline_size < content_inline_size &&
num_unspecified_inline_sizes == 0 {
if num_unspecified_inline_sizes == 0 {
let ratio = content_inline_size.to_subpx() /
total_column_inline_size.to_subpx();
for column_inline_size in self.column_intrinsic_inline_sizes.iter() {
@ -445,6 +447,16 @@ pub struct ColumnIntrinsicInlineSize {
}
impl ColumnIntrinsicInlineSize {
/// Returns a newly-initialized `ColumnIntrinsicInlineSize` with all fields blank.
pub fn new() -> ColumnIntrinsicInlineSize {
ColumnIntrinsicInlineSize {
preferred: Au(0),
minimum_length: Au(0),
percentage: 0.0,
constrained: false,
}
}
/// Returns the true minimum size of this column, given the containing block's inline size.
/// Beware that this is generally only correct for fixed table layout. (Compare CSS 2.1 §
/// 17.5.2.1 with the algorithm in INTRINSIC § 4.)

View file

@ -17,7 +17,7 @@ use wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use std::fmt;
use style::ComputedValues;
use style::{ColSpanUnsignedIntegerAttribute, ComputedValues};
use sync::Arc;
/// A table formatting context.
@ -25,13 +25,17 @@ use sync::Arc;
pub struct TableCellFlow {
/// Data common to all block flows.
pub block_flow: BlockFlow,
/// The column span of this cell.
pub column_span: u32,
}
impl TableCellFlow {
pub fn from_node_and_fragment(node: &ThreadSafeLayoutNode, fragment: Fragment)
-> TableCellFlow {
TableCellFlow {
block_flow: BlockFlow::from_node_and_fragment(node, fragment)
block_flow: BlockFlow::from_node_and_fragment(node, fragment),
column_span: node.get_unsigned_integer_attribute(ColSpanUnsignedIntegerAttribute)
.unwrap_or(1),
}
}

View file

@ -41,7 +41,7 @@ pub struct TableRowFlow {
#[deriving(Encodable)]
pub struct CellIntrinsicInlineSize {
/// Inline sizes that this cell contributes to the column.
pub column_size: ColumnInlineSize,
pub column_size: ColumnIntrinsicInlineSize,
/// The column span of this cell.
pub column_span: u32,
}
@ -165,7 +165,7 @@ impl Flow for TableRowFlow {
}
fn column_intrinsic_inline_sizes<'a>(&'a mut self) -> &'a mut Vec<ColumnIntrinsicInlineSize> {
&mut self.column_intrinsic_inline_sizes
panic!("can't call column_intrinsic_inline_sizes() on table row")
}
fn column_computed_inline_sizes<'a>(&'a mut self) -> &'a mut Vec<ColumnComputedInlineSize> {
@ -193,9 +193,11 @@ impl Flow for TableRowFlow {
let child_specified_inline_size;
let child_column_span;
{
let child_style = kid.as_table_cell().fragment().style();
child_specified_inline_size = child_style.content_inline_size();
child_column_span = child_style.get_table()._servo_column_span
let child_table_cell = kid.as_table_cell();
child_specified_inline_size = child_table_cell.fragment()
.style()
.content_inline_size();
child_column_span = child_table_cell.column_span
}
// Collect minimum and preferred inline-sizes of the cell for automatic table layout
@ -248,31 +250,36 @@ impl Flow for TableRowFlow {
// Spread out the completed inline sizes among columns with spans > 1.
let mut computed_inline_size_for_cells = Vec::new();
let mut column_inline_size_iterator = self.column_inline_sizes.iter();
let mut column_computed_inline_size_iterator = self.column_computed_inline_sizes.iter();
for cell_intrinsic_inline_size in self.cell_intrinsic_inline_sizes.iter() {
//(intrinsic_inline_size_for_column, computed_inline_size_for_column) in
// Start with the computed inline size for the first column in the span.
let mut column_inline_size = match column_inline_size_iterator.next() {
Some(column_inline_size) => *column_inline_size,
None => {
// This could happen if there are too few cells in this row. Don't crash.
break
}
};
let mut column_computed_inline_size =
match column_computed_inline_size_iterator.next() {
Some(column_computed_inline_size) => *column_computed_inline_size,
None => {
// We're in fixed layout mode and there are more cells in this row than
// columns we know about. According to CSS 2.1 § 17.5.2.1, the behavior is
// now undefined. So just use zero.
//
// FIXME(pcwalton): $10 says this isn't Web compatible.
ColumnComputedInlineSize {
size: Au(0),
}
}
};
// Add in computed inline sizes for any extra columns in the span.
for _ in range(1, cell_intrinsic_inline_size.column_span) {
let extra_column_inline_size = match column_inline_size_iterator.next() {
Some(column_inline_size) => column_inline_size,
None => break,
};
column_inline_size.minimum_length = column_inline_size.minimum_length +
extra_column_inline_size.minimum_length;
column_inline_size.preferred = column_inline_size.preferred +
extra_column_inline_size.preferred;
let extra_column_computed_inline_size =
match column_computed_inline_size_iterator.next() {
Some(column_computed_inline_size) => column_computed_inline_size,
None => break,
};
column_computed_inline_size.size = column_computed_inline_size.size +
extra_column_computed_inline_size.size;
}
computed_inline_size_for_cells.push(column_inline_size)
computed_inline_size_for_cells.push(column_computed_inline_size)
}
// Push those inline sizes down to the cells.

View file

@ -6,13 +6,13 @@
#![deny(unsafe_blocks)]
use block::{BlockFlow, ISizeAndMarginsComputer};
use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayNotCollapse};
use construct::FlowConstructor;
use context::LayoutContext;
use flow::{mod, Flow, FlowClass, TableRowGroupFlowClass};
use flow::{Flow, FlowClass, TableRowGroupFlowClass};
use fragment::{Fragment, FragmentBoundsIterator};
use layout_debug;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, TableFlow};
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable};
use wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;

View file

@ -31,7 +31,7 @@ use style::{ComputedValues, CSSFloat};
use style::computed_values::table_layout;
use sync::Arc;
#[deriving(Encodable)]
#[deriving(Encodable, Show)]
pub enum TableLayout {
FixedLayout,
AutoLayout

View file

@ -36,6 +36,7 @@ use incremental::RestyleDamage;
use util::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper, OpaqueNodeMethods};
use util::{PrivateLayoutData};
use cssparser::RGBA;
use gfx::display_list::OpaqueNode;
use script::dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementCast};
use script::dom::bindings::codegen::InheritTypes::{HTMLImageElementCast, HTMLInputElementCast};
@ -53,7 +54,7 @@ use script::dom::node::{HAS_CHANGED, IS_DIRTY, HAS_DIRTY_SIBLINGS, HAS_DIRTY_DES
use script::dom::text::Text;
use script::layout_interface::LayoutChan;
use servo_msg::constellation_msg::{PipelineId, SubpageId};
use servo_util::str::{LengthOrPercentageOrAuto, SimpleColor, is_whitespace};
use servo_util::str::{LengthOrPercentageOrAuto, is_whitespace};
use std::kinds::marker::ContravariantLifetime;
use std::mem;
use string_cache::{Atom, Namespace};
@ -613,7 +614,7 @@ impl<'le> TElementAttributes for LayoutElement<'le> {
}
}
fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<SimpleColor> {
fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<RGBA> {
unsafe {
self.element.get_simple_color_attribute_for_layout(attribute)
}
@ -937,6 +938,18 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
}
}
pub fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute)
-> Option<u32> {
unsafe {
match ElementCast::to_js(self.get_jsmanaged()) {
Some(element) => {
(*element.unsafe_get()).get_unsigned_integer_attribute_for_layout(attribute)
}
None => panic!("not an element!")
}
}
}
/// Get the description of how to account for recent style changes.
/// This is a simple bitfield and fine to copy by value.
pub fn restyle_damage(self) -> RestyleDamage {