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

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

Issue 2772503004: [LayoutNG] Add NGInlineBreakToken and back of NGInlineLayoutAlgorithm (Closed)
Patch Set: Rename Created 3 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_inline_node.h" 5 #include "core/layout/ng/ng_inline_node.h"
6 6
7 #include "core/layout/LayoutTestHelper.h" 7 #include "core/layout/LayoutTestHelper.h"
8 #include "core/layout/ng/ng_constraint_space.h" 8 #include "core/layout/ng/ng_constraint_space.h"
9 #include "core/layout/ng/ng_constraint_space_builder.h" 9 #include "core/layout/ng/ng_constraint_space_builder.h"
10 #include "core/layout/ng/ng_fragment_builder.h" 10 #include "core/layout/ng/ng_fragment_builder.h"
11 #include "core/layout/ng/ng_line_builder.h" 11 #include "core/layout/ng/ng_inline_layout_algorithm.h"
12 #include "core/layout/ng/ng_physical_box_fragment.h" 12 #include "core/layout/ng/ng_physical_box_fragment.h"
13 #include "core/layout/ng/ng_physical_line_box_fragment.h" 13 #include "core/layout/ng/ng_physical_line_box_fragment.h"
14 #include "core/layout/ng/ng_physical_text_fragment.h" 14 #include "core/layout/ng/ng_physical_text_fragment.h"
15 #include "core/layout/ng/ng_text_fragment.h" 15 #include "core/layout/ng/ng_text_fragment.h"
16 #include "core/layout/ng/ng_text_layout_algorithm.h"
17 #include "core/style/ComputedStyle.h" 16 #include "core/style/ComputedStyle.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace blink { 19 namespace blink {
21 20
22 class NGInlineNodeForTest : public NGInlineNode { 21 class NGInlineNodeForTest : public NGInlineNode {
23 public: 22 public:
24 using NGInlineNode::NGInlineNode; 23 using NGInlineNode::NGInlineNode;
25 24
26 LayoutObject* GetLayoutObject() override { return nullptr; } 25 LayoutObject* GetLayoutObject() override { return nullptr; }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if (!layout_block_flow_) 85 if (!layout_block_flow_)
87 SetupHtml("t", "<div id=t style='font:10px'>test</div>"); 86 SetupHtml("t", "<div id=t style='font:10px'>test</div>");
88 return new NGInlineNodeForTest(layout_object_, layout_block_flow_); 87 return new NGInlineNodeForTest(layout_object_, layout_block_flow_);
89 } 88 }
90 89
91 void CreateLine(NGInlineNode* node, 90 void CreateLine(NGInlineNode* node,
92 Vector<RefPtr<const NGPhysicalTextFragment>>* fragments_out) { 91 Vector<RefPtr<const NGPhysicalTextFragment>>* fragments_out) {
93 RefPtr<NGConstraintSpace> constraint_space = 92 RefPtr<NGConstraintSpace> constraint_space =
94 NGConstraintSpaceBuilder(kHorizontalTopBottom) 93 NGConstraintSpaceBuilder(kHorizontalTopBottom)
95 .ToConstraintSpace(kHorizontalTopBottom); 94 .ToConstraintSpace(kHorizontalTopBottom);
96 NGLineBuilder line_builder(node, constraint_space.get()); 95 RefPtr<NGLayoutResult> result =
96 NGInlineLayoutAlgorithm(node, constraint_space.get()).Layout();
97 97
98 NGTextLayoutAlgorithm algorithm(node);
99 algorithm.LayoutInline(&line_builder);
100
101 RefPtr<NGLayoutResult> result = line_builder.CreateFragments();
102 const NGPhysicalBoxFragment* container = 98 const NGPhysicalBoxFragment* container =
103 toNGPhysicalBoxFragment(result->PhysicalFragment().get()); 99 toNGPhysicalBoxFragment(result->PhysicalFragment().get());
104 EXPECT_EQ(container->Children().size(), 1u); 100 EXPECT_EQ(container->Children().size(), 1u);
105 const NGPhysicalLineBoxFragment* line = 101 const NGPhysicalLineBoxFragment* line =
106 toNGPhysicalLineBoxFragment(container->Children()[0].get()); 102 toNGPhysicalLineBoxFragment(container->Children()[0].get());
107 for (const auto& child : line->Children()) { 103 for (const auto& child : line->Children()) {
108 fragments_out->push_back(toNGPhysicalTextFragment(child.get())); 104 fragments_out->push_back(toNGPhysicalTextFragment(child.get()));
109 } 105 }
110 } 106 }
111 107
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 TEST_TEXT_FRAGMENT(fragments[3], node, 2u, 7u, 13u, TextDirection::kRtl); 305 TEST_TEXT_FRAGMENT(fragments[3], node, 2u, 7u, 13u, TextDirection::kRtl);
310 TEST_TEXT_FRAGMENT(fragments[4], node, 8u, 22u, 28u, TextDirection::kLtr); 306 TEST_TEXT_FRAGMENT(fragments[4], node, 8u, 22u, 28u, TextDirection::kLtr);
311 } 307 }
312 308
313 TEST_F(NGInlineNodeTest, MinMaxContentSize) { 309 TEST_F(NGInlineNodeTest, MinMaxContentSize) {
314 UseLayoutObjectAndAhem(); 310 UseLayoutObjectAndAhem();
315 NGInlineNodeForTest* node = CreateInlineNode(); 311 NGInlineNodeForTest* node = CreateInlineNode();
316 node->Append("AB CDE", style_.get(), layout_object_); 312 node->Append("AB CDE", style_.get(), layout_object_);
317 node->ShapeText(); 313 node->ShapeText();
318 MinMaxContentSize sizes = node->ComputeMinMaxContentSize(); 314 MinMaxContentSize sizes = node->ComputeMinMaxContentSize();
319 // TODO(kojii): min_content should be 20, but is 30 until NGLineBuilder 315 // TODO(kojii): min_content should be 20, but is 30 until
320 // implements trailing spaces correctly. 316 // NGInlineLayoutAlgorithm implements trailing spaces correctly.
321 EXPECT_EQ(30, sizes.min_content); 317 EXPECT_EQ(30, sizes.min_content);
322 EXPECT_EQ(60, sizes.max_content); 318 EXPECT_EQ(60, sizes.max_content);
323 } 319 }
324 320
325 TEST_F(NGInlineNodeTest, MinMaxContentSizeElementBoundary) { 321 TEST_F(NGInlineNodeTest, MinMaxContentSizeElementBoundary) {
326 UseLayoutObjectAndAhem(); 322 UseLayoutObjectAndAhem();
327 NGInlineNodeForTest* node = CreateInlineNode(); 323 NGInlineNodeForTest* node = CreateInlineNode();
328 node->Append("A B", style_.get(), layout_object_); 324 node->Append("A B", style_.get(), layout_object_);
329 node->Append("C D", style_.get(), layout_object_); 325 node->Append("C D", style_.get(), layout_object_);
330 node->ShapeText(); 326 node->ShapeText();
331 MinMaxContentSize sizes = node->ComputeMinMaxContentSize(); 327 MinMaxContentSize sizes = node->ComputeMinMaxContentSize();
332 // |min_content| should be the width of "BC" because there is an element 328 // |min_content| should be the width of "BC" because there is an element
333 // boundary between "B" and "C" but no break opportunities. 329 // boundary between "B" and "C" but no break opportunities.
334 // TODO(kojii): min_content should be 20, but is 30 until NGLineBuilder 330 // TODO(kojii): min_content should be 20, but is 30 until
335 // implements trailing spaces correctly. 331 // NGInlineLayoutAlgorithm implements trailing spaces correctly.
336 EXPECT_EQ(30, sizes.min_content); 332 EXPECT_EQ(30, sizes.min_content);
337 EXPECT_EQ(60, sizes.max_content); 333 EXPECT_EQ(60, sizes.max_content);
338 } 334 }
339 335
340 } // namespace blink 336 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698