Commit 9c758824 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Implement dom-snapshot inspector protocol

This patch implements dom-snapshot inspector protocol for
LayoutNG.

The offset is not implemented yet in this patch, and thus
2 more tests do not pass yet.

Bug: 636993
Change-Id: I0b57685cc6777ab8d06fbce8b5c8d935aed2648c
Reviewed-on: https://chromium-review.googlesource.com/1175758
Commit-Queue: Koji Ishii <kojii@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583394}
parent 6c6404c6
......@@ -826,19 +826,19 @@ int InspectorDOMSnapshotAgent::VisitLayoutTreeNode(LayoutObject* layout_object,
if (layout_object->IsText()) {
LayoutText* layout_text = ToLayoutText(layout_object);
layout_tree_node->setLayoutText(layout_text->GetText());
if (layout_text->HasTextBoxes()) {
Vector<LayoutText::TextBoxInfo> text_boxes = layout_text->GetTextBoxInfo();
if (!text_boxes.IsEmpty()) {
std::unique_ptr<protocol::Array<protocol::DOMSnapshot::InlineTextBox>>
inline_text_nodes =
protocol::Array<protocol::DOMSnapshot::InlineTextBox>::create();
for (const InlineTextBox* text_box : layout_text->TextBoxes()) {
FloatRect local_coords_text_box_rect(text_box->FrameRect());
for (const LayoutText::TextBoxInfo& text_box : text_boxes) {
FloatRect absolute_coords_text_box_rect =
layout_object->LocalToAbsoluteQuad(local_coords_text_box_rect)
layout_object->LocalToAbsoluteQuad(FloatRect(text_box.local_rect))
.BoundingBox();
inline_text_nodes->addItem(
protocol::DOMSnapshot::InlineTextBox::create()
.setStartCharacterIndex(text_box->Start())
.setNumCharacters(text_box->Len())
.setStartCharacterIndex(text_box.dom_start_offset)
.setNumCharacters(text_box.dom_length)
.setBoundingBox(
BuildRectForFloatRect(absolute_coords_text_box_rect))
.build());
......
......@@ -238,6 +238,32 @@ void LayoutText::DeleteTextBoxes() {
text_boxes_.DeleteLineBoxes();
}
Vector<LayoutText::TextBoxInfo> LayoutText::GetTextBoxInfo() const {
Vector<TextBoxInfo> results;
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
auto fragments = NGPaintFragment::InlineFragmentsFor(this);
if (fragments.IsInLayoutNGInlineFormattingContext()) {
for (const NGPaintFragment* fragment : fragments) {
const NGPhysicalTextFragment& text_fragment =
ToNGPhysicalTextFragment(fragment->PhysicalFragment());
results.push_back(TextBoxInfo{
{fragment->InlineOffsetToContainerBox().ToLayoutPoint(),
text_fragment.Size().ToLayoutSize()},
// TODO(kojii): Compute DOM offset, not text content offset.
text_fragment.StartOffset(),
text_fragment.Length()});
}
return results;
}
}
for (const InlineTextBox* text_box : TextBoxes()) {
results.push_back(
TextBoxInfo{text_box->FrameRect(), text_box->Start(), text_box->Len()});
}
return results;
}
base::Optional<FloatPoint> LayoutText::GetUpperLeftCorner() const {
DCHECK(!IsBR());
if (HasLegacyTextBoxes()) {
......
......@@ -225,6 +225,14 @@ class CORE_EXPORT LayoutText : public LayoutObject {
// All callers should call HasTextBoxes instead, and take NG into account.
bool HasLegacyTextBoxes() const { return FirstTextBox(); }
// Compute the rect and offset of text boxes for this LayoutText.
struct TextBoxInfo {
LayoutRect local_rect;
unsigned dom_start_offset;
unsigned dom_length;
};
Vector<TextBoxInfo> GetTextBoxInfo() const;
// Returns the Position in DOM that corresponds to the given offset in the
// |text_| string.
// TODO(layout-dev): Fix it when text-transform changes text length.
......
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