layout: Freeze flex item properly

Fix the currently logic that a item will freeze if it should
grow(shrink) and its basesize is less(more) than its min(max) size. Also
fix the divide by zero error when an item should shrink but it has zero
length and zero min size.
This commit is contained in:
Pu Xingyu 2016-08-06 21:31:37 +08:00
parent 414204c909
commit 2c2c60e44d
3 changed files with 5 additions and 8 deletions

View file

@ -276,9 +276,8 @@ impl FlexLine {
// https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths // https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths
for item in items.iter_mut().filter(|i| !(i.is_strut && collapse)) { for item in items.iter_mut().filter(|i| !(i.is_strut && collapse)) {
item.main_size = max(item.min_size, min(item.base_size, item.max_size)); item.main_size = max(item.min_size, min(item.base_size, item.max_size));
if item.main_size != item.base_size if (self.free_space > Au(0) && (item.flex_grow == 0.0 || item.base_size >= item.max_size)) ||
|| (self.free_space > Au(0) && item.flex_grow == 0.0) (self.free_space < Au(0) && (item.flex_shrink == 0.0 || item.base_size <= item.min_size)) {
|| (self.free_space < Au(0) && item.flex_shrink == 0.0) {
item.is_frozen = true; item.is_frozen = true;
} else { } else {
item.is_frozen = false; item.is_frozen = false;
@ -311,7 +310,7 @@ impl FlexLine {
(item.flex_shrink * item.base_size.0 as f32 / total_scaled, item.min_size) (item.flex_shrink * item.base_size.0 as f32 / total_scaled, item.min_size)
}; };
let variation = self.free_space.scale_by(factor); let variation = self.free_space.scale_by(factor);
if variation.0.abs() > (end_size - item.main_size).0.abs() { if variation.0.abs() >= (end_size - item.main_size).0.abs() {
// Use constraint as the target main size, and freeze item. // Use constraint as the target main size, and freeze item.
total_variation += end_size - item.main_size; total_variation += end_size - item.main_size;
item.main_size = end_size; item.main_size = end_size;

View file

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

View file

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