W3C home > Mailing lists > Public > www-style@w3.org > April 2014

[css-flexbox] Tweaking the old "resolving flexible lengths" algorithm to produce same behavior as new algorithm

From: Daniel Holbert <dholbert@mozilla.com>
Date: Fri, 18 Apr 2014 14:54:57 -0700
Message-ID: <53519F31.4080602@mozilla.com>
To: www-style list <www-style@w3.org>, "Tab Atkins Jr." <jackalmage@gmail.com>
As noted in
 http://lists.w3.org/Archives/Public/www-style/2014Apr/0223.html
I'm curious how much the old "resolving flexible lengths" algorithm
would have to change to produce the same results as the new (quite
differently-worded/structured) algorithm.

For reference, the old algorithm is available here:
http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#resolve-flexible-lengths

After some thought, I *think* the old algorithm can be changed to
produce the same results as the new one if we simply insert a "step
4.5", as follows:

 # Step 4.5: Adjust Free Space
 #   Compute the sum of the unfrozen flex items' flex factors.
 #   If this sum is less than 1, then multiply the free space
 #   by this sum (reducing the magnitude of the free space).

In other words: if our flex items have flex-grow values that sum up to
0.5, then this makes us only distribute 50% of the free space. Similarly
for the flex-shrink values -- if there's negative free space and the
flex-shrink values sum to 0.8, then we'll only allow ourselves to use
80% of the negative free space.

I believe this tweak produces the same results as the new "resoling
flexible lengths" algorithm, with one (nice) exception: this version
doesn't have the bug that I described in the other thread that I started
today, with frozen items' flex-shrink values impacting other items'
resolved sizes. That thread is:
  http://lists.w3.org/Archives/Public/www-style/2014Apr/0246.html

Please correct me if I'm missing something, though.

QUESTION:
=========
If I'm correct that my suggested "step 4.5" makes us match the new spec
behavior [please sanity-check me on that], then: would it be worth
rolling back to the longer-implemented & more-hardened old algorithm
text, and inserting the step that I laid out above, rather then using
the all-new algorithm text?

(IMHO, the old algorithm is conceptually similar to follow, too -- i.e.
I admit I didn't entirely understand what was going on in the new
algorithm until I implemented it.  But I may be biased from having
worked with the old algorithm for longer.)

Thanks,
~Daniel
Received on Friday, 18 April 2014 21:55:26 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:39:21 UTC