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

Make LayoutTreeAsText to utilize NGInlineCursor instead of...

Make LayoutTreeAsText to utilize NGInlineCursor instead of NGInlineFragmentTraversal::SelfFragmentsOf()

This patch makes |LayoutTreeAsText| to utilize |NGInlineCursor| instead of
|NGInlineFragmentTraversal::SelfFragmentsOf()| as preparation for migrating
|NGFragmentItem|.

Bug: 982194
Change-Id: I78a568464330228940e18ebd7cc836630627aea3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852324
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705003}
parent 2e08982c
......@@ -46,7 +46,8 @@
#include "third_party/blink/renderer/core/layout/layout_table_cell.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/line/inline_text_box.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_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_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/list/layout_ng_list_item.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
......@@ -450,21 +451,17 @@ static void WriteTextRun(WTF::TextStream& ts,
}
static void WriteTextFragment(WTF::TextStream& ts,
const NGPhysicalFragment& physical_fragment,
PhysicalOffset offset_to_container_box) {
const auto* physical_text_fragment =
DynamicTo<NGPhysicalTextFragment>(physical_fragment);
if (!physical_text_fragment)
return;
const ComputedStyle& style = physical_fragment.Style();
const LayoutObject* layout_object,
PhysicalRect rect,
const ComputedStyle& style,
StringView text,
LayoutUnit inline_size) {
// TODO(layout-dev): Dump physical coordinates when removing the legacy inline
// layout code.
NGTextFragment fragment(style.GetWritingMode(), *physical_text_fragment);
PhysicalOffset offset_to_container_box = rect.offset;
if (UNLIKELY(style.IsFlippedBlocksWritingMode())) {
if (physical_fragment.GetLayoutObject()) {
PhysicalRect rect(offset_to_container_box, physical_fragment.Size());
const LayoutBlock* containing_block =
physical_fragment.GetLayoutObject()->ContainingBlock();
if (layout_object) {
const LayoutBlock* containing_block = layout_object->ContainingBlock();
LayoutRect layout_rect = containing_block->FlipForWritingMode(rect);
offset_to_container_box.left = layout_rect.X();
}
......@@ -473,14 +470,39 @@ static void WriteTextFragment(WTF::TextStream& ts,
// See WriteTextRun() for why we convert to int.
int x = offset_to_container_box.left.ToInt();
int y = offset_to_container_box.top.ToInt();
int logical_width =
(offset_to_container_box.left + fragment.InlineSize()).Ceil() - x;
int logical_width = (offset_to_container_box.left + inline_size).Ceil() - x;
ts << "text run at (" << x << "," << y << ") width " << logical_width;
ts << ": "
<< QuoteAndEscapeNonPrintables(physical_text_fragment->Text().ToString());
ts << ": " << QuoteAndEscapeNonPrintables(text.ToString());
ts << "\n";
}
static void WriteTextFragment(WTF::TextStream& ts,
const NGInlineCursor& cursor) {
if (const NGPaintFragment* const paint_fragment =
cursor.CurrentPaintFragment()) {
const auto* physical_text_fragment =
DynamicTo<NGPhysicalTextFragment>(paint_fragment->PhysicalFragment());
if (!physical_text_fragment)
return;
const NGTextFragment fragment(paint_fragment->Style().GetWritingMode(),
*physical_text_fragment);
WriteTextFragment(ts, paint_fragment->GetLayoutObject(),
PhysicalRect(paint_fragment->InlineOffsetToContainerBox(),
paint_fragment->Size()),
paint_fragment->Style(), physical_text_fragment->Text(),
fragment.InlineSize());
return;
}
DCHECK(cursor.CurrentItem());
const NGFragmentItem& item = *cursor.CurrentItem();
DCHECK(item.Type() == NGFragmentItem::kText ||
item.Type() == NGFragmentItem::kGeneratedText);
const LayoutUnit inline_size =
item.IsHorizontal() ? item.Size().width : item.Size().height;
WriteTextFragment(ts, item.GetLayoutObject(), item.Rect(), item.Style(),
item.Text(cursor.Items()), inline_size);
}
static void WritePaintProperties(WTF::TextStream& ts,
const LayoutObject& o,
int indent) {
......@@ -560,12 +582,12 @@ void Write(WTF::TextStream& ts,
if (o.IsText() && !o.IsBR()) {
const LayoutText& text = ToLayoutText(o);
if (const NGPhysicalBoxFragment* box_fragment =
text.ContainingBlockFlowFragment()) {
for (const auto& child :
NGInlineFragmentTraversal::SelfFragmentsOf(*box_fragment, &text)) {
if (const LayoutBlockFlow* block_flow = text.ContainingNGBlockFlow()) {
NGInlineCursor cursor(*block_flow);
cursor.MoveTo(text);
for (; cursor; cursor.MoveToNextForSameLayoutObject()) {
WriteIndent(ts, indent + 1);
WriteTextFragment(ts, *child.fragment, child.offset_to_container_box);
WriteTextFragment(ts, cursor);
}
} else {
for (InlineTextBox* box : text.TextBoxes()) {
......
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