Commit f22d17dd authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[FragmentItem] Implement |BuildBackplate|

This patch implements |BuildBackplate| for |NGFragmentItem|.

Bug: 982194
Change-Id: I352a8edef64d3c936d34075742e42d124c1bfdbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003150
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732329}
parent bd74f644
......@@ -119,8 +119,8 @@ template <typename Base>
bool LayoutNGBlockFlowMixin<
Base>::PaintedOutputOfObjectHasNoEffectRegardlessOfSize() const {
// LayoutNGBlockFlowMixin is in charge of paint invalidation of the first
// line.
if (PaintFragment())
// line and painting backplates.
if (PaintFragment() || Base::FragmentItems())
return false;
if (Base::StyleRef().HasColumnRule())
......
......@@ -167,48 +167,75 @@ bool FragmentRequiresLegacyFallback(const NGPhysicalFragment& fragment) {
// the paragraph level. Store the results in paragraph_backplates.
Vector<PhysicalRect> BuildBackplate(NGInlineCursor* descendants,
const PhysicalOffset& paint_offset) {
Vector<PhysicalRect> paragraph_backplates;
PhysicalRect current_backplate;
int consecutive_line_breaks = 0;
// The number of consecutive forced breaks that split the backplate by
// paragraph.
static constexpr int kMaxConsecutiveLineBreaks = 2;
struct Backplates {
STACK_ALLOCATED();
public:
void AddTextRect(const PhysicalRect& box_rect) {
if (consecutive_line_breaks >= kMaxConsecutiveLineBreaks) {
// This is a paragraph point.
paragraph_backplates.push_back(current_backplate);
current_backplate = PhysicalRect();
}
consecutive_line_breaks = 0;
current_backplate.Unite(box_rect);
}
void AddLineBreak() { consecutive_line_breaks++; }
Vector<PhysicalRect> paragraph_backplates;
PhysicalRect current_backplate;
int consecutive_line_breaks = 0;
} backplates;
// Build up and paint backplates of all child inline text boxes. We are not
// able to simply use the linebox rect to compute the backplate because the
// backplate should only be painted for inline text and not for atomic
// inlines.
for (; *descendants; descendants->MoveToNext()) {
const NGPaintFragment* child = descendants->CurrentPaintFragment();
if (!child) // TODO(kojii): Support NGFragmentItem
continue;
if (const NGPaintFragment* child = descendants->CurrentPaintFragment()) {
const NGPhysicalFragment& child_fragment = child->PhysicalFragment();
if (child_fragment.IsHiddenForPaint() || child_fragment.IsFloating())
continue;
if (auto* text_fragment =
DynamicTo<NGPhysicalTextFragment>(child_fragment)) {
if (text_fragment->IsLineBreak()) {
consecutive_line_breaks++;
backplates.AddLineBreak();
continue;
}
if (consecutive_line_breaks >= kMaxConsecutiveLineBreaks) {
// This is a paragraph point.
paragraph_backplates.push_back(current_backplate);
current_backplate = PhysicalRect();
PhysicalRect box_rect(
child->InlineOffsetToContainerBox() + paint_offset, child->Size());
backplates.AddTextRect(box_rect);
}
continue;
}
if (const NGFragmentItem* child_item = descendants->CurrentItem()) {
if (child_item->IsHiddenForPaint())
continue;
if (child_item->IsText()) {
if (child_item->IsLineBreak()) {
backplates.AddLineBreak();
continue;
}
consecutive_line_breaks = 0;
PhysicalRect box_rect(child->InlineOffsetToContainerBox() + paint_offset,
child->Size());
current_backplate.Unite(box_rect);
PhysicalRect box_rect(child_item->Offset() + paint_offset,
child_item->Size());
backplates.AddTextRect(box_rect);
}
continue;
}
NOTREACHED();
}
if (!current_backplate.IsEmpty())
paragraph_backplates.push_back(current_backplate);
return paragraph_backplates;
if (!backplates.current_backplate.IsEmpty())
backplates.paragraph_backplates.push_back(backplates.current_backplate);
return backplates.paragraph_backplates;
}
} // anonymous namespace
......
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