Commit 09223a46 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[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: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576165}
parent afa14822
......@@ -273,8 +273,6 @@ crbug.com/591099 external/wpt/css/css-writing-modes/available-size-017.html [ Pa
crbug.com/591099 external/wpt/css/css-writing-modes/available-size-018.html [ Failure ]
crbug.com/591099 external/wpt/css/css-writing-modes/block-flow-direction-vrl-009.xht [ Pass ]
crbug.com/591099 external/wpt/css/css-writing-modes/clip-rect-vlr-009.xht [ Failure ]
crbug.com/591099 external/wpt/css/css-writing-modes/float-vlr-013.xht [ Failure ]
crbug.com/591099 external/wpt/css/css-writing-modes/float-vrl-012.xht [ Failure ]
crbug.com/591099 external/wpt/css/css-writing-modes/line-box-direction-vrl-009.xht [ Pass ]
crbug.com/591099 external/wpt/css/css-writing-modes/line-box-height-vlr-021.xht [ Pass ]
crbug.com/591099 external/wpt/css/css-writing-modes/line-box-height-vlr-023.xht [ Pass ]
......
......@@ -5,6 +5,7 @@
#ifndef NGLineBreaker_h
#define NGLineBreaker_h
#include "base/optional.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/ng/exclusions/ng_line_layout_opportunity.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_item_result.h"
......@@ -98,12 +99,20 @@ class CORE_EXPORT NGLineBreaker {
void BreakText(NGInlineItemResult*,
const NGInlineItem&,
LayoutUnit available_width);
void TruncateTextEnd(NGInlineItemResult*);
scoped_refptr<ShapeResult> TruncateLineEndResult(
const NGInlineItemResult& item_result,
unsigned end_offset);
void UpdateShapeResult(NGInlineItemResult*);
scoped_refptr<ShapeResult> ShapeText(const NGInlineItem& item,
unsigned start,
unsigned end);
void HandleTrailingSpaces(const NGInlineItem&);
void RemoveTrailingCollapsibleSpace();
LayoutUnit TrailingCollapsibleSpaceWidth();
void ComputeTrailingCollapsibleSpace();
void AppendHyphen(const NGInlineItem& item);
void HandleControlItem(const NGInlineItem&);
......@@ -123,7 +132,6 @@ class CORE_EXPORT NGLineBreaker {
void MoveToNextOf(const NGInlineItemResult&);
void ComputeBaseDirection();
bool IsTrailing(const NGInlineItem&) const;
LayoutUnit AvailableWidth() const {
return line_opportunity_.AvailableInlineSize();
......@@ -202,6 +210,14 @@ class CORE_EXPORT NGLineBreaker {
bool previous_line_had_forced_break_ = false;
const Hyphenation* hyphenation_ = nullptr;
// Cache the result of |ComputeTrailingCollapsibleSpace| to avoid shaping
// multiple times.
struct TrailingCollapsibleSpace {
NGInlineItemResult* item_result;
scoped_refptr<const ShapeResult> collapsed_shape_result;
};
base::Optional<TrailingCollapsibleSpace> trailing_collapsible_space_;
// Keep track of handled float items. See HandleFloat().
unsigned handled_floats_end_item_index_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment