Commit 4cc79ac5 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[FragmentItem] Make items const

This patch adds `const` to the instances of |NGFragmentItem|.

Bug: 982194
Change-Id: Id8262130e0e516c904c4f441fb05b04076d866d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2139635Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758201}
parent 5927ec42
...@@ -23,7 +23,7 @@ NGFragmentItems::NGFragmentItems(NGFragmentItemsBuilder* builder) ...@@ -23,7 +23,7 @@ NGFragmentItems::NGFragmentItems(NGFragmentItemsBuilder* builder)
first_line_text_content_(std::move(builder->first_line_text_content_)) {} first_line_text_content_(std::move(builder->first_line_text_content_)) {}
void NGFragmentItems::AssociateWithLayoutObject() const { void NGFragmentItems::AssociateWithLayoutObject() const {
const Vector<scoped_refptr<NGFragmentItem>>* items = &items_; const Vector<scoped_refptr<const NGFragmentItem>>* items = &items_;
DCHECK(std::all_of(items->begin(), items->end(), [](const auto& item) { DCHECK(std::all_of(items->begin(), items->end(), [](const auto& item) {
return !item->DeltaToNextForSameLayoutObject(); return !item->DeltaToNextForSameLayoutObject();
})); }));
...@@ -62,8 +62,7 @@ void NGFragmentItems::ClearAssociatedFragments() const { ...@@ -62,8 +62,7 @@ void NGFragmentItems::ClearAssociatedFragments() const {
if (items_.size() <= 1) if (items_.size() <= 1)
return; return;
LayoutObject* last_object = nullptr; LayoutObject* last_object = nullptr;
for (const auto& item : base::span<const scoped_refptr<NGFragmentItem>>( for (const auto& item : base::make_span(items_.begin() + 1, items_.end())) {
items_.begin() + 1, items_.end())) {
if (!ShouldAssociateWithLayoutObject(*item)) { if (!ShouldAssociateWithLayoutObject(*item)) {
// These items are not associated and that no need to clear. // These items are not associated and that no need to clear.
DCHECK_EQ(item->DeltaToNextForSameLayoutObject(), 0u); DCHECK_EQ(item->DeltaToNextForSameLayoutObject(), 0u);
......
...@@ -20,7 +20,9 @@ class CORE_EXPORT NGFragmentItems { ...@@ -20,7 +20,9 @@ class CORE_EXPORT NGFragmentItems {
public: public:
NGFragmentItems(NGFragmentItemsBuilder* builder); NGFragmentItems(NGFragmentItemsBuilder* builder);
const Vector<scoped_refptr<NGFragmentItem>>& Items() const { return items_; } const Vector<scoped_refptr<const NGFragmentItem>>& Items() const {
return items_;
}
const String& Text(bool first_line) const { const String& Text(bool first_line) const {
return UNLIKELY(first_line) ? first_line_text_content_ : text_content_; return UNLIKELY(first_line) ? first_line_text_content_ : text_content_;
...@@ -36,7 +38,7 @@ class CORE_EXPORT NGFragmentItems { ...@@ -36,7 +38,7 @@ class CORE_EXPORT NGFragmentItems {
private: private:
// TODO(kojii): inline capacity TBD. // TODO(kojii): inline capacity TBD.
Vector<scoped_refptr<NGFragmentItem>> items_; Vector<scoped_refptr<const NGFragmentItem>> items_;
String text_content_; String text_content_;
String first_line_text_content_; String first_line_text_content_;
}; };
......
...@@ -191,10 +191,10 @@ void NGFragmentItemsBuilder::AddItems(const NGFragmentItems& items, ...@@ -191,10 +191,10 @@ void NGFragmentItemsBuilder::AddItems(const NGFragmentItems& items,
first_line_text_content_ = items.Text(true); first_line_text_content_ = items.Text(true);
} }
const Vector<scoped_refptr<NGFragmentItem>>& NGFragmentItemsBuilder::Items( const Vector<scoped_refptr<const NGFragmentItem>>&
WritingMode writing_mode, NGFragmentItemsBuilder::Items(WritingMode writing_mode,
TextDirection direction, TextDirection direction,
const PhysicalSize& outer_size) { const PhysicalSize& outer_size) {
ConvertToPhysical(writing_mode, direction, outer_size); ConvertToPhysical(writing_mode, direction, outer_size);
return items_; return items_;
} }
...@@ -212,13 +212,13 @@ void NGFragmentItemsBuilder::ConvertToPhysical(WritingMode writing_mode, ...@@ -212,13 +212,13 @@ void NGFragmentItemsBuilder::ConvertToPhysical(WritingMode writing_mode,
// convert their logical offsets. // convert their logical offsets.
const WritingMode line_writing_mode = ToLineWritingMode(writing_mode); const WritingMode line_writing_mode = ToLineWritingMode(writing_mode);
scoped_refptr<NGFragmentItem>* item_iter = items_.begin(); scoped_refptr<const NGFragmentItem>* item_iter = items_.begin();
const LogicalOffset* offset = offsets_.begin(); const LogicalOffset* offset = offsets_.begin();
for (; item_iter != items_.end(); ++item_iter, ++offset) { for (; item_iter != items_.end(); ++item_iter, ++offset) {
DCHECK_NE(offset, offsets_.end()); DCHECK_NE(offset, offsets_.end());
NGFragmentItem* item = item_iter->get(); const NGFragmentItem* item = item_iter->get();
item->SetOffset(offset->ConvertToPhysical(writing_mode, direction, const_cast<NGFragmentItem*>(item)->SetOffset(offset->ConvertToPhysical(
outer_size, item->Size())); writing_mode, direction, outer_size, item->Size()));
// Transform children of lines separately from children of the block, // Transform children of lines separately from children of the block,
// because they may have different directions from the block. To do // because they may have different directions from the block. To do
...@@ -236,7 +236,7 @@ void NGFragmentItemsBuilder::ConvertToPhysical(WritingMode writing_mode, ...@@ -236,7 +236,7 @@ void NGFragmentItemsBuilder::ConvertToPhysical(WritingMode writing_mode,
item = item_iter->get(); item = item_iter->get();
// Use `kLtr` because inline items are after bidi-reoder, and that // Use `kLtr` because inline items are after bidi-reoder, and that
// their offset is visual, not logical. // their offset is visual, not logical.
item->SetOffset( const_cast<NGFragmentItem*>(item)->SetOffset(
offset->ConvertToPhysical(line_writing_mode, TextDirection::kLtr, offset->ConvertToPhysical(line_writing_mode, TextDirection::kLtr,
line_box_bounds.size, item->Size()) + line_box_bounds.size, item->Size()) +
line_box_bounds.offset); line_box_bounds.offset);
...@@ -251,7 +251,7 @@ void NGFragmentItemsBuilder::ConvertToPhysical(WritingMode writing_mode, ...@@ -251,7 +251,7 @@ void NGFragmentItemsBuilder::ConvertToPhysical(WritingMode writing_mode,
base::Optional<LogicalOffset> NGFragmentItemsBuilder::LogicalOffsetFor( base::Optional<LogicalOffset> NGFragmentItemsBuilder::LogicalOffsetFor(
const LayoutObject& layout_object) const { const LayoutObject& layout_object) const {
DCHECK_EQ(items_.size(), offsets_.size()); DCHECK_EQ(items_.size(), offsets_.size());
for (const scoped_refptr<NGFragmentItem>& item : items_) { for (const scoped_refptr<const NGFragmentItem>& item : items_) {
if (item->GetLayoutObject() == &layout_object) if (item->GetLayoutObject() == &layout_object)
return offsets_[&item - items_.begin()]; return offsets_[&item - items_.begin()];
} }
......
...@@ -73,7 +73,7 @@ class CORE_EXPORT NGFragmentItemsBuilder { ...@@ -73,7 +73,7 @@ class CORE_EXPORT NGFragmentItemsBuilder {
// containing block geometry for OOF-positioned nodes. // containing block geometry for OOF-positioned nodes.
// //
// Once this method has been called, new items cannot be added. // Once this method has been called, new items cannot be added.
const Vector<scoped_refptr<NGFragmentItem>>& const Vector<scoped_refptr<const NGFragmentItem>>&
Items(WritingMode, TextDirection, const PhysicalSize& outer_size); Items(WritingMode, TextDirection, const PhysicalSize& outer_size);
// Build a |NGFragmentItems|. The builder cannot build twice because data set // Build a |NGFragmentItems|. The builder cannot build twice because data set
...@@ -90,7 +90,7 @@ class CORE_EXPORT NGFragmentItemsBuilder { ...@@ -90,7 +90,7 @@ class CORE_EXPORT NGFragmentItemsBuilder {
TextDirection direction, TextDirection direction,
const PhysicalSize& outer_size); const PhysicalSize& outer_size);
Vector<scoped_refptr<NGFragmentItem>> items_; Vector<scoped_refptr<const NGFragmentItem>> items_;
Vector<LogicalOffset> offsets_; Vector<LogicalOffset> offsets_;
String text_content_; String text_content_;
String first_line_text_content_; String first_line_text_content_;
......
...@@ -45,7 +45,7 @@ class CORE_EXPORT NGInlineCursorPosition { ...@@ -45,7 +45,7 @@ class CORE_EXPORT NGInlineCursorPosition {
STACK_ALLOCATED(); STACK_ALLOCATED();
public: public:
using ItemsSpan = base::span<const scoped_refptr<NGFragmentItem>>; using ItemsSpan = base::span<const scoped_refptr<const NGFragmentItem>>;
const NGPaintFragment* PaintFragment() const { return paint_fragment_; } const NGPaintFragment* PaintFragment() const { return paint_fragment_; }
const NGFragmentItem* Item() const { return item_; } const NGFragmentItem* Item() const { return item_; }
...@@ -170,7 +170,7 @@ class CORE_EXPORT NGInlineCursor { ...@@ -170,7 +170,7 @@ class CORE_EXPORT NGInlineCursor {
STACK_ALLOCATED(); STACK_ALLOCATED();
public: public:
using ItemsSpan = base::span<const scoped_refptr<NGFragmentItem>>; using ItemsSpan = base::span<const scoped_refptr<const NGFragmentItem>>;
explicit NGInlineCursor(const LayoutBlockFlow& block_flow); explicit NGInlineCursor(const LayoutBlockFlow& block_flow);
explicit NGInlineCursor(const NGFragmentItems& items); explicit NGInlineCursor(const NGFragmentItems& items);
......
...@@ -78,7 +78,7 @@ void GatherInlineContainerFragmentsFromLinebox( ...@@ -78,7 +78,7 @@ void GatherInlineContainerFragmentsFromLinebox(
} }
void GatherInlineContainerFragmentsFromItems( void GatherInlineContainerFragmentsFromItems(
const Vector<scoped_refptr<NGFragmentItem>>& items, const Vector<scoped_refptr<const NGFragmentItem>>& items,
const PhysicalOffset& box_offset, const PhysicalOffset& box_offset,
NGBoxFragmentBuilder::InlineContainingBlockMap* inline_containing_block_map, NGBoxFragmentBuilder::InlineContainingBlockMap* inline_containing_block_map,
HashMap<const LayoutObject*, LineBoxPair>* containing_linebox_map) { HashMap<const LayoutObject*, LineBoxPair>* containing_linebox_map) {
......
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