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

Make NGInlineCursor::MoveTo(const LayoutObject&) to work with rootless cursor

This patch changes |NGInlineCursor::MoveTo(const LayoutObject&)| to work with
rootless cursor for both |NGPaintFragment| and |NGFragmentItem| before this
patch it works only for |NGPaintFragment|.


[1] http://crrev.com/c/1895258 Introduce NGInlineCursor::
MoveTo{Next,Previous}InlineLeaf{,IgnoringLineBreak}()


Note: This is follow-up of the patch[1].
Bug: 982194
Change-Id: I87f868f23c51454b6b7fc94311a458bb46c88de7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1896477
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712873}
parent 327f7787
...@@ -550,28 +550,40 @@ void NGInlineCursor::MakeNull() { ...@@ -550,28 +550,40 @@ void NGInlineCursor::MakeNull() {
void NGInlineCursor::InternalMoveTo(const LayoutObject& layout_object) { void NGInlineCursor::InternalMoveTo(const LayoutObject& layout_object) {
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext()); DCHECK(layout_object.IsInLayoutNGInlineFormattingContext());
// If this cursor is rootless, find the root of the inline formatting context.
if (!HasRoot()) {
const LayoutBlockFlow& root = *layout_object.RootInlineFormattingContext();
DCHECK(&root);
SetRoot(root);
if (!HasRoot()) {
const auto fragments =
NGPaintFragment::InlineFragmentsFor(&layout_object);
if (!fragments.IsInLayoutNGInlineFormattingContext() ||
fragments.IsEmpty())
return MakeNull();
// external/wpt/css/css-scroll-anchoring/text-anchor-in-vertical-rl.html
// reaches here.
root_paint_fragment_ = fragments.front().Root();
}
}
if (fragment_items_) { if (fragment_items_) {
item_iter_ = items_.begin(); item_iter_ = items_.begin();
while (current_item_ && CurrentLayoutObject() != &layout_object) while (current_item_ && CurrentLayoutObject() != &layout_object)
MoveToNextItem(); MoveToNextItem();
return; return;
} }
const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object); if (root_paint_fragment_) {
if (!fragments.IsInLayoutNGInlineFormattingContext() || fragments.IsEmpty()) const auto fragments = NGPaintFragment::InlineFragmentsFor(&layout_object);
return MakeNull(); if (!fragments.IsInLayoutNGInlineFormattingContext() || fragments.IsEmpty())
if (!root_paint_fragment_) { return MakeNull();
// We reach here in case of |ScrollANchor::NotifyBeforeLayout()| via return MoveTo(fragments.front());
// |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) {
DCHECK(layout_object.IsInLayoutNGInlineFormattingContext()) << layout_object; DCHECK(layout_object.IsInLayoutNGInlineFormattingContext()) << layout_object;
InternalMoveTo(layout_object); InternalMoveTo(layout_object);
if (*this) { if (*this || !HasRoot()) {
layout_inline_ = nullptr; layout_inline_ = nullptr;
return; return;
} }
...@@ -583,17 +595,6 @@ void NGInlineCursor::MoveTo(const LayoutObject& layout_object) { ...@@ -583,17 +595,6 @@ void NGInlineCursor::MoveTo(const LayoutObject& layout_object) {
if (!layout_inline_) if (!layout_inline_)
return; return;
// If this cursor is rootless, find the root of the inline formatting context.
if (!HasRoot()) {
const LayoutBlockFlow* root = layout_object.RootInlineFormattingContext();
DCHECK(root);
SetRoot(*root);
if (!HasRoot()) {
DCHECK(IsNull());
return;
}
}
MoveToFirst(); MoveToFirst();
while (IsNotNull() && !IsInclusiveDescendantOf(layout_object)) while (IsNotNull() && !IsInclusiveDescendantOf(layout_object))
MoveToNext(); MoveToNext();
......
...@@ -441,15 +441,7 @@ TEST_P(NGInlineCursorTest, Previous) { ...@@ -441,15 +441,7 @@ TEST_P(NGInlineCursorTest, Previous) {
InsertStyleElement("b { background: gray; }"); InsertStyleElement("b { background: gray; }");
NGInlineCursor cursor = NGInlineCursor cursor =
SetupCursor("<div id=root>abc<b>DEF</b><br>xyz</div>"); SetupCursor("<div id=root>abc<b>DEF</b><br>xyz</div>");
// TDOO(yosin): We'll use |MoveTo(*cursor.GetLayoutBlockFlow()->LastChild())| cursor.MoveTo(*cursor.GetLayoutBlockFlow()->LastChild());
// once |MoveTo()| works with rootless cursor.
while (cursor) {
NGInlineCursor next(cursor);
next.MoveToNext();
if (!next)
break;
cursor = next;
}
Vector<String> list; Vector<String> list;
while (cursor) { while (cursor) {
list.push_back(ToDebugString(cursor)); list.push_back(ToDebugString(cursor));
...@@ -464,15 +456,7 @@ TEST_P(NGInlineCursorTest, PreviousInlineLeaf) { ...@@ -464,15 +456,7 @@ TEST_P(NGInlineCursorTest, PreviousInlineLeaf) {
InsertStyleElement("b { background: gray; }"); InsertStyleElement("b { background: gray; }");
NGInlineCursor cursor = NGInlineCursor cursor =
SetupCursor("<div id=root>abc<b>DEF</b><br>xyz</div>"); SetupCursor("<div id=root>abc<b>DEF</b><br>xyz</div>");
// TDOO(yosin): We'll use |MoveTo(*cursor.GetLayoutBlockFlow()->LastChild())| cursor.MoveTo(*cursor.GetLayoutBlockFlow()->LastChild());
// once |MoveTo()| works with rootless cursor.
while (cursor) {
NGInlineCursor next(cursor);
next.MoveToNext();
if (!next)
break;
cursor = next;
}
Vector<String> list; Vector<String> list;
while (cursor) { while (cursor) {
list.push_back(ToDebugString(cursor)); list.push_back(ToDebugString(cursor));
...@@ -486,15 +470,7 @@ TEST_P(NGInlineCursorTest, PreviousInlineLeafIgnoringLineBreak) { ...@@ -486,15 +470,7 @@ TEST_P(NGInlineCursorTest, PreviousInlineLeafIgnoringLineBreak) {
InsertStyleElement("b { background: gray; }"); InsertStyleElement("b { background: gray; }");
NGInlineCursor cursor = NGInlineCursor cursor =
SetupCursor("<div id=root>abc<b>DEF</b><br>xyz</div>"); SetupCursor("<div id=root>abc<b>DEF</b><br>xyz</div>");
// TDOO(yosin): We'll use |MoveTo(*cursor.GetLayoutBlockFlow()->LastChild())| cursor.MoveTo(*cursor.GetLayoutBlockFlow()->LastChild());
// once |MoveTo()| works with rootless cursor.
while (cursor) {
NGInlineCursor next(cursor);
next.MoveToNext();
if (!next)
break;
cursor = next;
}
Vector<String> list; Vector<String> list;
while (cursor) { while (cursor) {
list.push_back(ToDebugString(cursor)); list.push_back(ToDebugString(cursor));
......
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