Skip to content

Commit

Permalink
Auto merge of #12754 - stshine:no-divide-by-zero, r=pcwalton
Browse files Browse the repository at this point in the history
Fix unexpected freeze of flex item

<!-- Please describe your changes on the following line: -->

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. This
also fix the divide by zero error when an item should shrink but it has
zero length and zero min size.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12754)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Aug 8, 2016
2 parents 0b98321 + 2c2c60e commit a83fed2
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 a83fed2

Please sign in to comment.