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 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1997 fragment = iterator.NextChild(); | 1997 fragment = iterator.NextChild(); |
1998 ASSERT_TRUE(fragment); | 1998 ASSERT_TRUE(fragment); |
1999 EXPECT_EQ(LayoutUnit(194), fragment->LeftOffset()); | 1999 EXPECT_EQ(LayoutUnit(194), fragment->LeftOffset()); |
2000 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); | 2000 EXPECT_EQ(LayoutUnit(), fragment->TopOffset()); |
2001 EXPECT_EQ(LayoutUnit(16), fragment->Width()); | 2001 EXPECT_EQ(LayoutUnit(16), fragment->Width()); |
2002 EXPECT_EQ(LayoutUnit(50), fragment->Height()); | 2002 EXPECT_EQ(LayoutUnit(50), fragment->Height()); |
2003 EXPECT_EQ(0UL, fragment->Children().size()); | 2003 EXPECT_EQ(0UL, fragment->Children().size()); |
2004 EXPECT_FALSE(iterator.NextChild()); | 2004 EXPECT_FALSE(iterator.NextChild()); |
2005 } | 2005 } |
2006 | 2006 |
| 2007 // Verifies that we position empty blocks and floats correctly inside of the |
| 2008 // block that establishes new BFC. |
| 2009 TEST_F(NGBlockLayoutAlgorithmTest, PositionEmptyBlocksInNewBfc) { |
| 2010 setBodyInnerHTML(R"HTML( |
| 2011 <style> |
| 2012 #container { |
| 2013 overflow: hidden; |
| 2014 } |
| 2015 #empty-block1 { |
| 2016 margin: 8px; |
| 2017 } |
| 2018 #left-float { |
| 2019 float: left; |
| 2020 background: red; |
| 2021 height: 20px; |
| 2022 width: 10px; |
| 2023 margin: 15px; |
| 2024 } |
| 2025 #empty-block2 { |
| 2026 margin-top: 50px; |
| 2027 } |
| 2028 </style> |
| 2029 <div id="container"> |
| 2030 <div id="left-float"></div> |
| 2031 <div id="empty-block1"></div> |
| 2032 <div id="empty-block2"></div> |
| 2033 </div> |
| 2034 )HTML"); |
| 2035 Element* body = document().getElementsByTagName("body")->item(0); |
| 2036 auto& floating_objects = |
| 2037 const_cast<FloatingObjects*>( |
| 2038 toLayoutBlockFlow(body->layoutObject())->floatingObjects()) |
| 2039 ->mutableSet(); |
| 2040 ASSERT_EQ(1UL, floating_objects.size()); |
| 2041 auto floating_object = floating_objects.takeFirst(); |
| 2042 // left-float's margin = 15. |
| 2043 EXPECT_THAT(LayoutUnit(15), floating_object->x()); |
| 2044 EXPECT_THAT(LayoutUnit(15), floating_object->y()); |
| 2045 |
| 2046 RefPtr<const NGPhysicalBoxFragment> html_fragment; |
| 2047 std::tie(html_fragment, std::ignore) = RunBlockLayoutAlgorithmForElement( |
| 2048 document().getElementsByTagName("html")->item(0)); |
| 2049 auto* body_fragment = |
| 2050 toNGPhysicalBoxFragment(html_fragment->Children()[0].get()); |
| 2051 auto* container_fragment = |
| 2052 toNGPhysicalBoxFragment(body_fragment->Children()[0].get()); |
| 2053 auto* empty_block1 = |
| 2054 toNGPhysicalBoxFragment(container_fragment->Children()[0].get()); |
| 2055 // empty-block1's margin == 8 |
| 2056 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(8), LayoutUnit(8)), |
| 2057 empty_block1->Offset()); |
| 2058 |
| 2059 auto* empty_block2 = |
| 2060 toNGPhysicalBoxFragment(container_fragment->Children()[1].get()); |
| 2061 // empty-block2's margin == 50 |
| 2062 EXPECT_THAT(NGPhysicalOffset(LayoutUnit(0), LayoutUnit(50)), |
| 2063 empty_block2->Offset()); |
| 2064 } |
| 2065 |
2007 } // namespace | 2066 } // namespace |
2008 } // namespace blink | 2067 } // namespace blink |
OLD | NEW |