| OLD | NEW |
| 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/ng/layout_ng_block_flow.h" | 9 #include "core/layout/ng/layout_ng_block_flow.h" |
| 10 #include "core/layout/ng/ng_block_node.h" | 10 #include "core/layout/ng/ng_block_node.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 protected: | 53 protected: |
| 54 void SetUp() override { | 54 void SetUp() override { |
| 55 style_ = ComputedStyle::create(); | 55 style_ = ComputedStyle::create(); |
| 56 RenderingTest::SetUp(); | 56 RenderingTest::SetUp(); |
| 57 enableCompositing(); | 57 enableCompositing(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 RefPtr<NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( | 60 RefPtr<NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( |
| 61 NGConstraintSpace* space, | 61 NGConstraintSpace* space, |
| 62 NGBlockNode* first_child) { | 62 NGBlockNode* first_child) { |
| 63 NGBlockNode parent(style_.get()); | 63 NGBlockNode* node = new NGBlockNode(style_.get()); |
| 64 parent.SetFirstChild(first_child); | 64 node->SetFirstChild(first_child); |
| 65 | 65 |
| 66 RefPtr<NGPhysicalFragment> fragment = | 66 RefPtr<NGPhysicalFragment> fragment = |
| 67 NGBlockLayoutAlgorithm(/* layout_object */ nullptr, style_.get(), | 67 NGBlockLayoutAlgorithm(node, space).Layout(); |
| 68 first_child, space) | |
| 69 .Layout(); | |
| 70 | 68 |
| 71 return toNGPhysicalBoxFragment(fragment.get()); | 69 return toNGPhysicalBoxFragment(fragment.get()); |
| 72 } | 70 } |
| 73 | 71 |
| 74 std::pair<RefPtr<NGPhysicalBoxFragment>, NGConstraintSpace*> | 72 std::pair<RefPtr<NGPhysicalBoxFragment>, NGConstraintSpace*> |
| 75 RunBlockLayoutAlgorithmForElement(Element* element) { | 73 RunBlockLayoutAlgorithmForElement(Element* element) { |
| 76 LayoutNGBlockFlow* block_flow = | 74 LayoutNGBlockFlow* block_flow = |
| 77 toLayoutNGBlockFlow(element->layoutObject()); | 75 toLayoutNGBlockFlow(element->layoutObject()); |
| 76 NGBlockNode* node = new NGBlockNode(block_flow); |
| 78 NGConstraintSpace* space = | 77 NGConstraintSpace* space = |
| 79 NGConstraintSpace::CreateFromLayoutObject(*block_flow); | 78 NGConstraintSpace::CreateFromLayoutObject(*block_flow); |
| 80 RefPtr<NGPhysicalBoxFragment> fragment = RunBlockLayoutAlgorithm( | 79 |
| 81 space, new NGBlockNode(element->layoutObject()->slowFirstChild())); | 80 RefPtr<NGPhysicalFragment> fragment = |
| 82 return std::make_pair(std::move(fragment), space); | 81 NGBlockLayoutAlgorithm(node, space).Layout(); |
| 82 return std::make_pair(toNGPhysicalBoxFragment(fragment.get()), space); |
| 83 } | 83 } |
| 84 | 84 |
| 85 MinAndMaxContentSizes RunComputeMinAndMax(NGBlockNode* first_child) { | 85 MinAndMaxContentSizes RunComputeMinAndMax(NGBlockNode* first_child) { |
| 86 // The constraint space is not used for min/max computation, but we need | 86 // The constraint space is not used for min/max computation, but we need |
| 87 // it to create the algorithm. | 87 // it to create the algorithm. |
| 88 NGConstraintSpace* space = | 88 NGConstraintSpace* space = |
| 89 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, | 89 ConstructConstraintSpace(kHorizontalTopBottom, TextDirection::kLtr, |
| 90 NGLogicalSize(LayoutUnit(), LayoutUnit())); | 90 NGLogicalSize(LayoutUnit(), LayoutUnit())); |
| 91 NGBlockLayoutAlgorithm algorithm(/* layout_object */ nullptr, style_.get(), | 91 NGBlockNode* node = new NGBlockNode(style_.get()); |
| 92 first_child, space); | 92 node->SetFirstChild(first_child); |
| 93 |
| 94 NGBlockLayoutAlgorithm algorithm(node, space); |
| 93 EXPECT_TRUE(algorithm.ComputeMinAndMaxContentSizes().has_value()); | 95 EXPECT_TRUE(algorithm.ComputeMinAndMaxContentSizes().has_value()); |
| 94 return *algorithm.ComputeMinAndMaxContentSizes(); | 96 return *algorithm.ComputeMinAndMaxContentSizes(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 RefPtr<ComputedStyle> style_; | 99 RefPtr<ComputedStyle> style_; |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { | 102 TEST_F(NGBlockLayoutAlgorithmTest, FixedSize) { |
| 101 style_->setWidth(Length(30, Fixed)); | 103 style_->setWidth(Length(30, Fixed)); |
| 102 style_->setHeight(Length(40, Fixed)); | 104 style_->setHeight(Length(40, Fixed)); |
| (...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2000 EXPECT_EQ(LayoutUnit(194), fragment->LeftOffset()); | 2002 EXPECT_EQ(LayoutUnit(194), fragment->LeftOffset()); |
| 2001 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 2003 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
| 2002 EXPECT_EQ(LayoutUnit(16), fragment->Width()); | 2004 EXPECT_EQ(LayoutUnit(16), fragment->Width()); |
| 2003 EXPECT_EQ(LayoutUnit(50), fragment->Height()); | 2005 EXPECT_EQ(LayoutUnit(50), fragment->Height()); |
| 2004 EXPECT_EQ(0UL, fragment->Children().size()); | 2006 EXPECT_EQ(0UL, fragment->Children().size()); |
| 2005 EXPECT_FALSE(iterator.NextChild()); | 2007 EXPECT_FALSE(iterator.NextChild()); |
| 2006 } | 2008 } |
| 2007 | 2009 |
| 2008 } // namespace | 2010 } // namespace |
| 2009 } // namespace blink | 2011 } // namespace blink |
| OLD | NEW |