Commit 7b478a07 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make LayoutText::CollectLineBoxRects() to utilize NGInlineCursor

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


This patch also makes |NGInlineCursor::MoveTo()| to work during layout to use
previous layout result for scroll anchoring.

Bug: 982194
Change-Id: I9f046540ab797f274b88072f26bb241e101175d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1855152
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706323}
parent d9604dc7
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_abstract_inline_text_box.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_abstract_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_fragment_item.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.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_node.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_offset_mapping.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_offset_mapping.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
...@@ -450,17 +449,16 @@ static IntRect EllipsisRectForBox(InlineTextBox* box, ...@@ -450,17 +449,16 @@ static IntRect EllipsisRectForBox(InlineTextBox* box,
template <typename PhysicalRectCollector> template <typename PhysicalRectCollector>
void LayoutText::CollectLineBoxRects(const PhysicalRectCollector& yield, void LayoutText::CollectLineBoxRects(const PhysicalRectCollector& yield,
ClippingOption option) const { ClippingOption option) const {
if (const NGPhysicalBoxFragment* box_fragment = if (IsInLayoutNGInlineFormattingContext()) {
ContainingBlockFlowFragment()) { NGInlineCursor cursor;
const auto children = cursor.MoveTo(*this);
NGInlineFragmentTraversal::SelfFragmentsOf(*box_fragment, this); for (; cursor; cursor.MoveToNextForSameLayoutObject()) {
for (const auto& child : children) {
if (UNLIKELY(option != ClippingOption::kNoClipping)) { if (UNLIKELY(option != ClippingOption::kNoClipping)) {
DCHECK_EQ(option, ClippingOption::kClipToEllipsis); DCHECK_EQ(option, ClippingOption::kClipToEllipsis);
if (child.fragment->IsHiddenForPaint()) if (cursor.IsHiddenForPaint())
continue; continue;
} }
yield(child.RectInContainerBox()); yield(cursor.CurrentRect());
} }
return; return;
} }
......
...@@ -54,7 +54,9 @@ NGInlineCursor::NGInlineCursor(const LayoutBlockFlow& block_flow) { ...@@ -54,7 +54,9 @@ NGInlineCursor::NGInlineCursor(const LayoutBlockFlow& block_flow) {
return; return;
} }
NOTREACHED(); // We reach here in case of |ScrollANchor::NotifyBeforeLayout()| via
// |LayoutText::PhysicalLinesBoundingBox()|
// See external/wpt/css/css-scroll-anchoring/wrapped-text.html
} }
NGInlineCursor::NGInlineCursor(const NGFragmentItems& items) NGInlineCursor::NGInlineCursor(const NGFragmentItems& items)
...@@ -75,6 +77,8 @@ NGInlineCursor::NGInlineCursor(const NGInlineCursor& other) ...@@ -75,6 +77,8 @@ NGInlineCursor::NGInlineCursor(const NGInlineCursor& other)
current_paint_fragment_(other.current_paint_fragment_), current_paint_fragment_(other.current_paint_fragment_),
layout_inline_(other.layout_inline_) {} layout_inline_(other.layout_inline_) {}
NGInlineCursor::NGInlineCursor() = default;
bool NGInlineCursor::operator==(const NGInlineCursor& other) const { bool NGInlineCursor::operator==(const NGInlineCursor& other) const {
if (root_paint_fragment_) { if (root_paint_fragment_) {
return root_paint_fragment_ == other.root_paint_fragment_ && return root_paint_fragment_ == other.root_paint_fragment_ &&
...@@ -262,6 +266,10 @@ const PhysicalOffset NGInlineCursor::CurrentOffset() const { ...@@ -262,6 +266,10 @@ const PhysicalOffset NGInlineCursor::CurrentOffset() const {
return PhysicalOffset(); return PhysicalOffset();
} }
const PhysicalRect NGInlineCursor::CurrentRect() const {
return PhysicalRect(CurrentOffset(), CurrentSize());
}
TextDirection NGInlineCursor::CurrentResolvedDirection() const { TextDirection NGInlineCursor::CurrentResolvedDirection() const {
if (current_paint_fragment_) if (current_paint_fragment_)
return current_paint_fragment_->PhysicalFragment().ResolvedDirection(); return current_paint_fragment_->PhysicalFragment().ResolvedDirection();
...@@ -317,21 +325,26 @@ void NGInlineCursor::MakeNull() { ...@@ -317,21 +325,26 @@ void NGInlineCursor::MakeNull() {
} }
if (fragment_items_) if (fragment_items_)
return MoveToItem(items_.end()); return MoveToItem(items_.end());
NOTREACHED();
} }
void NGInlineCursor::InternalMoveTo(const LayoutObject& layout_object) { void NGInlineCursor::InternalMoveTo(const LayoutObject& layout_object) {
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext()); DCHECK(layout_object.IsInLayoutNGInlineFormattingContext());
if (root_paint_fragment_) { if (fragment_items_) {
const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object); item_iter_ = items_.begin();
if (!fragments.IsInLayoutNGInlineFormattingContext() || fragments.IsEmpty()) while (current_item_ && CurrentLayoutObject() != &layout_object)
return MakeNull(); MoveToNextItem();
return MoveTo(fragments.front()); return;
} }
DCHECK(IsItemCursor()); const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object);
item_iter_ = items_.begin(); if (!fragments.IsInLayoutNGInlineFormattingContext() || fragments.IsEmpty())
while (current_item_ && CurrentLayoutObject() != &layout_object) return MakeNull();
MoveToNextItem(); if (!root_paint_fragment_) {
// We reach here in case of |ScrollANchor::NotifyBeforeLayout()| via
// |LayoutText::PhysicalLinesBoundingBox()|
// See external/wpt/css/css-scroll-anchoring/wrapped-text.html
root_paint_fragment_ = fragments.front().Root();
}
return MoveTo(fragments.front());
} }
void NGInlineCursor::MoveTo(const LayoutObject& layout_object) { void NGInlineCursor::MoveTo(const LayoutObject& layout_object) {
......
...@@ -21,6 +21,7 @@ class NGFragmentItems; ...@@ -21,6 +21,7 @@ class NGFragmentItems;
class NGPaintFragment; class NGPaintFragment;
class NGPhysicalBoxFragment; class NGPhysicalBoxFragment;
struct PhysicalOffset; struct PhysicalOffset;
struct PhysicalRect;
struct PhysicalSize; struct PhysicalSize;
// This class traverses fragments in an inline formatting context. // This class traverses fragments in an inline formatting context.
...@@ -38,6 +39,7 @@ class CORE_EXPORT NGInlineCursor { ...@@ -38,6 +39,7 @@ class CORE_EXPORT NGInlineCursor {
explicit NGInlineCursor(const NGFragmentItems& items); explicit NGInlineCursor(const NGFragmentItems& items);
explicit NGInlineCursor(const NGPaintFragment& root_paint_fragment); explicit NGInlineCursor(const NGPaintFragment& root_paint_fragment);
NGInlineCursor(const NGInlineCursor& other); NGInlineCursor(const NGInlineCursor& other);
NGInlineCursor();
bool operator==(const NGInlineCursor& other) const; bool operator==(const NGInlineCursor& other) const;
bool operator!=(const NGInlineCursor& other) const { bool operator!=(const NGInlineCursor& other) const {
...@@ -110,6 +112,7 @@ class CORE_EXPORT NGInlineCursor { ...@@ -110,6 +112,7 @@ class CORE_EXPORT NGInlineCursor {
// The offset relative to the root of the inline formatting context. // The offset relative to the root of the inline formatting context.
const PhysicalOffset CurrentOffset() const; const PhysicalOffset CurrentOffset() const;
const PhysicalRect CurrentRect() const;
const PhysicalSize CurrentSize() const; const PhysicalSize CurrentSize() const;
// Returns start/end of offset in text content of current text fragment. // Returns start/end of offset in text content of current text fragment.
...@@ -171,11 +174,6 @@ class CORE_EXPORT NGInlineCursor { ...@@ -171,11 +174,6 @@ class CORE_EXPORT NGInlineCursor {
private: private:
using ItemsSpan = base::span<const std::unique_ptr<NGFragmentItem>>; using ItemsSpan = base::span<const std::unique_ptr<NGFragmentItem>>;
// |NGInlineCursor| is either paint fragment cursor or fragment item cursor.
// TODO(yosin): When we implement default constructor of |NGInlineCursor|,
// we'll call it "void cursor" instead of "null cursor".
NGInlineCursor() = delete;
// True if current position is descendant or self of |layout_object|. // True if current position is descendant or self of |layout_object|.
// Note: This function is used for moving cursor in culled inline boxes. // Note: This function is used for moving cursor in culled inline boxes.
bool IsInclusiveDescendantOf(const LayoutObject& layout_object) const; bool IsInclusiveDescendantOf(const LayoutObject& layout_object) const;
......
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