summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm_test.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm_test.cc193
1 files changed, 63 insertions, 130 deletions
diff --git a/chromium/third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm_test.cc b/chromium/third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm_test.cc
index 3c1aa36a1bc..fbb4e323541 100644
--- a/chromium/third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm_test.cc
+++ b/chromium/third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm_test.cc
@@ -9,9 +9,11 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_box_state.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_child_layout_context.h"
+#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
+#include "third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space_builder.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_result.h"
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
@@ -50,6 +52,14 @@ TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) {
NGConstraintSpace constraint_space = builder.ToConstraintSpace();
NGInlineChildLayoutContext context;
+ NGBoxFragmentBuilder container_builder(block_flow, block_flow->Style(),
+ block_flow->Style()->GetWritingMode(),
+ block_flow->Style()->Direction());
+ NGFragmentItemsBuilder items_builder(&container_builder);
+ if (RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
+ container_builder.SetItemsBuilder(&items_builder);
+ context.SetItemsBuilder(&items_builder);
+ }
scoped_refptr<const NGLayoutResult> layout_result =
inline_node.Layout(constraint_space, nullptr, &context);
const auto& line1 = layout_result->PhysicalFragment();
@@ -68,95 +78,6 @@ TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) {
EXPECT_TRUE(line3.BreakToken()->IsFinished());
}
-TEST_F(NGInlineLayoutAlgorithmTest, GenerateHyphen) {
- LoadAhem();
- SetBodyInnerHTML(R"HTML(
- <!DOCTYPE html>
- <style>
- html, body { margin: 0; }
- #container {
- font: 10px/1 Ahem;
- width: 5ch;
- }
- </style>
- <div id=container>abc&shy;def</div>
- )HTML");
- scoped_refptr<const NGPhysicalBoxFragment> block =
- GetBoxFragmentByElementId("container");
- EXPECT_EQ(2u, block->Children().size());
- const NGPhysicalLineBoxFragment& line1 =
- To<NGPhysicalLineBoxFragment>(*block->Children()[0].get());
-
- // The hyphen is in its own NGPhysicalTextFragment.
- EXPECT_EQ(2u, line1.Children().size());
- EXPECT_EQ(NGPhysicalFragment::kFragmentText, line1.Children()[1]->Type());
- const auto& hyphen = To<NGPhysicalTextFragment>(*line1.Children()[1].get());
- EXPECT_EQ(String(u"\u2010"), hyphen.Text().ToString());
- // It should have the same LayoutObject as the hyphened word.
- EXPECT_EQ(line1.Children()[0]->GetLayoutObject(), hyphen.GetLayoutObject());
-}
-
-TEST_F(NGInlineLayoutAlgorithmTest, GenerateEllipsis) {
- LoadAhem();
- SetBodyInnerHTML(R"HTML(
- <!DOCTYPE html>
- <style>
- html, body { margin: 0; }
- #container {
- font: 10px/1 Ahem;
- width: 5ch;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- </style>
- <div id=container>123456</div>
- )HTML");
- scoped_refptr<const NGPhysicalBoxFragment> block =
- GetBoxFragmentByElementId("container");
- EXPECT_EQ(1u, block->Children().size());
- const auto& line1 =
- To<NGPhysicalLineBoxFragment>(*block->Children()[0].get());
-
- // The ellipsis is in its own NGPhysicalTextFragment.
- EXPECT_EQ(3u, line1.Children().size());
- const auto& ellipsis = To<NGPhysicalTextFragment>(*line1.Children().back());
- EXPECT_EQ(String(u"\u2026"), ellipsis.Text().ToString());
- // It should have the same LayoutObject as the clipped word.
- EXPECT_EQ(line1.Children()[0]->GetLayoutObject(), ellipsis.GetLayoutObject());
-}
-
-TEST_F(NGInlineLayoutAlgorithmTest, EllipsisInlineBoxOnly) {
- LoadAhem();
- SetBodyInnerHTML(R"HTML(
- <!DOCTYPE html>
- <style>
- html, body { margin: 0; }
- #container {
- font: 10px/1 Ahem;
- width: 5ch;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- span {
- border: solid 10ch blue;
- }
- </style>
- <div id=container><span></span></div>
- )HTML");
- scoped_refptr<const NGPhysicalBoxFragment> block =
- GetBoxFragmentByElementId("container");
- EXPECT_EQ(1u, block->Children().size());
- const auto& line1 =
- To<NGPhysicalLineBoxFragment>(*block->Children()[0].get());
-
- // There should not be ellipsis in this line.
- for (const auto& child : line1.Children()) {
- if (const auto* text = DynamicTo<NGPhysicalTextFragment>(child.get())) {
- EXPECT_FALSE(text->IsEllipsis());
- }
- }
-}
-
// This test ensures box fragments are generated when necessary, even when the
// line is empty. One such case is when the line contains a containing box of an
// out-of-flow object.
@@ -179,7 +100,7 @@ TEST_F(NGInlineLayoutAlgorithmTest,
}
</style>
<div id=container>
- <oof-container>
+ <oof-container id=target>
<oof></oof>
</oof-container>
</div>
@@ -190,15 +111,17 @@ TEST_F(NGInlineLayoutAlgorithmTest,
ASSERT_TRUE(container);
EXPECT_EQ(LayoutUnit(), container->Size().height);
- EXPECT_EQ(2u, container->Children().size());
- const auto& linebox =
- To<NGPhysicalLineBoxFragment>(*container->Children()[0]);
-
- EXPECT_EQ(1u, linebox.Children().size());
- EXPECT_EQ(PhysicalSize(), linebox.Size());
-
- const auto& oof_container = To<NGPhysicalBoxFragment>(*linebox.Children()[0]);
- EXPECT_EQ(PhysicalSize(), oof_container.Size());
+ NGInlineCursor line_box(*block_flow);
+ ASSERT_TRUE(line_box);
+ ASSERT_TRUE(line_box.Current().IsLineBox());
+ EXPECT_EQ(PhysicalSize(), line_box.Current().Size());
+
+ NGInlineCursor off_container(line_box);
+ off_container.MoveToNext();
+ ASSERT_TRUE(off_container);
+ ASSERT_EQ(GetLayoutObjectByElementId("target"),
+ off_container.Current().GetLayoutObject());
+ EXPECT_EQ(PhysicalSize(), off_container.Current().Size());
}
// This test ensures that if an inline box generates (or does not generate) box
@@ -219,21 +142,31 @@ TEST_F(NGInlineLayoutAlgorithmTest, BoxForEndMargin) {
}
</style>
<!-- This line wraps, and only 2nd line has a border. -->
- <div id=container>12 <span>3 45</span> 6</div>
+ <div id=container>12 <span id=span>3 45</span> 6</div>
)HTML");
auto* block_flow =
To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"));
- const NGPhysicalBoxFragment* block_box = block_flow->CurrentFragment();
- ASSERT_TRUE(block_box);
- EXPECT_EQ(2u, block_box->Children().size());
- const auto& line_box1 =
- To<NGPhysicalLineBoxFragment>(*block_box->Children()[0].get());
- EXPECT_EQ(2u, line_box1.Children().size());
+ NGInlineCursor line_box(*block_flow);
+ ASSERT_TRUE(line_box) << "line_box is at start of first line.";
+ ASSERT_TRUE(line_box.Current().IsLineBox());
+ line_box.MoveToNextLine();
+ ASSERT_TRUE(line_box) << "line_box is at start of second line.";
+ NGInlineCursor cursor(line_box);
+ ASSERT_TRUE(line_box.Current().IsLineBox());
+ cursor.MoveToNext();
+ ASSERT_TRUE(cursor);
+ EXPECT_EQ(GetLayoutObjectByElementId("span"),
+ cursor.Current().GetLayoutObject());
// The <span> generates a box fragment for the 2nd line because it has a
// right border. It should also generate a box fragment for the 1st line even
// though there's no borders on the 1st line.
- EXPECT_EQ(NGPhysicalFragment::kFragmentBox, line_box1.Children()[1]->Type());
+ const NGPhysicalBoxFragment* box_fragment = cursor.Current().BoxFragment();
+ ASSERT_TRUE(box_fragment);
+ EXPECT_EQ(NGPhysicalFragment::kFragmentBox, box_fragment->Type());
+
+ line_box.MoveToNextLine();
+ ASSERT_FALSE(line_box) << "block_flow has two lines.";
}
// A block with inline children generates fragment tree as follows:
@@ -257,8 +190,8 @@ TEST_F(NGInlineLayoutAlgorithmTest, ContainerBorderPadding) {
auto* block_flow =
To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"));
NGBlockNode block_node(block_flow);
- NGConstraintSpace space = NGConstraintSpace::CreateFromLayoutObject(
- *block_flow, false /* is_layout_root */);
+ NGConstraintSpace space =
+ NGConstraintSpace::CreateFromLayoutObject(*block_flow);
scoped_refptr<const NGLayoutResult> layout_result = block_node.Layout(space);
EXPECT_TRUE(layout_result->BfcBlockOffset().has_value());
@@ -289,17 +222,13 @@ TEST_F(NGInlineLayoutAlgorithmTest, MAYBE_VerticalAlignBottomReplaced) {
)HTML");
auto* block_flow =
To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"));
- NGInlineNode inline_node(block_flow);
- NGInlineChildLayoutContext context;
- NGConstraintSpace space = NGConstraintSpace::CreateFromLayoutObject(
- *block_flow, false /* is_layout_root */);
- scoped_refptr<const NGLayoutResult> layout_result =
- inline_node.Layout(space, nullptr, &context);
-
- const auto& line = layout_result->PhysicalFragment();
- EXPECT_EQ(LayoutUnit(96), line.Size().height);
- PhysicalOffset img_offset = line.Children()[0].Offset();
- EXPECT_EQ(LayoutUnit(0), img_offset.top);
+ NGInlineCursor cursor(*block_flow);
+ ASSERT_TRUE(cursor);
+ EXPECT_EQ(LayoutUnit(96), cursor.Current().Size().height);
+ cursor.MoveToNext();
+ ASSERT_TRUE(cursor);
+ EXPECT_EQ(LayoutUnit(0), cursor.Current().OffsetInContainerBlock().top)
+ << "Offset top of <img> should be zero.";
}
// Verifies that text can flow correctly around floats that were positioned
@@ -393,7 +322,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, TextFloatsAroundInlineFloatThatFitsOnLine) {
ASSERT_TRUE(block_box);
// Two lines.
- EXPECT_EQ(2u, block_box->Children().size());
+ ASSERT_EQ(2u, block_box->Children().size());
PhysicalOffset first_line_offset = block_box->Children()[1].Offset();
// 30 == narrow-float's width.
@@ -521,20 +450,24 @@ TEST_F(NGInlineLayoutAlgorithmTest, InkOverflow) {
auto* block_flow =
To<LayoutBlockFlow>(GetLayoutObjectByElementId("container"));
const NGPaintFragment* paint_fragment = block_flow->PaintFragment();
- ASSERT_TRUE(paint_fragment);
- const NGPhysicalFragment& box_fragment = paint_fragment->PhysicalFragment();
-
+ const NGPhysicalBoxFragment& box_fragment = *block_flow->CurrentFragment();
+ if (paint_fragment)
+ ASSERT_EQ(&paint_fragment->PhysicalFragment(), &box_fragment);
EXPECT_EQ(LayoutUnit(10), box_fragment.Size().height);
- PhysicalRect ink_overflow = paint_fragment->InkOverflow();
+ NGInlineCursor cursor(*block_flow);
+ PhysicalRect ink_overflow = cursor.Current().InkOverflow();
EXPECT_EQ(LayoutUnit(-5), ink_overflow.offset.top);
EXPECT_EQ(LayoutUnit(20), ink_overflow.size.height);
- // |ContentsInkOverflow| should match to |InkOverflow|, except the width
- // because |<div id=container>| might be wider than the content.
- EXPECT_EQ(ink_overflow.offset, paint_fragment->ContentsInkOverflow().offset);
- EXPECT_EQ(ink_overflow.size.height,
- paint_fragment->ContentsInkOverflow().size.height);
+ if (paint_fragment) {
+ // |ContentsInkOverflow| should match to |InkOverflow|, except the width
+ // because |<div id=container>| might be wider than the content.
+ const PhysicalRect contents_ink_overflow =
+ paint_fragment->ContentsInkOverflow();
+ EXPECT_EQ(ink_overflow.offset, contents_ink_overflow.offset);
+ EXPECT_EQ(ink_overflow.size.height, contents_ink_overflow.size.height);
+ }
}
#undef MAYBE_VerticalAlignBottomReplaced