Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_text_layout_algorithm_test.cc

Issue 2764753007: [LayoutNG] Add NGLineBoxFragment (Closed)
Patch Set: Rebase again as other CLs landed faster Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_text_fragment_builder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/ng/ng_base_layout_algorithm_test.h" 5 #include "core/layout/ng/ng_base_layout_algorithm_test.h"
6 6
7 #include "core/dom/TagCollection.h" 7 #include "core/dom/TagCollection.h"
8 #include "core/layout/line/InlineTextBox.h" 8 #include "core/layout/line/InlineTextBox.h"
9 #include "core/layout/ng/ng_inline_node.h" 9 #include "core/layout/ng/ng_inline_node.h"
10 #include "core/layout/ng/ng_physical_line_box_fragment.h"
10 #include "core/layout/ng/ng_physical_text_fragment.h" 11 #include "core/layout/ng/ng_physical_text_fragment.h"
11 #include "platform/geometry/LayoutPoint.h" 12 #include "platform/geometry/LayoutPoint.h"
12 #include "platform/geometry/LayoutRect.h" 13 #include "platform/geometry/LayoutRect.h"
13 14
14 namespace blink { 15 namespace blink {
15 namespace { 16 namespace {
16 17
17 class NGTextLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {}; 18 class NGTextLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {};
18 19
19 // Verifies that text can flow correctly around floats that were positioned 20 // Verifies that text can flow correctly around floats that were positioned
(...skipping 29 matching lines...) Expand all
49 )HTML"); 50 )HTML");
50 // ** Run LayoutNG algorithm ** 51 // ** Run LayoutNG algorithm **
51 RefPtr<NGConstraintSpace> space; 52 RefPtr<NGConstraintSpace> space;
52 RefPtr<NGPhysicalBoxFragment> html_fragment; 53 RefPtr<NGPhysicalBoxFragment> html_fragment;
53 std::tie(html_fragment, space) = RunBlockLayoutAlgorithmForElement( 54 std::tie(html_fragment, space) = RunBlockLayoutAlgorithmForElement(
54 document().getElementsByTagName("html")->item(0)); 55 document().getElementsByTagName("html")->item(0));
55 auto* body_fragment = 56 auto* body_fragment =
56 toNGPhysicalBoxFragment(html_fragment->Children()[0].get()); 57 toNGPhysicalBoxFragment(html_fragment->Children()[0].get());
57 auto* container_fragment = 58 auto* container_fragment =
58 toNGPhysicalBoxFragment(body_fragment->Children()[0].get()); 59 toNGPhysicalBoxFragment(body_fragment->Children()[0].get());
59 auto* text_fragments_wrapper = 60 auto* line_box_fragments_wrapper =
60 toNGPhysicalBoxFragment(container_fragment->Children()[0].get()); 61 toNGPhysicalBoxFragment(container_fragment->Children()[0].get());
62 Vector<NGPhysicalTextFragment*> text_fragments;
63 for (const auto& child : line_box_fragments_wrapper->Children()) {
64 auto* line_box = toNGPhysicalLineBoxFragment(child.get());
65 EXPECT_EQ(1u, line_box->Children().size());
66 for (const auto& text : line_box->Children())
67 text_fragments.push_back(toNGPhysicalTextFragment(text.get()));
68 }
61 69
62 LayoutText* layout_text = 70 LayoutText* layout_text =
63 toLayoutText(getLayoutObjectByElementId("text")->slowFirstChild()); 71 toLayoutText(getLayoutObjectByElementId("text")->slowFirstChild());
64 ASSERT(layout_text->hasTextBoxes()); 72 ASSERT(layout_text->hasTextBoxes());
65 73
66 ASSERT_EQ(4UL, text_fragments_wrapper->Children().size()); 74 ASSERT_EQ(4UL, text_fragments.size());
67 75
68 auto* text_fragment1 = 76 auto* text_fragment1 = text_fragments[0];
69 toNGPhysicalTextFragment(text_fragments_wrapper->Children()[0].get());
70 // 40 = #left-float1' width 30 + #left-float2 10 77 // 40 = #left-float1' width 30 + #left-float2 10
71 EXPECT_EQ(LayoutUnit(40), text_fragment1->LeftOffset()); 78 EXPECT_EQ(LayoutUnit(40), text_fragment1->LeftOffset());
72 EXPECT_EQ("The quick ", text_fragment1->Text()); 79 EXPECT_EQ("The quick ", text_fragment1->Text());
73 InlineTextBox* inline_text_box1 = layout_text->firstTextBox(); 80 InlineTextBox* inline_text_box1 = layout_text->firstTextBox();
74 EXPECT_EQ(LayoutUnit(40), inline_text_box1->x()); 81 EXPECT_EQ(LayoutUnit(40), inline_text_box1->x());
75 82
76 auto* text_fragment2 = 83 auto* text_fragment2 = text_fragments[1];
77 toNGPhysicalTextFragment(text_fragments_wrapper->Children()[1].get());
78 // 40 = #left-float1' width 30 84 // 40 = #left-float1' width 30
79 EXPECT_EQ(LayoutUnit(30), text_fragment2->LeftOffset()); 85 EXPECT_EQ(LayoutUnit(30), text_fragment2->LeftOffset());
80 EXPECT_EQ("brown fox ", text_fragment2->Text()); 86 EXPECT_EQ("brown fox ", text_fragment2->Text());
81 InlineTextBox* inline_text_box2 = inline_text_box1->nextTextBox(); 87 InlineTextBox* inline_text_box2 = inline_text_box1->nextTextBox();
82 EXPECT_EQ(LayoutUnit(30), inline_text_box2->x()); 88 EXPECT_EQ(LayoutUnit(30), inline_text_box2->x());
83 89
84 auto* text_fragment3 = 90 auto* text_fragment3 = text_fragments[2];
85 toNGPhysicalTextFragment(text_fragments_wrapper->Children()[2].get());
86 EXPECT_EQ(LayoutUnit(), text_fragment3->LeftOffset()); 91 EXPECT_EQ(LayoutUnit(), text_fragment3->LeftOffset());
87 EXPECT_EQ("jumps over the lazy ", text_fragment3->Text()); 92 EXPECT_EQ("jumps over the lazy ", text_fragment3->Text());
88 InlineTextBox* inline_text_box3 = inline_text_box2->nextTextBox(); 93 InlineTextBox* inline_text_box3 = inline_text_box2->nextTextBox();
89 EXPECT_EQ(LayoutUnit(), inline_text_box3->x()); 94 EXPECT_EQ(LayoutUnit(), inline_text_box3->x());
90 } 95 }
91 96
92 // Verifies that text correctly flows around the inline float that fits on 97 // Verifies that text correctly flows around the inline float that fits on
93 // the same text line. 98 // the same text line.
94 TEST_F(NGTextLayoutAlgorithmTest, TextFloatsAroundInlineFloatThatFitsOnLine) { 99 TEST_F(NGTextLayoutAlgorithmTest, TextFloatsAroundInlineFloatThatFitsOnLine) {
95 setBodyInnerHTML(R"HTML( 100 setBodyInnerHTML(R"HTML(
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 Element* narrow_float = document().getElementById("left-narrow"); 203 Element* narrow_float = document().getElementById("left-narrow");
199 // 160 float-wide's width + 8 body's margin. 204 // 160 float-wide's width + 8 body's margin.
200 EXPECT_EQ(160 + 8, narrow_float->offsetLeft()); 205 EXPECT_EQ(160 + 8, narrow_float->offsetLeft());
201 206
202 // On the same line. 207 // On the same line.
203 EXPECT_EQ(wide_float->offsetTop(), narrow_float->offsetTop()); 208 EXPECT_EQ(wide_float->offsetTop(), narrow_float->offsetTop());
204 } 209 }
205 210
206 } // namespace 211 } // namespace
207 } // namespace blink 212 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_text_fragment_builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698