Add Minor fixes and tests

This commit is contained in:
Pu Xingyu 2016-07-26 00:50:35 +08:00
parent 62dd3f4df4
commit 60e2f44a19
199 changed files with 34 additions and 611 deletions

View file

@ -3089,7 +3089,7 @@ impl ISizeAndMarginsComputer for FlexItem {
container_block_size); container_block_size);
} }
// Literally do nothing. // The used inline size and margins are set by parent flex flow, do nothing here.
fn solve_inline_size_constraints(&self, fn solve_inline_size_constraints(&self,
block: &mut BlockFlow, block: &mut BlockFlow,
_: &ISizeConstraintInput) _: &ISizeConstraintInput)

View file

@ -55,13 +55,13 @@ impl AxisSize {
Some(size) => AxisSize::Definite(size.scale_by(percent)), Some(size) => AxisSize::Definite(size.scale_by(percent)),
None => AxisSize::Infinite None => AxisSize::Infinite
} }
}, }
LengthOrPercentageOrAuto::Calc(calc) => { LengthOrPercentageOrAuto::Calc(calc) => {
match content_size { match content_size {
Some(size) => AxisSize::Definite(size.scale_by(calc.percentage())), Some(size) => AxisSize::Definite(size.scale_by(calc.percentage())),
None => AxisSize::Infinite None => AxisSize::Infinite
} }
}, }
LengthOrPercentageOrAuto::Auto => { LengthOrPercentageOrAuto::Auto => {
AxisSize::MinMax(MinMaxConstraint::new(content_size, min, max)) AxisSize::MinMax(MinMaxConstraint::new(content_size, min, max))
} }
@ -136,7 +136,7 @@ impl FlexItem {
let flex_grow = style.get_position().flex_grow; let flex_grow = style.get_position().flex_grow;
let flex_shrink = style.get_position().flex_shrink; let flex_shrink = style.get_position().flex_shrink;
let order = style.get_position().order; let order = style.get_position().order;
// TODO(stshine): for item with visibility:collapse, set is_strut to true. // TODO(stshine): for item with 'visibility:collapse', set is_strut to true.
FlexItem { FlexItem {
main_size: Au(0), main_size: Au(0),
@ -196,7 +196,7 @@ impl FlexItem {
} }
} }
/// Return the outer main size of the item, including paddings and margins, /// Returns the outer main size of the item, including paddings and margins,
/// clamped by max and min size. /// clamped by max and min size.
pub fn outer_main_size(&self, direction: Direction) -> Au { pub fn outer_main_size(&self, direction: Direction) -> Au {
let ref fragment = self.flow.as_block().fragment; let ref fragment = self.flow.as_block().fragment;
@ -212,7 +212,8 @@ impl FlexItem {
- fragment.box_sizing_boundary(direction) + outer_width - fragment.box_sizing_boundary(direction) + outer_width
} }
pub fn auto_margin_num(&self, direction: Direction) -> i32 { /// Returns the number of auto margins in given direction.
pub fn auto_margin_count(&self, direction: Direction) -> i32 {
let margin = self.style.logical_margin(); let margin = self.style.logical_margin();
let mut margin_count = 0; let mut margin_count = 0;
match direction { match direction {
@ -243,9 +244,9 @@ impl FlexItem {
struct FlexLine { struct FlexLine {
/// Range of items belong to this line in 'self.items'. /// Range of items belong to this line in 'self.items'.
pub range: Range<usize>, pub range: Range<usize>,
/// Remainig free space of this line, items will grow or shrink based on it being positive or negative. /// Remaining free space of this line, items will grow or shrink based on it being positive or negative.
pub free_space: Au, pub free_space: Au,
/// the number of auto margins of items. /// The number of auto margins of items.
pub auto_margin_count: i32, pub auto_margin_count: i32,
/// Line size in the block direction. /// Line size in the block direction.
pub cross_size: Au, pub cross_size: Au,
@ -262,7 +263,7 @@ impl FlexLine {
} }
/// This method implements the flexible lengths resolving algorithm. /// This method implements the flexible lengths resolving algorithm.
/// The 'collapse' parameter is used to indicate whether items with 'visibility: hidden' /// The 'collapse' parameter is used to indicate whether items with 'visibility: collapse'
/// is included in length resolving. The result main size is stored in 'item.main_size'. /// is included in length resolving. The result main size is stored in 'item.main_size'.
/// https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths /// https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths
pub fn flex_resolve(&mut self, items: &mut [FlexItem], collapse: bool) { pub fn flex_resolve(&mut self, items: &mut [FlexItem], collapse: bool) {
@ -399,15 +400,11 @@ impl FlexFlow {
/// Note that when the container main size is infinite(i.e. A column flexbox with auto height), /// Note that when the container main size is infinite(i.e. A column flexbox with auto height),
/// we do not need to do flex resolving and this can be considered as a fast-path, so the /// we do not need to do flex resolving and this can be considered as a fast-path, so the
/// 'container_size' param does not need to be 'None'. A line has to contain at least one item; /// 'container_size' param does not need to be 'None'. A line has to contain at least one item;
/// (expect this) if the container can be multi-line the sum of outer main size of items should /// (except this) if the container can be multi-line the sum of outer main size of items should
/// be less than the container size; a line should be filled by items as much as possible. /// be less than the container size; a line should be filled by items as much as possible.
/// After been collected in a line a item should have its main sizes initialized. /// After been collected in a line a item should have its main sizes initialized.
fn get_flex_line(&mut self, container_size: Au) -> Option<FlexLine> { fn get_flex_line(&mut self, container_size: Au) -> Option<FlexLine> {
let start = if self.lines.len() == 0 { let start = self.lines.last().map(|line| line.range.end).unwrap_or(0);
0
} else {
self.lines[self.lines.len()-1].range.end
};
if start == self.items.len() { if start == self.items.len() {
return None; return None;
} }
@ -416,13 +413,13 @@ impl FlexFlow {
let mut margin_count = 0; let mut margin_count = 0;
let items = &mut self.items[start..]; let items = &mut self.items[start..];
for mut item in items.iter_mut() { for mut item in items {
item.init_sizes(container_size, self.main_mode); item.init_sizes(container_size, self.main_mode);
let outer_main_size = item.outer_main_size(self.main_mode); let outer_main_size = item.outer_main_size(self.main_mode);
if total_line_size + outer_main_size > container_size && end != start && self.is_wrappable { if total_line_size + outer_main_size > container_size && end != start && self.is_wrappable {
break; break;
} }
margin_count += item.auto_margin_num(self.main_mode); margin_count += item.auto_margin_count(self.main_mode);
total_line_size += outer_main_size; total_line_size += outer_main_size;
end += 1; end += 1;
} }
@ -563,7 +560,7 @@ impl FlexFlow {
let explicit_content_size = self let explicit_content_size = self
.block_flow .block_flow
.explicit_block_size(parent_container_size) .explicit_block_size(parent_container_size)
.map(|x| if x < box_border { Au(0) } else { x - box_border }); .map(|x| max(x - box_border, Au(0)));
let containing_block_text_align = let containing_block_text_align =
self.block_flow.fragment.style().get_inheritedtext().text_align; self.block_flow.fragment.style().get_inheritedtext().text_align;
@ -571,7 +568,7 @@ impl FlexFlow {
let items = &mut self.items[line.range.clone()]; let items = &mut self.items[line.range.clone()];
line.flex_resolve(items, false); line.flex_resolve(items, false);
// TODO(stshine): if this flex line contain children that have // TODO(stshine): if this flex line contain children that have
// property visibility:hidden, exclude them and resolve again. // property visibility:collapse, exclude them and resolve again.
let item_count = items.len() as i32; let item_count = items.len() as i32;
let mut cur_i = inline_start_content_edge; let mut cur_i = inline_start_content_edge;
@ -583,10 +580,10 @@ impl FlexFlow {
} else { } else {
line.free_space / (item_count - 1) line.free_space / (item_count - 1)
} }
}, }
justify_content::T::space_around => { justify_content::T::space_around => {
line.free_space / item_count line.free_space / item_count
}, }
_ => Au(0), _ => Au(0),
} }
} else { } else {
@ -594,7 +591,7 @@ impl FlexFlow {
}; };
match self.block_flow.fragment.style().get_position().justify_content { match self.block_flow.fragment.style().get_position().justify_content {
// Overflow equally in both end. // Overflow equally in both ends of line.
justify_content::T::center | justify_content::T::space_around => { justify_content::T::center | justify_content::T::space_around => {
cur_i += (line.free_space - item_interval * (item_count - 1)) / 2; cur_i += (line.free_space - item_interval * (item_count - 1)) / 2;
} }
@ -711,12 +708,12 @@ impl FlexFlow {
if line_count == 1 { if line_count == 1 {
Au(0) Au(0)
} else { } else {
free_space /(line_count - 1) free_space / (line_count - 1)
} }
}, }
align_content::T::space_around => { align_content::T::space_around => {
free_space / line_count free_space / line_count
}, }
_ => Au(0), _ => Au(0),
}; };
@ -733,7 +730,7 @@ impl FlexFlow {
for line in &self.lines { for line in &self.lines {
for mut item in self.items[line.range.clone()].iter_mut() { for mut item in self.items[line.range.clone()].iter_mut() {
let auto_margin_count = item.auto_margin_num(Direction::Block); let auto_margin_count = item.auto_margin_count(Direction::Block);
let mut block = flow_ref::deref_mut(&mut item.flow).as_mut_block(); let mut block = flow_ref::deref_mut(&mut item.flow).as_mut_block();
let margin = block.fragment.style().logical_margin(); let margin = block.fragment.style().logical_margin();
@ -773,7 +770,7 @@ impl FlexFlow {
if !self.cross_reverse { if !self.cross_reverse {
cur_b cur_b
} else { } else {
self.block_flow.fragment.border_padding.block_start *2 self.block_flow.fragment.border_padding.block_start * 2
+ total_cross_size - cur_b - line.cross_size + total_cross_size - cur_b - line.cross_size
}; };
// TODO(stshine): support baseline alignment. // TODO(stshine): support baseline alignment.
@ -902,7 +899,7 @@ impl Flow for FlexFlow {
inline_start_content_edge, inline_start_content_edge,
inline_end_content_edge, inline_end_content_edge,
content_inline_size) content_inline_size)
}, }
Direction::Block => { Direction::Block => {
self.available_main_size = available_block_size; self.available_main_size = available_block_size;
self.available_cross_size = available_inline_size; self.available_cross_size = available_inline_size;

View file

@ -1102,6 +1102,8 @@ impl Fragment {
} }
} }
/// Returns the border width in given direction if this fragment has property
/// 'box-sizing: border-box'. The `border_padding` field should have been initialized.
pub fn box_sizing_boundary(&self, direction: Direction) -> Au { pub fn box_sizing_boundary(&self, direction: Direction) -> Au {
match (self.style().get_position().box_sizing, direction) { match (self.style().get_position().box_sizing, direction) {
(box_sizing::T::border_box, Direction::Inline) => { (box_sizing::T::border_box, Direction::Inline) => {

View file

@ -1,3 +0,0 @@
[align-content-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[align-content-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[align-content-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[align-content-005.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[align-content-006.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[align-self-005.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[css-box-justify-content.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-004.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-align-items-center.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-basis-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-basis-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-basis-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-basis-004.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-basis-005.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-basis-006.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-basis-008.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-box-wrap.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-container-margin.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-direction-modify.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-flow-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-flow-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-flow-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-flow-004.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-flow-005.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-flow-006.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-grow-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-grow-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-grow-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-grow-005.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-items-flexibility.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-shrink-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-shrink-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-shrink-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-shrink-004.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-shrink-005.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-shrink-006.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flex-shrink-007.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-abspos-child-001a.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-anonymous-items-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-basic-block-horiz-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-flex-wrap-default.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-flex-wrap-horiz-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-flex-wrap-horiz-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-flex-wrap-nowrap.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-items-as-stacking-contexts-002.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-items-as-stacking-contexts-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-justify-content-horiz-001a.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-justify-content-horiz-001b.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-justify-content-horiz-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-mbp-horiz-001-reverse.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-mbp-horiz-001.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-mbp-horiz-002a.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-mbp-horiz-002b.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-mbp-horiz-003-reverse.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-mbp-horiz-003.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-whitespace-handling-001b.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox-writing-mode-007.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-content-center.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-content-flexend.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-content-flexstart.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-content-spacearound.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-content-spacebetween.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-content-stretch-2.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-content-stretch.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-items-center-2.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-items-center.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-items-flexend-2.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-items-flexend.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-items-flexstart-2.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-items-flexstart.htm]
type: reftest
expected: FAIL

View file

@ -0,0 +1,3 @@
[flexbox_align-items-stretch-writing-modes.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-items-stretch.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-self-auto.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-self-baseline.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-self-center.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-self-flexend.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-self-flexstart.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_align-self-stretch.htm]
type: reftest
expected: FAIL

View file

@ -1,5 +1,4 @@
[flexbox_computedstyle_min-width-auto.htm] [flexbox_computedstyle_min-width-auto.htm]
type: testharness type: testharness
[flexbox | computed style | min-width: auto] expected: TIMEOUT
expected: FAIL

View file

@ -1,3 +1,4 @@
[flexbox_direction-row-reverse.htm] [flexbox_direction-row-reverse.htm]
type: reftest type: reftest
expected: FAIL expected:
if os == "mac": FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-1-unitless-basis.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-N-shrink.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-N-unitless-basis.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-N.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-Npercent-shrink.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-Npercent.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-auto-shrink.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-0-auto.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-1-1-unitless-basis.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-1-N-shrink.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-1-N-unitless-basis.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-1-N.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-1-Npercent-shrink.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-1-Npercent.htm]
type: reftest
expected: FAIL

View file

@ -1,3 +0,0 @@
[flexbox_flex-0-1-auto-shrink.htm]
type: reftest
expected: FAIL

Some files were not shown because too many files have changed in this diff Show more