Commit 8603f044 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Support atomic inline+nbsp quirks

This patch adds a quirks for atomic inline+nbsp defined in
CSS Text, saying:
> for Web-compatibility, introduces a soft wrap opportunity
> between itself and any adjacent U+00A0 NO-BREAK SPACE
> character.
https://www.w3.org/TR/css-text-3/#line-break-details

This is resolved at:
https://lists.w3.org/Archives/Public/www-style/2015Mar/0187.html
> zcorpan: I checked httparchive for nbsp before/after an
> image, and there were 16k matches. About 130k pages in the
> set, so about 12% of all the pages match the query.

Bug: 993893, 1001793
Change-Id: I24c30b43f282c2005abccf5be4de68262875b87d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1792465
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694788}
parent 1f45b474
...@@ -483,6 +483,41 @@ void NGLineBreaker::ComputeLineLocation(NGLineInfo* line_info) const { ...@@ -483,6 +483,41 @@ void NGLineBreaker::ComputeLineLocation(NGLineInfo* line_info) const {
line_info->UpdateTextAlign(); line_info->UpdateTextAlign();
} }
// For Web-compatibility, allow break between an atomic inline and any adjacent
// U+00A0 NO-BREAK SPACE character.
// https://www.w3.org/TR/css-text-3/#line-break-details
bool NGLineBreaker::IsAtomicInlineBeforeNoBreakSpace(
const NGInlineItemResult& item_result) const {
DCHECK_EQ(item_result.item->Type(), NGInlineItem::kAtomicInline);
const String& text = Text();
DCHECK_GE(text.length(), item_result.end_offset);
return text.length() > item_result.end_offset &&
text[item_result.end_offset] == kNoBreakSpaceCharacter;
}
bool NGLineBreaker::IsAtomicInlineAfterNoBreakSpace(
const NGInlineItemResult& item_result) const {
DCHECK_EQ(item_result.item->Type(), NGInlineItem::kText);
const String& text = Text();
DCHECK_GE(text.length(), item_result.end_offset);
if (text[item_result.end_offset - 1] != kNoBreakSpaceCharacter ||
text.length() <= item_result.end_offset ||
text[item_result.end_offset] != kObjectReplacementCharacter)
return false;
// This kObjectReplacementCharacter can be any objects, such as a floating or
// an OOF object. Check if it's really an atomic inline.
const Vector<NGInlineItem>& items = Items();
for (const NGInlineItem* item = std::next(item_result.item);
item != items.end(); ++item) {
DCHECK_EQ(item->StartOffset(), item_result.end_offset);
if (item->Type() == NGInlineItem::kAtomicInline)
return true;
if (item->EndOffset() > item_result.end_offset)
break;
}
return false;
}
void NGLineBreaker::HandleText(const NGInlineItem& item, void NGLineBreaker::HandleText(const NGInlineItem& item,
const ShapeResult& shape_result, const ShapeResult& shape_result,
NGLineInfo* line_info) { NGLineInfo* line_info) {
...@@ -711,6 +746,9 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText( ...@@ -711,6 +746,9 @@ NGLineBreaker::BreakResult NGLineBreaker::BreakText(
DCHECK_EQ(item_result->end_offset, item.EndOffset()); DCHECK_EQ(item_result->end_offset, item.EndOffset());
item_result->can_break_after = item_result->can_break_after =
break_iterator_.IsBreakable(item_result->end_offset); break_iterator_.IsBreakable(item_result->end_offset);
if (!item_result->can_break_after && item.Type() == NGInlineItem::kText &&
IsAtomicInlineAfterNoBreakSpace(*item_result))
item_result->can_break_after = true;
trailing_whitespace_ = WhitespaceState::kUnknown; trailing_whitespace_ = WhitespaceState::kUnknown;
} }
return inline_size <= available_width ? kSuccess : kOverflow; return inline_size <= available_width ? kSuccess : kOverflow;
...@@ -1252,6 +1290,9 @@ bool NGLineBreaker::HandleAtomicInline( ...@@ -1252,6 +1290,9 @@ bool NGLineBreaker::HandleAtomicInline(
trailing_whitespace_ = WhitespaceState::kNone; trailing_whitespace_ = WhitespaceState::kNone;
position_ += item_result->inline_size; position_ += item_result->inline_size;
ComputeCanBreakAfter(item_result, auto_wrap_, break_iterator_); ComputeCanBreakAfter(item_result, auto_wrap_, break_iterator_);
if (!item_result->can_break_after &&
IsAtomicInlineBeforeNoBreakSpace(*item_result))
item_result->can_break_after = true;
if (UNLIKELY(is_sticky_image)) { if (UNLIKELY(is_sticky_image)) {
const auto& items = Items(); const auto& items = Items();
......
...@@ -163,6 +163,10 @@ class CORE_EXPORT NGLineBreaker { ...@@ -163,6 +163,10 @@ class CORE_EXPORT NGLineBreaker {
const NGInlineItem&, const NGInlineItem&,
LayoutUnit percentage_resolution_block_size_for_min_max, LayoutUnit percentage_resolution_block_size_for_min_max,
NGLineInfo*); NGLineInfo*);
bool IsAtomicInlineAfterNoBreakSpace(
const NGInlineItemResult& item_result) const;
bool IsAtomicInlineBeforeNoBreakSpace(
const NGInlineItemResult& item_result) const;
void HandleFloat(const NGInlineItem&, void HandleFloat(const NGInlineItem&,
Vector<LayoutObject*>* out_floats_for_min_max, Vector<LayoutObject*>* out_floats_for_min_max,
NGLineInfo*); NGLineInfo*);
......
...@@ -686,9 +686,6 @@ crbug.com/591099 external/wpt/css/css-text/boundary-shaping/boundary-shaping-009 ...@@ -686,9 +686,6 @@ crbug.com/591099 external/wpt/css/css-text/boundary-shaping/boundary-shaping-009
crbug.com/591099 external/wpt/css/css-text/hyphens/shy-styling-001.html [ Failure ] crbug.com/591099 external/wpt/css/css-text/hyphens/shy-styling-001.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/line-breaking/line-breaking-018.html [ Failure ] crbug.com/591099 external/wpt/css/css-text/line-breaking/line-breaking-018.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/line-breaking/line-breaking-019.html [ Failure ] crbug.com/591099 external/wpt/css/css-text/line-breaking/line-breaking-019.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/line-breaking/line-breaking-atomic-001.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/line-breaking/line-breaking-atomic-002.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/line-breaking/line-breaking-replaced-001.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/shaping/shaping-009.html [ Failure ] crbug.com/591099 external/wpt/css/css-text/shaping/shaping-009.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/shaping/shaping-010.html [ Failure ] crbug.com/591099 external/wpt/css/css-text/shaping/shaping-010.html [ Failure ]
crbug.com/591099 external/wpt/css/css-text/shaping/shaping-011.html [ Failure ] crbug.com/591099 external/wpt/css/css-text/shaping/shaping-011.html [ Failure ]
......
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