Commit d91cd688 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make LayoutInline to utilize NGInlineCursor

This patch change |LayoutInline| to utilize |NGInlineCursor| instead of
|NGInlineFragmentTraversal::SelfFragmentsOf()| as preparation of migrating to
|NGFragmentItem|.

Bug: 982194
Change-Id: I22f4c8ed1048c2903e198152cb5d7cd6bb12271b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862534
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706815}
parent c0197eb7
......@@ -37,7 +37,7 @@
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/line/inline_text_box.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_fragment_item.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_fragment_traversal.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
#include "third_party/blink/renderer/core/layout/ng/layout_ng_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/ng_outline_utils.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
......@@ -55,15 +55,6 @@ namespace blink {
namespace {
// TODO(layout-dev): Once we generate fragment for all inline element, we should
// use |LayoutObject::EnclosingBlockFlowFragment()|.
const NGPhysicalBoxFragment* ContainingBlockFlowFragmentOf(
const LayoutInline& node) {
if (!RuntimeEnabledFeatures::LayoutNGEnabled())
return nullptr;
return node.ContainingBlockFlowFragment();
}
// TODO(xiaochengh): Deduplicate with a similar function in ng_paint_fragment.cc
// ::before, ::after and ::first-letter can be hit test targets.
bool CanBeHitTestTargetPseudoNodeStyle(const ComputedStyle& style) {
......@@ -787,12 +778,10 @@ template <typename PhysicalRectCollector>
void LayoutInline::CollectLineBoxRects(
const PhysicalRectCollector& yield) const {
if (IsInLayoutNGInlineFormattingContext()) {
const auto* box_fragment = ContainingBlockFlowFragmentOf(*this);
if (!box_fragment)
return;
for (const auto& fragment :
NGInlineFragmentTraversal::SelfFragmentsOf(*box_fragment, this))
yield(fragment.RectInContainerBox());
NGInlineCursor cursor;
cursor.MoveTo(*this);
for (; cursor; cursor.MoveToNextForSameLayoutObject())
yield(cursor.CurrentRect());
return;
}
if (!AlwaysCreateLineBoxes()) {
......@@ -936,15 +925,11 @@ void LayoutInline::AbsoluteQuadsForSelf(Vector<FloatQuad>& quads,
base::Optional<PhysicalOffset> LayoutInline::FirstLineBoxTopLeftInternal()
const {
if (IsInLayoutNGInlineFormattingContext()) {
const NGPhysicalBoxFragment* box_fragment =
ContainingBlockFlowFragmentOf(*this);
if (!box_fragment)
NGInlineCursor cursor;
cursor.MoveTo(*this);
if (!cursor)
return base::nullopt;
const auto& fragments =
NGInlineFragmentTraversal::SelfFragmentsOf(*box_fragment, this);
if (fragments.IsEmpty())
return base::nullopt;
return fragments.front().offset_to_container_box;
return cursor.CurrentOffset();
}
if (const InlineBox* first_box = FirstLineBoxIncludingCulling()) {
LayoutPoint location = first_box->Location();
......@@ -1083,17 +1068,15 @@ bool LayoutInline::HitTestCulledInline(
DCHECK(ContainingNGBlockFlow());
DCHECK(container_fragment->IsDescendantOfNotSelf(
*ContainingNGBlockFlow()->PaintFragment()));
const auto& traversal_root =
To<NGPhysicalContainerFragment>(container_fragment->PhysicalFragment());
DCHECK(traversal_root.IsInline() || traversal_root.IsLineBox());
PhysicalOffset root_offset =
container_fragment->InlineOffsetToContainerBox();
const auto& descendants =
NGInlineFragmentTraversal::SelfFragmentsOf(traversal_root, this);
for (const auto& descendant : descendants) {
PhysicalRect rect = descendant.RectInContainerBox();
rect.Move(root_offset);
yield(rect);
DCHECK(container_fragment->PhysicalFragment().IsInline() ||
container_fragment->PhysicalFragment().IsLineBox());
NGInlineCursor cursor;
cursor.MoveTo(*this);
for (; cursor; cursor.MoveToNextForSameLayoutObject()) {
if (!cursor.CurrentPaintFragment()->IsDescendantOfNotSelf(
*container_fragment))
continue;
yield(cursor.CurrentRect());
}
} else {
DCHECK(!ContainingNGBlockFlow());
......@@ -1142,15 +1125,11 @@ PositionWithAffinity LayoutInline::PositionForPoint(
PhysicalRect LayoutInline::PhysicalLinesBoundingBox() const {
if (IsInLayoutNGInlineFormattingContext()) {
const NGPhysicalBoxFragment* box_fragment =
ContainingBlockFlowFragmentOf(*this);
if (!box_fragment)
return PhysicalRect();
NGInlineCursor cursor;
cursor.MoveTo(*this);
PhysicalRect bounding_box;
auto children =
NGInlineFragmentTraversal::SelfFragmentsOf(*box_fragment, this);
for (const auto& child : children)
bounding_box.UniteIfNonZero(child.RectInContainerBox());
for (; cursor; cursor.MoveToNextForSameLayoutObject())
bounding_box.UniteIfNonZero(cursor.CurrentRect());
return bounding_box;
}
......
......@@ -348,12 +348,19 @@ void NGInlineCursor::InternalMoveTo(const LayoutObject& layout_object) {
}
void NGInlineCursor::MoveTo(const LayoutObject& layout_object) {
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext()) << layout_object;
InternalMoveTo(layout_object);
if (IsNotNull() || !layout_object.IsLayoutInline()) {
layout_inline_ = nullptr;
return;
}
// In case of |layout_object| is cullred inline.
if (!fragment_items_ && !root_paint_fragment_) {
root_paint_fragment_ =
layout_object.RootInlineFormattingContext()->PaintFragment();
if (!root_paint_fragment_)
return MakeNull();
}
layout_inline_ = ToLayoutInline(&layout_object);
MoveToFirst();
while (IsNotNull() && !IsInclusiveDescendantOf(layout_object))
......@@ -437,8 +444,12 @@ void NGInlineCursor::MoveToNextForSameLayoutObject() {
}
if (current_paint_fragment_) {
if (auto* paint_fragment =
current_paint_fragment_->NextForSameLayoutObject())
current_paint_fragment_->NextForSameLayoutObject()) {
// |paint_fragment| can be in another fragment tree rooted by
// |root_paint_fragment_|, e.g. "multicol-span-all-restyle-002.html"
root_paint_fragment_ = paint_fragment->Root();
return MoveTo(*paint_fragment);
}
return MakeNull();
}
if (current_item_) {
......
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