OLD | NEW |
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/layout_ng_block_flow.h" |
| 10 #include "core/layout/ng/ng_block_break_token.h" |
| 11 #include "core/layout/ng/ng_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_inline_node.h" | 12 #include "core/layout/ng/ng_inline_node.h" |
10 #include "core/layout/ng/ng_physical_line_box_fragment.h" | 13 #include "core/layout/ng/ng_physical_line_box_fragment.h" |
11 #include "core/layout/ng/ng_physical_text_fragment.h" | 14 #include "core/layout/ng/ng_physical_text_fragment.h" |
12 #include "platform/geometry/LayoutPoint.h" | 15 #include "platform/geometry/LayoutPoint.h" |
13 #include "platform/geometry/LayoutRect.h" | 16 #include "platform/geometry/LayoutRect.h" |
14 | 17 |
15 namespace blink { | 18 namespace blink { |
16 namespace { | 19 namespace { |
17 | 20 |
18 class NGTextLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {}; | 21 class NGInlineLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {}; |
| 22 |
| 23 TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) { |
| 24 loadAhem(); |
| 25 setBodyInnerHTML(R"HTML( |
| 26 <!DOCTYPE html> |
| 27 <style> |
| 28 html { |
| 29 font: 10px/1 Ahem; |
| 30 } |
| 31 #container { |
| 32 width: 50px; height: 20px; |
| 33 } |
| 34 </style> |
| 35 <div id=container>123 456 789</div> |
| 36 )HTML"); |
| 37 |
| 38 // Perform 1st Layout. |
| 39 LayoutNGBlockFlow* block_flow = |
| 40 toLayoutNGBlockFlow(getLayoutObjectByElementId("container")); |
| 41 NGInlineNode* inline_node = |
| 42 new NGInlineNode(block_flow->firstChild(), block_flow); |
| 43 RefPtr<NGConstraintSpace> constraint_space = |
| 44 NGConstraintSpaceBuilder(NGWritingMode::kHorizontalTopBottom) |
| 45 .SetAvailableSize({LayoutUnit(50), LayoutUnit(20)}) |
| 46 .ToConstraintSpace(NGWritingMode::kHorizontalTopBottom); |
| 47 RefPtr<NGLayoutResult> layout_result = |
| 48 inline_node->Layout(constraint_space.get(), nullptr); |
| 49 auto* wrapper = |
| 50 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get()); |
| 51 |
| 52 // Test that the anonymous wrapper has 2 line boxes, and both have unfinished |
| 53 // break tokens. |
| 54 EXPECT_EQ(2u, wrapper->Children().size()); |
| 55 auto* line1 = toNGPhysicalLineBoxFragment(wrapper->Children()[0].get()); |
| 56 EXPECT_FALSE(line1->BreakToken()->IsFinished()); |
| 57 auto* line2 = toNGPhysicalLineBoxFragment(wrapper->Children()[1].get()); |
| 58 EXPECT_FALSE(line2->BreakToken()->IsFinished()); |
| 59 |
| 60 // Test that the wrapper has the break token from the last line as its child. |
| 61 auto* wrapper_break_token = toNGBlockBreakToken(wrapper->BreakToken()); |
| 62 EXPECT_EQ(wrapper_break_token->ChildBreakTokens()[0], line2->BreakToken()); |
| 63 EXPECT_FALSE(wrapper_break_token->IsFinished()); |
| 64 |
| 65 // Perform 2nd layout with the break token from the 2nd line. |
| 66 RefPtr<NGLayoutResult> layout_result2 = |
| 67 inline_node->Layout(constraint_space.get(), line2->BreakToken()); |
| 68 auto* wrapper2 = |
| 69 toNGPhysicalBoxFragment(layout_result2->PhysicalFragment().get()); |
| 70 |
| 71 // Test that the anonymous wrapper has 1 line boxes, and has a finished break |
| 72 // token. |
| 73 EXPECT_EQ(1u, wrapper2->Children().size()); |
| 74 auto* line3 = toNGPhysicalLineBoxFragment(wrapper2->Children()[0].get()); |
| 75 EXPECT_TRUE(line3->BreakToken()->IsFinished()); |
| 76 |
| 77 // Test that the wrapper has the break token without children. |
| 78 auto* wrapper2_break_token = toNGBlockBreakToken(wrapper2->BreakToken()); |
| 79 EXPECT_EQ(0u, wrapper2_break_token->ChildBreakTokens().size()); |
| 80 } |
19 | 81 |
20 // Verifies that text can flow correctly around floats that were positioned | 82 // Verifies that text can flow correctly around floats that were positioned |
21 // before the inline block. | 83 // before the inline block. |
22 TEST_F(NGTextLayoutAlgorithmTest, TextFloatsAroundFloatsBefore) { | 84 TEST_F(NGInlineLayoutAlgorithmTest, TextFloatsAroundFloatsBefore) { |
23 setBodyInnerHTML(R"HTML( | 85 setBodyInnerHTML(R"HTML( |
24 <!DOCTYPE html> | 86 <!DOCTYPE html> |
25 <style> | 87 <style> |
26 * { | 88 * { |
27 font-family: "Arial", sans-serif; | 89 font-family: "Arial", sans-serif; |
28 font-size: 19px; | 90 font-size: 19px; |
29 } | 91 } |
30 #container { | 92 #container { |
31 height: 200px; width: 200px; outline: solid blue; | 93 height: 200px; width: 200px; outline: solid blue; |
32 } | 94 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 151 |
90 auto* text_fragment3 = text_fragments[2]; | 152 auto* text_fragment3 = text_fragments[2]; |
91 EXPECT_EQ(LayoutUnit(), text_fragment3->LeftOffset()); | 153 EXPECT_EQ(LayoutUnit(), text_fragment3->LeftOffset()); |
92 EXPECT_EQ("jumps over the lazy ", text_fragment3->Text()); | 154 EXPECT_EQ("jumps over the lazy ", text_fragment3->Text()); |
93 InlineTextBox* inline_text_box3 = inline_text_box2->nextTextBox(); | 155 InlineTextBox* inline_text_box3 = inline_text_box2->nextTextBox(); |
94 EXPECT_EQ(LayoutUnit(), inline_text_box3->x()); | 156 EXPECT_EQ(LayoutUnit(), inline_text_box3->x()); |
95 } | 157 } |
96 | 158 |
97 // Verifies that text correctly flows around the inline float that fits on | 159 // Verifies that text correctly flows around the inline float that fits on |
98 // the same text line. | 160 // the same text line. |
99 TEST_F(NGTextLayoutAlgorithmTest, TextFloatsAroundInlineFloatThatFitsOnLine) { | 161 TEST_F(NGInlineLayoutAlgorithmTest, TextFloatsAroundInlineFloatThatFitsOnLine) { |
100 setBodyInnerHTML(R"HTML( | 162 setBodyInnerHTML(R"HTML( |
101 <!DOCTYPE html> | 163 <!DOCTYPE html> |
102 <style> | 164 <style> |
103 * { | 165 * { |
104 font-family: "Arial", sans-serif; | 166 font-family: "Arial", sans-serif; |
105 font-size: 19px; | 167 font-size: 19px; |
106 } | 168 } |
107 #container { | 169 #container { |
108 height: 200px; width: 200px; outline: solid orange; | 170 height: 200px; width: 200px; outline: solid orange; |
109 } | 171 } |
(...skipping 16 matching lines...) Expand all Loading... |
126 EXPECT_EQ(LayoutUnit(30), inline_text_box1->x()); | 188 EXPECT_EQ(LayoutUnit(30), inline_text_box1->x()); |
127 | 189 |
128 Element* narrow_float = document().getElementById("narrow-float"); | 190 Element* narrow_float = document().getElementById("narrow-float"); |
129 // 8 == body's margin. | 191 // 8 == body's margin. |
130 EXPECT_EQ(8, narrow_float->offsetLeft()); | 192 EXPECT_EQ(8, narrow_float->offsetLeft()); |
131 EXPECT_EQ(8, narrow_float->offsetTop()); | 193 EXPECT_EQ(8, narrow_float->offsetTop()); |
132 } | 194 } |
133 | 195 |
134 // Verifies that the inline float got pushed to the next line if it doesn't | 196 // Verifies that the inline float got pushed to the next line if it doesn't |
135 // fit the current line. | 197 // fit the current line. |
136 TEST_F(NGTextLayoutAlgorithmTest, | 198 TEST_F(NGInlineLayoutAlgorithmTest, |
137 TextFloatsAroundInlineFloatThatDoesNotFitOnLine) { | 199 TextFloatsAroundInlineFloatThatDoesNotFitOnLine) { |
138 setBodyInnerHTML(R"HTML( | 200 setBodyInnerHTML(R"HTML( |
139 <!DOCTYPE html> | 201 <!DOCTYPE html> |
140 <style> | 202 <style> |
141 * { | 203 * { |
142 font-family: "Arial", sans-serif; | 204 font-family: "Arial", sans-serif; |
143 font-size: 19px; | 205 font-size: 19px; |
144 } | 206 } |
145 #container { | 207 #container { |
146 height: 200px; width: 200px; outline: solid orange; | 208 height: 200px; width: 200px; outline: solid orange; |
(...skipping 16 matching lines...) Expand all Loading... |
163 EXPECT_EQ(LayoutUnit(), inline_text_box1->x()); | 225 EXPECT_EQ(LayoutUnit(), inline_text_box1->x()); |
164 | 226 |
165 Element* wide_float = document().getElementById("wide-float"); | 227 Element* wide_float = document().getElementById("wide-float"); |
166 // 8 == body's margin. | 228 // 8 == body's margin. |
167 EXPECT_EQ(8, wide_float->offsetLeft()); | 229 EXPECT_EQ(8, wide_float->offsetLeft()); |
168 } | 230 } |
169 | 231 |
170 // Verifies that if an inline float pushed to the next line then all others | 232 // Verifies that if an inline float pushed to the next line then all others |
171 // following inline floats positioned with respect to the float's top edge | 233 // following inline floats positioned with respect to the float's top edge |
172 // alignment rule. | 234 // alignment rule. |
173 TEST_F(NGTextLayoutAlgorithmTest, | 235 TEST_F(NGInlineLayoutAlgorithmTest, |
174 FloatsArePositionedWithRespectToTopEdgeAlignmentRule) { | 236 FloatsArePositionedWithRespectToTopEdgeAlignmentRule) { |
175 setBodyInnerHTML(R"HTML( | 237 setBodyInnerHTML(R"HTML( |
176 <!DOCTYPE html> | 238 <!DOCTYPE html> |
177 <style> | 239 <style> |
178 * { | 240 * { |
179 font-family: "Arial", sans-serif; | 241 font-family: "Arial", sans-serif; |
180 font-size: 19px; | 242 font-size: 19px; |
181 } | 243 } |
182 #container { | 244 #container { |
183 height: 200px; width: 200px; outline: solid orange; | 245 height: 200px; width: 200px; outline: solid orange; |
(...skipping 19 matching lines...) Expand all Loading... |
203 Element* narrow_float = document().getElementById("left-narrow"); | 265 Element* narrow_float = document().getElementById("left-narrow"); |
204 // 160 float-wide's width + 8 body's margin. | 266 // 160 float-wide's width + 8 body's margin. |
205 EXPECT_EQ(160 + 8, narrow_float->offsetLeft()); | 267 EXPECT_EQ(160 + 8, narrow_float->offsetLeft()); |
206 | 268 |
207 // On the same line. | 269 // On the same line. |
208 EXPECT_EQ(wide_float->offsetTop(), narrow_float->offsetTop()); | 270 EXPECT_EQ(wide_float->offsetTop(), narrow_float->offsetTop()); |
209 } | 271 } |
210 | 272 |
211 } // namespace | 273 } // namespace |
212 } // namespace blink | 274 } // namespace blink |
OLD | NEW |