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

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

Issue 2739683006: Use Opportunity Iterator to position text fragments in NGLineBuilder (Closed)
Patch Set: add font-family 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
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_block_layout_algorithm.h" 5 #include "core/layout/ng/ng_block_layout_algorithm.h"
6 6
7 #include "core/dom/NodeComputedStyle.h" 7 #include "core/dom/NodeComputedStyle.h"
8 #include "core/dom/TagCollection.h" 8 #include "core/dom/TagCollection.h"
9 #include "core/layout/LayoutTestHelper.h" 9 #include "core/layout/LayoutTestHelper.h"
10 #include "core/layout/ng/layout_ng_block_flow.h" 10 #include "core/layout/ng/layout_ng_block_flow.h"
11 #include "core/layout/ng/ng_base_layout_algorithm_test.h"
11 #include "core/layout/ng/ng_block_break_token.h" 12 #include "core/layout/ng/ng_block_break_token.h"
12 #include "core/layout/ng/ng_block_node.h" 13 #include "core/layout/ng/ng_block_node.h"
13 #include "core/layout/ng/ng_constraint_space.h" 14 #include "core/layout/ng/ng_constraint_space.h"
14 #include "core/layout/ng/ng_constraint_space_builder.h" 15 #include "core/layout/ng/ng_constraint_space_builder.h"
15 #include "core/layout/ng/ng_floating_object.h" 16 #include "core/layout/ng/ng_floating_object.h"
16 #include "core/layout/ng/ng_length_utils.h" 17 #include "core/layout/ng/ng_length_utils.h"
17 #include "core/layout/ng/ng_physical_box_fragment.h" 18 #include "core/layout/ng/ng_physical_box_fragment.h"
18 #include "core/layout/ng/ng_physical_fragment.h" 19 #include "core/layout/ng/ng_physical_fragment.h"
19 #include "core/style/ComputedStyle.h" 20 #include "core/style/ComputedStyle.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace blink { 23 namespace blink {
24 namespace { 24 namespace {
25 25
26 using testing::ElementsAre; 26 using testing::ElementsAre;
27 using testing::Pointee; 27 using testing::Pointee;
28 28
29 RefPtr<NGConstraintSpace> ConstructConstraintSpace( 29 RefPtr<NGConstraintSpace> ConstructConstraintSpace(
30 NGWritingMode writing_mode, 30 NGWritingMode writing_mode,
31 TextDirection direction, 31 TextDirection direction,
32 NGLogicalSize size, 32 NGLogicalSize size,
33 bool shrink_to_fit = false, 33 bool shrink_to_fit = false,
34 LayoutUnit fragmentainer_space_available = LayoutUnit()) { 34 LayoutUnit fragmentainer_space_available = LayoutUnit()) {
35 NGFragmentationType block_fragmentation = 35 NGFragmentationType block_fragmentation =
36 fragmentainer_space_available != LayoutUnit() 36 fragmentainer_space_available != LayoutUnit()
37 ? NGFragmentationType::kFragmentColumn 37 ? NGFragmentationType::kFragmentColumn
38 : NGFragmentationType::kFragmentNone; 38 : NGFragmentationType::kFragmentNone;
39 39
40 return NGConstraintSpaceBuilder(writing_mode) 40 return NGConstraintSpaceBuilder(writing_mode)
41 .SetAvailableSize(size) 41 .SetAvailableSize(size)
42 .SetPercentageResolutionSize(size) 42 .SetPercentageResolutionSize(size)
43 .SetInitialContainingBlockSize(size.ConvertToPhysical(writing_mode)) 43 .SetInitialContainingBlockSize(size.ConvertToPhysical(writing_mode))
44 .SetTextDirection(direction) 44 .SetTextDirection(direction)
45 .SetIsShrinkToFit(shrink_to_fit) 45 .SetIsShrinkToFit(shrink_to_fit)
46 .SetFragmentainerSpaceAvailable(fragmentainer_space_available) 46 .SetFragmentainerSpaceAvailable(fragmentainer_space_available)
47 .SetFragmentationType(block_fragmentation) 47 .SetFragmentationType(block_fragmentation)
48 .ToConstraintSpace(writing_mode); 48 .ToConstraintSpace(writing_mode);
49 } 49 }
50 50
51 typedef bool TestParamLayoutNG; 51 class NGBlockLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {
52 class NGBlockLayoutAlgorithmTest
53 : public ::testing::WithParamInterface<TestParamLayoutNG>,
54 public RenderingTest {
55 public:
56 NGBlockLayoutAlgorithmTest() {
57 RuntimeEnabledFeatures::setLayoutNGEnabled(true);
58 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(true);
59 }
60 ~NGBlockLayoutAlgorithmTest() {
61 RuntimeEnabledFeatures::setLayoutNGEnabled(false);
62 RuntimeEnabledFeatures::setLayoutNGInlineEnabled(false);
63 }
64
65 protected: 52 protected:
66 void SetUp() override { 53 void SetUp() override {
54 NGBaseLayoutAlgorithmTest::SetUp();
67 style_ = ComputedStyle::create(); 55 style_ = ComputedStyle::create();
68 RenderingTest::SetUp();
69 enableCompositing();
70 } 56 }
71 57
72 RefPtr<NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( 58 RefPtr<NGPhysicalBoxFragment> RunBlockLayoutAlgorithm(
73 NGConstraintSpace* space, 59 NGConstraintSpace* space,
74 NGBlockNode* node) { 60 NGBlockNode* node) {
75 RefPtr<NGLayoutResult> result = 61 RefPtr<NGLayoutResult> result =
76 NGBlockLayoutAlgorithm(node, space).Layout(); 62 NGBlockLayoutAlgorithm(node, space).Layout();
77 63
78 return toNGPhysicalBoxFragment(result->PhysicalFragment().get()); 64 return toNGPhysicalBoxFragment(result->PhysicalFragment().get());
79 } 65 }
80 66
81 std::pair<RefPtr<NGPhysicalBoxFragment>, RefPtr<NGConstraintSpace>>
82 RunBlockLayoutAlgorithmForElement(Element* element) {
83 LayoutNGBlockFlow* block_flow =
84 toLayoutNGBlockFlow(element->layoutObject());
85 NGBlockNode* node = new NGBlockNode(block_flow);
86 RefPtr<NGConstraintSpace> space =
87 NGConstraintSpace::CreateFromLayoutObject(*block_flow);
88
89 RefPtr<NGLayoutResult> result =
90 NGBlockLayoutAlgorithm(node, space.get()).Layout();
91 return std::make_pair(
92 toNGPhysicalBoxFragment(result->PhysicalFragment().get()), space);
93 }
94
95 MinMaxContentSize RunComputeMinAndMax(NGBlockNode* node) { 67 MinMaxContentSize RunComputeMinAndMax(NGBlockNode* node) {
96 // The constraint space is not used for min/max computation, but we need 68 // The constraint space is not used for min/max computation, but we need
97 // it to create the algorithm. 69 // it to create the algorithm.
98 RefPtr<NGConstraintSpace> space = 70 RefPtr<NGConstraintSpace> space =
99 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, 71 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr,
100 NGLogicalSize(LayoutUnit(), LayoutUnit())); 72 NGLogicalSize(LayoutUnit(), LayoutUnit()));
101 73
102 NGBlockLayoutAlgorithm algorithm(node, space.get()); 74 NGBlockLayoutAlgorithm algorithm(node, space.get());
103 EXPECT_TRUE(algorithm.ComputeMinMaxContentSize().has_value()); 75 EXPECT_TRUE(algorithm.ComputeMinMaxContentSize().has_value());
104 return *algorithm.ComputeMinMaxContentSize(); 76 return *algorithm.ComputeMinMaxContentSize();
(...skipping 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 2333
2362 child = iterator.NextChild(); 2334 child = iterator.NextChild();
2363 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size()); 2335 EXPECT_EQ(NGPhysicalSize(LayoutUnit(150), LayoutUnit(100)), child->Size());
2364 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset()); 2336 EXPECT_EQ(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(40)), child->Offset());
2365 2337
2366 EXPECT_FALSE(iterator.NextChild()); 2338 EXPECT_FALSE(iterator.NextChild());
2367 } 2339 }
2368 2340
2369 } // namespace 2341 } // namespace
2370 } // namespace blink 2342 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698