Commit 6ef521bf authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Get rid of NGPaintFragmentTraversalContext

Because of |NGPaintFragmentTraversal| and |NGPaintFragmentTraversalContext|
provide same functionalities and we prefer |NGPaintFragmentTraversal|, this
patch removes |NGPaintFragmentTraversalContext| by replacing usage of them by
|NGPaintFragmentTraversal| to simplify code base for improving code health and
ease of introducing |NGFragmentItem|.

Bug: 982194
Change-Id: I6b1f031ef54cd25eb8df56e8a2ed17dd1c5eb288
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1689907
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691508}
parent b1dd5a23
...@@ -35,8 +35,10 @@ class AbstractInlineBox { ...@@ -35,8 +35,10 @@ class AbstractInlineBox {
explicit AbstractInlineBox(const InlineBox& box) explicit AbstractInlineBox(const InlineBox& box)
: type_(InstanceType::kOldLayout), inline_box_(&box) {} : type_(InstanceType::kOldLayout), inline_box_(&box) {}
explicit AbstractInlineBox(const NGPaintFragment& fragment) explicit AbstractInlineBox(const NGPaintFragment& paint_fragment)
: AbstractInlineBox(NGPaintFragmentTraversalContext::Create(&fragment)) {} : AbstractInlineBox(
NGPaintFragmentTraversal(*paint_fragment.ContainerLineBox(),
paint_fragment)) {}
bool IsNotNull() const { return type_ != InstanceType::kNull; } bool IsNotNull() const { return type_ != InstanceType::kNull; }
bool IsNull() const { return !IsNotNull(); } bool IsNull() const { return !IsNotNull(); }
...@@ -52,7 +54,7 @@ class AbstractInlineBox { ...@@ -52,7 +54,7 @@ class AbstractInlineBox {
case InstanceType::kOldLayout: case InstanceType::kOldLayout:
return inline_box_ == other.inline_box_; return inline_box_ == other.inline_box_;
case InstanceType::kNG: case InstanceType::kNG:
return paint_fragment_ == other.paint_fragment_; return paint_fragment_.get() == other.paint_fragment_.get();
} }
NOTREACHED(); NOTREACHED();
return false; return false;
...@@ -66,8 +68,8 @@ class AbstractInlineBox { ...@@ -66,8 +68,8 @@ class AbstractInlineBox {
const NGPaintFragment& GetNGPaintFragment() const { const NGPaintFragment& GetNGPaintFragment() const {
DCHECK(IsNG()); DCHECK(IsNG());
DCHECK(!paint_fragment_.IsNull()); DCHECK(!paint_fragment_.IsAtEnd());
return *paint_fragment_.GetFragment(); return *paint_fragment_;
} }
UBiDiLevel BidiLevel() const { UBiDiLevel BidiLevel() const {
...@@ -89,9 +91,10 @@ class AbstractInlineBox { ...@@ -89,9 +91,10 @@ class AbstractInlineBox {
const InlineBox* result = GetInlineBox().PrevLeafChild(); const InlineBox* result = GetInlineBox().PrevLeafChild();
return result ? AbstractInlineBox(*result) : AbstractInlineBox(); return result ? AbstractInlineBox(*result) : AbstractInlineBox();
} }
const NGPaintFragmentTraversalContext result = NGPaintFragmentTraversal result(paint_fragment_);
NGPaintFragmentTraversal::PreviousInlineLeafOf(paint_fragment_); result.MoveToPreviousInlineLeaf();
return result.IsNull() ? AbstractInlineBox() : AbstractInlineBox(result); return result.IsAtEnd() ? AbstractInlineBox()
: AbstractInlineBox(std::move(result));
} }
AbstractInlineBox PrevLeafChildIgnoringLineBreak() const { AbstractInlineBox PrevLeafChildIgnoringLineBreak() const {
...@@ -100,10 +103,10 @@ class AbstractInlineBox { ...@@ -100,10 +103,10 @@ class AbstractInlineBox {
const InlineBox* result = GetInlineBox().PrevLeafChildIgnoringLineBreak(); const InlineBox* result = GetInlineBox().PrevLeafChildIgnoringLineBreak();
return result ? AbstractInlineBox(*result) : AbstractInlineBox(); return result ? AbstractInlineBox(*result) : AbstractInlineBox();
} }
const NGPaintFragmentTraversalContext result = NGPaintFragmentTraversal result(paint_fragment_);
NGPaintFragmentTraversal::PreviousInlineLeafOfIgnoringLineBreak( result.MoveToPreviousInlineLeafIgnoringLineBreak();
paint_fragment_); return result.IsAtEnd() ? AbstractInlineBox()
return result.IsNull() ? AbstractInlineBox() : AbstractInlineBox(result); : AbstractInlineBox(std::move(result));
} }
AbstractInlineBox NextLeafChild() const { AbstractInlineBox NextLeafChild() const {
...@@ -112,9 +115,10 @@ class AbstractInlineBox { ...@@ -112,9 +115,10 @@ class AbstractInlineBox {
const InlineBox* result = GetInlineBox().NextLeafChild(); const InlineBox* result = GetInlineBox().NextLeafChild();
return result ? AbstractInlineBox(*result) : AbstractInlineBox(); return result ? AbstractInlineBox(*result) : AbstractInlineBox();
} }
const NGPaintFragmentTraversalContext result = NGPaintFragmentTraversal result(paint_fragment_);
NGPaintFragmentTraversal::NextInlineLeafOf(paint_fragment_); result.MoveToNextInlineLeaf();
return result.IsNull() ? AbstractInlineBox() : AbstractInlineBox(result); return result.IsAtEnd() ? AbstractInlineBox()
: AbstractInlineBox(std::move(result));
} }
AbstractInlineBox NextLeafChildIgnoringLineBreak() const { AbstractInlineBox NextLeafChildIgnoringLineBreak() const {
...@@ -123,10 +127,10 @@ class AbstractInlineBox { ...@@ -123,10 +127,10 @@ class AbstractInlineBox {
const InlineBox* result = GetInlineBox().NextLeafChildIgnoringLineBreak(); const InlineBox* result = GetInlineBox().NextLeafChildIgnoringLineBreak();
return result ? AbstractInlineBox(*result) : AbstractInlineBox(); return result ? AbstractInlineBox(*result) : AbstractInlineBox();
} }
const NGPaintFragmentTraversalContext result = NGPaintFragmentTraversal result(paint_fragment_);
NGPaintFragmentTraversal::NextInlineLeafOfIgnoringLineBreak( result.MoveToNextInlineLeafIgnoringLineBreak();
paint_fragment_); return result.IsAtEnd() ? AbstractInlineBox()
return result.IsNull() ? AbstractInlineBox() : AbstractInlineBox(result); : AbstractInlineBox(std::move(result));
} }
TextDirection ParagraphDirection() const { TextDirection ParagraphDirection() const {
...@@ -137,8 +141,8 @@ class AbstractInlineBox { ...@@ -137,8 +141,8 @@ class AbstractInlineBox {
} }
private: private:
explicit AbstractInlineBox(const NGPaintFragmentTraversalContext& fragment) explicit AbstractInlineBox(NGPaintFragmentTraversal&& fragment)
: type_(InstanceType::kNG), paint_fragment_(fragment) {} : type_(InstanceType::kNG), paint_fragment_(std::move(fragment)) {}
enum class InstanceType { kNull, kOldLayout, kNG }; enum class InstanceType { kNull, kOldLayout, kNG };
InstanceType type_; InstanceType type_;
...@@ -146,7 +150,7 @@ class AbstractInlineBox { ...@@ -146,7 +150,7 @@ class AbstractInlineBox {
// Only one of |inline_box_| or |paint_fragment_| is used, but we cannot make // Only one of |inline_box_| or |paint_fragment_| is used, but we cannot make
// them union because of non-trivial destructor. // them union because of non-trivial destructor.
const InlineBox* inline_box_; const InlineBox* inline_box_;
NGPaintFragmentTraversalContext paint_fragment_; NGPaintFragmentTraversal paint_fragment_;
}; };
// |SideAffinity| represents the left or right side of a leaf inline // |SideAffinity| represents the left or right side of a leaf inline
......
...@@ -13,32 +13,6 @@ namespace blink { ...@@ -13,32 +13,6 @@ namespace blink {
class NGPaintFragment; class NGPaintFragment;
// Represents an NGPaintFragment by its parent and its index in the parent's
// |Children()| vector.
struct CORE_EXPORT NGPaintFragmentTraversalContext {
STACK_ALLOCATED();
public:
NGPaintFragmentTraversalContext() = default;
explicit NGPaintFragmentTraversalContext(const NGPaintFragment* fragment);
NGPaintFragmentTraversalContext(const NGPaintFragment* parent,
unsigned index);
// TODO(kojii): deprecated, prefer constructors to avoid unexpected
// instantiation.
static NGPaintFragmentTraversalContext Create(const NGPaintFragment*);
bool IsNull() const { return !parent; }
const NGPaintFragment* GetFragment() const;
bool operator==(const NGPaintFragmentTraversalContext& other) const {
return parent == other.parent && index == other.index;
}
const NGPaintFragment* parent = nullptr;
unsigned index = 0;
Vector<NGPaintFragment*, 16> siblings;
};
// Utility class for traversing the paint fragment tree. // Utility class for traversing the paint fragment tree.
// //
// This class has two groups of functions; one is a traversing cursor, by // This class has two groups of functions; one is a traversing cursor, by
...@@ -48,6 +22,11 @@ class CORE_EXPORT NGPaintFragmentTraversal { ...@@ -48,6 +22,11 @@ class CORE_EXPORT NGPaintFragmentTraversal {
STACK_ALLOCATED(); STACK_ALLOCATED();
public: public:
NGPaintFragmentTraversal(const NGPaintFragmentTraversal& other);
NGPaintFragmentTraversal(NGPaintFragmentTraversal&& other);
NGPaintFragmentTraversal();
NGPaintFragmentTraversal& operator=(const NGPaintFragmentTraversal& other);
// Create an instance to traverse descendants of |root|. // Create an instance to traverse descendants of |root|.
explicit NGPaintFragmentTraversal(const NGPaintFragment& root); explicit NGPaintFragmentTraversal(const NGPaintFragment& root);
...@@ -90,6 +69,15 @@ class CORE_EXPORT NGPaintFragmentTraversal { ...@@ -90,6 +69,15 @@ class CORE_EXPORT NGPaintFragmentTraversal {
// Note: When |IsAtEnd()| is true, this function does nothing. // Note: When |IsAtEnd()| is true, this function does nothing.
void MoveToPrevious(); void MoveToPrevious();
// Returns the previous/next inline leaf fragment (text or atomic inline) of
// the passed fragment, which itself must be inline.
void MoveToPreviousInlineLeaf();
void MoveToNextInlineLeaf();
// Variants of the above two skipping line break fragments.
void MoveToPreviousInlineLeafIgnoringLineBreak();
void MoveToNextInlineLeafIgnoringLineBreak();
// //
// Following functions are static, similar to DOM traversal utilities. // Following functions are static, similar to DOM traversal utilities.
// //
...@@ -189,27 +177,21 @@ class CORE_EXPORT NGPaintFragmentTraversal { ...@@ -189,27 +177,21 @@ class CORE_EXPORT NGPaintFragmentTraversal {
// paint fragment of a line box. // paint fragment of a line box.
static NGPaintFragment* PreviousLineOf(const NGPaintFragment& line); static NGPaintFragment* PreviousLineOf(const NGPaintFragment& line);
// Returns the previous/next inline leaf fragment (text or atomic inline)of
// the passed fragment, which itself must be inline.
static NGPaintFragmentTraversalContext PreviousInlineLeafOf(
const NGPaintFragmentTraversalContext&);
static NGPaintFragmentTraversalContext NextInlineLeafOf(
const NGPaintFragmentTraversalContext&);
// Variants of the above two skipping line break fragments.
static NGPaintFragmentTraversalContext PreviousInlineLeafOfIgnoringLineBreak(
const NGPaintFragmentTraversalContext&);
static NGPaintFragmentTraversalContext NextInlineLeafOfIgnoringLineBreak(
const NGPaintFragmentTraversalContext&);
private: private:
void EnsureIndex();
bool IsInlineLeaf() const;
bool IsLineBreak() const;
void MoveToFirstChild();
void MoveToLastChild();
void Reset();
// |current_| holds a |NGPaintFragment| specified by |index|th child of // |current_| holds a |NGPaintFragment| specified by |index|th child of
// |parent| of the last element of |stack_|. // |parent| of the last element of |stack_|.
const NGPaintFragment* current_ = nullptr; const NGPaintFragment* current_ = nullptr;
// The root of subtree where traversing is taken place. |root_| is excluded // The root of subtree where traversing is taken place. |root_| is excluded
// from traversal. |current_| can't |root_|. // from traversal. |current_| can't |root_|.
const NGPaintFragment& root_; const NGPaintFragment* root_ = nullptr;
// Keep a list of siblings for MoveToPrevious(). // Keep a list of siblings for MoveToPrevious().
// TODO(kojii): We could keep a stack of this to avoid repetitive // TODO(kojii): We could keep a stack of this to avoid repetitive
...@@ -217,8 +199,6 @@ class CORE_EXPORT NGPaintFragmentTraversal { ...@@ -217,8 +199,6 @@ class CORE_EXPORT NGPaintFragmentTraversal {
// sharing with NGPaintFragmentTraversalContext. // sharing with NGPaintFragmentTraversalContext.
unsigned current_index_ = 0; unsigned current_index_ = 0;
Vector<NGPaintFragment*, 16> siblings_; Vector<NGPaintFragment*, 16> siblings_;
DISALLOW_COPY_AND_ASSIGN(NGPaintFragmentTraversal);
}; };
} // namespace blink } // namespace blink
......
...@@ -1261,13 +1261,11 @@ static AXObject* NextOnLineInternalNG(const AXObject& ax_object) { ...@@ -1261,13 +1261,11 @@ static AXObject* NextOnLineInternalNG(const AXObject& ax_object) {
const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object); const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object);
if (fragments.IsEmpty() || !fragments.IsInLayoutNGInlineFormattingContext()) if (fragments.IsEmpty() || !fragments.IsInLayoutNGInlineFormattingContext())
return nullptr; return nullptr;
for (NGPaintFragmentTraversalContext runner = NGPaintFragmentTraversal runner(*fragments.back().ContainerLineBox(),
NGPaintFragmentTraversal::NextInlineLeafOf( fragments.back());
NGPaintFragmentTraversalContext::Create(&fragments.back())); for (runner.MoveToNextInlineLeaf(); !runner.IsAtEnd();
!runner.IsNull(); runner.MoveToNextInlineLeaf()) {
runner = NGPaintFragmentTraversal::NextInlineLeafOf(runner)) { LayoutObject* runner_layout_object = runner->GetMutableLayoutObject();
LayoutObject* runner_layout_object =
runner.GetFragment()->GetMutableLayoutObject();
if (AXObject* result = if (AXObject* result =
ax_object.AXObjectCache().GetOrCreate(runner_layout_object)) ax_object.AXObjectCache().GetOrCreate(runner_layout_object))
return result; return result;
...@@ -1341,13 +1339,11 @@ static AXObject* PreviousOnLineInlineNG(const AXObject& ax_object) { ...@@ -1341,13 +1339,11 @@ static AXObject* PreviousOnLineInlineNG(const AXObject& ax_object) {
const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object); const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object);
if (fragments.IsEmpty() || !fragments.IsInLayoutNGInlineFormattingContext()) if (fragments.IsEmpty() || !fragments.IsInLayoutNGInlineFormattingContext())
return nullptr; return nullptr;
for (NGPaintFragmentTraversalContext runner = NGPaintFragmentTraversal runner(*fragments.front().ContainerLineBox(),
NGPaintFragmentTraversal::PreviousInlineLeafOf( fragments.front());
NGPaintFragmentTraversalContext::Create(&fragments.front())); for (runner.MoveToPreviousInlineLeaf(); !runner.IsAtEnd();
!runner.IsNull(); runner.MoveToPreviousInlineLeaf()) {
runner = NGPaintFragmentTraversal::PreviousInlineLeafOf(runner)) { LayoutObject* earlier_layout_object = runner->GetMutableLayoutObject();
LayoutObject* earlier_layout_object =
runner.GetFragment()->GetMutableLayoutObject();
if (AXObject* result = if (AXObject* result =
ax_object.AXObjectCache().GetOrCreate(earlier_layout_object)) ax_object.AXObjectCache().GetOrCreate(earlier_layout_object))
return result; return result;
......
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