[LayoutNG] Fix float fitting logic when there are trailing spaces

When computing whether a float can fit in the line or not,
NGLineBreaker needs to know the current width after trailing
spaces are collapsed. The current logic removes trailing
spaces before computing it, but only at the end of the block.

To compute this correctly on each wrapped line, this patch
adds TrailingCollapsibleSpaceWidth() that computes without
removing it, so that it can be removed only when the float
fits. This allows us to check whether the float can fit or
not for each wrapped line.

In many cases, the computed trailing spaces will be removed.
This patch also adds a cache to avoid computint it twice,
because it may involve re-shaping.

Rather large refactoring in order to split computing and
removing, to avoid computing twice, and to avoid failures
due to rewinding positioned floats.

Bug: 862066
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ica6ce94fca63d5bdcf7784eead53dba6e680e177
Reviewed-on: https://chromium-review.googlesource.com/1133599
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576165}
3 files changed