Commit 73a5a05e authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[FragmentItem] Paint floats

This patch adds NGFragmentItem painting code path for
floating objects.

There should be more then one tests that turn to pass. I'll
update FlagExpectations once we've got the try-bot.

Bug: 982194
Change-Id: I83e74338251bbe754e82ce0dcf69164293d494f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865924
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706912}
parent 081f4cc4
......@@ -80,11 +80,17 @@ void NGFragmentItemsBuilder::AddItems(Child* child_begin, Child* child_end) {
const NGPhysicalBoxFragment& box =
To<NGPhysicalBoxFragment>(child.layout_result->PhysicalFragment());
if (child.children_count <= 1) {
// Compute |has_floating_descendants_| to optimize tree traversal in
// paint.
if (!has_floating_descendants_ && box.IsFloating())
has_floating_descendants_ = true;
items_.push_back(std::make_unique<NGFragmentItem>(box, 1));
offsets_.push_back(child.offset);
++child_iter;
continue;
}
DCHECK(!box.IsFloating());
// Children of inline boxes are flattened and added to |items_|, with the
// count of descendant items to preserve the tree structure.
......
......@@ -25,6 +25,9 @@ class CORE_EXPORT NGFragmentItemsBuilder {
public:
NGFragmentItemsBuilder(NGBoxFragmentBuilder* box_builder) {}
// Returns true if we have any floating descendants.
bool HasFloatingDescendants() const { return has_floating_descendants_; }
const String& TextContent(bool first_line) const {
return UNLIKELY(first_line && first_line_text_content_)
? first_line_text_content_
......@@ -75,6 +78,8 @@ class CORE_EXPORT NGFragmentItemsBuilder {
// Keeps children of a line until the offset is determined. See |AddLine|.
ChildList current_line_;
bool has_floating_descendants_ = false;
#if DCHECK_IS_ON()
const NGPhysicalLineBoxFragment* current_line_fragment_ = nullptr;
bool is_converted_to_physical_ = false;
......
......@@ -227,6 +227,9 @@ scoped_refptr<const NGLayoutResult> NGBoxFragmentBuilder::ToBoxFragment(
}
}
if (!has_floating_descendants_ && items_builder_)
has_floating_descendants_ = items_builder_->HasFloatingDescendants();
scoped_refptr<const NGPhysicalBoxFragment> fragment =
NGPhysicalBoxFragment::Create(this, block_or_line_writing_mode);
fragment->CheckType();
......
......@@ -504,6 +504,27 @@ void NGBoxFragmentPainter::PaintInlineFloatingChildren(
}
}
void NGBoxFragmentPainter::PaintFloatingItems(const PaintInfo& paint_info) {
DCHECK(items_);
DCHECK(PhysicalFragment().HasFloatingDescendants());
for (const std::unique_ptr<NGFragmentItem>& item : items_->Items()) {
const NGPhysicalBoxFragment* child_fragment = item->BoxFragment();
if (!child_fragment || child_fragment->HasSelfPaintingLayer() ||
!child_fragment->IsFloating())
continue;
// TODO(kojii): The float is outside of the inline formatting context and
// that it maybe another NG inline formatting context, NG block layout, or
// legacy. NGBoxFragmentPainter can handle only the first case. In order
// to cover more tests for other two cases, we always fallback to legacy,
// which will forward back to NGBoxFragmentPainter if the float is for
// NGBoxFragmentPainter. We can shortcut this for the first case when
// we're more stable.
ObjectPainter(*child_fragment->GetLayoutObject())
.PaintAllPhasesAtomically(paint_info);
}
}
void NGBoxFragmentPainter::PaintBlockFloatingChildren(
const NGPhysicalContainerFragment& container,
const PaintInfo& paint_info) {
......@@ -540,6 +561,10 @@ void NGBoxFragmentPainter::PaintFloats(const PaintInfo& paint_info) {
PaintInlineFloatingChildren(paint_fragment_->Children(), float_paint_info);
return;
}
if (items_) {
PaintFloatingItems(float_paint_info);
return;
}
PaintBlockFloatingChildren(PhysicalFragment(), float_paint_info);
}
......
......@@ -110,6 +110,7 @@ class NGBoxFragmentPainter : public BoxPainterBase {
const PhysicalOffset& paint_offset);
void PaintInlineFloatingChildren(NGPaintFragment::ChildList,
const PaintInfo&);
void PaintFloatingItems(const PaintInfo&);
void PaintBlockFloatingChildren(const NGPhysicalContainerFragment&,
const PaintInfo&);
void PaintFloats(const PaintInfo&);
......
......@@ -533,7 +533,6 @@ crbug.com/982194 external/wpt/compat/webkit-text-fill-color-property-002.html [
crbug.com/982194 external/wpt/contacts/contacts-select.https.window.html [ Failure ]
crbug.com/982194 external/wpt/css/CSS2/cascade-import/cascade-import-dynamic-002.xht [ Failure ]
crbug.com/982194 external/wpt/css/CSS2/cascade-import/cascade-import-dynamic-004.xht [ Failure ]
crbug.com/982194 external/wpt/css/CSS2/floats/float-nowrap-5.html [ Failure ]
crbug.com/982194 external/wpt/css/CSS2/floats/floats-placement-001.html [ Failure ]
crbug.com/982194 external/wpt/css/CSS2/floats/floats-placement-002.html [ Failure ]
crbug.com/982194 external/wpt/css/CSS2/floats/intrinsic-size-float-and-line.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