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

[FragmentItem] Remove |NGFragmentItem::ItemsFor|

This function was added to be the same interface as
|NGPaintFragment::InlineFragmentsFor|, but as
|NGInlineCursor| evoles, it has the same functionality
though |MoveTo(const LayoutObject&)| and
|MoveToNextForSameLayoutObject()|.

Now we prefer |NGInlineCurosr| for all traversals that this
patch removes |ItemsFor()| function and switch all usages to
|NGInlineCusror|.

Bug: 982194
Change-Id: Ia9dfd4f608d8cfc2c5f6ccc5b40b1e1dda0876f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2022445Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735349}
parent 3bc054cd
......@@ -281,7 +281,11 @@ PhysicalRect NGFragmentItem::LocalVisualRectFor(
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext());
PhysicalRect visual_rect;
for (const NGFragmentItem& item : ItemsFor(layout_object)) {
NGInlineCursor cursor;
for (cursor.MoveTo(layout_object); cursor;
cursor.MoveToNextForSameLayoutObject()) {
DCHECK(cursor.Current().Item());
const NGFragmentItem& item = *cursor.Current().Item();
if (UNLIKELY(item.IsHiddenForPaint()))
continue;
PhysicalRect child_visual_rect = item.SelfInkOverflow();
......@@ -445,49 +449,6 @@ unsigned NGFragmentItem::TextOffsetForPoint(
return inline_offset <= size.inline_size / 2 ? StartOffset() : EndOffset();
}
NGFragmentItem::ItemsForLayoutObject NGFragmentItem::ItemsFor(
const LayoutObject& layout_object) {
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext());
DCHECK(layout_object.IsText() || layout_object.IsLayoutInline() ||
(layout_object.IsBox() && layout_object.IsInline()));
if (const LayoutBlockFlow* block_flow =
layout_object.RootInlineFormattingContext()) {
if (const NGPhysicalBoxFragment* fragment = block_flow->CurrentFragment()) {
if (wtf_size_t index = layout_object.FirstInlineFragmentItemIndex()) {
const auto& items = fragment->Items()->Items();
return ItemsForLayoutObject(items, index, items[index].get());
}
// TODO(yosin): Once we update all usages of |FirstInlineFragment()|,
// we should get rid of below code.
if (const NGFragmentItems* items = fragment->Items()) {
for (unsigned i = 0; i < items->Items().size(); ++i) {
const NGFragmentItem* item = items->Items()[i].get();
if (item->GetLayoutObject() == &layout_object)
return ItemsForLayoutObject(items->Items(), i, item);
}
}
}
}
return ItemsForLayoutObject();
}
NGFragmentItem::ItemsForLayoutObject::Iterator&
NGFragmentItem::ItemsForLayoutObject::Iterator::operator++() {
// TODO(kojii): This is a hot function needed by paint and several other
// operations. Make this fast, by not iterating.
if (!current_)
return *this;
if (!current_->delta_to_next_for_same_layout_object_) {
current_ = nullptr;
return *this;
}
index_ += current_->delta_to_next_for_same_layout_object_;
current_ = (*items_)[index_].get();
return *this;
}
std::ostream& operator<<(std::ostream& ostream, const NGFragmentItem& item) {
ostream << "{";
switch (item.Type()) {
......
......@@ -177,52 +177,6 @@ class CORE_EXPORT NGFragmentItem : public DisplayItemClient {
IntRect VisualRect() const override;
IntRect PartialInvalidationVisualRect() const override;
// Find |NGFragmentItem|s that are associated with a |LayoutObject|.
class CORE_EXPORT ItemsForLayoutObject {
STACK_ALLOCATED();
public:
ItemsForLayoutObject() = default;
ItemsForLayoutObject(const Vector<std::unique_ptr<NGFragmentItem>>& items,
unsigned first_index,
const NGFragmentItem* first_item)
: items_(&items), first_item_(first_item), first_index_(first_index) {}
bool IsEmpty() const { return !items_; }
class CORE_EXPORT Iterator {
public:
Iterator(const Vector<std::unique_ptr<NGFragmentItem>>* items,
unsigned index,
const NGFragmentItem* item)
: current_(item), items_(items), index_(index) {}
const NGFragmentItem& operator*() const { return *current_; }
const NGFragmentItem& operator->() const { return *current_; }
Iterator& operator++();
bool operator==(const Iterator& other) const {
return current_ == other.current_;
}
bool operator!=(const Iterator& other) const {
return current_ != other.current_;
}
private:
const NGFragmentItem* current_;
const Vector<std::unique_ptr<NGFragmentItem>>* items_;
unsigned index_;
};
using iterator = Iterator;
iterator begin() const {
return Iterator(items_, first_index_, first_item_);
}
iterator end() const { return Iterator(nullptr, 0, nullptr); }
private:
const Vector<std::unique_ptr<NGFragmentItem>>* items_;
const NGFragmentItem* first_item_;
unsigned first_index_;
};
static ItemsForLayoutObject ItemsFor(const LayoutObject& layout_object);
static PhysicalRect LocalVisualRectFor(const LayoutObject& layout_object);
// Re-compute the ink overflow for the |cursor| until its end.
......
......@@ -8,6 +8,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_fragment_items.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
......@@ -22,9 +23,12 @@ class NGFragmentItemTest : public NGLayoutTest,
Vector<const NGFragmentItem*> ItemsForAsVector(
const LayoutObject& layout_object) {
const auto items = NGFragmentItem::ItemsFor(layout_object);
Vector<const NGFragmentItem*> list;
for (const NGFragmentItem& item : items) {
NGInlineCursor cursor;
for (cursor.MoveTo(layout_object); cursor;
cursor.MoveToNextForSameLayoutObject()) {
DCHECK(cursor.Current().Item());
const NGFragmentItem& item = *cursor.Current().Item();
EXPECT_EQ(item.GetLayoutObject(), &layout_object);
list.push_back(&item);
}
......
......@@ -124,7 +124,7 @@ class CORE_EXPORT NGInlineCursor {
// or after last fragment in tree.
bool IsNull() const { return !Current(); }
bool IsNotNull() const { return Current(); }
explicit operator bool() const { return Current(); }
operator bool() const { return Current(); }
// True if fragment at the current position can have children.
bool CanHaveChildren() const;
......
......@@ -34,7 +34,14 @@ inline bool HasMultiplePaintFragments(const LayoutObject& layout_object) {
}
inline bool HasMultipleFragmentItems(const LayoutObject& layout_object) {
return HasMultipleItems(NGFragmentItem::ItemsFor(layout_object));
NGInlineCursor cursor;
cursor.MoveTo(layout_object);
DCHECK(cursor);
if (cursor) {
cursor.MoveToNextForSameLayoutObject();
return cursor;
}
return false;
}
} // 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