Skip to content

Commit

Permalink
layout: Freeze flex item properly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stshine committed Aug 8, 2016
1 parent 414204c commit 2c2c60e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 deletions components/layout/flex.rs
Expand Up @@ -276,9 +276,8 @@ impl FlexLine {
// https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths
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));
if item.main_size != item.base_size
|| (self.free_space > Au(0) && item.flex_grow == 0.0)
|| (self.free_space < Au(0) && item.flex_shrink == 0.0) {
if (self.free_space > Au(0) && (item.flex_grow == 0.0 || item.base_size >= item.max_size)) ||
(self.free_space < Au(0) && (item.flex_shrink == 0.0 || item.base_size <= item.min_size)) {
item.is_frozen = true;
} else {
item.is_frozen = false;
Expand Down Expand Up @@ -311,7 +310,7 @@ impl FlexLine {
(item.flex_shrink * item.base_size.0 as f32 / total_scaled, item.min_size)
};
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.
total_variation += end_size - item.main_size;
item.main_size = end_size;
Expand Down

This file was deleted.

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

0 comments on commit 2c2c60e

Please sign in to comment.