Commit b7a0650c authored by Koji Ishii's avatar Koji Ishii Committed by Chromium LUCI CQ

Remove NGPaintFragment from NGBoxFragmentPainter

Bug: 1154531
Change-Id: I28fae7f200063d3f6abf29f8bca0ec143e33f520
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586292
Auto-Submit: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836346}
parent bb86908a
......@@ -171,32 +171,6 @@ bool HitTestCulledInlineAncestors(
return false;
}
bool HitTestCulledInlineAncestors(
HitTestResult& result,
const NGInlineCursor& parent_cursor,
const NGPaintFragment& fragment,
const NGInlineCursorPosition& previous_sibling,
const HitTestLocation& hit_test_location,
const PhysicalOffset& physical_offset) {
DCHECK(fragment.Parent());
DCHECK(fragment.PhysicalFragment().IsInline());
// Ellipsis can appear under a different parent from the ellipsized object
// that it can confuse culled inline logic.
if (UNLIKELY(fragment.IsEllipsis()))
return false;
const NGPaintFragment& parent = *fragment.Parent();
// To be passed as |accumulated_offset| to LayoutInline::HitTestCulledInline,
// where it equals the physical offset of the containing block in paint layer.
const PhysicalOffset fallback_accumulated_offset =
physical_offset - fragment.OffsetInContainerFragment();
const LayoutObject* limit_layout_object =
parent.PhysicalFragment().IsLineBox() ? parent.Parent()->GetLayoutObject()
: parent.GetLayoutObject();
return HitTestCulledInlineAncestors(
result, parent_cursor, fragment.GetLayoutObject(), limit_layout_object,
previous_sibling, hit_test_location, fallback_accumulated_offset);
}
bool HitTestCulledInlineAncestors(
HitTestResult& result,
const NGPhysicalBoxFragment& container,
......@@ -280,23 +254,6 @@ Vector<PhysicalRect> BuildBackplate(NGInlineCursor* descendants,
// backplate should only be painted for inline text and not for atomic
// inlines.
for (; *descendants; descendants->MoveToNext()) {
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()) {
backplates.AddLineBreak();
continue;
}
PhysicalRect box_rect(child->OffsetInContainerFragment() + paint_offset,
child->Size());
backplates.AddTextRect(box_rect);
}
continue;
}
if (const NGFragmentItem* child_item = descendants->CurrentItem()) {
if (child_item->IsHiddenForPaint())
continue;
......@@ -377,8 +334,6 @@ unsigned FragmentainerUniqueIdentifier(const NGPhysicalBoxFragment& fragment) {
} // anonymous namespace
PhysicalRect NGBoxFragmentPainter::SelfInkOverflow() const {
if (paint_fragment_)
return paint_fragment_->SelfInkOverflow();
if (box_item_)
return box_item_->SelfInkOverflow();
const NGPhysicalFragment& fragment = PhysicalFragment();
......@@ -591,43 +546,6 @@ void NGBoxFragmentPainter::PaintObject(
}
} else if (!fragment.IsInlineFormattingContext()) {
PaintBlockChildren(paint_info, paint_offset);
} else if (!RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
// This is the NGPaintFragment code path. We need the check for
// !LayoutNGFragmentItemEnabled above, since it's possible to come up
// with an empty (item-less) box that's in an inline formatting context,
// even when that feature is enabled. This happens when an inline-level
// float descendant gets block-fragmented. When resuming float layout in
// the next fragment, the float will no longer be associated with a line
// or a fragment item (this is an implementation detail), but rather a
// regular box fragment child of this container. If there's no inline
// content to put in that fragment, there'll be no items, just the box
// fragment for the float. In that case, we have no work to do here.
//
// <div style="columns:2; column-fill:auto; height:100px;">
// <div id="child">
// <div id="fl" style="float:left; height:150px;"></div>
// text
// </div>
// </div>
//
// #child will get two fragments. The first one will contain a line with
// items for a 100px tall #fl fragment, and the text. The second
// fragment of #child will just contain a regular box fragment child for
// the remaining 50px of #fl - no items (all in-flow content fits in the
// first fragment).
DCHECK(paint_fragment_);
if (fragment.IsBlockFlow()) {
PaintBlockFlowContents(paint_info, paint_offset);
} else if (ShouldPaintDescendantOutlines(paint_info.phase)) {
// TODO(kojii): |PaintInlineChildrenOutlines()| should do the work
// instead. Legacy does so, and is more efficient. But NG outline
// logic currently depends on |PaintInlineChildren()|.
PaintInlineChildren(paint_fragment_->Children(),
paint_info.ForDescendants(), paint_offset);
} else {
PaintInlineChildren(paint_fragment_->Children(), paint_info,
paint_offset);
}
}
}
......@@ -678,8 +596,7 @@ void NGBoxFragmentPainter::PaintBlockFlowContents(
// When the layout-tree gets into a bad state, we can end up trying to paint
// a fragment with inline children, without a paint fragment. See:
// http://crbug.com/1022545
if ((!paint_fragment_ && !items_) ||
(layout_object && layout_object->NeedsLayout())) {
if (!items_ || (layout_object && layout_object->NeedsLayout())) {
NOTREACHED();
return;
}
......@@ -711,11 +628,6 @@ void NGBoxFragmentPainter::PaintBlockFlowContents(
return;
}
if (paint_fragment_) {
NGInlineCursor children(*paint_fragment_);
PaintLineBoxChildren(&children, paint_info.ForDescendants(), paint_offset);
return;
}
DCHECK(items_);
NGInlineCursor children(fragment, *items_);
PaintLineBoxChildren(&children, paint_info.ForDescendants(), paint_offset);
......@@ -1328,11 +1240,6 @@ void NGBoxFragmentPainter::PaintInlineChildBoxUsingLegacyFallback(
const PaintInfo& paint_info) {
const LayoutObject* child_layout_object = fragment.GetLayoutObject();
DCHECK(child_layout_object);
if (child_layout_object->PaintFragment()) {
// This object will use NGBoxFragmentPainter.
child_layout_object->Paint(paint_info);
return;
}
if (child_layout_object->IsAtomicInlineLevel()) {
// Pre-NG painters also expect callers to use |PaintAllPhasesAtomically()|
......@@ -1417,8 +1324,7 @@ void NGBoxFragmentPainter::PaintInlineItems(const PaintInfo& paint_info,
inline void NGBoxFragmentPainter::PaintLineBox(
const NGPhysicalFragment& line_box_fragment,
const DisplayItemClient& display_item_client,
const NGPaintFragment* line_box_paint_fragment,
const NGFragmentItem* line_box_item,
const NGFragmentItem& line_box_item,
wtf_size_t line_fragment_id,
const PaintInfo& paint_info,
const PhysicalOffset& child_offset) {
......@@ -1427,7 +1333,6 @@ inline void NGBoxFragmentPainter::PaintLineBox(
base::Optional<ScopedDisplayItemFragment> display_item_fragment;
if (ShouldRecordHitTestData(paint_info)) {
if (line_box_item)
display_item_fragment.emplace(paint_info.context, line_fragment_id);
PhysicalRect border_box = line_box_fragment.LocalRect();
border_box.offset += child_offset;
......@@ -1439,11 +1344,10 @@ inline void NGBoxFragmentPainter::PaintLineBox(
// Paint the background of the `::first-line` line box.
if (NGLineBoxFragmentPainter::NeedsPaint(line_box_fragment)) {
if (!display_item_fragment && line_box_item)
if (!display_item_fragment)
display_item_fragment.emplace(paint_info.context, line_fragment_id);
NGLineBoxFragmentPainter line_box_painter(
line_box_fragment, line_box_paint_fragment, line_box_item,
PhysicalFragment(), paint_fragment_);
NGLineBoxFragmentPainter line_box_painter(line_box_fragment, line_box_item,
PhysicalFragment());
line_box_painter.PaintBackgroundBorderShadow(paint_info, child_offset);
}
}
......@@ -1483,48 +1387,8 @@ void NGBoxFragmentPainter::PaintLineBoxChildren(
return;
}
if (UNLIKELY(children->IsItemCursor())) {
DCHECK(children->IsItemCursor());
PaintLineBoxChildItems(children, paint_info, paint_offset);
return;
}
const bool is_horizontal = box_fragment_.Style().IsHorizontalWritingMode();
for (; *children; children->MoveToNextSkippingChildren()) {
const NGPaintFragment* line = children->CurrentPaintFragment();
DCHECK(line);
const NGPhysicalFragment& child_fragment = line->PhysicalFragment();
DCHECK(!child_fragment.IsOutOfFlowPositioned());
if (child_fragment.IsFloating())
continue;
// Check if CullRect intersects with this child, only in block direction
// because soft-wrap and <br> needs to paint outside of InkOverflow() in
// inline direction.
const PhysicalOffset child_offset = paint_offset + line->Offset();
PhysicalRect child_rect = line->InkOverflow();
if (is_horizontal) {
LayoutUnit y = child_rect.offset.top + child_offset.top;
if (!paint_info.GetCullRect().IntersectsVerticalRange(
y, y + child_rect.size.height))
continue;
} else {
LayoutUnit x = child_rect.offset.left + child_offset.left;
if (!paint_info.GetCullRect().IntersectsHorizontalRange(
x, x + child_rect.size.width))
continue;
}
if (child_fragment.IsListMarker()) {
PaintAtomicInlineChild(*line, paint_info);
continue;
}
DCHECK(child_fragment.IsLineBox());
PaintLineBox(
child_fragment, *line, line, /* line_box_item */ nullptr,
// |line_fragment_id| is used only when |NGFragmentItem| is enabled.
/* line_fragment_id */ 0, paint_info, child_offset);
PaintInlineChildren(line->Children(), paint_info, child_offset);
}
}
void NGBoxFragmentPainter::PaintLineBoxChildItems(
......@@ -1562,8 +1426,7 @@ void NGBoxFragmentPainter::PaintLineBoxChildItems(
child_item->LineBoxFragment();
DCHECK(line_box_fragment);
PaintLineBox(*line_box_fragment, *child_item->GetDisplayItemClient(),
/* line_box_paint_fragment */ nullptr, child_item,
line_fragment_id++, paint_info, child_offset);
*child_item, line_fragment_id++, paint_info, child_offset);
NGInlineCursor line_box_cursor = children->CursorForDescendants();
PaintInlineItems(paint_info, paint_offset,
child_item->OffsetInContainerFragment(),
......@@ -1616,70 +1479,6 @@ void NGBoxFragmentPainter::PaintBackplate(NGInlineCursor* line_boxes,
paint_info.context.FillRect(FloatRect(backplate), backplate_color);
}
void NGBoxFragmentPainter::PaintInlineChildren(
NGPaintFragment::ChildList inline_children,
const PaintInfo& paint_info,
const PhysicalOffset& paint_offset) {
// TODO(kojii): Move kOutline painting into a |PaintInlineChildrenOutlines()|
// method instead as it would be more efficient. Would require repeating some
// of the code below though.
// This DCHECK can then match to |InlineFlowBoxPainter::Paint|.
DCHECK_NE(paint_info.phase, PaintPhase::kDescendantOutlinesOnly);
for (const NGPaintFragment* child : inline_children) {
const NGPhysicalFragment& child_fragment = child->PhysicalFragment();
if (child_fragment.IsHiddenForPaint())
continue;
if (child_fragment.IsFloating())
continue;
// Skip if this child does not intersect with CullRect.
if (!paint_info.IntersectsCullRect(child->InkOverflow(),
paint_offset + child->Offset()) &&
// Don't skip empty size text in order to paint selection for <br>.
!(child_fragment.IsText() && child_fragment.Size().IsEmpty() &&
HasSelection(child_fragment.GetLayoutObject())))
continue;
if (child_fragment.Type() == NGPhysicalFragment::kFragmentText) {
DCHECK(!child_fragment.HasSelfPaintingLayer() ||
To<NGPhysicalTextFragment>(child_fragment).IsEllipsis());
PaintTextChild(*child, paint_info, paint_offset);
} else if (child_fragment.Type() == NGPhysicalFragment::kFragmentBox) {
if (child_fragment.HasSelfPaintingLayer())
continue;
if (child_fragment.IsAtomicInline())
PaintAtomicInlineChild(*child, paint_info);
else
NGInlineBoxFragmentPainter(*child).Paint(paint_info, paint_offset);
} else {
NOTREACHED();
}
}
}
void NGBoxFragmentPainter::PaintAtomicInlineChild(const NGPaintFragment& child,
const PaintInfo& paint_info) {
// Inline children should be painted by PaintInlineChild.
DCHECK(child.PhysicalFragment().IsAtomicInline());
const NGPhysicalFragment& fragment = child.PhysicalFragment();
if (child.HasSelfPaintingLayer())
return;
if (fragment.Type() == NGPhysicalFragment::kFragmentBox &&
FragmentRequiresLegacyFallback(fragment)) {
PaintInlineChildBoxUsingLegacyFallback(fragment, paint_info);
} else {
NGBoxFragmentPainter(child).PaintAllPhasesAtomically(paint_info);
}
}
void NGBoxFragmentPainter::PaintTextChild(const NGPaintFragment& paint_fragment,
const PaintInfo& paint_info,
const PhysicalOffset& paint_offset) {
NOTREACHED();
}
void NGBoxFragmentPainter::PaintTextItem(const NGInlineCursor& cursor,
const PaintInfo& paint_info,
const PhysicalOffset& paint_offset,
......@@ -1785,10 +1584,6 @@ bool NGBoxFragmentPainter::IsPaintingScrollingBackground(
bool NGBoxFragmentPainter::ShouldPaint(
const ScopedPaintState& paint_state) const {
// TODO(layout-dev): Add support for scrolling, see BlockPainter::ShouldPaint.
if (paint_fragment_) {
return paint_state.LocalRectIntersectsCullRect(
paint_fragment_->InkOverflow());
}
const NGPhysicalBoxFragment& fragment = PhysicalFragment();
if (!fragment.IsInlineBox()) {
return paint_state.LocalRectIntersectsCullRect(
......@@ -1810,13 +1605,6 @@ void NGBoxFragmentPainter::PaintTextClipMask(GraphicsContext& context,
return;
}
if (paint_fragment_) {
NGInlineBoxFragmentPainter inline_box_painter(*paint_fragment_);
PaintTextClipMask(paint_info, paint_offset - paint_fragment_->Offset(),
&inline_box_painter);
return;
}
DCHECK(inline_box_cursor_);
DCHECK(box_item_);
NGInlineBoxFragmentPainter inline_box_painter(*inline_box_cursor_,
......@@ -2023,13 +1811,6 @@ bool NGBoxFragmentPainter::NodeAtPoint(const HitTestContext& hit_test,
inline_box_cursor_->ContainerFragment(), bounds_rect,
physical_offset - box_item_->OffsetInContainerFragment()))
return true;
} else if (paint_fragment_ &&
paint_fragment_->PhysicalFragment().IsInline()) {
if (hit_test.AddNodeToResult(
fragment.NodeForHitTest(), /* box_fragment */ nullptr,
bounds_rect,
physical_offset - paint_fragment_->OffsetInContainerFragment()))
return true;
} else {
if (hit_test.AddNodeToResult(fragment.NodeForHitTest(), &box_fragment_,
bounds_rect, physical_offset))
......@@ -2077,36 +1858,6 @@ bool NGBoxFragmentPainter::HitTestAllPhases(
return inside;
}
bool NGBoxFragmentPainter::HitTestTextFragment(
const HitTestContext& hit_test,
const NGInlineBackwardCursor& cursor,
const PhysicalOffset& physical_offset) {
if (hit_test.action != kHitTestForeground)
return false;
const NGPaintFragment* text_paint_fragment = cursor.Current().PaintFragment();
DCHECK(text_paint_fragment);
const auto& text_fragment =
To<NGPhysicalTextFragment>(text_paint_fragment->PhysicalFragment());
if (!IsVisibleToHitTest(text_fragment, hit_test.result->GetHitTestRequest()))
return false;
// TODO(layout-dev): Clip to line-top/bottom.
PhysicalRect border_rect(physical_offset, text_fragment.Size());
PhysicalRect rect(PixelSnappedIntRect(border_rect));
if (UNLIKELY(hit_test.result->GetHitTestRequest().GetType() &
HitTestRequest::kHitTestVisualOverflow)) {
rect = text_fragment.SelfInkOverflow();
rect.Move(border_rect.offset);
}
if (!hit_test.location.Intersects(rect))
return false;
return hit_test.AddNodeToResult(
text_fragment.NodeForHitTest(), &cursor.ContainerFragment(), rect,
physical_offset - text_paint_fragment->OffsetInContainerFragment());
}
bool NGBoxFragmentPainter::HitTestTextItem(
const HitTestContext& hit_test,
const NGFragmentItem& text_item,
......@@ -2208,22 +1959,6 @@ bool NGBoxFragmentPainter::HitTestChildBoxFragment(
return false;
if (!FragmentRequiresLegacyFallback(fragment)) {
if (const NGPaintFragment* paint_fragment =
backward_cursor.Current().PaintFragment()) {
if (fragment.IsPaintedAtomically()) {
return HitTestAllPhasesInFragment(fragment, hit_test.location,
physical_offset, hit_test.result);
}
if (fragment.IsInlineBox()) {
return NGBoxFragmentPainter(*paint_fragment)
.NodeAtPoint(hit_test, physical_offset);
}
// When traversing into a different inline formatting context,
// |inline_root_offset| needs to be updated.
return NGBoxFragmentPainter(*paint_fragment)
.NodeAtPoint(*hit_test.result, hit_test.location, physical_offset,
hit_test.action);
}
if (fragment.IsPaintedAtomically()) {
return HitTestAllPhasesInFragment(fragment, hit_test.location,
physical_offset, hit_test.result);
......@@ -2304,11 +2039,6 @@ bool NGBoxFragmentPainter::HitTestChildBoxItem(
bool NGBoxFragmentPainter::HitTestChildren(
const HitTestContext& hit_test,
const PhysicalOffset& accumulated_offset) {
if (paint_fragment_) {
NGInlineCursor cursor(*paint_fragment_);
return HitTestChildren(hit_test, PhysicalFragment(), cursor,
accumulated_offset);
}
if (UNLIKELY(inline_box_cursor_)) {
NGInlineCursor descendants = inline_box_cursor_->CursorForDescendants();
if (descendants) {
......@@ -2343,8 +2073,6 @@ bool NGBoxFragmentPainter::HitTestChildren(
const NGPhysicalBoxFragment& container,
const NGInlineCursor& children,
const PhysicalOffset& accumulated_offset) {
if (children.IsPaintFragmentCursor())
return HitTestPaintFragmentChildren(hit_test, children, accumulated_offset);
if (children.IsItemCursor())
return HitTestItemsChildren(hit_test, container, children);
// Hits nothing if there were no children.
......@@ -2395,54 +2123,6 @@ bool NGBoxFragmentPainter::HitTestBlockChildren(
return false;
}
bool NGBoxFragmentPainter::HitTestPaintFragmentChildren(
const HitTestContext& hit_test,
const NGInlineCursor& children,
const PhysicalOffset& accumulated_offset) {
DCHECK(children.IsPaintFragmentCursor());
for (NGInlineBackwardCursor cursor(children); cursor;) {
const NGPaintFragment* child_paint_fragment =
cursor.Current().PaintFragment();
DCHECK(child_paint_fragment);
const NGPhysicalFragment& child_fragment =
child_paint_fragment->PhysicalFragment();
if (child_fragment.HasSelfPaintingLayer()) {
cursor.MoveToPreviousSibling();
continue;
}
const PhysicalOffset child_offset =
child_paint_fragment->Offset() + accumulated_offset;
if (child_fragment.Type() == NGPhysicalFragment::kFragmentBox) {
if (HitTestChildBoxFragment(hit_test,
To<NGPhysicalBoxFragment>(child_fragment),
cursor, child_offset))
return true;
} else if (child_fragment.Type() == NGPhysicalFragment::kFragmentLineBox) {
if (HitTestLineBoxFragment(hit_test,
To<NGPhysicalLineBoxFragment>(child_fragment),
cursor, child_offset))
return true;
} else if (child_fragment.Type() == NGPhysicalFragment::kFragmentText) {
if (HitTestTextFragment(hit_test, cursor, child_offset))
return true;
}
cursor.MoveToPreviousSibling();
if (child_fragment.IsInline() && hit_test.action == kHitTestForeground) {
// Hit test culled inline boxes between |fragment| and its parent
// fragment.
if (HitTestCulledInlineAncestors(*hit_test.result, children,
*child_paint_fragment, cursor.Current(),
hit_test.location, child_offset))
return true;
}
}
return false;
}
bool NGBoxFragmentPainter::HitTestItemsChildren(
const HitTestContext& hit_test,
const NGPhysicalBoxFragment& container,
......@@ -2654,13 +2334,8 @@ IntRect NGBoxFragmentPainter::VisualRect(const PhysicalOffset& paint_offset) {
DynamicTo<LayoutBox>(box_fragment_.GetLayoutObject()))
return BoxPainter(*layout_box).VisualRect(paint_offset);
PhysicalRect ink_overflow;
if (paint_fragment_)
ink_overflow = paint_fragment_->InkOverflow();
else if (box_item_)
ink_overflow = box_item_->InkOverflow();
else
NOTREACHED();
DCHECK(box_item_);
PhysicalRect ink_overflow = box_item_->InkOverflow();
ink_overflow.Move(paint_offset);
return EnclosingIntRect(ink_overflow);
}
......
......@@ -10,7 +10,6 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
#include "third_party/blink/renderer/core/paint/box_painter_base.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/platform/geometry/layout_point.h"
#include "third_party/blink/renderer/platform/geometry/layout_size.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
......@@ -36,11 +35,6 @@ class NGBoxFragmentPainter : public BoxPainterBase {
public:
NGBoxFragmentPainter(const NGPhysicalBoxFragment&);
// Construct for a box fragment. |NGPaintFragment| for this
// box if this box has inline formatting context, otherwise |nullptr|.
NGBoxFragmentPainter(const NGPhysicalBoxFragment&, const NGPaintFragment*);
// Construct for an inline formatting context.
NGBoxFragmentPainter(const NGPaintFragment&);
// Construct for an inline box.
NGBoxFragmentPainter(const NGInlineCursor& inline_box_cursor,
const NGFragmentItem& item,
......@@ -102,7 +96,6 @@ class NGBoxFragmentPainter : public BoxPainterBase {
private:
NGBoxFragmentPainter(const NGPhysicalBoxFragment&,
const DisplayItemClient& display_item_client,
const NGPaintFragment* = nullptr,
const NGInlineCursor* inline_box_cursor = nullptr,
const NGFragmentItem* = nullptr);
......@@ -138,25 +131,17 @@ class NGBoxFragmentPainter : public BoxPainterBase {
const PhysicalOffset& paint_offset);
void PaintLineBox(const NGPhysicalFragment& line_box_fragment,
const DisplayItemClient& display_item_client,
const NGPaintFragment* line_box_paint_fragment,
const NGFragmentItem* line_box_item,
const NGFragmentItem& line_box_item,
wtf_size_t line_fragment_id,
const PaintInfo&,
const PhysicalOffset& paint_offset);
void PaintBackplate(NGInlineCursor* descendants,
const PaintInfo&,
const PhysicalOffset& paint_offset);
void PaintInlineChildren(NGPaintFragment::ChildList,
const PaintInfo&,
const PhysicalOffset& paint_offset);
void PaintInlineChildBoxUsingLegacyFallback(const NGPhysicalFragment&,
const PaintInfo&);
void PaintBlockFlowContents(const PaintInfo&,
const PhysicalOffset& paint_offset);
void PaintAtomicInlineChild(const NGPaintFragment&, const PaintInfo&);
void PaintTextChild(const NGPaintFragment&,
const PaintInfo&,
const PhysicalOffset& paint_offset);
void PaintTextItem(const NGInlineCursor& cursor,
const PaintInfo&,
const PhysicalOffset& paint_offset,
......@@ -247,9 +232,6 @@ class NGBoxFragmentPainter : public BoxPainterBase {
const HitTestLocation&,
PhysicalOffset,
HitTestAction);
bool HitTestPaintFragmentChildren(const HitTestContext& hit_test,
const NGInlineCursor& children,
const PhysicalOffset& physical_offset);
bool HitTestItemsChildren(const HitTestContext& hit_test,
const NGPhysicalBoxFragment& container,
const NGInlineCursor& children);
......@@ -309,10 +291,6 @@ class NGBoxFragmentPainter : public BoxPainterBase {
const NGPhysicalBoxFragment& box_fragment_;
const DisplayItemClient& display_item_client_;
// If this box has inline children, either |paint_fragment_| or |items_| is
// not null, depends on |LayoutNGFragmentItemEnabled|. TODO(kojii): Remove
// |NGPaintFragment| once the transition is done. crbug.com/982194
const NGPaintFragment* paint_fragment_;
const NGFragmentItems* items_;
const NGFragmentItem* box_item_ = nullptr;
const NGInlineCursor* inline_box_cursor_ = nullptr;
......@@ -321,47 +299,23 @@ class NGBoxFragmentPainter : public BoxPainterBase {
inline NGBoxFragmentPainter::NGBoxFragmentPainter(
const NGPhysicalBoxFragment& box,
const DisplayItemClient& display_item_client,
const NGPaintFragment* paint_fragment,
const NGInlineCursor* inline_box_cursor,
const NGFragmentItem* box_item)
: BoxPainterBase(&box.GetDocument(), box.Style(), box.GeneratingNode()),
box_fragment_(box),
display_item_client_(display_item_client),
paint_fragment_(paint_fragment),
items_(box.Items()),
box_item_(box_item),
inline_box_cursor_(inline_box_cursor) {
DCHECK(box.IsBox() || box.IsRenderedLegend());
DCHECK_EQ(box.PostLayout(), &box);
#if DCHECK_IS_ON()
if (RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
DCHECK(!paint_fragment_);
if (inline_box_cursor_)
DCHECK_EQ(inline_box_cursor_->Current().Item(), box_item_);
if (box_item_)
DCHECK_EQ(box_item_->BoxFragment(), &box);
DCHECK_EQ(box.IsInlineBox(), !!inline_box_cursor_);
DCHECK_EQ(box.IsInlineBox(), !!box_item_);
} else {
DCHECK(!inline_box_cursor_);
DCHECK(!box_item_);
if (paint_fragment)
DCHECK_EQ(&paint_fragment->PhysicalFragment(), &box);
if (box.IsInlineBox()) {
DCHECK(paint_fragment_);
} else if (box.IsInlineFormattingContext()) {
// If no children, there maybe or may not be NGPaintFragment.
// TODO(kojii): To be investigated if this correct or should be fixed.
if (!box.Children().empty()) {
if (!box.GetLayoutObject() ||
!box.GetLayoutObject()->ChildPaintBlockedByDisplayLock()) {
DCHECK(paint_fragment);
}
}
} else {
// We may not have |paint_fragment_| nor |box_item_|.
}
}
#endif
}
......@@ -369,37 +323,15 @@ inline NGBoxFragmentPainter::NGBoxFragmentPainter(
const NGPhysicalBoxFragment& fragment)
: NGBoxFragmentPainter(fragment,
*fragment.GetLayoutObject(),
/* paint_fragment */ nullptr,
/* inline_box_cursor */ nullptr,
/* box_item */ nullptr) {}
inline NGBoxFragmentPainter::NGBoxFragmentPainter(
const NGPhysicalBoxFragment& fragment,
const NGPaintFragment* paint_fragment)
: NGBoxFragmentPainter(
fragment,
paint_fragment
? *static_cast<const DisplayItemClient*>(paint_fragment)
: *static_cast<const DisplayItemClient*>(
fragment.GetLayoutObject()),
paint_fragment,
/* inline_box_cursor */ nullptr,
/* box_item */ nullptr) {}
inline NGBoxFragmentPainter::NGBoxFragmentPainter(
const NGPaintFragment& paint_fragment)
: NGBoxFragmentPainter(
To<NGPhysicalBoxFragment>(paint_fragment.PhysicalFragment()),
paint_fragment,
&paint_fragment) {}
inline NGBoxFragmentPainter::NGBoxFragmentPainter(
const NGInlineCursor& inline_box_cursor,
const NGFragmentItem& item,
const NGPhysicalBoxFragment& fragment)
: NGBoxFragmentPainter(fragment,
*item.GetDisplayItemClient(),
/* paint_fragment */ nullptr,
&inline_box_cursor,
&item) {
DCHECK_EQ(item.BoxFragment(), &fragment);
......
......@@ -10,7 +10,6 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_fragment.h"
#include "third_party/blink/renderer/core/paint/background_image_geometry.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_phase.h"
......@@ -30,10 +29,6 @@ bool HasMultipleItems(const Items items) {
return iter != items.end() && ++iter != items.end();
}
inline bool HasMultiplePaintFragments(const LayoutObject& layout_object) {
return HasMultipleItems(NGPaintFragment::InlineFragmentsFor(&layout_object));
}
inline bool MayHaveMultipleFragmentItems(const NGFragmentItem& item,
const LayoutObject& layout_object) {
return !item.IsFirstForNode() || !item.IsLastForNode() ||
......@@ -54,30 +49,17 @@ PhysicalBoxSides NGInlineBoxFragmentPainter::SidesToInclude() const {
void NGInlineBoxFragmentPainter::Paint(const PaintInfo& paint_info,
const PhysicalOffset& paint_offset) {
base::Optional<ScopedDisplayItemFragment> display_item_fragment;
if (inline_box_item_) {
display_item_fragment.emplace(paint_info.context,
inline_box_item_->FragmentId());
}
ScopedDisplayItemFragment display_item_fragment(
paint_info.context, inline_box_item_.FragmentId());
const PhysicalOffset adjusted_paint_offset =
paint_offset + (inline_box_paint_fragment_
? inline_box_paint_fragment_->Offset()
: inline_box_item_->OffsetInContainerFragment());
paint_offset + inline_box_item_.OffsetInContainerFragment();
if (paint_info.phase == PaintPhase::kForeground)
PaintBackgroundBorderShadow(paint_info, adjusted_paint_offset);
const bool suppress_box_decoration_background = true;
if (inline_box_paint_fragment_) {
NGBoxFragmentPainter box_painter(PhysicalFragment(),
inline_box_paint_fragment_);
box_painter.PaintObject(paint_info, adjusted_paint_offset,
suppress_box_decoration_background);
return;
}
DCHECK(inline_box_cursor_);
DCHECK(inline_box_item_);
NGBoxFragmentPainter box_painter(*inline_box_cursor_, *inline_box_item_,
NGBoxFragmentPainter box_painter(*inline_box_cursor_, inline_box_item_,
PhysicalFragment());
box_painter.PaintObject(paint_info, adjusted_paint_offset,
suppress_box_decoration_background);
......@@ -116,27 +98,15 @@ void NGInlineBoxFragmentPainterBase::PaintBackgroundBorderShadow(
DCHECK(inline_box_fragment_.GetLayoutObject());
const LayoutObject& layout_object = *inline_box_fragment_.GetLayoutObject();
DCHECK(inline_box_paint_fragment_ || inline_box_item_);
bool object_may_have_multiple_boxes =
inline_box_paint_fragment_
? HasMultiplePaintFragments(layout_object)
: MayHaveMultipleFragmentItems(*inline_box_item_, layout_object);
MayHaveMultipleFragmentItems(inline_box_item_, layout_object);
// TODO(eae): Switch to LayoutNG version of BackgroundImageGeometry.
BackgroundImageGeometry geometry(*static_cast<const LayoutBoxModelObject*>(
inline_box_fragment_.GetLayoutObject()));
if (inline_box_paint_fragment_) {
NGBoxFragmentPainter box_painter(
To<NGPhysicalBoxFragment>(inline_box_fragment_),
inline_box_paint_fragment_);
PaintBoxDecorationBackground(
box_painter, paint_info, paint_offset, adjusted_frame_rect, geometry,
object_may_have_multiple_boxes, SidesToInclude());
return;
}
DCHECK(inline_box_cursor_);
NGBoxFragmentPainter box_painter(
*inline_box_cursor_, *inline_box_item_,
*inline_box_cursor_, inline_box_item_,
To<NGPhysicalBoxFragment>(inline_box_fragment_));
PaintBoxDecorationBackground(
box_painter, paint_info, paint_offset, adjusted_frame_rect, geometry,
......@@ -145,13 +115,7 @@ void NGInlineBoxFragmentPainterBase::PaintBackgroundBorderShadow(
IntRect NGInlineBoxFragmentPainterBase::VisualRect(
const PhysicalOffset& paint_offset) {
PhysicalRect overflow_rect;
if (inline_box_paint_fragment_) {
overflow_rect = inline_box_paint_fragment_->SelfInkOverflow();
} else {
DCHECK(inline_box_item_);
overflow_rect = inline_box_item_->SelfInkOverflow();
}
PhysicalRect overflow_rect = inline_box_item_.SelfInkOverflow();
overflow_rect.Move(paint_offset);
return EnclosingIntRect(overflow_rect);
}
......@@ -162,14 +126,9 @@ void NGLineBoxFragmentPainter::PaintBackgroundBorderShadow(
DCHECK_EQ(paint_info.phase, PaintPhase::kForeground);
DCHECK_EQ(inline_box_fragment_.Type(), NGPhysicalFragment::kFragmentLineBox);
DCHECK(NeedsPaint(inline_box_fragment_));
#if DCHECK_IS_ON()
if (RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
DCHECK(inline_box_item_);
// |NGFragmentItem| uses the fragment id when painting the background of
// line boxes. Please see |NGFragmentItem::kInitialLineFragmentId|.
DCHECK_NE(paint_info.context.GetPaintController().CurrentFragment(), 0u);
}
#endif
if (line_style_ == style_ ||
line_style_.Visibility() != EVisibility::kVisible)
......@@ -208,7 +167,7 @@ void NGLineBoxFragmentPainter::PaintBackgroundBorderShadow(
const LayoutBlockFlow& layout_block_flow =
*To<LayoutBlockFlow>(block_fragment_.GetLayoutObject());
BackgroundImageGeometry geometry(layout_block_flow);
NGBoxFragmentPainter box_painter(block_fragment_, block_paint_fragment_);
NGBoxFragmentPainter box_painter(block_fragment_);
PaintBoxDecorationBackground(
box_painter, paint_info, paint_offset, rect, geometry,
/*object_has_multiple_boxes*/ false, PhysicalBoxSides());
......@@ -228,20 +187,11 @@ void NGInlineBoxFragmentPainterBase::ComputeFragmentOffsetOnLine(
LayoutUnit after;
bool before_self = true;
for (; cursor; cursor.MoveToNextForSameLayoutObject()) {
if (inline_box_paint_fragment_) {
DCHECK(cursor.CurrentPaintFragment());
if (cursor.CurrentPaintFragment() == inline_box_paint_fragment_) {
before_self = false;
continue;
}
} else {
DCHECK(inline_box_item_);
DCHECK(cursor.CurrentItem());
if (cursor.CurrentItem() == inline_box_item_) {
if (cursor.CurrentItem() == &inline_box_item_) {
before_self = false;
continue;
}
}
const NGPhysicalBoxFragment* box_fragment = cursor.Current().BoxFragment();
DCHECK(box_fragment);
if (before_self)
......@@ -338,24 +288,6 @@ void NGInlineBoxFragmentPainter::PaintAllFragments(
if (UNLIKELY(block_flow->NeedsLayout()))
return;
if (!RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_inline);
// TODO(kojii): The root of this inline formatting context should have a
// PaintFragment, but it looks like there's a case it doesn't stand.
// crbug.com/969096
CHECK(block_flow->PaintFragment() || fragments.IsEmpty());
for (const NGPaintFragment* fragment : fragments) {
PhysicalOffset child_offset = paint_offset +
fragment->OffsetInContainerFragment() -
fragment->Offset();
DCHECK(fragment->PhysicalFragment().IsBox());
NGInlineBoxFragmentPainter(*fragment).Paint(paint_info, child_offset);
}
return;
}
NGInlineCursor cursor(*block_flow);
cursor.MoveTo(layout_inline);
if (!cursor)
......@@ -380,10 +312,8 @@ void NGInlineBoxFragmentPainter::PaintAllFragments(
#if DCHECK_IS_ON()
void NGInlineBoxFragmentPainter::CheckValid() const {
if (inline_box_item_) {
DCHECK(inline_box_cursor_);
DCHECK_EQ(inline_box_cursor_->Current().Item(), inline_box_item_);
}
DCHECK_EQ(inline_box_cursor_->Current().Item(), &inline_box_item_);
DCHECK_EQ(inline_box_fragment_.Type(),
NGPhysicalFragment::NGFragmentType::kFragmentBox);
......
......@@ -13,7 +13,6 @@
namespace blink {
class NGPaintFragment;
struct PaintInfo;
struct PhysicalRect;
......@@ -28,11 +27,9 @@ class NGInlineBoxFragmentPainterBase : public InlineBoxPainterBase {
LayoutUnit* total_width) const;
protected:
NGInlineBoxFragmentPainterBase(
const NGPhysicalFragment& inline_box_fragment,
NGInlineBoxFragmentPainterBase(const NGPhysicalFragment& inline_box_fragment,
const NGInlineCursor* inline_box_cursor,
const NGPaintFragment* inline_box_paint_fragment,
const NGFragmentItem* inline_box_item,
const NGFragmentItem& inline_box_item,
const LayoutObject& layout_object,
const ComputedStyle& style,
const ComputedStyle& line_style)
......@@ -42,42 +39,18 @@ class NGInlineBoxFragmentPainterBase : public InlineBoxPainterBase {
style,
line_style),
inline_box_fragment_(inline_box_fragment),
inline_box_paint_fragment_(inline_box_paint_fragment),
inline_box_item_(inline_box_item),
inline_box_cursor_(inline_box_cursor) {
#if DCHECK_IS_ON()
if (inline_box_cursor) {
DCHECK(inline_box_item);
DCHECK_EQ(inline_box_cursor->Current().Item(), inline_box_item);
}
if (inline_box_paint_fragment) {
DCHECK_EQ(&inline_box_paint_fragment->PhysicalFragment(),
&inline_box_fragment);
DCHECK(!inline_box_item);
} else if (inline_box_item) {
if (inline_box_item->BoxFragment())
DCHECK_EQ(inline_box_item->BoxFragment(), &inline_box_fragment);
if (inline_box_cursor)
DCHECK_EQ(inline_box_cursor->Current().Item(), &inline_box_item);
if (inline_box_item.BoxFragment())
DCHECK_EQ(inline_box_item.BoxFragment(), &inline_box_fragment);
else
DCHECK_EQ(inline_box_item->LineBoxFragment(), &inline_box_fragment);
} else {
NOTREACHED();
}
DCHECK_EQ(inline_box_item.LineBoxFragment(), &inline_box_fragment);
#endif
}
// Constructor for |NGPaintFragment|.
NGInlineBoxFragmentPainterBase(const NGPaintFragment& inline_box_fragment,
const LayoutObject& layout_object,
const ComputedStyle& style,
const ComputedStyle& line_style)
: NGInlineBoxFragmentPainterBase(inline_box_fragment.PhysicalFragment(),
/* inline_box_cursor */ nullptr,
&inline_box_fragment,
/* inline_box_item */ nullptr,
layout_object,
style,
line_style) {}
// Constructor for |NGFragmentItem|.
NGInlineBoxFragmentPainterBase(
const NGInlineCursor& inline_box_cursor,
......@@ -88,17 +61,14 @@ class NGInlineBoxFragmentPainterBase : public InlineBoxPainterBase {
const ComputedStyle& line_style)
: NGInlineBoxFragmentPainterBase(inline_box_fragment,
&inline_box_cursor,
/* inline_box_paint_fragment */ nullptr,
&inline_box_item,
inline_box_item,
layout_object,
style,
line_style) {}
const DisplayItemClient& GetDisplayItemClient() const {
if (inline_box_paint_fragment_)
return *inline_box_paint_fragment_;
DCHECK(inline_box_item_);
return *inline_box_item_->GetDisplayItemClient();
DCHECK(inline_box_item_.GetDisplayItemClient());
return *inline_box_item_.GetDisplayItemClient();
}
virtual PhysicalBoxSides SidesToInclude() const = 0;
......@@ -123,8 +93,7 @@ class NGInlineBoxFragmentPainterBase : public InlineBoxPainterBase {
IntRect VisualRect(const PhysicalOffset& paint_offset);
const NGPhysicalFragment& inline_box_fragment_;
const NGPaintFragment* inline_box_paint_fragment_ = nullptr;
const NGFragmentItem* inline_box_item_ = nullptr;
const NGFragmentItem& inline_box_item_;
const NGInlineCursor* inline_box_cursor_ = nullptr;
};
......@@ -134,18 +103,6 @@ class NGInlineBoxFragmentPainter : public NGInlineBoxFragmentPainterBase {
STACK_ALLOCATED();
public:
// Constructor for |NGPaintFragment|.
NGInlineBoxFragmentPainter(const NGPaintFragment& inline_box_fragment)
: NGInlineBoxFragmentPainterBase(inline_box_fragment,
*inline_box_fragment.GetLayoutObject(),
inline_box_fragment.Style(),
inline_box_fragment.Style()) {
DCHECK_EQ(inline_box_fragment.PhysicalFragment().Type(),
NGPhysicalFragment::NGFragmentType::kFragmentBox);
DCHECK_EQ(inline_box_fragment.PhysicalFragment().BoxType(),
NGPhysicalFragment::NGBoxType::kInlineBox);
}
// Constructor for |NGFragmentItem|.
NGInlineBoxFragmentPainter(const NGInlineCursor& inline_box_cursor,
const NGFragmentItem& inline_box_item,
......@@ -194,15 +151,11 @@ class NGLineBoxFragmentPainter : public NGInlineBoxFragmentPainterBase {
public:
NGLineBoxFragmentPainter(const NGPhysicalFragment& line_box_fragment,
const NGPaintFragment* line_box_paint_fragment,
const NGFragmentItem* line_box_item,
const NGPhysicalBoxFragment& block_fragment,
const NGPaintFragment* block_paint_fragment)
const NGFragmentItem& line_box_item,
const NGPhysicalBoxFragment& block_fragment)
: NGLineBoxFragmentPainter(line_box_fragment,
line_box_paint_fragment,
line_box_item,
block_fragment,
block_paint_fragment,
*block_fragment.GetLayoutObject()) {}
static bool NeedsPaint(const NGPhysicalFragment& line_fragment) {
......@@ -218,15 +171,12 @@ class NGLineBoxFragmentPainter : public NGInlineBoxFragmentPainterBase {
private:
NGLineBoxFragmentPainter(const NGPhysicalFragment& line_box_fragment,
const NGPaintFragment* line_box_paint_fragment,
const NGFragmentItem* line_box_item,
const NGFragmentItem& line_box_item,
const NGPhysicalBoxFragment& block_fragment,
const NGPaintFragment* block_paint_fragment,
const LayoutObject& layout_block_flow)
: NGInlineBoxFragmentPainterBase(
line_box_fragment,
/* inline_box_cursor */ nullptr,
line_box_paint_fragment,
line_box_item,
layout_block_flow,
// Use the style from the containing block. |line_fragment.Style()|
......@@ -235,8 +185,7 @@ class NGLineBoxFragmentPainter : public NGInlineBoxFragmentPainterBase {
// TODO(kojii): Reconsider |line_fragment.Style()|.
layout_block_flow.StyleRef(),
layout_block_flow.FirstLineStyleRef()),
block_fragment_(block_fragment),
block_paint_fragment_(block_paint_fragment) {
block_fragment_(block_fragment) {
DCHECK_EQ(line_box_fragment.Type(),
NGPhysicalFragment::NGFragmentType::kFragmentLineBox);
DCHECK(NeedsPaint(line_box_fragment));
......@@ -250,7 +199,6 @@ class NGLineBoxFragmentPainter : public NGInlineBoxFragmentPainterBase {
PhysicalBoxSides SidesToInclude() const final { return PhysicalBoxSides(); }
const NGPhysicalBoxFragment& block_fragment_;
const NGPaintFragment* block_paint_fragment_;
};
} // namespace blink
......
......@@ -642,17 +642,8 @@ void NGTableCellPainter::PaintBoxDecorationBackground(
DisplayItem::kBoxDecorationBackground, visual_rect);
PhysicalRect paint_rect(paint_offset, fragment_.Size());
const NGPaintFragment* paint_fragment =
To<LayoutNGTableCell>(fragment_.GetLayoutObject())->PaintFragment();
if (paint_fragment) {
NGBoxFragmentPainter(*paint_fragment)
.PaintBoxDecorationBackgroundWithRectImpl(paint_info, paint_rect,
box_decoration_data);
} else {
NGBoxFragmentPainter(fragment_).PaintBoxDecorationBackgroundWithRectImpl(
paint_info, paint_rect, box_decoration_data);
}
}
// Inspired by TableCellPainter::PaintBackground.
......
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